Search in sources :

Example 1 with COMPUTE_TASK_FINISHED

use of org.apache.ignite.internal.client.thin.ClientNotificationType.COMPUTE_TASK_FINISHED 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;
    });
}
Also used : ClientClusterGroup(org.apache.ignite.client.ClientClusterGroup) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) ClientFeatureNotSupportedByServerException(org.apache.ignite.client.ClientFeatureNotSupportedByServerException) U(org.apache.ignite.internal.util.typedef.internal.U) CompletableFuture(java.util.concurrent.CompletableFuture) RESOURCE_CLOSE(org.apache.ignite.internal.client.thin.ClientOperation.RESOURCE_CLOSE) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ByteBuffer(java.nio.ByteBuffer) Future(java.util.concurrent.Future) ClientException(org.apache.ignite.client.ClientException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClientConnectionException(org.apache.ignite.client.ClientConnectionException) COMPUTE_TASK_FINISHED(org.apache.ignite.internal.client.thin.ClientNotificationType.COMPUTE_TASK_FINISHED) ClientStatus(org.apache.ignite.internal.processors.platform.client.ClientStatus) BinaryRawWriterEx(org.apache.ignite.internal.binary.BinaryRawWriterEx) F(org.apache.ignite.internal.util.typedef.F) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteClientFuture(org.apache.ignite.client.IgniteClientFuture) UUID(java.util.UUID) COMPUTE_TASK_EXECUTE(org.apache.ignite.internal.client.thin.ClientOperation.COMPUTE_TASK_EXECUTE) ExecutionException(java.util.concurrent.ExecutionException) Consumer(java.util.function.Consumer) Nullable(org.jetbrains.annotations.Nullable) BinaryByteBufferInputStream(org.apache.ignite.internal.binary.streams.BinaryByteBufferInputStream) ClientCompute(org.apache.ignite.client.ClientCompute) AtomicReference(java.util.concurrent.atomic.AtomicReference) CompletableFuture(java.util.concurrent.CompletableFuture) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) ClientException(org.apache.ignite.client.ClientException) UUID(java.util.UUID)

Aggregations

ByteBuffer (java.nio.ByteBuffer)1 Collection (java.util.Collection)1 UUID (java.util.UUID)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1 Future (java.util.concurrent.Future)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Consumer (java.util.function.Consumer)1 Function (java.util.function.Function)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 ClientClusterGroup (org.apache.ignite.client.ClientClusterGroup)1 ClientCompute (org.apache.ignite.client.ClientCompute)1 ClientConnectionException (org.apache.ignite.client.ClientConnectionException)1 ClientException (org.apache.ignite.client.ClientException)1 ClientFeatureNotSupportedByServerException (org.apache.ignite.client.ClientFeatureNotSupportedByServerException)1 IgniteClientFuture (org.apache.ignite.client.IgniteClientFuture)1 BinaryRawWriterEx (org.apache.ignite.internal.binary.BinaryRawWriterEx)1 BinaryByteBufferInputStream (org.apache.ignite.internal.binary.streams.BinaryByteBufferInputStream)1 COMPUTE_TASK_FINISHED (org.apache.ignite.internal.client.thin.ClientNotificationType.COMPUTE_TASK_FINISHED)1