Search in sources :

Example 26 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)

Example 27 with ClientInvocation

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

the class ClientSmartListenerService method invoke.

private void invoke(ClientRegistrationKey registrationKey, Connection connection) throws Exception {
    //This method should only be called from registrationExecutor
    assert (Thread.currentThread().getName().contains("eventRegistration"));
    Map<Connection, ClientEventRegistration> registrationMap = registrations.get(registrationKey);
    if (registrationMap.containsKey(connection)) {
        return;
    }
    ListenerMessageCodec codec = registrationKey.getCodec();
    ClientMessage request = codec.encodeAddRequest(true);
    EventHandler handler = registrationKey.getHandler();
    handler.beforeListenerRegister();
    ClientInvocation invocation = new ClientInvocation(client, request, connection);
    invocation.setEventHandler(handler);
    ClientInvocationFuture future = invocation.invokeUrgent();
    ClientMessage clientMessage;
    try {
        clientMessage = future.get();
    } catch (Exception e) {
        throw ExceptionUtil.rethrow(e, Exception.class);
    }
    String serverRegistrationId = codec.decodeAddResponse(clientMessage);
    handler.onListenerRegister();
    long correlationId = request.getCorrelationId();
    ClientEventRegistration registration = new ClientEventRegistration(serverRegistrationId, correlationId, connection, codec);
    registrationMap.put(connection, registration);
}
Also used : ListenerMessageCodec(com.hazelcast.client.spi.impl.ListenerMessageCodec) ClientConnection(com.hazelcast.client.connection.nio.ClientConnection) 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) HazelcastException(com.hazelcast.core.HazelcastException) IOException(java.io.IOException) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture)

Example 28 with ClientInvocation

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

the class XATransactionProxy method invoke.

private ClientMessage invoke(ClientMessage request) {
    try {
        final ClientInvocation clientInvocation = new ClientInvocation(client, request, connection);
        final Future<ClientMessage> future = clientInvocation.invoke();
        return future.get();
    } catch (Exception e) {
        throw ExceptionUtil.rethrow(e);
    }
}
Also used : ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) TransactionException(com.hazelcast.transaction.TransactionException) TransactionNotActiveException(com.hazelcast.transaction.TransactionNotActiveException) XAException(javax.transaction.xa.XAException)

Example 29 with ClientInvocation

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

the class ClientProxy method destroy.

@Override
public final void destroy() {
    if (preDestroy()) {
        onDestroy();
        ClientMessage clientMessage = ClientDestroyProxyCodec.encodeRequest(getDistributedObjectName(), getServiceName());
        context.removeProxy(this);
        try {
            new ClientInvocation(getClient(), clientMessage).invoke().get();
            postDestroy();
        } catch (Exception e) {
            throw ExceptionUtil.rethrow(e);
        }
    }
}
Also used : ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage)

Example 30 with ClientInvocation

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

the class ProxyManager method initialize.

private void initialize(ClientProxy clientProxy) throws Exception {
    final Address initializationTarget = findNextAddressToSendCreateRequest();
    final Connection connection = getTargetOrOwnerConnection(initializationTarget);
    final ClientMessage clientMessage = ClientCreateProxyCodec.encodeRequest(clientProxy.getDistributedObjectName(), clientProxy.getServiceName(), initializationTarget);
    final ClientContext context = new ClientContext(client, this);
    new ClientInvocation(client, clientMessage, connection).invoke().get();
    clientProxy.setContext(context);
    clientProxy.onInitialize();
}
Also used : Address(com.hazelcast.nio.Address) Connection(com.hazelcast.nio.Connection) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage)

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