use of org.apache.ignite.internal.client.thin.ClientOperation.COMPUTE_TASK_EXECUTE in project ignite by apache.
the class ClientComputeImpl method executeAsync0.
/**
* @param taskName Task name.
* @param arg Argument.
* @param clusterGrp Cluster group.
* @param flags Flags.
* @param timeout Timeout.
*/
private <T, R> IgniteClientFuture<R> executeAsync0(String taskName, @Nullable T arg, ClientClusterGroupImpl clusterGrp, byte flags, long timeout) throws ClientException {
Collection<UUID> nodeIds = clusterGrp.nodeIds();
if (F.isEmpty(taskName))
throw new ClientException("Task name can't be null or empty.");
if (nodeIds != null && nodeIds.isEmpty())
throw new ClientException("Cluster group is empty.");
Consumer<PayloadOutputChannel> payloadWriter = ch -> writeExecuteTaskRequest(ch, taskName, arg, nodeIds, flags, timeout);
Function<PayloadInputChannel, ClientComputeTask<R>> payloadReader = ch -> {
Long taskId = ch.in().readLong();
ClientComputeTask<R> task = new ClientComputeTask<>(utils, ch.clientChannel(), taskId);
ch.clientChannel().addNotificationListener(COMPUTE_TASK_FINISHED, taskId, task);
return task;
};
IgniteClientFuture<ClientComputeTask<R>> initFut = ch.serviceAsync(COMPUTE_TASK_EXECUTE, payloadWriter, payloadReader);
CompletableFuture<R> resFut = new CompletableFuture<>();
AtomicReference<Object> cancellationToken = new AtomicReference<>();
initFut.handle((task, err) -> handleExecuteInitFuture(resFut, cancellationToken, task, err));
return new IgniteClientFutureImpl<>(resFut, mayInterruptIfRunning -> {
// 2. initFut has completed - cancel compute future.
if (!cancellationToken.compareAndSet(null, mayInterruptIfRunning)) {
GridFutureAdapter<?> fut = (GridFutureAdapter<?>) cancellationToken.get();
if (!cancelGridFuture(fut, mayInterruptIfRunning))
return false;
}
resFut.cancel(mayInterruptIfRunning);
return true;
});
}
Aggregations