Search in sources :

Example 11 with EventRegistration

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);
    }
}
Also used : QueryCacheListenerAdapter(com.hazelcast.map.impl.querycache.QueryCacheListenerAdapter) ListenerAdapter(com.hazelcast.map.impl.ListenerAdapter) EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) ContextMutexFactory(com.hazelcast.internal.util.ContextMutexFactory)

Example 12 with EventRegistration

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());
    }
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) EntryEventData(com.hazelcast.map.impl.event.EntryEventData)

Example 13 with EventRegistration

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);
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) EventService(com.hazelcast.spi.impl.eventservice.EventService)

Example 14 with EventRegistration

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);
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) EventService(com.hazelcast.spi.impl.eventservice.EventService) CachePartitionLostEventFilter(com.hazelcast.cache.impl.event.CachePartitionLostEventFilter) Member(com.hazelcast.cluster.Member) LinkedList(java.util.LinkedList)

Example 15 with EventRegistration

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);
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) EventService(com.hazelcast.spi.impl.eventservice.EventService)

Aggregations

EventRegistration (com.hazelcast.spi.impl.eventservice.EventRegistration)67 EventService (com.hazelcast.spi.impl.eventservice.EventService)45 Data (com.hazelcast.internal.serialization.Data)8 EventFilter (com.hazelcast.spi.impl.eventservice.EventFilter)7 UUID (java.util.UUID)7 Address (com.hazelcast.cluster.Address)4 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 ListenerAdapters.createListenerAdapter (com.hazelcast.map.impl.ListenerAdapters.createListenerAdapter)4 QueryCacheListenerAdapter (com.hazelcast.map.impl.querycache.QueryCacheListenerAdapter)4 CachePartitionLostEventFilter (com.hazelcast.cache.impl.event.CachePartitionLostEventFilter)3 CollectionEventFilter (com.hazelcast.collection.impl.collection.CollectionEventFilter)3 MapPartitionLostEventFilter (com.hazelcast.map.impl.MapPartitionLostEventFilter)3 MapEventData (com.hazelcast.map.impl.event.MapEventData)3 Registration (com.hazelcast.spi.impl.eventservice.impl.Registration)3 InternalCachePartitionLostListenerAdapter (com.hazelcast.cache.impl.event.InternalCachePartitionLostListenerAdapter)2 ItemListener (com.hazelcast.collection.ItemListener)2 EntryEventFilter (com.hazelcast.map.impl.EntryEventFilter)2 EntryEventData (com.hazelcast.map.impl.event.EntryEventData)2 AssertTask (com.hazelcast.test.AssertTask)2 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)2