use of org.apache.ratis.util.TaskQueue in project ozone by apache.
the class ContainerStateMachine method submitTask.
private CompletableFuture<ContainerCommandResponseProto> submitTask(ContainerCommandRequestProto request, DispatcherContext.Builder context, Consumer<Exception> exceptionHandler) {
final long containerId = request.getContainerID();
final TaskQueue queue = containerTaskQueues.computeIfAbsent(containerId, id -> new TaskQueue("container" + id));
final CheckedSupplier<ContainerCommandResponseProto, Exception> task = () -> {
try {
return runCommand(request, context.build());
} catch (Exception e) {
exceptionHandler.accept(e);
throw e;
}
};
final CompletableFuture<ContainerCommandResponseProto> f = queue.submit(task, executor);
// after the task is completed, remove the queue if the queue is empty.
f.thenAccept(dummy -> containerTaskQueues.computeIfPresent(containerId, (id, q) -> q.isEmpty() ? null : q));
return f;
}
Aggregations