Search in sources :

Example 1 with EventListenerFilter

use of com.hazelcast.map.impl.EventListenerFilter 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.includeValue, parameters.key, predicate);
    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 EventListenerFilter

use of com.hazelcast.map.impl.EventListenerFilter 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 3 with EventListenerFilter

use of com.hazelcast.map.impl.EventListenerFilter in project hazelcast by hazelcast.

the class MapEventPublisherImpl method publishMapEvent.

@Override
public void publishMapEvent(Address caller, String mapName, EntryEventType eventType, int numberOfEntriesAffected) {
    Collection<EventRegistration> mapsListenerRegistrations = getRegistrations(mapName);
    if (isEmpty(mapsListenerRegistrations)) {
        return;
    }
    Collection<EventRegistration> registrations = null;
    for (EventRegistration registration : mapsListenerRegistrations) {
        EventFilter filter = registration.getFilter();
        if (filter instanceof EventListenerFilter) {
            if (!filter.eval(eventType.getType())) {
                continue;
            }
        }
        if (!(filter instanceof MapPartitionLostEventFilter)) {
            if (registrations == null) {
                registrations = new ArrayList<EventRegistration>();
            }
            registrations.add(registration);
        }
    }
    if (isEmpty(registrations)) {
        return;
    }
    String source = getThisNodesAddress();
    MapEventData mapEventData = new MapEventData(source, mapName, caller, eventType.getType(), numberOfEntriesAffected);
    publishEventInternal(registrations, mapEventData, mapName.hashCode());
}
Also used : EventRegistration(com.hazelcast.spi.EventRegistration) MapPartitionLostEventFilter(com.hazelcast.map.impl.MapPartitionLostEventFilter) EntryEventFilter(com.hazelcast.map.impl.EntryEventFilter) TrueEventFilter(com.hazelcast.spi.impl.eventservice.impl.TrueEventFilter) MapPartitionLostEventFilter(com.hazelcast.map.impl.MapPartitionLostEventFilter) QueryEventFilter(com.hazelcast.map.impl.query.QueryEventFilter) EventFilter(com.hazelcast.spi.EventFilter) EventListenerFilter(com.hazelcast.map.impl.EventListenerFilter)

Example 4 with EventListenerFilter

use of com.hazelcast.map.impl.EventListenerFilter in project hazelcast by hazelcast.

the class EntryEventDataCacheTest method createInvalidationEventRejectingFilter.

private static EventListenerFilter createInvalidationEventRejectingFilter() {
    ListenerAdapter listenerAdapter = createListenerAdapter(new EntryAddedListener() {

        @Override
        public void entryAdded(EntryEvent event) {
        }
    });
    int flags = setAndGetListenerFlags(listenerAdapter);
    return new EventListenerFilter(flags, TrueEventFilter.INSTANCE);
}
Also used : ListenerAdapters.createListenerAdapter(com.hazelcast.map.impl.ListenerAdapters.createListenerAdapter) ListenerAdapter(com.hazelcast.map.impl.ListenerAdapter) EntryEvent(com.hazelcast.core.EntryEvent) EntryAddedListener(com.hazelcast.map.listener.EntryAddedListener) EventListenerFilter(com.hazelcast.map.impl.EventListenerFilter)

Example 5 with EventListenerFilter

use of com.hazelcast.map.impl.EventListenerFilter in project hazelcast by hazelcast.

the class EntryEventDataCacheTest method filteringStrategy_rejects_invalidation_events.

@Test
public void filteringStrategy_rejects_invalidation_events() throws Exception {
    EventListenerFilter filter = createInvalidationEventRejectingFilter();
    int matched = filteringStrategy.doFilter(filter, null, null, null, INVALIDATION, "mapName");
    assertEquals(FILTER_DOES_NOT_MATCH, matched);
}
Also used : EventListenerFilter(com.hazelcast.map.impl.EventListenerFilter) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

EventListenerFilter (com.hazelcast.map.impl.EventListenerFilter)6 QueryEventFilter (com.hazelcast.map.impl.query.QueryEventFilter)4 EntryEventFilter (com.hazelcast.map.impl.EntryEventFilter)2 MapPartitionLostEventFilter (com.hazelcast.map.impl.MapPartitionLostEventFilter)2 Predicate (com.hazelcast.query.Predicate)2 TrueEventFilter (com.hazelcast.spi.impl.eventservice.impl.TrueEventFilter)2 EntryEvent (com.hazelcast.core.EntryEvent)1 ListenerAdapter (com.hazelcast.map.impl.ListenerAdapter)1 ListenerAdapters.createListenerAdapter (com.hazelcast.map.impl.ListenerAdapters.createListenerAdapter)1 UuidFilter (com.hazelcast.map.impl.nearcache.invalidation.UuidFilter)1 EntryAddedListener (com.hazelcast.map.listener.EntryAddedListener)1 EventFilter (com.hazelcast.spi.EventFilter)1 EventRegistration (com.hazelcast.spi.EventRegistration)1 ParallelTest (com.hazelcast.test.annotation.ParallelTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 Test (org.junit.Test)1