Search in sources :

Example 46 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 47 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 48 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 49 with ClientInvocation

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

the class AbstractClientCacheProxyBase method invoke.

protected ClientMessage invoke(ClientMessage clientMessage, Data keyData) {
    try {
        int partitionId = clientContext.getPartitionService().getPartitionId(keyData);
        Future future = new ClientInvocation((HazelcastClientInstanceImpl) clientContext.getHazelcastInstance(), clientMessage, partitionId).invoke();
        return (ClientMessage) future.get();
    } catch (Exception e) {
        throw rethrow(e);
    }
}
Also used : ClientDelegatingFuture(com.hazelcast.client.util.ClientDelegatingFuture) Future(java.util.concurrent.Future) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) CacheException(javax.cache.CacheException) ExecutionException(java.util.concurrent.ExecutionException)

Example 50 with ClientInvocation

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

the class CallbackAwareClientDelegatingFutureTest method test_CallbackAwareClientDelegatingFuture.

private void test_CallbackAwareClientDelegatingFuture(boolean timeout, boolean error) throws ExecutionException, InterruptedException {
    if (timeout && error) {
        throw new IllegalArgumentException("Only one of the `timeout` and `error` parameters can be enabled at the same time!");
    }
    int timeoutMillis = timeout ? 5000 : -1;
    createCache(timeoutMillis, error);
    ClientMessage getRequest = createGetRequest(1);
    ClientMessageDecoder decoder = CACHE_GET_RESPONSE_DECODER;
    ClientInvocation invocation = new ClientInvocation(client, getRequest, 0);
    ClientInvocationFuture invocationFuture = invocation.invoke();
    final AtomicBoolean responseCalled = new AtomicBoolean();
    final AtomicBoolean failureCalled = new AtomicBoolean();
    OneShotExecutionCallback callback = new OneShotExecutionCallback() {

        @Override
        protected void onResponseInternal(Object response) {
            responseCalled.set(true);
        }

        @Override
        protected void onFailureInternal(Throwable t) {
            failureCalled.set(true);
        }
    };
    CallbackAwareClientDelegatingFuture callbackAwareInvocationFuture = new CallbackAwareClientDelegatingFuture(invocationFuture, client.getSerializationService(), decoder, callback);
    if (timeoutMillis > 0) {
        try {
            callbackAwareInvocationFuture.get(timeoutMillis / 2, TimeUnit.MILLISECONDS);
            fail("Timeout expected!");
        } catch (TimeoutException e) {
            // Timeout expected
            assertTrue(failureCalled.get());
            assertFalse(responseCalled.get());
        }
    } else {
        if (error) {
            try {
                callbackAwareInvocationFuture.get();
                fail("CacheLoaderException expected!");
            } catch (ExecutionException e) {
                // Exception expected
                assertTrue(e.getCause() instanceof CacheLoaderException);
                assertTrue(failureCalled.get());
                assertFalse(responseCalled.get());
            }
        } else {
            try {
                callbackAwareInvocationFuture.get();
                assertTrue(responseCalled.get());
                assertFalse(failureCalled.get());
            } catch (CacheLoaderException e) {
                fail("CacheLoaderException not expected!");
            }
        }
    }
}
Also used : ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ClientMessageDecoder(com.hazelcast.client.impl.ClientMessageDecoder) CacheLoaderException(javax.cache.integration.CacheLoaderException) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

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