Search in sources :

Example 36 with EventRegistration

use of com.hazelcast.spi.impl.eventservice.EventRegistration in project hazelcast by hazelcast.

the class MapServiceContextImpl method addLocalPartitionLostListener.

@Override
public UUID addLocalPartitionLostListener(MapPartitionLostListener listener, String mapName) {
    ListenerAdapter listenerAdapter = new InternalMapPartitionLostListenerAdapter(listener);
    EventFilter filter = new MapPartitionLostEventFilter();
    EventRegistration registration = eventService.registerLocalListener(SERVICE_NAME, mapName, filter, listenerAdapter);
    return registration.getId();
}
Also used : ListenerAdapters.createListenerAdapter(com.hazelcast.map.impl.ListenerAdapters.createListenerAdapter) EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) EventFilter(com.hazelcast.spi.impl.eventservice.EventFilter)

Example 37 with EventRegistration

use of com.hazelcast.spi.impl.eventservice.EventRegistration in project hazelcast by hazelcast.

the class MapServiceContextImpl method addListenerInternalAsync.

private CompletableFuture<UUID> addListenerInternalAsync(Object listener, EventFilter filter, String mapName) {
    ListenerAdapter listenerAdaptor = createListenerAdapter(listener);
    filter = adoptEventFilter(filter, listenerAdaptor);
    return eventService.registerListenerAsync(SERVICE_NAME, mapName, filter, listenerAdaptor).thenApplyAsync(EventRegistration::getId, CALLER_RUNS);
}
Also used : ListenerAdapters.createListenerAdapter(com.hazelcast.map.impl.ListenerAdapters.createListenerAdapter) EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration)

Example 38 with EventRegistration

use of com.hazelcast.spi.impl.eventservice.EventRegistration in project hazelcast by hazelcast.

the class MapServiceContextImpl method addLocalListenerAdapter.

@Override
public UUID addLocalListenerAdapter(ListenerAdapter adapter, String mapName) {
    EventService eventService = getNodeEngine().getEventService();
    EventRegistration registration = eventService.registerLocalListener(MapService.SERVICE_NAME, mapName, adapter);
    return registration.getId();
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) EventService(com.hazelcast.spi.impl.eventservice.EventService)

Example 39 with EventRegistration

use of com.hazelcast.spi.impl.eventservice.EventRegistration in project hazelcast by hazelcast.

the class MapServiceContextImpl method addPartitionLostListener.

@Override
public UUID addPartitionLostListener(MapPartitionLostListener listener, String mapName) {
    ListenerAdapter listenerAdapter = new InternalMapPartitionLostListenerAdapter(listener);
    EventFilter filter = new MapPartitionLostEventFilter();
    EventRegistration registration = eventService.registerListener(SERVICE_NAME, mapName, filter, listenerAdapter);
    return registration.getId();
}
Also used : ListenerAdapters.createListenerAdapter(com.hazelcast.map.impl.ListenerAdapters.createListenerAdapter) EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) EventFilter(com.hazelcast.spi.impl.eventservice.EventFilter)

Example 40 with EventRegistration

use of com.hazelcast.spi.impl.eventservice.EventRegistration in project hazelcast by hazelcast.

the class MapEventPublisherImpl method publishEvent.

/**
 * Publish the event to the specified listener {@code registrations} if
 * the event passes the filters specified by the {@link FilteringStrategy}.
 * <p>
 * The method uses the hashcode of the {@code dataKey} to order the
 * events in the event subsystem. This means that all events for the same
 * key will be ordered. Events with different keys need not be ordered.
 *
 * @param registrations the listener registrations to which we are publishing
 * @param caller        the address of the caller that caused the event
 * @param mapName       the map name
 * @param eventType     the event type
 * @param dataKey       the key of the event map entry
 * @param oldValue      the old value of the map entry
 * @param newValue      the new value of the map entry
 * @param mergingValue  the value used when performing a merge
 *                      operation in case of a {@link EntryEventType#MERGED} event.
 *                      This value together with the old value produced the new value.
 */
private void publishEvent(Collection<EventRegistration> registrations, Address caller, String mapName, EntryEventType eventType, Data dataKey, Object oldValue, Object newValue, Object mergingValue) {
    EntryEventDataCache eventDataCache = filteringStrategy.getEntryEventDataCache();
    int orderKey = pickOrderKey(dataKey);
    for (EventRegistration registration : registrations) {
        publishEventQuietly(caller, mapName, eventType, dataKey, oldValue, newValue, mergingValue, eventDataCache, orderKey, registration);
    }
    // if events were generated, execute the post-publish hook on each one
    if (!eventDataCache.isEmpty()) {
        postPublishEvent(eventDataCache.eventDataIncludingValues(), eventDataCache.eventDataExcludingValues());
    }
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration)

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