Search in sources :

Example 6 with ClientInvocationFuture

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

the class ClientExecutorServiceProxy method submitToKeyOwnerInternal.

private <T> void submitToKeyOwnerInternal(Callable<T> task, Object key, ExecutionCallback<T> callback) {
    checkNotNull(task, "task should not be null");
    String uuid = getUUID();
    int partitionId = getPartitionId(key);
    ClientMessage request = ExecutorServiceSubmitToPartitionCodec.encodeRequest(name, uuid, toData(task), partitionId);
    ClientInvocationFuture f = invokeOnPartitionOwner(request, partitionId);
    SerializationService serializationService = getContext().getSerializationService();
    ClientDelegatingFuture<T> delegatingFuture = new ClientDelegatingFuture<T>(f, serializationService, SUBMIT_TO_PARTITION_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)

Example 7 with ClientInvocationFuture

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

the class AbstractClientCacheProxy method getInternal.

protected Object getInternal(final K key, ExpiryPolicy expiryPolicy, boolean async) {
    final long start = System.nanoTime();
    ensureOpen();
    validateNotNull(key);
    final Data keyData = toData(key);
    Object cached = getCachedValue(keyData, !async);
    if (cached != NOT_CACHED) {
        return asCompletedFutureOrValue(cached, async);
    }
    final long reservationId = tryReserveForUpdate(keyData);
    final Data expiryPolicyData = toData(expiryPolicy);
    ClientMessage request = CacheGetCodec.encodeRequest(nameWithPrefix, keyData, expiryPolicyData);
    ClientInvocationFuture future;
    try {
        final int partitionId = clientContext.getPartitionService().getPartitionId(keyData);
        final HazelcastClientInstanceImpl client = (HazelcastClientInstanceImpl) clientContext.getHazelcastInstance();
        final ClientInvocation clientInvocation = new ClientInvocation(client, request, partitionId);
        future = clientInvocation.invoke();
    } catch (Throwable t) {
        invalidateNearCache(keyData);
        throw rethrow(t);
    }
    SerializationService serializationService = clientContext.getSerializationService();
    ClientDelegatingFuture<V> delegatingFuture = new ClientDelegatingFuture<V>(future, serializationService, cacheGetResponseDecoder);
    if (async) {
        if (nearCache != null) {
            delegatingFuture.andThenInternal(new ExecutionCallback<Data>() {

                public void onResponse(Data valueData) {
                    storeInNearCache(keyData, valueData, null, reservationId, false);
                    if (statisticsEnabled) {
                        handleStatisticsOnGet(start, valueData);
                    }
                }

                public void onFailure(Throwable t) {
                    invalidateNearCache(keyData);
                }
            }, false);
        }
        return delegatingFuture;
    } else {
        try {
            V value = toObject(delegatingFuture.get());
            if (nearCache != null) {
                storeInNearCache(keyData, (Data) delegatingFuture.getResponse(), value, reservationId, false);
            }
            if (statisticsEnabled) {
                handleStatisticsOnGet(start, value);
            }
            return value;
        } catch (Throwable e) {
            invalidateNearCache(keyData);
            throw rethrowAllowedTypeFirst(e, CacheException.class);
        }
    }
}
Also used : ClientDelegatingFuture(com.hazelcast.client.util.ClientDelegatingFuture) CacheException(javax.cache.CacheException) SerializationService(com.hazelcast.spi.serialization.SerializationService) Data(com.hazelcast.nio.serialization.Data) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl)

Example 8 with ClientInvocationFuture

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

the class AbstractClientCacheProxyBase method submitLoadAllTask.

