Search in sources :

Example 1 with QueryEventFilter

use of com.hazelcast.map.impl.query.QueryEventFilter in project hazelcast by hazelcast.

the class MapAddEntryListenerToKeyWithPredicateMessageTask method getEventFilter.

@Override
protected EventFilter getEventFilter() {
    Predicate predicate = serializationService.toObject(parameters.predicate);
    QueryEventFilter eventFilter = new QueryEventFilter(parameters.key, predicate, parameters.includeValue);
    return new EventListenerFilter(parameters.listenerFlags, eventFilter);
}
Also used : QueryEventFilter(com.hazelcast.map.impl.query.QueryEventFilter) EventListenerFilter(com.hazelcast.map.impl.EventListenerFilter) Predicate(com.hazelcast.query.Predicate)

Example 2 with QueryEventFilter

use of com.hazelcast.map.impl.query.QueryEventFilter in project hazelcast by hazelcast.

the class DefaultQueryCache method addEntryListener.

@Override
public UUID addEntryListener(MapListener listener, Predicate<K, V> predicate, boolean includeValue) {
    checkNotNull(listener, "listener cannot be null");
    checkNotNull(predicate, "predicate cannot be null");
    QueryCacheEventService eventService = getEventService();
    EventFilter filter = new QueryEventFilter(null, predicate, includeValue);
    String mapName = delegate.getName();
    return eventService.addListener(mapName, cacheId, listener, filter);
}
Also used : QueryCacheEventService(com.hazelcast.map.impl.querycache.QueryCacheEventService) QueryEventFilter(com.hazelcast.map.impl.query.QueryEventFilter) EntryEventFilter(com.hazelcast.map.impl.EntryEventFilter) QueryEventFilter(com.hazelcast.map.impl.query.QueryEventFilter) EventFilter(com.hazelcast.spi.impl.eventservice.EventFilter)

Example 3 with QueryEventFilter

use of com.hazelcast.map.impl.query.QueryEventFilter in project hazelcast by hazelcast.

the class DefaultQueryCache method addEntryListener.

@Override
public UUID addEntryListener(MapListener listener, Predicate<K, V> predicate, K key, boolean includeValue) {
    checkNotNull(listener, "listener cannot be null");
    checkNotNull(predicate, "predicate cannot be null");
    checkNotNull(key, "key cannot be null");
    QueryCacheEventService eventService = getEventService();
    EventFilter filter = new QueryEventFilter(toData(key), predicate, includeValue);
    String mapName = delegate.getName();
    return eventService.addListener(mapName, cacheId, listener, filter);
}
Also used : QueryCacheEventService(com.hazelcast.map.impl.querycache.QueryCacheEventService) QueryEventFilter(com.hazelcast.map.impl.query.QueryEventFilter) EntryEventFilter(com.hazelcast.map.impl.EntryEventFilter) QueryEventFilter(com.hazelcast.map.impl.query.QueryEventFilter) EventFilter(com.hazelcast.spi.impl.eventservice.EventFilter)

Example 4 with QueryEventFilter

use of com.hazelcast.map.impl.query.QueryEventFilter in project hazelcast by hazelcast.

the class PartitionAccumulatorRegistry method createEventFilter.

private EventFilter createEventFilter() {
    boolean includeValue = info.isIncludeValue();
    Predicate predicate = info.getPredicate();
    return new QueryEventFilter(null, predicate, includeValue);
}
Also used : QueryEventFilter(com.hazelcast.map.impl.query.QueryEventFilter) Predicate(com.hazelcast.query.Predicate)

Example 5 with QueryEventFilter

use of com.hazelcast.map.impl.query.QueryEventFilter in project hazelcast by hazelcast.

the class QueryCacheNaturalFilteringStrategy method doFilter.

@SuppressWarnings({ "checkstyle:npathcomplexity", "checkstyle:cyclomaticcomplexity" })
@Override
public int doFilter(EventFilter filter, Data dataKey, Object oldValue, 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 (filter instanceof TrueEventFilter) {
        return originalFilterEventTypeMatches ? eventType.getType() : FILTER_DOES_NOT_MATCH;
    }
    if (filter instanceof QueryEventFilter) {
        int effectiveEventType = processQueryEventFilterWithAlternativeEventType(filter, eventType, dataKey, oldValue, 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)

Aggregations

QueryEventFilter (com.hazelcast.map.impl.query.QueryEventFilter)8 EntryEventFilter (com.hazelcast.map.impl.EntryEventFilter)3 EventListenerFilter (com.hazelcast.map.impl.EventListenerFilter)3 UuidFilter (com.hazelcast.map.impl.nearcache.invalidation.UuidFilter)2 QueryCacheEventService (com.hazelcast.map.impl.querycache.QueryCacheEventService)2 Predicate (com.hazelcast.query.Predicate)2 EventFilter (com.hazelcast.spi.impl.eventservice.EventFilter)2 MapAssignAndGetUuidsOperation (com.hazelcast.client.impl.protocol.task.map.MapAssignAndGetUuidsOperation)1 MapAssignAndGetUuidsOperationFactory (com.hazelcast.client.impl.protocol.task.map.MapAssignAndGetUuidsOperationFactory)1 IndexIterationPointer (com.hazelcast.internal.iteration.IndexIterationPointer)1 LocalRecordStoreStatsImpl (com.hazelcast.internal.monitor.impl.LocalRecordStoreStatsImpl)1 BatchNearCacheInvalidation (com.hazelcast.internal.nearcache.impl.invalidation.BatchNearCacheInvalidation)1 SingleNearCacheInvalidation (com.hazelcast.internal.nearcache.impl.invalidation.SingleNearCacheInvalidation)1 ArrayDataSerializableFactory (com.hazelcast.internal.serialization.impl.ArrayDataSerializableFactory)1 ConstructorFunction (com.hazelcast.internal.util.ConstructorFunction)1 MapPartitionLostEventFilter (com.hazelcast.map.impl.MapPartitionLostEventFilter)1 MapEntriesWithCursor (com.hazelcast.map.impl.iterator.MapEntriesWithCursor)1 MapKeysWithCursor (com.hazelcast.map.impl.iterator.MapKeysWithCursor)1 InternalEventJournalMapEvent (com.hazelcast.map.impl.journal.InternalEventJournalMapEvent)1 MapEventJournalSubscribeOperation (com.hazelcast.map.impl.journal.MapEventJournalSubscribeOperation)1