use of com.hazelcast.spi.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;
final Address caller = nodeEngine.getThisAddress();
final 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.EventRegistration in project hazelcast by hazelcast.
the class MultiMapService method addListener.
public String addListener(String name, EventListener listener, Data key, boolean includeValue, boolean local) {
EventService eventService = nodeEngine.getEventService();
EventRegistration registration;
final MultiMapEventFilter filter = new MultiMapEventFilter(includeValue, key);
if (local) {
registration = eventService.registerLocalListener(SERVICE_NAME, name, filter, listener);
} else {
registration = eventService.registerListener(SERVICE_NAME, name, filter, listener);
}
return registration.getId();
}
use of com.hazelcast.spi.EventRegistration in project hazelcast by hazelcast.
the class CollectionOperation method publishEvent.
protected void publishEvent(ItemEventType eventType, Data data) {
EventService eventService = getNodeEngine().getEventService();
Collection<EventRegistration> registrations = eventService.getRegistrations(getServiceName(), name);
final Address address = getNodeEngine().getThisAddress();
for (EventRegistration registration : registrations) {
CollectionEventFilter filter = (CollectionEventFilter) registration.getFilter();
final boolean includeValue = filter.isIncludeValue();
CollectionEvent event = new CollectionEvent(name, includeValue ? data : null, eventType, address);
eventService.publishEvent(getServiceName(), registration, event, name.hashCode());
}
}
use of com.hazelcast.spi.EventRegistration in project hazelcast by hazelcast.
the class BatchInvalidator method sendInvalidations.
private void sendInvalidations(String dataStructureName, List<Invalidation> invalidations) {
// There will always be at least one listener which listens invalidations. This is the reason behind eager creation
// of BatchNearCacheInvalidation instance here. There is a causality between listener and invalidation. Only if we have
// a listener, we can have an invalidation, otherwise invalidations are not generated.
Invalidation invalidation = new BatchNearCacheInvalidation(dataStructureName, invalidations);
Collection<EventRegistration> registrations = eventService.getRegistrations(serviceName, dataStructureName);
for (EventRegistration registration : registrations) {
if (eventFilter.apply(registration)) {
// find worker queue of striped executor by using subscribers' address.
// we want to send all batch invalidations belonging to same subscriber go into
// the same workers queue.
int orderKey = registration.getSubscriber().hashCode();
eventService.publishEvent(serviceName, registration, invalidation, orderKey);
}
}
}
use of com.hazelcast.spi.EventRegistration in project hazelcast by hazelcast.
the class Invalidator method sendImmediately.
protected final void sendImmediately(Invalidation invalidation, int orderKey) {
String dataStructureName = invalidation.getName();
Collection<EventRegistration> registrations = eventService.getRegistrations(serviceName, dataStructureName);
for (EventRegistration registration : registrations) {
if (eventFilter.apply(registration)) {
eventService.publishEvent(serviceName, registration, invalidation, orderKey);
}
}
}
Aggregations