Search in sources :

Example 16 with ClientDelegatingFuture

use of com.hazelcast.client.util.ClientDelegatingFuture in project hazelcast by hazelcast.

the class AbstractClientInternalCacheProxy method putInternalAsync.

private Object putInternalAsync(final V value, final boolean isGet, final long start, final Data keyData, final Data valueData, ClientInvocationFuture future) {
    OneShotExecutionCallback<V> oneShotExecutionCallback = null;
    if (nearCache != null || statisticsEnabled) {
        oneShotExecutionCallback = new OneShotExecutionCallback<V>() {

            @Override
            protected void onResponseInternal(V responseData) {
                if (nearCache != null) {
                    if (cacheOnUpdate) {
                        storeInNearCache(keyData, valueData, value, NOT_RESERVED, cacheOnUpdate);
                    } else {
                        invalidateNearCache(keyData);
                    }
                }
                if (statisticsEnabled) {
                    handleStatisticsOnPut(isGet, start, responseData);
                }
            }

            @Override
            protected void onFailureInternal(Throwable t) {
            }
        };
    }
    SerializationService serializationService = clientContext.getSerializationService();
    if (oneShotExecutionCallback == null) {
        return new ClientDelegatingFuture<V>(future, serializationService, PUT_RESPONSE_DECODER);
    }
    ClientDelegatingFuture<V> delegatingFuture = new CallbackAwareClientDelegatingFuture<V>(future, serializationService, PUT_RESPONSE_DECODER, oneShotExecutionCallback);
    delegatingFuture.andThenInternal(oneShotExecutionCallback, true);
    return delegatingFuture;
}
Also used : ClientDelegatingFuture(com.hazelcast.client.util.ClientDelegatingFuture) SerializationService(com.hazelcast.spi.serialization.SerializationService)

Example 17 with ClientDelegatingFuture

use of com.hazelcast.client.util.ClientDelegatingFuture in project hazelcast by hazelcast.

the class AbstractClientInternalCacheProxy method removeAsyncInternal.

protected <T> ICompletableFuture<T> removeAsyncInternal(K key, V oldValue, boolean hasOldValue, boolean withCompletionEvent, boolean async) {
    final long start = System.nanoTime();
    ensureOpen();
    if (hasOldValue) {
        validateNotNull(key, oldValue);
        CacheProxyUtil.validateConfiguredTypes(cacheConfig, key, oldValue);
    } else {
        validateNotNull(key);
        CacheProxyUtil.validateConfiguredTypes(cacheConfig, key);
    }
    Data keyData = toData(key);
    Data oldValueData = toData(oldValue);
    int completionId = withCompletionEvent ? nextCompletionId() : -1;
    ClientMessage request = CacheRemoveCodec.encodeRequest(nameWithPrefix, keyData, oldValueData, completionId);
    ClientInvocationFuture future;
    try {
        future = invoke(request, keyData, completionId);
        invalidateNearCache(keyData);
    } catch (Exception e) {
        throw rethrow(e);
    }
    ClientDelegatingFuture<T> delegatingFuture = new ClientDelegatingFuture<T>(future, clientContext.getSerializationService(), REMOVE_RESPONSE_DECODER);
    if (async && statisticsEnabled) {
        delegatingFuture.andThenInternal(new ExecutionCallback<T>() {

            public void onResponse(T response) {
                handleStatisticsOnRemove(false, start, response);
            }

            public void onFailure(Throwable t) {
            }
        }, true);
    }
    return delegatingFuture;
}
Also used : ClientDelegatingFuture(com.hazelcast.client.util.ClientDelegatingFuture) CacheEventData(com.hazelcast.cache.impl.CacheEventData) Data(com.hazelcast.nio.serialization.Data) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) CacheException(javax.cache.CacheException) ExecutionException(java.util.concurrent.ExecutionException) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture)

Example 18 with ClientDelegatingFuture

use of com.hazelcast.client.util.ClientDelegatingFuture in project hazelcast by hazelcast.

the class ClientMapProxy method submitToKeyInternal.

public void submitToKeyInternal(Data keyData, EntryProcessor entryProcessor, final ExecutionCallback callback) {
    ClientMessage request = MapSubmitToKeyCodec.encodeRequest(name, toData(entryProcessor), keyData, getThreadId());
    try {
        ClientInvocationFuture future = invokeOnKeyOwner(request, keyData);
        SerializationService serializationService = getContext().getSerializationService();
        ClientDelegatingFuture clientDelegatingFuture = new ClientDelegatingFuture(future, serializationService, SUBMIT_TO_KEY_RESPONSE_DECODER);
        clientDelegatingFuture.andThen(callback);
    } catch (Exception e) {
        throw rethrow(e);
    }
}
Also used : ClientDelegatingFuture(com.hazelcast.client.util.ClientDelegatingFuture) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) SerializationService(com.hazelcast.spi.serialization.SerializationService) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) HazelcastException(com.hazelcast.core.HazelcastException) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture)

Example 19 with ClientDelegatingFuture

use of com.hazelcast.client.util.ClientDelegatingFuture 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, partitionId).invoke();
    return new ClientDelegatingFuture<T>(future, getSerializationService(), RETRIEVE_RESPONSE_DECODER);
}
Also used : ClientDelegatingFuture(com.hazelcast.client.util.ClientDelegatingFuture) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture)

Example 20 with ClientDelegatingFuture

use of com.hazelcast.client.util.ClientDelegatingFuture in project hazelcast by hazelcast.

the class ClientExecutorServiceProxy method submitToTargetInternal.

private <T> void submitToTargetInternal(Callable<T> task, Address address, ExecutionCallback<T> callback) {
    checkNotNull(task, "task should not be null");
    String uuid = getUUID();
    ClientMessage request = ExecutorServiceSubmitToAddressCodec.encodeRequest(name, uuid, toData(task), address);
    ClientInvocationFuture f = invokeOnTarget(request, address);
    SerializationService serializationService = getContext().getSerializationService();
    ClientDelegatingFuture<T> delegatingFuture = new ClientDelegatingFuture<T>(f, serializationService, SUBMIT_TO_ADDRESS_DECODER);
    delegatingFuture.andThen(callback);
}
Also used : ClientDelegatingFuture(com.hazelcast.client.util.ClientDelegatingFuture) SerializationService(com.hazelcast.spi.serialization.SerializationService) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture)

Aggregations

ClientDelegatingFuture (com.hazelcast.client.util.ClientDelegatingFuture)20 ClientInvocationFuture (com.hazelcast.client.spi.impl.ClientInvocationFuture)17 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)16 Data (com.hazelcast.nio.serialization.Data)8 SerializationService (com.hazelcast.spi.serialization.SerializationService)8 ClientInvocation (com.hazelcast.client.spi.impl.ClientInvocation)7 ExecutionException (java.util.concurrent.ExecutionException)7 CacheException (javax.cache.CacheException)6 CacheEventData (com.hazelcast.cache.impl.CacheEventData)5 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)4 StaleSequenceException (com.hazelcast.ringbuffer.StaleSequenceException)3 HazelcastClientInstanceImpl (com.hazelcast.client.impl.HazelcastClientInstanceImpl)2 HazelcastException (com.hazelcast.core.HazelcastException)2 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)2 ClientConfig (com.hazelcast.client.config.ClientConfig)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 HazelcastOverloadException (com.hazelcast.core.HazelcastOverloadException)1 IExecutorService (com.hazelcast.core.IExecutorService)1 IMap (com.hazelcast.core.IMap)1 MAX_BATCH_SIZE (com.hazelcast.ringbuffer.impl.RingbufferProxy.MAX_BATCH_SIZE)1