Search in sources :

Example 41 with ClientInvocation

use of com.hazelcast.client.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, partitionId);
        Future<ClientMessage> future = clientInvocation.invoke();
        ClientMessage responseMessage = future.get();
        SerializationService serializationService = client.getSerializationService();
        return deserializeCacheConfig(client, responseMessage, serializationService, clientInvocation);
    } catch (Exception e) {
        throw rethrow(e);
    }
}
Also used : SerializationService(com.hazelcast.spi.serialization.SerializationService) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) IOException(java.io.IOException)

Example 42 with ClientInvocation

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

the class ClientInvokerWrapper method invokeOnAllPartitions.

@Override
public Object invokeOnAllPartitions(Object request) {
    try {
        ClientMessage clientRequest = (ClientMessage) request;
        final Future future = new ClientInvocation(getClient(), clientRequest).invoke();
        Object result = future.get();
        return context.toObject(result);
    } catch (Exception e) {
        throw rethrow(e);
    }
}
Also used : Future(java.util.concurrent.Future) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage)

Example 43 with ClientInvocation

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

the class ClientInvokerWrapper method invokeOnPartitionOwner.

@Override
public Future invokeOnPartitionOwner(Object request, int partitionId) {
    checkNotNull(request, "request cannot be null");
    checkNotNegative(partitionId, "partitionId");
    ClientMessage clientRequest = (ClientMessage) request;
    ClientInvocation clientInvocation = new ClientInvocation(getClient(), clientRequest, partitionId);
    return clientInvocation.invoke();
}
Also used : ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage)

Example 44 with ClientInvocation

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

the class ClientDurableExecutorServiceProxy method submitToPartition.

private <T> DurableExecutorServiceFuture<T> submitToPartition(Callable<T> task, int partitionId, T result) {
    checkNotNull(task, "task should not be null");
    SerializationService serService = getSerializationService();
    ClientMessage request = DurableExecutorSubmitToPartitionCodec.encodeRequest(name, serService.toData(task));
    int sequence;
    try {
        ClientMessage response = invokeOnPartition(request, partitionId);
        sequence = DurableExecutorSubmitToPartitionCodec.decodeResponse(response).response;
    } catch (Throwable t) {
        return new ClientDurableExecutorServiceCompletedFuture<T>(t, getUserExecutor());
    }
    ClientMessage clientMessage = DurableExecutorRetrieveResultCodec.encodeRequest(name, sequence);
    ClientInvocationFuture future = new ClientInvocation(getClient(), clientMessage, partitionId).invoke();
    long taskId = Bits.combineToLong(partitionId, sequence);
    return new ClientDurableExecutorServiceDelegatingFuture<T>(future, serService, RETRIEVE_RESPONSE_DECODER, result, taskId);
}
Also used : SerializationService(com.hazelcast.spi.serialization.SerializationService) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture)

Example 45 with ClientInvocation

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

the class ClientNonSmartListenerService method invoke.

private ClientEventRegistration invoke(ClientRegistrationKey registrationKey) throws Exception {
    EventHandler handler = registrationKey.getHandler();
    handler.beforeListenerRegister();
    ClientMessage request = registrationKey.getCodec().encodeAddRequest(false);
    ClientInvocation invocation = new ClientInvocation(client, request);
    invocation.setEventHandler(handler);
    ClientInvocationFuture future = invocation.invoke();
    String registrationId = registrationKey.getCodec().decodeAddResponse(future.get());
    handler.onListenerRegister();
    Connection connection = future.getInvocation().getSendConnection();
    return new ClientEventRegistration(registrationId, request.getCorrelationId(), connection, registrationKey.getCodec());
}
Also used : Connection(com.hazelcast.nio.Connection) EventHandler(com.hazelcast.client.spi.EventHandler) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture)

Aggregations

ClientInvocation (com.hazelcast.client.spi.impl.ClientInvocation)52 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)47 ClientInvocationFuture (com.hazelcast.client.spi.impl.ClientInvocationFuture)25 Address (com.hazelcast.nio.Address)13 ExecutionException (java.util.concurrent.ExecutionException)13 ClientDelegatingFuture (com.hazelcast.client.util.ClientDelegatingFuture)10 Data (com.hazelcast.nio.serialization.Data)10 HazelcastClientInstanceImpl (com.hazelcast.client.impl.HazelcastClientInstanceImpl)9 TimeoutException (java.util.concurrent.TimeoutException)9 StaleTaskException (com.hazelcast.scheduledexecutor.StaleTaskException)6 ArrayList (java.util.ArrayList)6 Future (java.util.concurrent.Future)6 Member (com.hazelcast.core.Member)5 SerializationService (com.hazelcast.spi.serialization.SerializationService)5 IOException (java.io.IOException)5 ClientConnection (com.hazelcast.client.connection.nio.ClientConnection)4 HazelcastException (com.hazelcast.core.HazelcastException)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 CacheException (javax.cache.CacheException)4