Search in sources :

Example 1 with ClientInvocationFuture

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

the class ClientCacheProxySupport method setExpiryPolicyInternal.

protected boolean setExpiryPolicyInternal(K key, ExpiryPolicy expiryPolicy) {
    ensureOpen();
    validateNotNull(key);
    validateNotNull(expiryPolicy);
    Data keyData = toData(key);
    Data expiryPolicyData = toData(expiryPolicy);
    List<Data> list = Collections.singletonList(keyData);
    ClientMessage request = CacheSetExpiryPolicyCodec.encodeRequest(nameWithPrefix, list, expiryPolicyData);
    ClientInvocationFuture future = invoke(request, keyData, IGNORE_COMPLETION);
    ClientDelegatingFuture<Boolean> delegatingFuture = newDelegatingFuture(future, CacheSetExpiryPolicyCodec::decodeResponse);
    try {
        return delegatingFuture.get();
    } catch (Throwable e) {
        throw rethrowAllowedTypeFirst(e, CacheException.class);
    }
}
Also used : CacheSetExpiryPolicyCodec(com.hazelcast.client.impl.protocol.codec.CacheSetExpiryPolicyCodec) CacheException(javax.cache.CacheException) Data(com.hazelcast.internal.serialization.Data) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Example 2 with ClientInvocationFuture

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

the class ClientCacheProxySupport method getInternal.

private ClientDelegatingFuture<V> getInternal(Data keyData, ExpiryPolicy expiryPolicy, boolean deserializeResponse) {
    Data expiryPolicyData = toData(expiryPolicy);
    ClientMessage request = CacheGetCodec.encodeRequest(nameWithPrefix, keyData, expiryPolicyData);
    int partitionId = getContext().getPartitionService().getPartitionId(keyData);
    ClientInvocation clientInvocation = new ClientInvocation(getClient(), request, name, partitionId);
    ClientInvocationFuture future = clientInvocation.invoke();
    return newDelegatingFuture(future, CacheGetCodec::decodeResponse, deserializeResponse);
}
Also used : CacheGetCodec(com.hazelcast.client.impl.protocol.codec.CacheGetCodec) Data(com.hazelcast.internal.serialization.Data) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Example 3 with ClientInvocationFuture

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

the class ClientCacheProxySupport method callPutSync.

protected V callPutSync(K key, Data keyData, V value, Data valueData, Data expiryPolicyData, boolean isGet) throws InterruptedException, ExecutionException {
    ClientInvocationFuture invocationFuture = putInternal(keyData, valueData, expiryPolicyData, isGet, true);
    ClientDelegatingFuture<V> delegatingFuture = newDelegatingFuture(invocationFuture, CachePutCodec::decodeResponse);
    return delegatingFuture.get();
}
Also used : CachePutCodec(com.hazelcast.client.impl.protocol.codec.CachePutCodec) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Example 4 with ClientInvocationFuture

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

the class ClientCacheProxySupport method getAndRemoveInternal.

private <T> ClientDelegatingFuture<T> getAndRemoveInternal(Data keyData, boolean withCompletionEvent) {
    int completionId = withCompletionEvent ? nextCompletionId() : -1;
    ClientMessage request = CacheGetAndRemoveCodec.encodeRequest(nameWithPrefix, keyData, completionId);
    ClientInvocationFuture future = invoke(request, keyData, completionId);
    return newDelegatingFuture(future, CacheGetAndRemoveCodec::decodeResponse);
}
Also used : CacheGetAndRemoveCodec(com.hazelcast.client.impl.protocol.codec.CacheGetAndRemoveCodec) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Example 5 with ClientInvocationFuture

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

the class ClientCacheProxySupport method submitLoadAllTask.

