Class AsyncExecution
- java.lang.Object
-
- com.yahoo.search.searchchain.AsyncExecution
-
public class AsyncExecution extends java.lang.Object
Provides asynchronous execution of searchchains.AsyncExecution is implemented as an asynchronous wrapper around Execution that returns Future.
This is used in the following wayExecution execution = new Execution(searchChain, context); AsyncExecution asyncExecution = new AsyncExecution(execution); Future<Result> future = asyncExecution.search(query) try { result = future.get(timeout, TimeUnit.milliseconds); } catch(TimeoutException e) { // Handle timeout }
Note that the query is not a thread safe object and cannot be shared between multiple concurrent executions - a clone() must be made, or a new query created for each AsyncExecution instance.
- Author:
- Arne Bergene Fossaa
- See Also:
Execution
-
-
Constructor Summary
Constructors Constructor Description AsyncExecution(com.yahoo.component.chain.Chain<? extends Searcher> chain, Execution execution)
Creates an async execution.AsyncExecution(com.yahoo.component.chain.Chain<? extends Searcher> chain, Execution.Context context)
Creates an async execution.AsyncExecution(Execution execution)
Creates an async execution from an existing execution.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description FutureResult
fill(Result result, java.lang.String summaryClass)
The future of this functions returns the original ResultFutureResult
search(Query query)
Does an async search, note that the query argument cannot simultaneously be used to execute any other searches, a clone() must be made of the query for each async execution if the same query is to be used in more than one.FutureResult
searchAndFill(Query query)
static java.util.List<Result>
waitForAll(java.util.Collection<FutureResult> tasks, long timeoutMs)
-
-
-
Constructor Detail
-
AsyncExecution
public AsyncExecution(com.yahoo.component.chain.Chain<? extends Searcher> chain, Execution execution)
Creates an async execution.- Parameters:
chain
- the chain to executeexecution
- the execution holding the context of this
-
AsyncExecution
public AsyncExecution(com.yahoo.component.chain.Chain<? extends Searcher> chain, Execution.Context context)
Creates an async execution.- Parameters:
chain
- the chain to executecontext
- the the context of this
-
AsyncExecution
public AsyncExecution(Execution execution)
Creates an async execution from an existing execution. This async execution will execute the chain from the given execution, starting from the next searcher in that chain. This is handy to execute multiple queries to the rest of the chain in parallel. If the Execution is freshly instantiated, the search will obviously start from the first searcher.
The state of the given execution is read on construction of this and not used later - the argument execution can be reused for other purposes.
- Parameters:
execution
- the execution from which the state of this is created- See Also:
Execution(Chain, com.yahoo.search.searchchain.Execution.Context)
,AsyncExecution(Chain, Execution)
-
-
Method Detail
-
search
public FutureResult search(Query query)
Does an async search, note that the query argument cannot simultaneously be used to execute any other searches, a clone() must be made of the query for each async execution if the same query is to be used in more than one.- See Also:
Execution
-
searchAndFill
public FutureResult searchAndFill(Query query)
-
fill
public FutureResult fill(Result result, java.lang.String summaryClass)
The future of this functions returns the original Result- See Also:
Execution
-
waitForAll
public static java.util.List<Result> waitForAll(java.util.Collection<FutureResult> tasks, long timeoutMs)
-
-