Class 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 way
     Execution 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 Detail

      • AsyncExecution

        public AsyncExecution​(com.yahoo.component.chain.Chain<? extends Searcher> chain,
                              Execution execution)
        Creates an async execution.
        Parameters:
        chain - the chain to execute
        execution - 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 execute
        context - 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
      • 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)