use of com.hazelcast.spi.impl.eventservice.EventRegistration in project hazelcast by hazelcast.
the class MultiMapService method addListenerAsync.
public CompletableFuture<UUID> addListenerAsync(String name, @Nonnull EventListener listener, Data key, boolean includeValue) {
EventService eventService = nodeEngine.getEventService();
MultiMapEventFilter filter = new MultiMapEventFilter(includeValue, key);
return eventService.registerListenerAsync(SERVICE_NAME, name, filter, listener).thenApplyAsync(EventRegistration::getId, CALLER_RUNS);
}
use of com.hazelcast.spi.impl.eventservice.EventRegistration in project hazelcast by hazelcast.
the class MultiMapEventsPublisher method publishEntryEvent.
public final void publishEntryEvent(String multiMapName, EntryEventType eventType, Data key, Object newValue, Object oldValue) {
EventService eventService = nodeEngine.getEventService();
Collection<EventRegistration> registrations = eventService.getRegistrations(MultiMapService.SERVICE_NAME, multiMapName);
for (EventRegistration registration : registrations) {
MultiMapEventFilter filter = (MultiMapEventFilter) registration.getFilter();
if (filter.getKey() == null || filter.getKey().equals(key)) {
Data dataNewValue = filter.isIncludeValue() ? nodeEngine.toData(newValue) : null;
Data dataOldValue = filter.isIncludeValue() ? nodeEngine.toData(oldValue) : null;
Address caller = nodeEngine.getThisAddress();
String source = caller.toString();
EntryEventData event = new EntryEventData(source, multiMapName, caller, key, dataNewValue, dataOldValue, eventType.getType());
eventService.publishEvent(MultiMapService.SERVICE_NAME, registration, event, multiMapName.hashCode());
}
}
}
use of com.hazelcast.spi.impl.eventservice.EventRegistration in project hazelcast by hazelcast.
the class MultiMapEventsPublisher method publishMultiMapEvent.
public void publishMultiMapEvent(String mapName, EntryEventType eventType, int numberOfEntriesAffected) {
EventService eventService = nodeEngine.getEventService();
Collection<EventRegistration> registrations = eventService.getRegistrations(MultiMapService.SERVICE_NAME, mapName);
if (registrations.isEmpty()) {
return;
}
Address caller = nodeEngine.getThisAddress();
String source = caller.toString();
MapEventData mapEventData = new MapEventData(source, mapName, caller, eventType.getType(), numberOfEntriesAffected);
eventService.publishEvent(MultiMapService.SERVICE_NAME, registrations, mapEventData, mapName.hashCode());
}
use of com.hazelcast.spi.impl.eventservice.EventRegistration in project hazelcast by hazelcast.
the class EventServiceImpl method publishEvent.
@Override
public void publishEvent(String serviceName, Collection<EventRegistration> registrations, Object event, int orderKey) {
Data eventData = null;
for (EventRegistration registration : registrations) {
if (!(registration instanceof Registration)) {
throw new IllegalArgumentException();
}
if (isLocal(registration)) {
executeLocal(serviceName, event, registration, orderKey);
continue;
}
if (eventData == null) {
eventData = serializationService.toData(event);
}
EventEnvelope eventEnvelope = new EventEnvelope(registration.getId(), serviceName, eventData);
sendEvent(registration.getSubscriber(), eventEnvelope, orderKey);
}
}
use of com.hazelcast.spi.impl.eventservice.EventRegistration in project hazelcast by hazelcast.
the class EventServiceImpl method publishRemoteEvent.
/**
* {@inheritDoc}
*
* @param serviceName service name
* @param registrations multiple event registrations
* @param event event object
* @param orderKey order key
* @throws IllegalArgumentException if any registration is not an instance of {@link Registration}
*/
@Override
public void publishRemoteEvent(String serviceName, Collection<EventRegistration> registrations, Object event, int orderKey) {
if (registrations.isEmpty()) {
return;
}
Data eventData = serializationService.toData(event);
for (EventRegistration registration : registrations) {
if (!(registration instanceof Registration)) {
throw new IllegalArgumentException();
}
if (isLocal(registration)) {
continue;
}
EventEnvelope eventEnvelope = new EventEnvelope(registration.getId(), serviceName, eventData);
sendEvent(registration.getSubscriber(), eventEnvelope, orderKey);
}
}
Aggregations