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;
}
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;
}
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;
}
Aggregations