Search in sources :

Example 61 with ClientInvocation

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

the class ClientCacheHelper method createCacheConfig.

/**
 * Creates a new cache configuration on Hazelcast members.
 *
 * @param client         the client instance which will send the operation to server
 * @param newCacheConfig the cache configuration to be sent to server
 * @param <K>            type of the key of the cache
 * @param <V>            type of the value of the cache
 * @param urgent         whether creating the config is urgent or not(urgent messages can be send in DISCONNECTED state )
 * @return the created cache configuration
 * @see com.hazelcast.cache.impl.operation.AddCacheConfigOperation
 */
static <K, V> CacheConfig<K, V> createCacheConfig(HazelcastClientInstanceImpl client, CacheConfig<K, V> newCacheConfig, boolean urgent) {
    try {
        String nameWithPrefix = newCacheConfig.getNameWithPrefix();
        int partitionId = client.getClientPartitionService().getPartitionId(nameWithPrefix);
        InternalSerializationService serializationService = client.getSerializationService();
        ClientMessage request = CacheCreateConfigCodec.encodeRequest(CacheConfigHolder.of(newCacheConfig, serializationService), true);
        ClientInvocation clientInvocation = new ClientInvocation(client, request, nameWithPrefix, partitionId);
        Future<ClientMessage> future = urgent ? clientInvocation.invokeUrgent() : clientInvocation.invoke();
        final ClientMessage response = future.get();
        final CacheConfigHolder cacheConfigHolder = CacheCreateConfigCodec.decodeResponse(response);
        if (cacheConfigHolder == null) {
            return null;
        }
        return cacheConfigHolder.asCacheConfig(serializationService);
    } catch (Exception e) {
        throw rethrow(e);
    }
}
Also used : CacheConfigHolder(com.hazelcast.client.impl.protocol.codec.holder.CacheConfigHolder) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage)

Example 62 with ClientInvocation

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

the class ClientCacheProxy method readFromEventJournal.

@Override
public <T> InternalCompletableFuture<ReadResultSet<T>> readFromEventJournal(long startSequence, int minSize, int maxSize, int partitionId, Predicate<? super EventJournalCacheEvent<K, V>> predicate, Function<? super EventJournalCacheEvent<K, V>, ? extends T> projection) {
    if (maxSize < minSize) {
        throw new IllegalArgumentException("maxSize " + maxSize + " must be greater or equal to minSize " + minSize);
    }
    final SerializationService ss = getSerializationService();
    final ClientMessage request = CacheEventJournalReadCodec.encodeRequest(nameWithPrefix, startSequence, minSize, maxSize, ss.toData(predicate), ss.toData(projection));
    final ClientInvocationFuture fut = new ClientInvocation(getClient(), request, getName(), partitionId).invoke();
    return new ClientDelegatingFuture<>(fut, ss, eventJournalReadResponseDecoder);
}
Also used : ClientDelegatingFuture(com.hazelcast.client.impl.ClientDelegatingFuture) SerializationService(com.hazelcast.internal.serialization.SerializationService) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Example 63 with ClientInvocation

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

the class ClientCacheProxySupport method invoke.

private ClientMessage invoke(ClientMessage clientMessage, Data keyData) {
    try {
        int partitionId = getContext().getPartitionService().getPartitionId(keyData);
        Future future = new ClientInvocation(getClient(), clientMessage, getName(), partitionId).invoke();
        return (ClientMessage) future.get();
    } catch (Exception e) {
        throw rethrow(e);
    }
}
Also used : 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) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) EntryProcessorException(javax.cache.processor.EntryProcessorException) CacheException(javax.cache.CacheException) ExecutionException(java.util.concurrent.ExecutionException)

Example 64 with ClientInvocation

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

the class ClientCacheInvalidationMetaDataFetcher method fetchMetadataOf.

@Override
protected InternalCompletableFuture fetchMetadataOf(Member member, List<String> names) {
    ClientMessage message = encodeRequest(names, member.getUuid());
    ClientInvocation invocation = new ClientInvocation(clientImpl, message, null, member.getUuid());
    return invocation.invoke();
}
Also used : ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage)

Example 65 with ClientInvocation

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

the class CountDownLatchProxy method await.

@Override
public boolean await(long timeout, TimeUnit unit) {
    checkNotNull(unit);
    long timeoutMillis = Math.max(0, unit.toMillis(timeout));
    ClientMessage request = CountDownLatchAwaitCodec.encodeRequest(groupId, objectName, newUnsecureUUID(), timeoutMillis);
    ClientMessage response = new ClientInvocation(getClient(), request, name).invoke().joinInternal();
    return CountDownLatchAwaitCodec.decodeResponse(response);
}
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