Search in sources :

Example 16 with ClientInvocation

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

the class ClientRingbufferProxy method addAsync.

@Override
public InternalCompletableFuture<Long> addAsync(@Nonnull E item, @Nonnull OverflowPolicy overflowPolicy) {
    checkNotNull(item, "item can't be null");
    checkNotNull(overflowPolicy, "overflowPolicy can't be null");
    Data element = toData(item);
    ClientMessage request = RingbufferAddCodec.encodeRequest(name, overflowPolicy.getId(), element);
    try {
        ClientInvocationFuture future = new ClientInvocation(getClient(), request, getName(), partitionId).invoke();
        return new ClientDelegatingFuture<>(future, getSerializationService(), RingbufferAddCodec::decodeResponse);
    } catch (Exception e) {
        throw rethrow(e);
    }
}
Also used : ClientDelegatingFuture(com.hazelcast.client.impl.ClientDelegatingFuture) RingbufferAddCodec(com.hazelcast.client.impl.protocol.codec.RingbufferAddCodec) Data(com.hazelcast.internal.serialization.Data) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) StaleSequenceException(com.hazelcast.ringbuffer.StaleSequenceException) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Example 17 with ClientInvocation

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

the class ClientTransactionUtil method invoke.

/**
 * Handles the invocation exception for transactions so that users will not see internal exceptions.
 * <p>
 * More specifically IOException, because in case of a IO problem in ClientInvocation that send to a connection
 * sends IOException to user. This wraps that exception into a TransactionException.
 */
public static ClientMessage invoke(ClientMessage request, Object objectName, HazelcastClientInstanceImpl client, Connection connection) {
    try {
        final ClientInvocation clientInvocation = new ClientInvocation(client, request, objectName, connection);
        final Future<ClientMessage> future = clientInvocation.invoke();
        return future.get();
    } catch (Exception e) {
        throw rethrow(e, TRANSACTION_EXCEPTION_WRAPPER);
    }
}
Also used : ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) TransactionException(com.hazelcast.transaction.TransactionException)

Example 18 with ClientInvocation

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

the class PartitionSpecificClientProxy method invokeOnPartitionInterruptibly.

protected <T> T invokeOnPartitionInterruptibly(ClientMessage clientMessage, long invocationTimeoutSeconds) throws InterruptedException {
    try {
        ClientInvocation clientInvocation = new ClientInvocation(getClient(), clientMessage, getName(), partitionId);
        clientInvocation.setInvocationTimeoutMillis(invocationTimeoutSeconds);
        final Future future = clientInvocation.invoke();
        return (T) future.get();
    } catch (Exception e) {
        throw ExceptionUtil.rethrowAllowInterrupted(e);
    }
}
Also used : Future(java.util.concurrent.Future) ClientDelegatingFuture(com.hazelcast.client.impl.ClientDelegatingFuture) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation)

Example 19 with ClientInvocation

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

the class ClientProxySessionManager method requestNewSession.

@Override
protected SessionResponse requestNewSession(RaftGroupId groupId) {
    ClientMessage request = CPSessionCreateSessionCodec.encodeRequest(groupId, client.getName());
    ClientMessage response = new ClientInvocation(client, request, "sessionManager").invoke().joinInternal();
    CPSessionCreateSessionCodec.ResponseParameters params = CPSessionCreateSessionCodec.decodeResponse(response);
    return new SessionResponse(params.sessionId, params.ttlMillis, params.heartbeatMillis);
}
Also used : ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) SessionResponse(com.hazelcast.cp.internal.session.SessionResponse) CPSessionCreateSessionCodec(com.hazelcast.client.impl.protocol.codec.CPSessionCreateSessionCodec)

Example 20 with ClientInvocation

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

the class ClientProxySessionManager method generateThreadId.

@Override
protected long generateThreadId(RaftGroupId groupId) {
    ClientMessage request = CPSessionGenerateThreadIdCodec.encodeRequest(groupId);
    ClientMessage response = new ClientInvocation(client, request, "sessionManager").invoke().joinInternal();
    return CPSessionGenerateThreadIdCodec.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