Search in sources :

Example 6 with EventHandler

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

the class ClientNearCacheInvalidationTest method registerInvalidationListener.

private void registerInvalidationListener(AtomicInteger counter) {
    EventHandler handler = new NearCacheRepairingHandler(counter);
    ListenerMessageCodec listenerCodec = createInvalidationListenerCodec();
    final HazelcastClientInstanceImpl clientInstance = testContext.client.client;
    clientInstance.getListenerService().registerListener(listenerCodec, handler);
}
Also used : ListenerMessageCodec(com.hazelcast.client.spi.impl.ListenerMessageCodec) EventHandler(com.hazelcast.client.spi.EventHandler) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl)

Example 7 with EventHandler

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

the class AbstractClientInternalCacheProxy method registerInvalidationListener.

private void registerInvalidationListener() {
    if (nearCache == null || !nearCache.isInvalidatedOnChange()) {
        return;
    }
    ListenerMessageCodec listenerCodec = createInvalidationListenerCodec();
    ClientListenerService listenerService = clientContext.getListenerService();
    EventHandler eventHandler = createInvalidationEventHandler();
    nearCacheMembershipRegistrationId = listenerService.registerListener(listenerCodec, eventHandler);
}
Also used : ClientListenerService(com.hazelcast.client.spi.ClientListenerService) ListenerMessageCodec(com.hazelcast.client.spi.impl.ListenerMessageCodec) EventHandler(com.hazelcast.client.spi.EventHandler)

Example 8 with EventHandler

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

the class ClientQueryCacheEventService method listenPublisher.

@Override
public String listenPublisher(String mapName, String cacheName, ListenerAdapter adapter) {
    final String listenerName = generateListenerName(mapName, cacheName);
    EventHandler handler = new QueryCacheHandler(adapter);
    return listenerService.registerListener(createPublisherListenerCodec(listenerName), handler);
}
Also used : EventHandler(com.hazelcast.client.spi.EventHandler)

Example 9 with EventHandler

use of com.hazelcast.client.spi.EventHandler 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 10 with EventHandler

use of com.hazelcast.client.spi.EventHandler 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)

Aggregations

EventHandler (com.hazelcast.client.spi.EventHandler)11 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)3 ListenerMessageCodec (com.hazelcast.client.spi.impl.ListenerMessageCodec)3 Connection (com.hazelcast.nio.Connection)3 ParallelTest (com.hazelcast.test.annotation.ParallelTest)3 QuickTest (com.hazelcast.test.annotation.QuickTest)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Test (org.junit.Test)3 CacheClearTest (com.hazelcast.cache.CacheClearTest)2 HazelcastClientInstanceImpl (com.hazelcast.client.impl.HazelcastClientInstanceImpl)2 ClientListenerService (com.hazelcast.client.spi.ClientListenerService)2 ClientInvocation (com.hazelcast.client.spi.impl.ClientInvocation)2 ClientInvocationFuture (com.hazelcast.client.spi.impl.ClientInvocationFuture)2 CacheConfig (com.hazelcast.config.CacheConfig)2 NearCacheConfig (com.hazelcast.config.NearCacheConfig)2 AssertTask (com.hazelcast.test.AssertTask)2 Map (java.util.Map)2 CacheEventListenerAdaptor (com.hazelcast.cache.impl.CacheEventListenerAdaptor)1 ClientConfig (com.hazelcast.client.config.ClientConfig)1 ClientConnection (com.hazelcast.client.connection.nio.ClientConnection)1