Search in sources :

Example 41 with EventRegistration

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

the class MapEventPublisherImpl method publishMapPartitionLostEvent.

@Override
public void publishMapPartitionLostEvent(Address caller, String mapName, int partitionId) {
    Collection<EventRegistration> registrations = new LinkedList<>();
    for (EventRegistration registration : getRegistrations(mapName)) {
        if (registration.getFilter() instanceof MapPartitionLostEventFilter) {
            registrations.add(registration);
        }
    }
    if (registrations.isEmpty()) {
        return;
    }
    String thisNodesAddress = getThisNodesAddress();
    MapPartitionEventData eventData = new MapPartitionEventData(thisNodesAddress, mapName, caller, partitionId);
    publishEventInternal(registrations, eventData, partitionId);
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) MapPartitionLostEventFilter(com.hazelcast.map.impl.MapPartitionLostEventFilter) LinkedList(java.util.LinkedList)

Example 42 with EventRegistration

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

the class ReplicatedMapEventPublishingService method fireMapClearedEvent.

public void fireMapClearedEvent(int deletedEntrySize, String name) {
    EventService eventService = nodeEngine.getEventService();
    Collection<EventRegistration> registrations = eventService.getRegistrations(SERVICE_NAME, name);
    if (registrations.isEmpty()) {
        return;
    }
    MapEventData mapEventData = new MapEventData(name, name, nodeEngine.getThisAddress(), EntryEventType.CLEAR_ALL.getType(), deletedEntrySize);
    eventService.publishEvent(SERVICE_NAME, registrations, mapEventData, name.hashCode());
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) EventService(com.hazelcast.spi.impl.eventservice.EventService) MapEventData(com.hazelcast.map.impl.event.MapEventData)

Example 43 with EventRegistration

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

the class NodeQueryCacheEventService method publishLocalEvent.

// TODO needs refactoring.
private void publishLocalEvent(String cacheId, Object eventData, Extractors extractors) {
    Collection<EventRegistration> eventRegistrations = getRegistrations(cacheId);
    if (eventRegistrations.isEmpty()) {
        return;
    }
    for (EventRegistration eventRegistration : eventRegistrations) {
        Registration registration = (Registration) eventRegistration;
        Object listener = registration.getListener();
        if (!(listener instanceof QueryCacheListenerAdapter)) {
            continue;
        }
        Object eventDataToPublish = eventData;
        int orderKey = -1;
        if (eventDataToPublish instanceof LocalCacheWideEventData) {
            orderKey = cacheId.hashCode();
        } else if (eventDataToPublish instanceof LocalEntryEventData) {
            LocalEntryEventData localEntryEventData = (LocalEntryEventData) eventDataToPublish;
            if (localEntryEventData.getEventType() != EventLostEvent.EVENT_TYPE) {
                EventFilter filter = registration.getFilter();
                if (!canPassFilter(localEntryEventData, filter, extractors)) {
                    continue;
                } else {
                    boolean includeValue = isIncludeValue(filter);
                    eventDataToPublish = includeValue ? localEntryEventData : localEntryEventData.cloneWithoutValue();
                    Data keyData = localEntryEventData.getKeyData();
                    orderKey = keyData == null ? -1 : keyData.hashCode();
                }
            }
        }
        publishEventInternal(registration, eventDataToPublish, orderKey);
    }
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) LocalEntryEventData(com.hazelcast.map.impl.querycache.event.LocalEntryEventData) EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) Registration(com.hazelcast.spi.impl.eventservice.impl.Registration) QueryCacheListenerAdapter(com.hazelcast.map.impl.querycache.QueryCacheListenerAdapter) LocalCacheWideEventData(com.hazelcast.map.impl.querycache.event.LocalCacheWideEventData) EventData(com.hazelcast.map.impl.event.EventData) Data(com.hazelcast.internal.serialization.Data) LocalEntryEventData(com.hazelcast.map.impl.querycache.event.LocalEntryEventData) EntryEventFilter(com.hazelcast.map.impl.EntryEventFilter) TrueEventFilter(com.hazelcast.spi.impl.eventservice.impl.TrueEventFilter) EventFilter(com.hazelcast.spi.impl.eventservice.EventFilter) LocalCacheWideEventData(com.hazelcast.map.impl.querycache.event.LocalCacheWideEventData)

Example 44 with EventRegistration

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

the class NodeQueryCacheEventService method sendEventToSubscriber.

@Override
public void sendEventToSubscriber(String name, Object eventData, int orderKey) {
    Collection<EventRegistration> eventRegistrations = getRegistrations(name);
    if (eventRegistrations.isEmpty()) {
        return;
    }
    for (EventRegistration eventRegistration : eventRegistrations) {
        Registration registration = (Registration) eventRegistration;
        Object listener = registration.getListener();
        if (listener instanceof QueryCacheListenerAdapter) {
            continue;
        }
        publishEventInternal(registration, eventData, orderKey);
    }
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) Registration(com.hazelcast.spi.impl.eventservice.impl.Registration) QueryCacheListenerAdapter(com.hazelcast.map.impl.querycache.QueryCacheListenerAdapter)

Example 45 with EventRegistration

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

the class NodeQueryCacheEventService method hasListener.

@Override
public boolean hasListener(String mapName, String cacheId) {
    Collection<EventRegistration> eventRegistrations = getRegistrations(cacheId);
    if (eventRegistrations.isEmpty()) {
        return false;
    }
    for (EventRegistration eventRegistration : eventRegistrations) {
        Registration registration = (Registration) eventRegistration;
        Object listener = registration.getListener();
        if (listener instanceof QueryCacheListenerAdapter) {
            return true;
        }
    }
    return false;
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) Registration(com.hazelcast.spi.impl.eventservice.impl.Registration) QueryCacheListenerAdapter(com.hazelcast.map.impl.querycache.QueryCacheListenerAdapter)

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