Search in sources :

Example 6 with EventHandler

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

the class ClientListenerServiceImpl method invoke.

protected void invoke(ClientListenerRegistration listenerRegistration, Connection connection) throws Exception {
    // This method should only be called from registrationExecutor
    assert (Thread.currentThread().getName().contains("eventRegistration"));
    if (listenerRegistration.getConnectionRegistrations().containsKey(connection)) {
        return;
    }
    ListenerMessageCodec codec = listenerRegistration.getCodec();
    ClientMessage request = codec.encodeAddRequest(registersLocalOnly());
    EventHandler handler = listenerRegistration.getHandler();
    if (logger.isFinestEnabled()) {
        logger.finest("Register attempt of " + listenerRegistration + " to " + connection);
    }
    handler.beforeListenerRegister(connection);
    ClientInvocation invocation = new ClientInvocation(client, request, null, connection);
    invocation.setEventHandler(handler);
    ClientInvocationFuture future = invocation.invokeUrgent();
    ClientMessage clientMessage;
    try {
        clientMessage = future.get();
    } catch (Exception e) {
        throw ExceptionUtil.rethrow(e, Exception.class);
    }
    UUID serverRegistrationId = codec.decodeAddResponse(clientMessage);
    if (logger.isFinestEnabled()) {
        logger.finest("Registered " + listenerRegistration + " to " + connection);
    }
    handler.onListenerRegister(connection);
    long correlationId = request.getCorrelationId();
    ClientConnectionRegistration registration = new ClientConnectionRegistration(serverRegistrationId, correlationId);
    listenerRegistration.getConnectionRegistrations().put(connection, registration);
}
Also used : ListenerMessageCodec(com.hazelcast.client.impl.spi.impl.ListenerMessageCodec) EventHandler(com.hazelcast.client.impl.spi.EventHandler) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) UUID(java.util.UUID) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) HazelcastClientNotActiveException(com.hazelcast.client.HazelcastClientNotActiveException) HazelcastException(com.hazelcast.core.HazelcastException) IOException(java.io.IOException) TargetDisconnectedException(com.hazelcast.spi.exception.TargetDisconnectedException) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Example 7 with EventHandler

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

the class ClientInvocationServiceImpl method registerInvocation.

// package-visible for tests
void registerInvocation(ClientInvocation clientInvocation, ClientConnection connection) {
    ClientMessage clientMessage = clientInvocation.getClientMessage();
    long correlationId = clientMessage.getCorrelationId();
    invocations.put(correlationId, clientInvocation);
    EventHandler handler = clientInvocation.getEventHandler();
    if (handler != null) {
        connection.addEventHandler(correlationId, handler);
    }
}
Also used : EventHandler(com.hazelcast.client.impl.spi.EventHandler) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage)

Aggregations

EventHandler (com.hazelcast.client.impl.spi.EventHandler)7 ClientConnection (com.hazelcast.client.impl.connection.ClientConnection)2 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)2 Connection (com.hazelcast.internal.nio.Connection)2 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Test (org.junit.Test)2 CacheClearTest (com.hazelcast.cache.CacheClearTest)1 HazelcastClientNotActiveException (com.hazelcast.client.HazelcastClientNotActiveException)1 HazelcastClientInstanceImpl (com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl)1 ClientConnectionManager (com.hazelcast.client.impl.connection.ClientConnectionManager)1 ClientListenerService (com.hazelcast.client.impl.spi.ClientListenerService)1 ClientInvocation (com.hazelcast.client.impl.spi.impl.ClientInvocation)1 ClientInvocationFuture (com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)1 ListenerMessageCodec (com.hazelcast.client.impl.spi.impl.ListenerMessageCodec)1 CacheConfig (com.hazelcast.config.CacheConfig)1 NearCacheConfig (com.hazelcast.config.NearCacheConfig)1 HazelcastException (com.hazelcast.core.HazelcastException)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1