Search in sources :

Example 31 with ClientInvocationFuture

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

the class ClientDurableExecutorServiceProxy method submitToPartition.

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

Example 32 with ClientInvocationFuture

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

the class ClientDurableExecutorServiceProxy method retrieveAndDisposeResult.

@Override
public <T> Future<T> retrieveAndDisposeResult(long taskId) {
    int partitionId = Bits.extractInt(taskId, false);
    int sequence = Bits.extractInt(taskId, true);
    ClientMessage clientMessage = DurableExecutorRetrieveAndDisposeResultCodec.encodeRequest(name, sequence);
    ClientInvocationFuture future = new ClientInvocation(getClient(), clientMessage, getName(), partitionId).invoke();
    return new ClientDelegatingFuture<>(future, getSerializationService(), DurableExecutorRetrieveResultCodec::decodeResponse);
}
Also used : ClientDelegatingFuture(com.hazelcast.client.impl.ClientDelegatingFuture) DurableExecutorRetrieveResultCodec(com.hazelcast.client.impl.protocol.codec.DurableExecutorRetrieveResultCodec) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Example 33 with ClientInvocationFuture

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

the class DisabledOperationsTest method assertFailure.

private void assertFailure(ClientMessage clientMessage, String expectedExceptionMsg) throws Exception {
    ClientInvocation invocation = new ClientInvocation(client, clientMessage, null);
    ClientInvocationFuture future = invocation.invoke();
    assertThatThrownBy(() -> future.get(ASSERT_TRUE_EVENTUALLY_TIMEOUT, SECONDS)).hasCauseInstanceOf(AccessControlException.class).hasRootCauseMessage(expectedExceptionMsg);
}
Also used : AccessControlException(java.security.AccessControlException) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Example 34 with ClientInvocationFuture

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

the class ClientDelegatingFuture_SerializationExceptionTest method setup.

@Before
public void setup() {
    serializationService = new DefaultSerializationServiceBuilder().build();
    key = serializationService.toData("key");
    value = invalidData;
    logger = mock(ILogger.class);
    request = MapGetCodec.encodeRequest("test", key, 1L);
    response = MapGetCodec.encodeResponse(value);
    callIdSequence = mock(CallIdSequence.class);
    invocationFuture = new ClientInvocationFuture(mock(ClientInvocation.class), request, logger, callIdSequence);
    invocationFuture.complete(response);
    delegatingFuture = new ClientDelegatingFuture<>(invocationFuture, serializationService, MapGetCodec::decodeResponse, true);
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) ILogger(com.hazelcast.logging.ILogger) CallIdSequence(com.hazelcast.spi.impl.sequence.CallIdSequence) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture) Before(org.junit.Before)

Example 35 with ClientInvocationFuture

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

the class MCTrustedInterfacesTest method assertFailureOnUntrustedInterface.

private void assertFailureOnUntrustedInterface(ClientMessage clientMessage) throws Exception {
    ClientInvocation invocation = new ClientInvocation(((HazelcastClientProxy) client).client, clientMessage, null);
    ClientInvocationFuture future = invocation.invoke();
    try {
        future.get(ASSERT_TRUE_EVENTUALLY_TIMEOUT, SECONDS);
        fail("AccessControlException was expected.");
    } catch (ExecutionException e) {
        assertThat(e.getCause(), is(instanceOf(AccessControlException.class)));
    }
}
Also used : AccessControlException(java.security.AccessControlException) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ExecutionException(java.util.concurrent.ExecutionException) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Aggregations

ClientInvocationFuture (com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)65 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)54 ClientInvocation (com.hazelcast.client.impl.spi.impl.ClientInvocation)44 ClientDelegatingFuture (com.hazelcast.client.impl.ClientDelegatingFuture)34 Data (com.hazelcast.internal.serialization.Data)22 UUID (java.util.UUID)11 Nonnull (javax.annotation.Nonnull)6 ILogger (com.hazelcast.logging.ILogger)5 InternalCompletableFuture (com.hazelcast.spi.impl.InternalCompletableFuture)5 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)5 HazelcastClientInstanceImpl (com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl)4 IterationPointer (com.hazelcast.internal.iteration.IterationPointer)4 SerializationService (com.hazelcast.internal.serialization.SerializationService)4 CachePutCodec (com.hazelcast.client.impl.protocol.codec.CachePutCodec)3 DurableExecutorRetrieveResultCodec (com.hazelcast.client.impl.protocol.codec.DurableExecutorRetrieveResultCodec)3 Member (com.hazelcast.cluster.Member)3 ExecutionCallbackAdapter (com.hazelcast.executor.impl.ExecutionCallbackAdapter)3 StaleSequenceException (com.hazelcast.ringbuffer.StaleSequenceException)3 AccessControlException (java.security.AccessControlException)3 List (java.util.List)3