use of com.hazelcast.client.impl.spi.impl.ListenerMessageCodec in project hazelcast by hazelcast.
the class ClientCacheClearTest method registerInvalidationListener.
private void registerInvalidationListener(EventHandler handler, String nameWithPrefix) {
ListenerMessageCodec listenerCodec = createInvalidationListenerCodec(nameWithPrefix);
HazelcastClientProxy hzClient = (HazelcastClientProxy) client;
final HazelcastClientInstanceImpl clientInstance = hzClient.client;
clientInstance.getListenerService().registerListener(listenerCodec, handler);
}
use of com.hazelcast.client.impl.spi.impl.ListenerMessageCodec in project hazelcast by hazelcast.
the class ClientMapProxy method addEntryListenerInternal.
private UUID addEntryListenerInternal(@Nonnull ListenerAdapter<IMapEvent> listenerAdaptor, @Nonnull Predicate<K, V> predicate, @Nullable K key, boolean includeValue) {
int listenerFlags = setAndGetListenerFlags(listenerAdaptor);
Data keyData = toData(key);
Data predicateData = toData(predicate);
EventHandler<ClientMessage> handler = new ClientMapToKeyWithPredicateEventHandler(listenerAdaptor);
ListenerMessageCodec codec = createEntryListenerToKeyWithPredicateCodec(includeValue, listenerFlags, keyData, predicateData);
return registerListener(codec, handler);
}
use of com.hazelcast.client.impl.spi.impl.ListenerMessageCodec in project hazelcast by hazelcast.
the class ClientListenerServiceImpl method deregisterListenerInternal.
private Boolean deregisterListenerInternal(@Nullable UUID userRegistrationId) {
// This method should only be called from registrationExecutor
assert (Thread.currentThread().getName().contains("eventRegistration"));
ClientListenerRegistration listenerRegistration = registrations.remove(userRegistrationId);
if (listenerRegistration == null) {
return false;
}
Map<Connection, ClientConnectionRegistration> registrations = listenerRegistration.getConnectionRegistrations();
CompletableFuture[] futures = new CompletableFuture[registrations.size()];
int i = 0;
for (Map.Entry<Connection, ClientConnectionRegistration> entry : registrations.entrySet()) {
ClientConnectionRegistration registration = entry.getValue();
ClientConnection subscriber = (ClientConnection) entry.getKey();
// remove local handler
subscriber.removeEventHandler(registration.getCallId());
// the rest is for deleting remote registration
ListenerMessageCodec listenerMessageCodec = listenerRegistration.getCodec();
UUID serverRegistrationId = registration.getServerRegistrationId();
ClientMessage request = listenerMessageCodec.encodeRemoveRequest(serverRegistrationId);
if (request == null) {
futures[i++] = CompletableFuture.completedFuture(null);
continue;
}
ClientInvocation clientInvocation = new ClientInvocation(client, request, null, subscriber);
clientInvocation.setInvocationTimeoutMillis(Long.MAX_VALUE);
futures[i++] = clientInvocation.invokeUrgent().exceptionally(throwable -> {
if (!(throwable instanceof HazelcastClientNotActiveException || throwable instanceof IOException || throwable instanceof TargetDisconnectedException)) {
logger.warning("Deregistration of listener with ID " + userRegistrationId + " has failed for address " + subscriber.getRemoteAddress(), throwable);
}
return null;
});
}
CompletableFuture.allOf(futures).join();
return true;
}
use of com.hazelcast.client.impl.spi.impl.ListenerMessageCodec 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);
}
Aggregations