Search in sources :

Example 56 with ClientInvocation

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

the class MCMessageTasksTest method testGetMemberConfigMessageTask.

@Test
public void testGetMemberConfigMessageTask() throws Exception {
    ClientInvocation invocation = new ClientInvocation(getClientImpl(), MCGetMemberConfigCodec.encodeRequest(), null);
    ClientDelegatingFuture<String> future = new ClientDelegatingFuture<>(invocation.invoke(), getClientImpl().getSerializationService(), MCGetMemberConfigCodec::decodeResponse);
    assertFalse(isNullOrEmptyAfterTrim(future.get(ASSERT_TRUE_EVENTUALLY_TIMEOUT, SECONDS)));
}
Also used : ClientDelegatingFuture(com.hazelcast.client.impl.ClientDelegatingFuture) MCGetMemberConfigCodec(com.hazelcast.client.impl.protocol.codec.MCGetMemberConfigCodec) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 57 with ClientInvocation

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

the class ClientCacheIterator method fetch.

protected List fetch() {
    HazelcastClientInstanceImpl client = (HazelcastClientInstanceImpl) context.getHazelcastInstance();
    String name = cacheProxy.getPrefixedName();
    if (prefetchValues) {
        ClientMessage request = CacheIterateEntriesCodec.encodeRequest(name, encodePointers(pointers), fetchSize);
        try {
            ClientInvocation clientInvocation = new ClientInvocation(client, request, name, partitionIndex);
            ClientInvocationFuture future = clientInvocation.invoke();
            CacheIterateEntriesCodec.ResponseParameters responseParameters = CacheIterateEntriesCodec.decodeResponse(future.get());
            IterationPointer[] pointers = decodePointers(responseParameters.iterationPointers);
            setIterationPointers(responseParameters.entries, pointers);
            return responseParameters.entries;
        } catch (Exception e) {
            throw rethrow(e);
        }
    } else {
        ClientMessage request = CacheIterateCodec.encodeRequest(name, encodePointers(pointers), fetchSize);
        try {
            ClientInvocation clientInvocation = new ClientInvocation(client, request, name, partitionIndex);
            ClientInvocationFuture future = clientInvocation.invoke();
            CacheIterateCodec.ResponseParameters responseParameters = CacheIterateCodec.decodeResponse(future.get());
            IterationPointer[] pointers = decodePointers(responseParameters.iterationPointers);
            setIterationPointers(responseParameters.keys, pointers);
            return responseParameters.keys;
        } catch (Exception e) {
            throw rethrow(e);
        }
    }
}
Also used : CacheIterateCodec(com.hazelcast.client.impl.protocol.codec.CacheIterateCodec) CacheIterateEntriesCodec(com.hazelcast.client.impl.protocol.codec.CacheIterateEntriesCodec) IterationPointer(com.hazelcast.internal.iteration.IterationPointer) HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Example 58 with ClientInvocation

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

the class ClientCacheProxy method subscribeToEventJournal.

@Override
public InternalCompletableFuture<EventJournalInitialSubscriberState> subscribeToEventJournal(int partitionId) {
    final ClientMessage request = CacheEventJournalSubscribeCodec.encodeRequest(nameWithPrefix);
    final ClientInvocationFuture fut = new ClientInvocation(getClient(), request, getName(), partitionId).invoke();
    return new ClientDelegatingFuture<>(fut, getSerializationService(), eventJournalSubscribeResponseDecoder);
}
Also used : ClientDelegatingFuture(com.hazelcast.client.impl.ClientDelegatingFuture) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Example 59 with ClientInvocation

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

the class ClientCacheHelper method getCacheConfig.

/**
 * Gets the cache configuration from the server.
 *
 * @param client          the client instance which will send the operation to server
 * @param cacheName       full cache name with prefixes
 * @param simpleCacheName pure cache name without any prefix
 * @param <K>             type of the key of the cache
 * @param <V>             type of the value of the cache
 * @return the cache configuration if it can be found
 */
static <K, V> CacheConfig<K, V> getCacheConfig(HazelcastClientInstanceImpl client, String cacheName, String simpleCacheName) {
    ClientMessage request = CacheGetConfigCodec.encodeRequest(cacheName, simpleCacheName);
    try {
        int partitionId = client.getClientPartitionService().getPartitionId(cacheName);
        ClientInvocation clientInvocation = new ClientInvocation(client, request, cacheName, partitionId);
        Future<ClientMessage> future = clientInvocation.invoke();
        ClientMessage responseMessage = future.get();
        SerializationService serializationService = client.getSerializationService();
        CacheConfigHolder cacheConfigHolder = CacheGetConfigCodec.decodeResponse(responseMessage);
        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) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) SerializationService(com.hazelcast.internal.serialization.SerializationService) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage)

Example 60 with ClientInvocation

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

the class ClientCacheHelper method enableStatisticManagementOnNodes.

/**
 * Enables/disables statistics or management support of cache on the all servers in the cluster.
 *
 * @param client    the client instance which will send the operation to server
 * @param cacheName full cache name with prefixes
 * @param statOrMan flag that represents which one of the statistics or management will be enabled
 * @param enabled   flag which represents whether it is enable or disable
 */
static void enableStatisticManagementOnNodes(HazelcastClientInstanceImpl client, String cacheName, boolean statOrMan, boolean enabled) {
    Collection<Member> members = client.getClientClusterService().getMemberList();
    Collection<Future> futures = new ArrayList<Future>();
    for (Member member : members) {
        try {
            UUID uuid = member.getUuid();
            ClientMessage request = CacheManagementConfigCodec.encodeRequest(cacheName, statOrMan, enabled, uuid);
            ClientInvocation clientInvocation = new ClientInvocation(client, request, cacheName, uuid);
            Future<ClientMessage> future = clientInvocation.invoke();
            futures.add(future);
        } catch (Exception e) {
            sneakyThrow(e);
        }
    }
    // make sure all configs are created
    FutureUtil.waitWithDeadline(futures, CacheProxyUtil.AWAIT_COMPLETION_TIMEOUT_SECONDS, TimeUnit.SECONDS);
}
Also used : ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) UUID(java.util.UUID) Member(com.hazelcast.cluster.Member)

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