public class AsyncExecution extends Object
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.
Execution
Modifier and Type | Field and Description |
---|---|
private Execution |
execution
The execution this executes
|
private static Executor |
executorMain |
private static ThreadFactory |
threadFactory |
Modifier | Constructor and Description |
---|---|
|
AsyncExecution(com.yahoo.component.chain.Chain<? extends Searcher> chain,
Execution.Context context)
Creates an async execution.
|
|
AsyncExecution(com.yahoo.component.chain.Chain<? extends Searcher> chain,
Execution execution)
Creates an async execution.
|
private |
AsyncExecution(Execution.Context context,
com.yahoo.component.chain.Chain<? extends Searcher> chain) |
|
AsyncExecution(Execution execution)
Creates an async execution from an existing execution.
|
Modifier and Type | Method and Description |
---|---|
private static Executor |
createExecutor() |
FutureResult |
fill(Result result,
String summaryClass)
The future of this functions returns the original Result
|
private static Executor |
getExecutor() |
private static <T> Future<T> |
getFuture(Callable<T> callable) |
private FutureResult |
getFutureResult(Callable<Result> callable,
Query query) |
private static Future<Void> |
runTask(Runnable runnable) |
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.
|
FutureResult |
searchAndFill(Query query) |
static List<Result> |
waitForAll(Collection<FutureResult> tasks,
long timeoutMs) |
private static final ThreadFactory threadFactory
private static final Executor executorMain
private final Execution execution
public AsyncExecution(com.yahoo.component.chain.Chain<? extends Searcher> chain, Execution execution)
chain
- the chain to executeexecution
- the execution holding the context of thispublic AsyncExecution(com.yahoo.component.chain.Chain<? extends Searcher> chain, Execution.Context context)
chain
- the chain to executecontext
- the the context of thispublic 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.
execution
- the execution from which the state of this is createdExecution.Execution(Chain, com.yahoo.search.searchchain.Execution.Context)
,
AsyncExecution(Chain, Execution)
private AsyncExecution(Execution.Context context, com.yahoo.component.chain.Chain<? extends Searcher> chain)
private static Executor createExecutor()
public FutureResult search(Query query)
Execution
public FutureResult searchAndFill(Query query)
private static Executor getExecutor()
public FutureResult fill(Result result, String summaryClass)
Execution
private FutureResult getFutureResult(Callable<Result> callable, Query query)
public static List<Result> waitForAll(Collection<FutureResult> tasks, long timeoutMs)
Copyright © 2018. All rights reserved.