Search in sources :

Example 1 with ExecutionCallbackAdapter

use of com.hazelcast.executor.impl.ExecutionCallbackAdapter in project hazelcast by hazelcast.

the class ClientExecutorServiceProxy method submitToRandomWithCallbackInternal.

private <T> void submitToRandomWithCallbackInternal(Data task, ExecutionCallback<T> callback) {
    checkNotNull(task, "task should not be null");
    UUID uuid = getUUID();
    int partitionId = randomPartitionId();
    ClientMessage request = ExecutorServiceSubmitToPartitionCodec.encodeRequest(name, uuid, task);
    ClientInvocationFuture f = invokeOnPartitionOwner(request, partitionId);
    InternalCompletableFuture<T> delegatingFuture = (InternalCompletableFuture<T>) delegatingFuture(f, uuid, partitionId, (T) null);
    if (callback != null) {
        delegatingFuture.whenCompleteAsync(new ExecutionCallbackAdapter<>(callback)).whenCompleteAsync((v, t) -> {
            if (t instanceof RejectedExecutionException) {
                callback.onFailure(t);
            }
        }, ConcurrencyUtil.getDefaultAsyncExecutor());
    }
}
Also used : ExecutionCallbackAdapter(com.hazelcast.executor.impl.ExecutionCallbackAdapter) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) UUID(java.util.UUID) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Example 2 with ExecutionCallbackAdapter

use of com.hazelcast.executor.impl.ExecutionCallbackAdapter in project hazelcast by hazelcast.

the class ClientExecutorServiceProxy method submitToTargetInternal.

private <T> void submitToTargetInternal(@Nonnull Data task, Member member, @Nullable ExecutionCallback<T> callback) {
    checkNotNull(task, "task should not be null");
    UUID uuid = getUUID();
    ClientMessage request = ExecutorServiceSubmitToMemberCodec.encodeRequest(name, uuid, task, member.getUuid());
    ClientInvocationFuture f = invokeOnTarget(request, member);
    InternalCompletableFuture<T> delegatingFuture = (InternalCompletableFuture<T>) delegatingFuture(f, uuid, member, (T) null);
    if (callback != null) {
        delegatingFuture.whenCompleteAsync(new ExecutionCallbackAdapter<>(callback)).whenCompleteAsync((v, t) -> {
            if (t instanceof RejectedExecutionException) {
                callback.onFailure(t);
            }
        }, ConcurrencyUtil.getDefaultAsyncExecutor());
    }
}
Also used : ExecutionCallbackAdapter(com.hazelcast.executor.impl.ExecutionCallbackAdapter) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) UUID(java.util.UUID) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Example 3 with ExecutionCallbackAdapter

use of com.hazelcast.executor.impl.ExecutionCallbackAdapter in project hazelcast by hazelcast.

the class ClientExecutorServiceProxy method submitToKeyOwnerInternal.

private <T> Future<T> submitToKeyOwnerInternal(@Nonnull Data task, @Nonnull Object key, @Nullable ExecutionCallback<T> callback) {
    checkNotNull(task, "task should not be null");
    checkNotNull(key, "key should not be null");
    UUID uuid = getUUID();
    int partitionId = getPartitionId(key);
    ClientMessage request = ExecutorServiceSubmitToPartitionCodec.encodeRequest(name, uuid, task);
    ClientInvocationFuture f = invokeOnPartitionOwner(request, partitionId);
    InternalCompletableFuture<T> delegatingFuture = (InternalCompletableFuture<T>) delegatingFuture(f, uuid, partitionId, (T) null);
    if (callback != null) {
        delegatingFuture.whenCompleteAsync(new ExecutionCallbackAdapter<>(callback)).whenCompleteAsync((v, t) -> {
            if (t instanceof RejectedExecutionException) {
                callback.onFailure(t);
            }
        }, ConcurrencyUtil.getDefaultAsyncExecutor());
    }
    return delegatingFuture;
}
Also used : ExecutionCallbackAdapter(com.hazelcast.executor.impl.ExecutionCallbackAdapter) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) UUID(java.util.UUID) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Aggregations

ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)3 ClientInvocationFuture (com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)3 ExecutionCallbackAdapter (com.hazelcast.executor.impl.ExecutionCallbackAdapter)3 InternalCompletableFuture (com.hazelcast.spi.impl.InternalCompletableFuture)3 UUID (java.util.UUID)3 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)3