Search in sources :

Example 1 with ClientDelegatingFuture

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

Example 2 with ClientDelegatingFuture

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

the class SqlClientService method mappingDdl.

/**
 * Gets a SQL Mapping suggestion for the given IMap name.
 *
 * Used by Management Center.
 */
@Nonnull
public CompletableFuture<String> mappingDdl(Member member, String mapName) {
    checkNotNull(mapName);
    ClientInvocation invocation = new ClientInvocation(client, SqlMappingDdlCodec.encodeRequest(mapName), null, member.getUuid());
    return new ClientDelegatingFuture<>(invocation.invoke(), client.getSerializationService(), SqlMappingDdlCodec::decodeResponse);
}
Also used : ClientDelegatingFuture(com.hazelcast.client.impl.ClientDelegatingFuture) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) SqlMappingDdlCodec(com.hazelcast.client.impl.protocol.codec.SqlMappingDdlCodec) Nonnull(javax.annotation.Nonnull)

Example 3 with ClientDelegatingFuture

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

the class ClientRingbufferProxy method addAllAsync.

@Override
public InternalCompletableFuture<Long> addAllAsync(@Nonnull Collection<? extends E> collection, @Nonnull OverflowPolicy overflowPolicy) {
    checkNotNull(collection, "collection can't be null");
    checkNotNull(overflowPolicy, "overflowPolicy can't be null");
    checkFalse(collection.isEmpty(), "collection can't be empty");
    checkTrue(collection.size() <= MAX_BATCH_SIZE, "collection can't be larger than " + MAX_BATCH_SIZE);
    Collection<Data> dataCollection = objectToDataCollection(collection, getSerializationService());
    ClientMessage request = RingbufferAddAllCodec.encodeRequest(name, dataCollection, overflowPolicy.getId());
    try {
        ClientInvocationFuture future = new ClientInvocation(getClient(), request, getName(), partitionId).invoke();
        return new ClientDelegatingFuture<>(future, getSerializationService(), RingbufferAddAllCodec::decodeResponse);
    } catch (Exception e) {
        throw rethrow(e);
    }
}
Also used : ClientDelegatingFuture(com.hazelcast.client.impl.ClientDelegatingFuture) Data(com.hazelcast.internal.serialization.Data) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) RingbufferAddAllCodec(com.hazelcast.client.impl.protocol.codec.RingbufferAddAllCodec) StaleSequenceException(com.hazelcast.ringbuffer.StaleSequenceException) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Example 4 with ClientDelegatingFuture

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

the class ClientRingbufferProxy method readManyAsync.

@Override
public InternalCompletableFuture<ReadResultSet<E>> readManyAsync(long startSequence, int minCount, int maxCount, IFunction<E, Boolean> filter) {
    checkSequence(startSequence);
    checkNotNegative(minCount, "minCount can't be smaller than 0");
    checkTrue(maxCount >= minCount, "maxCount should be equal or larger than minCount");
    try {
        capacity();
    } catch (Throwable e) {
        return completedExceptionally(e);
    }
    checkTrue(maxCount <= capacity, "the maxCount should be smaller than or equal to the capacity");
    checkTrue(maxCount <= MAX_BATCH_SIZE, "maxCount can't be larger than " + MAX_BATCH_SIZE);
    ClientMessage request = RingbufferReadManyCodec.encodeRequest(name, startSequence, minCount, maxCount, toData(filter));
    try {
        ClientInvocationFuture invocationFuture = new ClientInvocation(getClient(), request, getName(), partitionId).invoke();
        return new ClientDelegatingFuture<>(invocationFuture, getSerializationService(), readManyAsyncResponseDecoder);
    } catch (Exception e) {
        throw rethrow(e);
    }
}
Also used : ClientDelegatingFuture(com.hazelcast.client.impl.ClientDelegatingFuture) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) StaleSequenceException(com.hazelcast.ringbuffer.StaleSequenceException) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Example 5 with ClientDelegatingFuture

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

the class ClientRingbufferProxy method addAsync.

@Override
public InternalCompletableFuture<Long> addAsync(@Nonnull E item, @Nonnull OverflowPolicy overflowPolicy) {
    checkNotNull(item, "item can't be null");
    checkNotNull(overflowPolicy, "overflowPolicy can't be null");
    Data element = toData(item);
    ClientMessage request = RingbufferAddCodec.encodeRequest(name, overflowPolicy.getId(), element);
    try {
        ClientInvocationFuture future = new ClientInvocation(getClient(), request, getName(), partitionId).invoke();
        return new ClientDelegatingFuture<>(future, getSerializationService(), RingbufferAddCodec::decodeResponse);
    } catch (Exception e) {
        throw rethrow(e);
    }
}
Also used : ClientDelegatingFuture(com.hazelcast.client.impl.ClientDelegatingFuture) RingbufferAddCodec(com.hazelcast.client.impl.protocol.codec.RingbufferAddCodec) Data(com.hazelcast.internal.serialization.Data) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) StaleSequenceException(com.hazelcast.ringbuffer.StaleSequenceException) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Aggregations

ClientDelegatingFuture (com.hazelcast.client.impl.ClientDelegatingFuture)54 ClientInvocation (com.hazelcast.client.impl.spi.impl.ClientInvocation)46 ClientInvocationFuture (com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)32 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)31 Test (org.junit.Test)17 Data (com.hazelcast.internal.serialization.Data)16 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)15 QuickTest (com.hazelcast.test.annotation.QuickTest)15 SerializationService (com.hazelcast.internal.serialization.SerializationService)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 ClientConfig (com.hazelcast.client.config.ClientConfig)3 StaleSequenceException (com.hazelcast.ringbuffer.StaleSequenceException)3 Nonnull (javax.annotation.Nonnull)3 AtomicLongAlterCodec (com.hazelcast.client.impl.protocol.codec.AtomicLongAlterCodec)2 AtomicRefSetCodec (com.hazelcast.client.impl.protocol.codec.AtomicRefSetCodec)2 MapGetCodec (com.hazelcast.client.impl.protocol.codec.MapGetCodec)2 SqlMappingDdlCodec (com.hazelcast.client.impl.protocol.codec.SqlMappingDdlCodec)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 IExecutorService (com.hazelcast.core.IExecutorService)2