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();
}
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);
}
}
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());
}
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);
}
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);
}
}
}
Aggregations