protected void submitLoadAllTask(ClientMessage request, CompletionListener completionListener, final Set<Data> keys) {
    final CompletionListener compListener = completionListener != null ? completionListener : NULL_COMPLETION_LISTENER;
    ClientDelegatingFuture<V> delegatingFuture = null;
    try {
        injectDependencies(completionListener);
        final long start = System.nanoTime();
        ClientInvocationFuture future = new ClientInvocation((HazelcastClientInstanceImpl) clientContext.getHazelcastInstance(), request).invoke();
        SerializationService serializationService = clientContext.getSerializationService();
        delegatingFuture = new ClientDelegatingFuture<V>(future, serializationService, LOAD_ALL_DECODER);
        final Future delFuture = delegatingFuture;
        loadAllCalls.put(delegatingFuture, compListener);
        delegatingFuture.andThen(new ExecutionCallback<V>() {

            @Override
            public void onResponse(V response) {
                loadAllCalls.remove(delFuture);
                onLoadAll(keys, response, start, System.nanoTime());
                compListener.onCompletion();
            }

            @Override
            public void onFailure(Throwable t) {
                loadAllCalls.remove(delFuture);
                handleFailureOnCompletionListener(compListener, t);
            }
        });
    } catch (Throwable t) {
        if (delegatingFuture != null) {
            loadAllCalls.remove(delegatingFuture);
        }
        handleFailureOnCompletionListener(compListener, t);
    }
}
Also used : CompletionListener(javax.cache.integration.CompletionListener) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) SerializationService(com.hazelcast.spi.serialization.SerializationService) ClientDelegatingFuture(com.hazelcast.client.util.ClientDelegatingFuture) Future(java.util.concurrent.Future) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture)

Example 9 with ClientInvocationFuture

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

the class ClientClusterWideIterator method fetch.

protected List fetch() {
    HazelcastClientInstanceImpl client = (HazelcastClientInstanceImpl) context.getHazelcastInstance();
    if (prefetchValues) {
        ClientMessage request = CacheIterateEntriesCodec.encodeRequest(cacheProxy.getPrefixedName(), partitionIndex, lastTableIndex, fetchSize);
        try {
            ClientInvocation clientInvocation = new ClientInvocation(client, request, partitionIndex);
            ClientInvocationFuture f = clientInvocation.invoke();
            CacheIterateEntriesCodec.ResponseParameters responseParameters = CacheIterateEntriesCodec.decodeResponse(f.get());
            setLastTableIndex(responseParameters.entries, responseParameters.tableIndex);
            return responseParameters.entries;
        } catch (Exception e) {
            throw ExceptionUtil.rethrow(e);
        }
    } else {
        ClientMessage request = CacheIterateCodec.encodeRequest(cacheProxy.getPrefixedName(), partitionIndex, lastTableIndex, fetchSize);
        try {
            ClientInvocation clientInvocation = new ClientInvocation(client, request, partitionIndex);
            ClientInvocationFuture f = clientInvocation.invoke();
            CacheIterateCodec.ResponseParameters responseParameters = CacheIterateCodec.decodeResponse(f.get());
            setLastTableIndex(responseParameters.keys, responseParameters.tableIndex);
            return responseParameters.keys;
        } catch (Exception e) {
            throw ExceptionUtil.rethrow(e);
        }
    }
}
Also used : CacheIterateCodec(com.hazelcast.client.impl.protocol.codec.CacheIterateCodec) CacheIterateEntriesCodec(com.hazelcast.client.impl.protocol.codec.CacheIterateEntriesCodec) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture)

Example 10 with ClientInvocationFuture

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

the class AbstractClientInternalCacheProxy method putInternal.

protected Object putInternal(K key, V value, ExpiryPolicy expiryPolicy, boolean isGet, boolean withCompletionEvent, boolean async) {
    long start = System.nanoTime();
    ensureOpen();
    validateNotNull(key, value);
    CacheProxyUtil.validateConfiguredTypes(cacheConfig, key, value);
    Data keyData = toData(key);
    Data valueData = toData(value);
    Data expiryPolicyData = toData(expiryPolicy);
    int completionId = withCompletionEvent ? nextCompletionId() : -1;
    ClientMessage request = CachePutCodec.encodeRequest(nameWithPrefix, keyData, valueData, expiryPolicyData, isGet, completionId);
    ClientInvocationFuture future;
    try {
        future = invoke(request, keyData, completionId);
    } catch (Exception e) {
        throw rethrow(e);
    }
    if (async) {
        return putInternalAsync(value, isGet, start, keyData, valueData, future);
    }
    return putInternalSync(value, isGet, start, keyData, valueData, future);
}
Also used : 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)

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