Search in sources :

Example 1 with QueryCacheListenerAdapter

use of com.hazelcast.map.impl.querycache.QueryCacheListenerAdapter 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 2 with QueryCacheListenerAdapter

use of com.hazelcast.map.impl.querycache.QueryCacheListenerAdapter 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.EventRegistration) Registration(com.hazelcast.spi.impl.eventservice.impl.Registration) EventRegistration(com.hazelcast.spi.EventRegistration) QueryCacheListenerAdapter(com.hazelcast.map.impl.querycache.QueryCacheListenerAdapter)

Example 3 with QueryCacheListenerAdapter

use of com.hazelcast.map.impl.querycache.QueryCacheListenerAdapter in project hazelcast by hazelcast.

the class NodeQueryCacheEventService method hasListener.

@Override
public boolean hasListener(String mapName, String cacheName) {
    String listenerName = generateListenerName(mapName, cacheName);
    Collection<EventRegistration> eventRegistrations = getRegistrations(listenerName);
    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.EventRegistration) Registration(com.hazelcast.spi.impl.eventservice.impl.Registration) EventRegistration(com.hazelcast.spi.EventRegistration) QueryCacheListenerAdapter(com.hazelcast.map.impl.querycache.QueryCacheListenerAdapter)

Aggregations

QueryCacheListenerAdapter (com.hazelcast.map.impl.querycache.QueryCacheListenerAdapter)3 EventRegistration (com.hazelcast.spi.EventRegistration)3 Registration (com.hazelcast.spi.impl.eventservice.impl.Registration)3 EntryEventFilter (com.hazelcast.map.impl.EntryEventFilter)1 EventData (com.hazelcast.map.impl.event.EventData)1 LocalCacheWideEventData (com.hazelcast.map.impl.querycache.event.LocalCacheWideEventData)1 LocalEntryEventData (com.hazelcast.map.impl.querycache.event.LocalEntryEventData)1 Data (com.hazelcast.nio.serialization.Data)1 EventFilter (com.hazelcast.spi.EventFilter)1 TrueEventFilter (com.hazelcast.spi.impl.eventservice.impl.TrueEventFilter)1