Search in sources :

Example 1 with LocalEntryEventData

use of com.hazelcast.map.impl.querycache.event.LocalEntryEventData 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 LocalEntryEventData

use of com.hazelcast.map.impl.querycache.event.LocalEntryEventData in project hazelcast by hazelcast.

the class EventPublisherHelper method publishEntryEvent.

/**
     * Publishes event upon a change on a key in {@code QueryCache}.
     *
     * @param mapName      the name of underlying map.
     * @param cacheName    the name of {@code QueryCache}
     * @param dataKey      the key in {@code Data} format.
     * @param dataNewValue the value in {@code Data} format.
     * @param oldRecord    the relevant {@code QueryCacheEntry}
     * @param context      the {@code QueryCacheContext}
     */
static void publishEntryEvent(QueryCacheContext context, String mapName, String cacheName, Data dataKey, Data dataNewValue, QueryCacheRecord oldRecord, EntryEventType eventType) {
    QueryCacheEventService eventService = getQueryCacheEventService(context);
    if (!eventService.hasListener(mapName, cacheName)) {
        return;
    }
    Object oldValue = getOldValue(oldRecord);
    LocalEntryEventData eventData = createLocalEntryEventData(cacheName, dataKey, dataNewValue, oldValue, eventType.getType(), -1, context);
    eventService.publish(mapName, cacheName, eventData, dataKey.hashCode());
}
Also used : QueryCacheEventService(com.hazelcast.map.impl.querycache.QueryCacheEventService) LocalEntryEventData(com.hazelcast.map.impl.querycache.event.LocalEntryEventData)

Example 3 with LocalEntryEventData

use of com.hazelcast.map.impl.querycache.event.LocalEntryEventData in project hazelcast by hazelcast.

the class EventPublisherHelper method publishEntryEvent.

/**
 * Publishes event upon a change on a key in {@code QueryCache}.
 *
 * @param mapName       the name of underlying map.
 * @param cacheId       the name of {@code QueryCache}
 * @param queryCacheKey the key in {@code Data} format.
 * @param dataNewValue  the value in {@code Data} format.
 * @param oldRecord     the relevant {@code QueryCacheEntry}
 * @param context       the {@code QueryCacheContext}
 */
static void publishEntryEvent(QueryCacheContext context, String mapName, String cacheId, Object queryCacheKey, Data dataNewValue, QueryCacheRecord oldRecord, EntryEventType eventType, Extractors extractors) {
    if (!hasListener(context, mapName, cacheId)) {
        return;
    }
    Data dataKey = context.getSerializationService().toData(queryCacheKey);
    QueryCacheEventService eventService = getQueryCacheEventService(context);
    Object oldValue = getOldValue(oldRecord);
    LocalEntryEventData eventData = createLocalEntryEventData(cacheId, dataKey, dataNewValue, oldValue, eventType.getType(), -1, context);
    eventService.publish(mapName, cacheId, eventData, dataKey.hashCode(), extractors);
}
Also used : QueryCacheEventService(com.hazelcast.map.impl.querycache.QueryCacheEventService) LocalEntryEventData(com.hazelcast.map.impl.querycache.event.LocalEntryEventData) Data(com.hazelcast.internal.serialization.Data) LocalCacheWideEventData(com.hazelcast.map.impl.querycache.event.LocalCacheWideEventData) LocalEntryEventData(com.hazelcast.map.impl.querycache.event.LocalEntryEventData) EventData(com.hazelcast.map.impl.event.EventData)

Example 4 with LocalEntryEventData

use of com.hazelcast.map.impl.querycache.event.LocalEntryEventData in project hazelcast by hazelcast.

the class EventPublisherHelper method createIMapEvent.

