use of com.hazelcast.spi.impl.eventservice.EventRegistration in project hazelcast by hazelcast.
the class NodeQueryCacheEventService method addListener.
@Override
public UUID addListener(String mapName, String cacheId, MapListener listener, EventFilter filter) {
checkHasText(mapName, "mapName");
checkHasText(cacheId, "cacheId");
checkNotNull(listener, "listener cannot be null");
ListenerAdapter queryCacheListenerAdaptor = createQueryCacheListenerAdaptor(listener);
ListenerAdapter listenerAdaptor = new SimpleQueryCacheListenerAdapter(queryCacheListenerAdaptor);
ContextMutexFactory.Mutex mutex = lifecycleMutexFactory.mutexFor(mapName);
try {
synchronized (mutex) {
EventRegistration registration = eventService.registerLocalListener(SERVICE_NAME, cacheId, filter == null ? TrueEventFilter.INSTANCE : filter, listenerAdaptor);
return registration.getId();
}
} finally {
closeResource(mutex);
}
}
use of com.hazelcast.spi.impl.eventservice.EventRegistration in project hazelcast by hazelcast.
the class ReplicatedMapEventPublishingService method fireEntryListenerEvent.
public void fireEntryListenerEvent(Data key, Data oldValue, Data value, EntryEventType eventType, String name, Address caller) {
Collection<EventRegistration> registrations = eventService.getRegistrations(SERVICE_NAME, name);
if (registrations.isEmpty()) {
return;
}
EntryEventData eventData = new EntryEventData(name, name, caller, key, value, oldValue, eventType.getType());
for (EventRegistration registration : registrations) {
if (!shouldPublish(key, oldValue, value, eventType, registration.getFilter())) {
continue;
}
eventService.publishEvent(SERVICE_NAME, registration, eventData, key.hashCode());
}
}
use of com.hazelcast.spi.impl.eventservice.EventRegistration in project hazelcast by hazelcast.
the class QueueService method addItemListenerAsync.
public CompletableFuture<UUID> addItemListenerAsync(String name, ItemListener listener, boolean includeValue) {
EventService eventService = nodeEngine.getEventService();
QueueEventFilter filter = new QueueEventFilter(includeValue);
return eventService.registerListenerAsync(QueueService.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 AbstractCacheService method publishCachePartitionLostEvent.
protected void publishCachePartitionLostEvent(String cacheName, int partitionId) {
Collection<EventRegistration> registrations = new LinkedList<>();
for (EventRegistration registration : getRegistrations(cacheName)) {
if (registration.getFilter() instanceof CachePartitionLostEventFilter) {
registrations.add(registration);
}
}
if (registrations.isEmpty()) {
return;
}
Member member = nodeEngine.getLocalMember();
CacheEventData eventData = new CachePartitionEventData(cacheName, partitionId, member);
EventService eventService = nodeEngine.getEventService();
eventService.publishEvent(SERVICE_NAME, registrations, eventData, partitionId);
}
use of com.hazelcast.spi.impl.eventservice.EventRegistration in project hazelcast by hazelcast.
the class AbstractCacheService method registerListener.
@Override
public UUID registerListener(String cacheNameWithPrefix, CacheEventListener listener, EventFilter eventFilter) {
EventService eventService = getNodeEngine().getEventService();
EventRegistration registration = eventService.registerListener(AbstractCacheService.SERVICE_NAME, cacheNameWithPrefix, eventFilter, listener);
return updateRegisteredListeners(listener, registration);
}
Aggregations