private void submitLoadAllTask(ClientMessage request, CompletionListener completionListener, final List<Data> binaryKeys) {
    final CompletionListener listener = completionListener != null ? injectDependencies(completionListener) : NULL_COMPLETION_LISTENER;
    ClientDelegatingFuture<V> delegatingFuture = null;
    try {
        final long startNanos = nowInNanosOrDefault();
        ClientInvocationFuture future = new ClientInvocation(getClient(), request, getName()).invoke();
        delegatingFuture = newDelegatingFuture(future, clientMessage -> Boolean.TRUE);
        final Future delFuture = delegatingFuture;
        loadAllCalls.put(delegatingFuture, listener);
        delegatingFuture.whenCompleteAsync((response, t) -> {
            if (t == null) {
                loadAllCalls.remove(delFuture);
                onLoadAll(binaryKeys, startNanos);
                listener.onCompletion();
            } else {
                loadAllCalls.remove(delFuture);
                handleFailureOnCompletionListener(listener, t);
            }
        });
    } catch (Throwable t) {
        if (delegatingFuture != null) {
            loadAllCalls.remove(delegatingFuture);
        }
        handleFailureOnCompletionListener(listener, t);
    }
}
Also used : ExceptionUtil.rethrowAllowedTypeFirst(com.hazelcast.internal.util.ExceptionUtil.rethrowAllowedTypeFirst) Member(com.hazelcast.cluster.Member) CachePutAllCodec(com.hazelcast.client.impl.protocol.codec.CachePutAllCodec) ExceptionUtil.rethrow(com.hazelcast.internal.util.ExceptionUtil.rethrow) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) Future(java.util.concurrent.Future) CacheSetExpiryPolicyCodec(com.hazelcast.client.impl.protocol.codec.CacheSetExpiryPolicyCodec) ICacheService(com.hazelcast.cache.impl.ICacheService) CacheEntryListenerConfiguration(javax.cache.configuration.CacheEntryListenerConfiguration) NULL_KEY_IS_NOT_ALLOWED(com.hazelcast.cache.impl.CacheProxyUtil.NULL_KEY_IS_NOT_ALLOWED) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CacheRemoveAllKeysCodec(com.hazelcast.client.impl.protocol.codec.CacheRemoveAllKeysCodec) Map(java.util.Map) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientCacheProxySupportUtil.getSafely(com.hazelcast.client.cache.impl.ClientCacheProxySupportUtil.getSafely) HazelcastCacheManager(com.hazelcast.cache.HazelcastCacheManager) CacheRemoveAllCodec(com.hazelcast.client.impl.protocol.codec.CacheRemoveAllCodec) CacheProxyUtil.validateNotNull(com.hazelcast.cache.impl.CacheProxyUtil.validateNotNull) CacheProxyUtil.validateConfiguredTypes(com.hazelcast.cache.impl.CacheProxyUtil.validateConfiguredTypes) ClientCacheProxySupportUtil.addCallback(com.hazelcast.client.cache.impl.ClientCacheProxySupportUtil.addCallback) NearCachingHook(com.hazelcast.internal.nearcache.impl.NearCachingHook) ClientPartitionService(com.hazelcast.client.impl.spi.ClientPartitionService) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) CacheConfig(com.hazelcast.config.CacheConfig) ExceptionUtil(com.hazelcast.internal.util.ExceptionUtil) Set(java.util.Set) UUID(java.util.UUID) CacheGetAndReplaceCodec(com.hazelcast.client.impl.protocol.codec.CacheGetAndReplaceCodec) CacheListenerRegistrationCodec(com.hazelcast.client.impl.protocol.codec.CacheListenerRegistrationCodec) ClientCacheProxySupportUtil.handleFailureOnCompletionListener(com.hazelcast.client.cache.impl.ClientCacheProxySupportUtil.handleFailureOnCompletionListener) List(java.util.List) ICacheInternal(com.hazelcast.cache.impl.ICacheInternal) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture) CacheManager(javax.cache.CacheManager) CachePutIfAbsentCodec(com.hazelcast.client.impl.protocol.codec.CachePutIfAbsentCodec) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) CacheGetCodec(com.hazelcast.client.impl.protocol.codec.CacheGetCodec) CacheEventListenerAdaptor(com.hazelcast.cache.impl.CacheEventListenerAdaptor) CacheEntryProcessorCodec(com.hazelcast.client.impl.protocol.codec.CacheEntryProcessorCodec) ManagedContext(com.hazelcast.core.ManagedContext) FutureUtil(com.hazelcast.internal.util.FutureUtil) CacheContainsKeyCodec(com.hazelcast.client.impl.protocol.codec.CacheContainsKeyCodec) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CollectionUtil.objectToDataCollection(com.hazelcast.internal.util.CollectionUtil.objectToDataCollection) CompletableFuture(java.util.concurrent.CompletableFuture) EmptyCompletionListener(com.hazelcast.client.cache.impl.ClientCacheProxySupportUtil.EmptyCompletionListener) ClientListenerService(com.hazelcast.client.impl.spi.ClientListenerService) EntryProcessorException(javax.cache.processor.EntryProcessorException) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) CacheSyncListenerCompleter(com.hazelcast.cache.impl.CacheSyncListenerCompleter) ExceptionUtil.sneakyThrow(com.hazelcast.internal.util.ExceptionUtil.sneakyThrow) ILogger(com.hazelcast.logging.ILogger) CacheClearCodec(com.hazelcast.client.impl.protocol.codec.CacheClearCodec) CacheEntryListener(javax.cache.event.CacheEntryListener) ClientContext(com.hazelcast.client.impl.spi.ClientContext) BiConsumer(java.util.function.BiConsumer) ClientMessageDecoder(com.hazelcast.client.impl.clientside.ClientMessageDecoder) CacheGetAndRemoveCodec(com.hazelcast.client.impl.protocol.codec.CacheGetAndRemoveCodec) CacheException(javax.cache.CacheException) CachePutCodec(com.hazelcast.client.impl.protocol.codec.CachePutCodec) Nonnull(javax.annotation.Nonnull) IGNORE_COMPLETION(com.hazelcast.cache.impl.operation.MutableOperation.IGNORE_COMPLETION) Timer(com.hazelcast.internal.util.Timer) IOUtil(com.hazelcast.internal.nio.IOUtil) ExpiryPolicy(javax.cache.expiry.ExpiryPolicy) Iterator(java.util.Iterator) Data(com.hazelcast.internal.serialization.Data) CompletionListener(javax.cache.integration.CompletionListener) CacheReplaceCodec(com.hazelcast.client.impl.protocol.codec.CacheReplaceCodec) CacheGetAllCodec(com.hazelcast.client.impl.protocol.codec.CacheGetAllCodec) ClientProxy(com.hazelcast.client.impl.spi.ClientProxy) CacheRemoveCodec(com.hazelcast.client.impl.protocol.codec.CacheRemoveCodec) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) AbstractMap(java.util.AbstractMap) ClientDelegatingFuture(com.hazelcast.client.impl.ClientDelegatingFuture) Closeable(java.io.Closeable) CacheLoadAllCodec(com.hazelcast.client.impl.protocol.codec.CacheLoadAllCodec) Collections(java.util.Collections) ClientCacheProxySupportUtil.handleFailureOnCompletionListener(com.hazelcast.client.cache.impl.ClientCacheProxySupportUtil.handleFailureOnCompletionListener) EmptyCompletionListener(com.hazelcast.client.cache.impl.ClientCacheProxySupportUtil.EmptyCompletionListener) CompletionListener(javax.cache.integration.CompletionListener) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) Future(java.util.concurrent.Future) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture) CompletableFuture(java.util.concurrent.CompletableFuture) ClientDelegatingFuture(com.hazelcast.client.impl.ClientDelegatingFuture) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) 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