public static IMapEvent createIMapEvent(EventData eventData, EventFilter filter, Member member, SerializationService serializationService) {
    String source = eventData.getSource();
    int eventType = eventData.getEventType();
    if (eventType == EventLostEvent.EVENT_TYPE) {
        LocalEntryEventData localEventData = (LocalEntryEventData) eventData;
        int partitionId = localEventData.getPartitionId();
        return new EventLostEvent(source, null, partitionId);
    }
    if (eventType == EntryEventType.CLEAR_ALL.getType() || eventType == EntryEventType.EVICT_ALL.getType()) {
        LocalCacheWideEventData localCacheWideEventData = (LocalCacheWideEventData) eventData;
        int numberOfEntriesAffected = localCacheWideEventData.getNumberOfEntriesAffected();
        return new MapEvent(source, null, eventType, numberOfEntriesAffected);
    }
    LocalEntryEventData localEntryEventData = (LocalEntryEventData) eventData;
    Data dataKey = localEntryEventData.getKeyData();
    Data dataNewValue = localEntryEventData.getValueData();
    Data dataOldValue = localEntryEventData.getOldValueData();
    boolean includeValue = isIncludeValue(filter);
    return new DataAwareEntryEvent(member, eventType, source, dataKey, (includeValue ? dataNewValue : null), (includeValue ? dataOldValue : null), null, serializationService);
}
Also used : LocalEntryEventData(com.hazelcast.map.impl.querycache.event.LocalEntryEventData) IMapEvent(com.hazelcast.map.IMapEvent) MapEvent(com.hazelcast.map.MapEvent) EventLostEvent(com.hazelcast.map.EventLostEvent) Data(com.hazelcast.internal.serialization.Data) LocalCacheWideEventData(com.hazelcast.map.impl.querycache.event.LocalCacheWideEventData) LocalEntryEventData(com.hazelcast.map.impl.querycache.event.LocalEntryEventData) EventData(com.hazelcast.map.impl.event.EventData) DataAwareEntryEvent(com.hazelcast.map.impl.DataAwareEntryEvent) LocalCacheWideEventData(com.hazelcast.map.impl.querycache.event.LocalCacheWideEventData)

Example 5 with LocalEntryEventData

use of com.hazelcast.map.impl.querycache.event.LocalEntryEventData in project hazelcast by hazelcast.

the class NodeQueryCacheEventService method canPassFilter.

private boolean canPassFilter(LocalEntryEventData localEntryEventData, EventFilter filter) {
    if (filter == null || filter instanceof TrueEventFilter) {
        return true;
    }
    NodeEngine nodeEngine = mapServiceContext.getNodeEngine();
    SerializationService serializationService = nodeEngine.getSerializationService();
    Data keyData = localEntryEventData.getKeyData();
    Object value = getValueOrOldValue(localEntryEventData);
    QueryableEntry entry = new QueryEntry((InternalSerializationService) serializationService, keyData, value, Extractors.empty());
    return filter.eval(entry);
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) QueryEntry(com.hazelcast.query.impl.QueryEntry) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) SerializationService(com.hazelcast.spi.serialization.SerializationService) 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) TrueEventFilter(com.hazelcast.spi.impl.eventservice.impl.TrueEventFilter) QueryableEntry(com.hazelcast.query.impl.QueryableEntry)

Aggregations

LocalEntryEventData (com.hazelcast.map.impl.querycache.event.LocalEntryEventData)8 EventData (com.hazelcast.map.impl.event.EventData)7 LocalCacheWideEventData (com.hazelcast.map.impl.querycache.event.LocalCacheWideEventData)6 Data (com.hazelcast.internal.serialization.Data)5 TrueEventFilter (com.hazelcast.spi.impl.eventservice.impl.TrueEventFilter)5 QueryEntry (com.hazelcast.query.impl.QueryEntry)3 EntryEventFilter (com.hazelcast.map.impl.EntryEventFilter)2 QueryCacheEventService (com.hazelcast.map.impl.querycache.QueryCacheEventService)2 QueryCacheListenerAdapter (com.hazelcast.map.impl.querycache.QueryCacheListenerAdapter)2 Data (com.hazelcast.nio.serialization.Data)2 QueryableEntry (com.hazelcast.query.impl.QueryableEntry)2 Registration (com.hazelcast.spi.impl.eventservice.impl.Registration)2 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)1 SerializationService (com.hazelcast.internal.serialization.SerializationService)1 EventLostEvent (com.hazelcast.map.EventLostEvent)1 IMapEvent (com.hazelcast.map.IMapEvent)1 MapEvent (com.hazelcast.map.MapEvent)1 DataAwareEntryEvent (com.hazelcast.map.impl.DataAwareEntryEvent)1 BatchEventData (com.hazelcast.map.impl.querycache.event.BatchEventData)1 QueryCacheEventData (com.hazelcast.map.impl.querycache.event.QueryCacheEventData)1