Search in sources :

Example 1 with FutureResponse

use of com.yahoo.processing.response.FutureResponse in project vespa by vespa-engine.

the class AsyncExecution method getFutureResponse.

private FutureResponse getFutureResponse(final Callable<Response> callable, final Request request) {
    final FutureResponse future = new FutureResponse(callable, execution, request);
    executorMain.execute(future.delegate());
    return future;
}
Also used : FutureResponse(com.yahoo.processing.response.FutureResponse)

Example 2 with FutureResponse

use of com.yahoo.processing.response.FutureResponse in project vespa by vespa-engine.

the class AsyncExecution method waitForAll.

/*
     * Waits for all futures until the given timeout. If a FutureResult isn't
     * done when the timeout expires, it will be cancelled, and it will return a
     * response. All unfinished Futures will be cancelled.
     *
     * @return the list of responses in the same order as returned from the task collection
     */
// Note that this may also be achieved using guava Futures. Not sure if this should be deprecated because of it.
public static List<Response> waitForAll(final Collection<FutureResponse> tasks, final long timeout) {
    // Copy the list in case it is modified while we are waiting
    final List<FutureResponse> workingTasks = new ArrayList<>(tasks);
    @SuppressWarnings({ "rawtypes", "unchecked" }) final Future task = getFuture(new Callable() {

        @Override
        public List<Future> call() {
            for (final FutureResponse task : workingTasks) {
                task.get();
            }
            return null;
        }
    });
    try {
        task.get(timeout, TimeUnit.MILLISECONDS);
    } catch (final TimeoutException | InterruptedException | ExecutionException e) {
    // Handle timeouts below
    }
    final List<Response> responses = new ArrayList<>(tasks.size());
    for (final FutureResponse future : workingTasks) responses.add(getTaskResponse(future));
    return responses;
}
Also used : ArrayList(java.util.ArrayList) FutureResponse(com.yahoo.processing.response.FutureResponse) Response(com.yahoo.processing.Response) FutureResponse(com.yahoo.processing.response.FutureResponse) List(java.util.List) ArrayList(java.util.ArrayList)

Example 3 with FutureResponse

use of com.yahoo.processing.response.FutureResponse in project vespa by vespa-engine.

the class Federator method process.

@SuppressWarnings("unchecked")
@Override
public Response process(Request request, Execution execution) {
    List<FutureResponse> futureResponses = new ArrayList<>(chains.size());
    for (Chain<? extends Processor> chain : chains) {
        futureResponses.add(new AsyncExecution(chain, execution).process(request));
    }
    Response response = execution.process(request);
    AsyncExecution.waitForAll(futureResponses, 1000);
    for (FutureResponse futureResponse : futureResponses) {
        Response federatedResponse = futureResponse.get();
        response.data().add(federatedResponse.data());
        response.mergeWith(federatedResponse);
    }
    return response;
}
Also used : FutureResponse(com.yahoo.processing.response.FutureResponse) Response(com.yahoo.processing.Response) FutureResponse(com.yahoo.processing.response.FutureResponse) AsyncExecution(com.yahoo.processing.execution.AsyncExecution) ArrayList(java.util.ArrayList)

Aggregations

FutureResponse (com.yahoo.processing.response.FutureResponse)3 Response (com.yahoo.processing.Response)2 ArrayList (java.util.ArrayList)2 AsyncExecution (com.yahoo.processing.execution.AsyncExecution)1 List (java.util.List)1