Search in sources :

Example 21 with ClientInvocationFuture

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

the class AbstractClientInternalCacheProxy method replaceInternal.

protected <T> ICompletableFuture<T> replaceInternal(K key, V oldValue, V newValue, ExpiryPolicy expiryPolicy, boolean hasOldValue, boolean withCompletionEvent, boolean async) {
    final long start = System.nanoTime();
    ensureOpen();
    if (hasOldValue) {
        validateNotNull(key, oldValue, newValue);
        CacheProxyUtil.validateConfiguredTypes(cacheConfig, key, oldValue, newValue);
    } else {
        validateNotNull(key, newValue);
        CacheProxyUtil.validateConfiguredTypes(cacheConfig, key, newValue);
    }
    Data keyData = toData(key);
    Data oldValueData = toData(oldValue);
    Data newValueData = toData(newValue);
    Data expiryPolicyData = toData(expiryPolicy);
    int completionId = withCompletionEvent ? nextCompletionId() : -1;
    ClientMessage request = CacheReplaceCodec.encodeRequest(nameWithPrefix, keyData, oldValueData, newValueData, expiryPolicyData, 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(), REPLACE_RESPONSE_DECODER);
    if (async && statisticsEnabled) {
        delegatingFuture.andThenInternal(new ExecutionCallback<T>() {

            public void onResponse(T response) {
                handleStatisticsOnReplace(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 22 with ClientInvocationFuture

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

the class AbstractClientInternalCacheProxy method replaceAndGetAsyncInternal.

protected <T> ICompletableFuture<T> replaceAndGetAsyncInternal(K key, V oldValue, V newValue, ExpiryPolicy expiryPolicy, boolean hasOldValue, boolean withCompletionEvent, boolean async) {
    final long start = System.nanoTime();
    ensureOpen();
    if (hasOldValue) {
        validateNotNull(key, oldValue, newValue);
        CacheProxyUtil.validateConfiguredTypes(cacheConfig, key, oldValue, newValue);
    } else {
        validateNotNull(key, newValue);
        CacheProxyUtil.validateConfiguredTypes(cacheConfig, key, newValue);
    }
    Data keyData = toData(key);
    Data newValueData = toData(newValue);
    Data expiryPolicyData = toData(expiryPolicy);
    int completionId = withCompletionEvent ? nextCompletionId() : -1;
    ClientMessage request = CacheGetAndReplaceCodec.encodeRequest(nameWithPrefix, keyData, newValueData, expiryPolicyData, 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(), GET_AND_REPLACE_RESPONSE_DECODER);
    if (async && statisticsEnabled) {
        delegatingFuture.andThenInternal(new ExecutionCallback<T>() {

            public void onResponse(T response) {
                handleStatisticsOnReplace(true, 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 23 with ClientInvocationFuture

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

the class AbstractClientInternalCacheProxy method invoke.

protected ClientInvocationFuture invoke(ClientMessage req, int partitionId, int completionId) {
    boolean completionOperation = completionId != -1;
    if (completionOperation) {
        registerCompletionLatch(completionId, 1);
    }
    try {
        HazelcastClientInstanceImpl client = (HazelcastClientInstanceImpl) clientContext.getHazelcastInstance();
        ClientInvocation clientInvocation = new ClientInvocation(client, req, partitionId);
        ClientInvocationFuture f = clientInvocation.invoke();
        if (completionOperation) {
            waitCompletionLatch(completionId, f);
        }
        return f;
    } catch (Throwable e) {
        if (e instanceof IllegalStateException) {
            close();
        }
        if (completionOperation) {
            deregisterCompletionLatch(completionId);
        }
        throw rethrowAllowedTypeFirst(e, CacheException.class);
    }
}
Also used : CacheException(javax.cache.CacheException) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture)

Example 24 with ClientInvocationFuture

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

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

the class ClientMapPartitionIterator method fetchWithoutPrefetchValues.

private List fetchWithoutPrefetchValues(HazelcastClientInstanceImpl client) {
    ClientMessage request = MapFetchKeysCodec.encodeRequest(mapProxy.getName(), partitionId, lastTableIndex, fetchSize);
    ClientInvocation clientInvocation = new ClientInvocation(client, request, partitionId);
    try {
        ClientInvocationFuture f = clientInvocation.invoke();
        MapFetchKeysCodec.ResponseParameters responseParameters = MapFetchKeysCodec.decodeResponse(f.get());
        setLastTableIndex(responseParameters.keys, responseParameters.tableIndex);
        return responseParameters.keys;
    } catch (Exception e) {
        throw ExceptionUtil.rethrow(e);
    }
}
Also used : ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) MapFetchKeysCodec(com.hazelcast.client.impl.protocol.codec.MapFetchKeysCodec) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture)

Aggregations

ClientInvocationFuture (com.hazelcast.client.spi.impl.ClientInvocationFuture)36 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)31 ClientInvocation (com.hazelcast.client.spi.impl.ClientInvocation)21 ClientDelegatingFuture (com.hazelcast.client.util.ClientDelegatingFuture)17 Data (com.hazelcast.nio.serialization.Data)9 SerializationService (com.hazelcast.spi.serialization.SerializationService)9 ExecutionException (java.util.concurrent.ExecutionException)9 CacheException (javax.cache.CacheException)7 CacheEventData (com.hazelcast.cache.impl.CacheEventData)6 HazelcastClientInstanceImpl (com.hazelcast.client.impl.HazelcastClientInstanceImpl)6 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)5 HazelcastException (com.hazelcast.core.HazelcastException)3 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)3 StaleSequenceException (com.hazelcast.ringbuffer.StaleSequenceException)3 ClientConnection (com.hazelcast.client.connection.nio.ClientConnection)2 EventHandler (com.hazelcast.client.spi.EventHandler)2 Connection (com.hazelcast.nio.Connection)2 CancellationException (java.util.concurrent.CancellationException)2 AuthenticationException (com.hazelcast.client.AuthenticationException)1 ClientMessageDecoder (com.hazelcast.client.impl.ClientMessageDecoder)1