Search in sources :

Example 1 with ClientInvocation

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

the class ClientCacheProxySupport method updateCacheListenerConfigOnOtherNodes.

protected void updateCacheListenerConfigOnOtherNodes(CacheEntryListenerConfiguration<K, V> cacheEntryListenerConfiguration, boolean isRegister) {
    Collection<Member> members = getContext().getClusterService().getMemberList();
    for (Member member : members) {
        try {
            UUID uuid = member.getUuid();
            Data configData = toData(cacheEntryListenerConfiguration);
            ClientMessage request = CacheListenerRegistrationCodec.encodeRequest(nameWithPrefix, configData, isRegister, uuid);
            ClientInvocation invocation = new ClientInvocation(getClient(), request, getName(), uuid);
            invocation.invoke();
        } catch (Exception e) {
            sneakyThrow(e);
        }
    }
}
Also used : Data(com.hazelcast.internal.serialization.Data) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) UUID(java.util.UUID) Member(com.hazelcast.cluster.Member) EntryProcessorException(javax.cache.processor.EntryProcessorException) CacheException(javax.cache.CacheException) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with ClientInvocation

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

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

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

the class ClientCacheProxySupport method invoke.

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

Example 5 with ClientInvocation

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

the class ClientJobProxy method invokeJoinJob.

@Override
protected CompletableFuture<Void> invokeJoinJob() {
    ClientMessage request = JetJoinSubmittedJobCodec.encodeRequest(getId(), lightJobCoordinator);
    ClientInvocation invocation = invocation(request, coordinatorId());
    // this invocation should never time out, as the job may be running for a long time
    // 0 is not supported
    invocation.setInvocationTimeoutMillis(Long.MAX_VALUE);
    return invocation.invoke().thenApply(c -> null);
}
Also used : ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage)

Aggregations

ClientInvocation (com.hazelcast.client.impl.spi.impl.ClientInvocation)129 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)97 ClientDelegatingFuture (com.hazelcast.client.impl.ClientDelegatingFuture)54 ClientInvocationFuture (com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)51 Test (org.junit.Test)23 Data (com.hazelcast.internal.serialization.Data)22 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)19 QuickTest (com.hazelcast.test.annotation.QuickTest)19 UUID (java.util.UUID)18 HazelcastClientInstanceImpl (com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl)16 Future (java.util.concurrent.Future)13 UuidUtil.newUnsecureUUID (com.hazelcast.internal.util.UuidUtil.newUnsecureUUID)9 ArrayList (java.util.ArrayList)9 Nonnull (javax.annotation.Nonnull)9 ExecutionException (java.util.concurrent.ExecutionException)8 InternalCompletableFuture (com.hazelcast.spi.impl.InternalCompletableFuture)7 Collection (java.util.Collection)6 List (java.util.List)6 Map (java.util.Map)6 TimeUnit (java.util.concurrent.TimeUnit)6