Search in sources :

Example 1 with TrueEventFilter

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

the class QueryCacheNaturalFilteringStrategy method doFilter.

@SuppressWarnings({ "checkstyle:npathcomplexity", "checkstyle:cyclomaticcomplexity" })
@Override
public int doFilter(EventFilter filter, Data dataKey, Object dataOldValue, Object dataValue, EntryEventType eventType, String mapNameOrNull) {
    if (filter instanceof MapPartitionLostEventFilter) {
        return FILTER_DOES_NOT_MATCH;
    }
    // Since the event type may change if we have a QueryEventFilter to evaluate,
    // the effective event type may change after execution of QueryEventFilter.eval
    EventListenerFilter filterAsEventListenerFilter = null;
    boolean originalFilterEventTypeMatches = true;
    if (filter instanceof EventListenerFilter) {
        int type = eventType.getType();
        if (type == INVALIDATION.getType()) {
            return FILTER_DOES_NOT_MATCH;
        }
        // evaluate whether the filter matches the original event type
        originalFilterEventTypeMatches = filter.eval(type);
        // hold a reference to the original event filter; this may be used later, in case there is a query event filter
        // and it alters the event type to be published
        filterAsEventListenerFilter = ((EventListenerFilter) filter);
        filter = ((EventListenerFilter) filter).getEventFilter();
        if (filter instanceof UuidFilter) {
            return FILTER_DOES_NOT_MATCH;
        }
    }
    if (originalFilterEventTypeMatches && filter instanceof TrueEventFilter) {
        return eventType.getType();
    }
    if (filter instanceof QueryEventFilter) {
        int effectiveEventType = processQueryEventFilterWithAlternativeEventType(filter, eventType, dataKey, dataOldValue, dataValue, mapNameOrNull);
        if (effectiveEventType == FILTER_DOES_NOT_MATCH) {
            return FILTER_DOES_NOT_MATCH;
        } else {
            // wants to listen for (if effective event type != original event type
            if (filterAsEventListenerFilter != null && effectiveEventType != eventType.getType()) {
                return filterAsEventListenerFilter.eval(effectiveEventType) ? effectiveEventType : FILTER_DOES_NOT_MATCH;
            } else {
                return effectiveEventType;
            }
        }
    }
    if (filter instanceof EntryEventFilter) {
        return (originalFilterEventTypeMatches && processEntryEventFilter(filter, dataKey)) ? eventType.getType() : FILTER_DOES_NOT_MATCH;
    }
    throw new IllegalArgumentException("Unknown EventFilter type = [" + filter.getClass().getCanonicalName() + "]");
}
Also used : UuidFilter(com.hazelcast.map.impl.nearcache.invalidation.UuidFilter) QueryEventFilter(com.hazelcast.map.impl.query.QueryEventFilter) EntryEventFilter(com.hazelcast.map.impl.EntryEventFilter) MapPartitionLostEventFilter(com.hazelcast.map.impl.MapPartitionLostEventFilter) EventListenerFilter(com.hazelcast.map.impl.EventListenerFilter) TrueEventFilter(com.hazelcast.spi.impl.eventservice.impl.TrueEventFilter)

Example 2 with TrueEventFilter

use of com.hazelcast.spi.impl.eventservice.impl.TrueEventFilter 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

TrueEventFilter (com.hazelcast.spi.impl.eventservice.impl.TrueEventFilter)2 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)1 EntryEventFilter (com.hazelcast.map.impl.EntryEventFilter)1 EventListenerFilter (com.hazelcast.map.impl.EventListenerFilter)1 MapPartitionLostEventFilter (com.hazelcast.map.impl.MapPartitionLostEventFilter)1 EventData (com.hazelcast.map.impl.event.EventData)1 UuidFilter (com.hazelcast.map.impl.nearcache.invalidation.UuidFilter)1 QueryEventFilter (com.hazelcast.map.impl.query.QueryEventFilter)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 QueryEntry (com.hazelcast.query.impl.QueryEntry)1 QueryableEntry (com.hazelcast.query.impl.QueryableEntry)1 NodeEngine (com.hazelcast.spi.NodeEngine)1 SerializationService (com.hazelcast.spi.serialization.SerializationService)1