use of com.hazelcast.client.spi.impl.ListenerMessageCodec in project hazelcast by hazelcast.
the class ClientSmartListenerService method deregisterListener.
@Override
public boolean deregisterListener(final String userRegistrationId) {
Future<Boolean> future = registrationExecutor.submit(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
ClientRegistrationKey key = new ClientRegistrationKey(userRegistrationId);
Map<Connection, ClientEventRegistration> registrationMap = registrations.get(key);
if (registrationMap == null) {
return false;
}
boolean successful = true;
for (ClientEventRegistration registration : registrationMap.values()) {
Connection subscriber = registration.getSubscriber();
try {
ListenerMessageCodec listenerMessageCodec = registration.getCodec();
String serverRegistrationId = registration.getServerRegistrationId();
ClientMessage request = listenerMessageCodec.encodeRemoveRequest(serverRegistrationId);
new ClientInvocation(client, request, subscriber).invoke().get();
removeEventHandler(registration.getCallId());
registrationMap.remove(subscriber);
} catch (Exception e) {
successful = false;
logger.warning("Deregistration of listener with id " + userRegistrationId + " has failed to address " + subscriber.getEndPoint(), e);
}
}
if (successful) {
registrations.remove(key);
}
return successful;
}
});
try {
return future.get();
} catch (Exception e) {
throw ExceptionUtil.rethrow(e);
}
}
use of com.hazelcast.client.spi.impl.ListenerMessageCodec 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.impl.ListenerMessageCodec 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.impl.ListenerMessageCodec 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);
}
use of com.hazelcast.client.spi.impl.ListenerMessageCodec in project hazelcast by hazelcast.
the class ClientMapProxy method addEntryListenerInternal.
private String addEntryListenerInternal(ListenerAdapter listenerAdaptor, Predicate<K, V> predicate, K key, final boolean includeValue) {
final int listenerFlags = setAndGetListenerFlags(listenerAdaptor);
final Data keyData = toData(key);
final Data predicateData = toData(predicate);
EventHandler<ClientMessage> handler = createHandler(listenerAdaptor);
ListenerMessageCodec codec = createEntryListenerToKeyWithPredicateCodec(includeValue, listenerFlags, keyData, predicateData);
return registerListener(codec, handler);
}
Aggregations