Search in sources :

Example 6 with EventRegistration

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

the class TopicDestroyTest method assertRegistrationSize.

void assertRegistrationSize(int size) {
    EventService eventService = getNode(instance).getNodeEngine().getEventService();
    Collection<EventRegistration> regs = eventService.getRegistrations(TopicService.SERVICE_NAME, topicName);
    assertEquals(size, regs.size());
}
Also used : EventRegistration(com.hazelcast.spi.EventRegistration) EventService(com.hazelcast.spi.EventService)

Example 7 with EventRegistration

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

the class NodeQueryCacheEventService method addListener.

@Override
public String addListener(String mapName, String cacheName, MapListener listener, EventFilter filter) {
    checkHasText(mapName, "mapName");
    checkHasText(cacheName, "cacheName");
    checkNotNull(listener, "listener cannot be null");
    ListenerAdapter queryCacheListenerAdaptor = createQueryCacheListenerAdaptor(listener);
    ListenerAdapter listenerAdaptor = new SimpleQueryCacheListenerAdapter(queryCacheListenerAdaptor);
    NodeEngine nodeEngine = mapServiceContext.getNodeEngine();
    EventService eventService = nodeEngine.getEventService();
    String listenerName = generateListenerName(mapName, cacheName);
    EventRegistration registration;
    if (filter == null) {
        registration = eventService.registerLocalListener(MapService.SERVICE_NAME, listenerName, listenerAdaptor);
    } else {
        registration = eventService.registerLocalListener(MapService.SERVICE_NAME, listenerName, filter, listenerAdaptor);
    }
    return registration.getId();
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) QueryCacheListenerAdapter(com.hazelcast.map.impl.querycache.QueryCacheListenerAdapter) ListenerAdapter(com.hazelcast.map.impl.ListenerAdapter) EventRegistration(com.hazelcast.spi.EventRegistration) QueryCacheEventService(com.hazelcast.map.impl.querycache.QueryCacheEventService) EventService(com.hazelcast.spi.EventService)

Example 8 with EventRegistration

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

the class NodeQueryCacheEventService method publishLocalEvent.

// TODO needs refactoring.
private void publishLocalEvent(String mapName, String cacheName, Object eventData) {
    String listenerName = generateListenerName(mapName, cacheName);
    Collection<EventRegistration> eventRegistrations = getRegistrations(listenerName);
    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 = listenerName.hashCode();
        } else if (eventDataToPublish instanceof LocalEntryEventData) {
            LocalEntryEventData localEntryEventData = (LocalEntryEventData) eventDataToPublish;
            if (localEntryEventData.getEventType() != EventLostEvent.EVENT_TYPE) {
                EventFilter filter = registration.getFilter();
                if (!canPassFilter(localEntryEventData, filter)) {
                    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.EventRegistration) LocalEntryEventData(com.hazelcast.map.impl.querycache.event.LocalEntryEventData) Registration(com.hazelcast.spi.impl.eventservice.impl.Registration) EventRegistration(com.hazelcast.spi.EventRegistration) 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.nio.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.EventFilter) LocalCacheWideEventData(com.hazelcast.map.impl.querycache.event.LocalCacheWideEventData)

Example 9 with EventRegistration

use of com.hazelcast.spi.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.EventRegistration) EntryEventData(com.hazelcast.map.impl.event.EntryEventData)

Example 10 with EventRegistration

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

the class EventServiceImpl method close.

@Override
public void close(EventRegistration eventRegistration) {
    Registration registration = (Registration) eventRegistration;
    Object listener = registration.getListener();
    if (!(listener instanceof Closeable)) {
        return;
    }
    try {
        ((Closeable) listener).close();
    } catch (IOException e) {
        EmptyStatement.ignore(e);
    }
}
Also used : EventRegistration(com.hazelcast.spi.EventRegistration) Closeable(java.io.Closeable) IOException(java.io.IOException)

Aggregations

EventRegistration (com.hazelcast.spi.EventRegistration)55 EventService (com.hazelcast.spi.EventService)37 Data (com.hazelcast.nio.serialization.Data)7 EventFilter (com.hazelcast.spi.EventFilter)7 Address (com.hazelcast.nio.Address)5 TrueEventFilter (com.hazelcast.spi.impl.eventservice.impl.TrueEventFilter)5 QueryCacheListenerAdapter (com.hazelcast.map.impl.querycache.QueryCacheListenerAdapter)4 CachePartitionLostEventFilter (com.hazelcast.cache.impl.event.CachePartitionLostEventFilter)3 ClientEndpoint (com.hazelcast.client.ClientEndpoint)3 CollectionEventFilter (com.hazelcast.collection.impl.collection.CollectionEventFilter)3 EntryEventFilter (com.hazelcast.map.impl.EntryEventFilter)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 InitialMembershipEvent (com.hazelcast.core.InitialMembershipEvent)2 ItemListener (com.hazelcast.core.ItemListener)2 Member (com.hazelcast.core.Member)2 MigrationEvent (com.hazelcast.core.MigrationEvent)2 MemberImpl (com.hazelcast.instance.MemberImpl)2