Search in sources :

Example 56 with ClientInvocationFuture

use of com.hazelcast.client.impl.spi.impl.ClientInvocationFuture 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)

Example 57 with ClientInvocationFuture

use of com.hazelcast.client.impl.spi.impl.ClientInvocationFuture in project hazelcast by hazelcast.

the class ClientDurableExecutorServiceProxy method retrieveResult.

@Override
public <T> Future<T> retrieveResult(long taskId) {
    int partitionId = Bits.extractInt(taskId, false);
    int sequence = Bits.extractInt(taskId, true);
    ClientMessage clientMessage = DurableExecutorRetrieveResultCodec.encodeRequest(name, sequence);
    ClientInvocationFuture future = new ClientInvocation(getClient(), clientMessage, getName(), partitionId).invoke();
    return new ClientDelegatingFuture<>(future, getSerializationService(), DurableExecutorRetrieveResultCodec::decodeResponse);
}
Also used : ClientDelegatingFuture(com.hazelcast.client.impl.ClientDelegatingFuture) DurableExecutorRetrieveResultCodec(com.hazelcast.client.impl.protocol.codec.DurableExecutorRetrieveResultCodec) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Example 58 with ClientInvocationFuture

use of com.hazelcast.client.impl.spi.impl.ClientInvocationFuture in project hazelcast by hazelcast.

the class ClientMapProxy method setAsyncInternal.

protected InternalCompletableFuture<Void> setAsyncInternal(long ttl, TimeUnit timeunit, Long maxIdle, TimeUnit maxIdleUnit, Object key, Object value) {
    try {
        Data keyData = toData(key);
        Data valueData = toData(value);
        long ttlMillis = timeInMsOrOneIfResultIsZero(ttl, timeunit);
        ClientMessage request;
        if (maxIdle != null) {
            request = MapSetWithMaxIdleCodec.encodeRequest(name, keyData, valueData, getThreadId(), ttlMillis, timeInMsOrOneIfResultIsZero(maxIdle, maxIdleUnit));
        } else {
            request = MapSetCodec.encodeRequest(name, keyData, valueData, getThreadId(), ttlMillis);
        }
        ClientInvocationFuture future = invokeOnKeyOwner(request, keyData);
        return new ClientDelegatingFuture<>(future, getSerializationService(), clientMessage -> null);
    } catch (Exception e) {
        throw rethrow(e);
    }
}
Also used : ClientDelegatingFuture(com.hazelcast.client.impl.ClientDelegatingFuture) Data(com.hazelcast.internal.serialization.Data) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Example 59 with ClientInvocationFuture

use of com.hazelcast.client.impl.spi.impl.ClientInvocationFuture in project hazelcast by hazelcast.

the class ClientMapProxy method putAsyncInternal.

protected InternalCompletableFuture<V> putAsyncInternal(long ttl, TimeUnit timeunit, Long maxIdle, TimeUnit maxIdleUnit, Object key, Object value) {
    try {
        Data keyData = toData(key);
        Data valueData = toData(value);
        long ttlMillis = timeInMsOrOneIfResultIsZero(ttl, timeunit);
        ClientMessage request;
        if (maxIdle != null) {
            request = MapPutWithMaxIdleCodec.encodeRequest(name, keyData, valueData, getThreadId(), ttlMillis, timeInMsOrOneIfResultIsZero(maxIdle, maxIdleUnit));
        } else {
            request = MapPutCodec.encodeRequest(name, keyData, valueData, getThreadId(), ttlMillis);
        }
        ClientInvocationFuture future = invokeOnKeyOwner(request, keyData);
        SerializationService ss = getSerializationService();
        return new ClientDelegatingFuture<>(future, ss, MapPutCodec::decodeResponse);
    } catch (Exception e) {
        throw rethrow(e);
    }
}
Also used : ClientDelegatingFuture(com.hazelcast.client.impl.ClientDelegatingFuture) MapPutCodec(com.hazelcast.client.impl.protocol.codec.MapPutCodec) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Example 60 with ClientInvocationFuture

use of com.hazelcast.client.impl.spi.impl.ClientInvocationFuture in project hazelcast by hazelcast.

the class IExecutorDelegatingFuture method waitForRequestToBeSend.

private void waitForRequestToBeSend() throws InterruptedException {
    ClientInvocationFuture future = getFuture();
    future.getInvocation().waitInvoked();
}
Also used : ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Aggregations

ClientInvocationFuture (com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)65 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)54 ClientInvocation (com.hazelcast.client.impl.spi.impl.ClientInvocation)44 ClientDelegatingFuture (com.hazelcast.client.impl.ClientDelegatingFuture)34 Data (com.hazelcast.internal.serialization.Data)22 UUID (java.util.UUID)11 Nonnull (javax.annotation.Nonnull)6 ILogger (com.hazelcast.logging.ILogger)5 InternalCompletableFuture (com.hazelcast.spi.impl.InternalCompletableFuture)5 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)5 HazelcastClientInstanceImpl (com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl)4 IterationPointer (com.hazelcast.internal.iteration.IterationPointer)4 SerializationService (com.hazelcast.internal.serialization.SerializationService)4 CachePutCodec (com.hazelcast.client.impl.protocol.codec.CachePutCodec)3 DurableExecutorRetrieveResultCodec (com.hazelcast.client.impl.protocol.codec.DurableExecutorRetrieveResultCodec)3 Member (com.hazelcast.cluster.Member)3 ExecutionCallbackAdapter (com.hazelcast.executor.impl.ExecutionCallbackAdapter)3 StaleSequenceException (com.hazelcast.ringbuffer.StaleSequenceException)3 AccessControlException (java.security.AccessControlException)3 List (java.util.List)3