Class AsyncExecution
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:
-
Constructor Summary
ConstructorDescriptionAsyncExecution
(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
Modifier and TypeMethodDescriptionThe future of this functions returns the original ResultDoes 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.searchAndFill
(Query query) waitForAll
(Collection<FutureResult> tasks, long timeoutMs)
-
Constructor Details
-
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
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:
-
-
Method Details
-
search
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:
-
searchAndFill
-
fill
The future of this functions returns the original Result- See Also:
-
waitForAll
-