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);
}
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);
}
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);
}
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());
}
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);
}
Aggregations