Search in sources :

Example 6 with EventFilter

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

the class QueryCacheEventPublisher method convertQueryCacheEventDataOrNull.

private QueryCacheEventData convertQueryCacheEventDataOrNull(PartitionAccumulatorRegistry registry, Data dataKey, Data dataNewValue, Data dataOldValue, int eventTypeId, int partitionId, String mapName) {
    EventFilter eventFilter = registry.getEventFilter();
    EntryEventType eventType = EntryEventType.getByType(eventTypeId);
    // filtering strategy
    if (filteringStrategy instanceof DefaultEntryEventFilteringStrategy) {
        eventType = getCQCEventTypeOrNull(eventType, eventFilter, dataKey, dataNewValue, dataOldValue, mapName);
    } else {
        int producedEventTypeId = filteringStrategy.doFilter(eventFilter, dataKey, dataOldValue, dataNewValue, eventType, mapName);
        if (producedEventTypeId == FilteringStrategy.FILTER_DOES_NOT_MATCH) {
            eventType = null;
        } else {
            eventType = EntryEventType.getByType(producedEventTypeId);
        }
    }
    if (eventType == null) {
        return null;
    }
    boolean includeValue = isIncludeValue(eventFilter);
    return newQueryCacheEventDataBuilder(includeValue).withPartitionId(partitionId).withDataKey(dataKey).withDataNewValue(dataNewValue).withEventType(eventType.getType()).withDataOldValue(dataOldValue).withSerializationService((serializationService)).build();
}
Also used : EntryEventType(com.hazelcast.core.EntryEventType) EventFilter(com.hazelcast.spi.impl.eventservice.EventFilter)

Example 7 with EventFilter

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

the class MapEventPublisherImpl method publishEventQuietly.

@SuppressWarnings("checkstyle:parameternumber")
private void publishEventQuietly(Address caller, String mapName, EntryEventType eventType, Data dataKey, Object oldValue, Object newValue, Object mergingValue, EntryEventDataCache eventDataCache, int orderKey, EventRegistration registration) {
    try {
        EventFilter filter = registration.getFilter();
        // a filtering strategy determines whether the event must be published on the specific
        // event registration and may alter the type of event to be published
        int eventTypeForPublishing = filteringStrategy.doFilter(filter, dataKey, oldValue, newValue, eventType, mapName);
        if (eventTypeForPublishing == FILTER_DOES_NOT_MATCH) {
            return;
        }
        EntryEventData eventDataToBePublished = eventDataCache.getOrCreateEventData(mapName, caller, dataKey, newValue, oldValue, mergingValue, eventTypeForPublishing, isIncludeValue(filter));
        eventService.publishEvent(SERVICE_NAME, registration, eventDataToBePublished, orderKey);
    } catch (Exception ex) {
        logger.warning("Event publication error for registration: " + registration, ex);
    }
}
Also used : 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.impl.eventservice.EventFilter)

Example 8 with EventFilter

use of com.hazelcast.spi.impl.eventservice.EventFilter 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<>();
            }
            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.impl.eventservice.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.impl.eventservice.EventFilter) EventListenerFilter(com.hazelcast.map.impl.EventListenerFilter)

Example 9 with EventFilter

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

the class MapServiceContextImpl method addPartitionLostListenerAsync.

@Override
public CompletableFuture<UUID> addPartitionLostListenerAsync(MapPartitionLostListener listener, String mapName) {
    ListenerAdapter listenerAdapter = new InternalMapPartitionLostListenerAdapter(listener);
    EventFilter filter = new MapPartitionLostEventFilter();
    return eventService.registerListenerAsync(SERVICE_NAME, mapName, filter, listenerAdapter).thenApplyAsync(EventRegistration::getId, CALLER_RUNS);
}
Also used : ListenerAdapters.createListenerAdapter(com.hazelcast.map.impl.ListenerAdapters.createListenerAdapter) EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) EventFilter(com.hazelcast.spi.impl.eventservice.EventFilter)

Example 10 with EventFilter

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

the class AbstractQueryCacheConfigurator method setEntryListener.

protected void setEntryListener(String mapName, String cacheId, QueryCacheConfig config) {
    for (EntryListenerConfig listenerConfig : config.getEntryListenerConfigs()) {
        MapListener listener = getListener(listenerConfig);
        if (listener != null) {
            EventFilter filter = new EntryEventFilter(null, listenerConfig.isIncludeValue());
            eventService.addListener(mapName, cacheId, listener, filter);
        }
    }
}
Also used : MapListener(com.hazelcast.map.listener.MapListener) EntryEventFilter(com.hazelcast.map.impl.EntryEventFilter) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) EntryEventFilter(com.hazelcast.map.impl.EntryEventFilter) EventFilter(com.hazelcast.spi.impl.eventservice.EventFilter)

Aggregations

EventFilter (com.hazelcast.spi.impl.eventservice.EventFilter)21 EntryEventFilter (com.hazelcast.map.impl.EntryEventFilter)7 EventRegistration (com.hazelcast.spi.impl.eventservice.EventRegistration)7 TrueEventFilter (com.hazelcast.spi.impl.eventservice.impl.TrueEventFilter)6 QueryEventFilter (com.hazelcast.map.impl.query.QueryEventFilter)5 ListenerAdapters.createListenerAdapter (com.hazelcast.map.impl.ListenerAdapters.createListenerAdapter)3 QueryCacheEventService (com.hazelcast.map.impl.querycache.QueryCacheEventService)3 ReplicatedEntryEventFilter (com.hazelcast.replicatedmap.impl.record.ReplicatedEntryEventFilter)3 ReplicatedQueryEventFilter (com.hazelcast.replicatedmap.impl.record.ReplicatedQueryEventFilter)3 Nonnull (javax.annotation.Nonnull)3 CachePartitionLostEventFilter (com.hazelcast.cache.impl.event.CachePartitionLostEventFilter)2 InternalCachePartitionLostListenerAdapter (com.hazelcast.cache.impl.event.InternalCachePartitionLostListenerAdapter)2 Data (com.hazelcast.internal.serialization.Data)2 MapPartitionLostEventFilter (com.hazelcast.map.impl.MapPartitionLostEventFilter)2 UUID (java.util.UUID)2 CacheService (com.hazelcast.cache.impl.CacheService)1 ICacheService (com.hazelcast.cache.impl.ICacheService)1 CachePartitionLostListener (com.hazelcast.cache.impl.event.CachePartitionLostListener)1 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)1 CacheAddPartitionLostListenerCodec (com.hazelcast.client.impl.protocol.codec.CacheAddPartitionLostListenerCodec)1