use of com.hazelcast.map.impl.MapPartitionLostEventFilter 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() + "]");
}
use of com.hazelcast.map.impl.MapPartitionLostEventFilter 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());
}
use of com.hazelcast.map.impl.MapPartitionLostEventFilter in project hazelcast by hazelcast.
the class MapPartitionLostListenerTest method testMapPartitionLostEventFilter.
@Test
public void testMapPartitionLostEventFilter() {
MapPartitionLostEventFilter filter = new MapPartitionLostEventFilter();
assertEquals(new MapPartitionLostEventFilter(), filter);
assertFalse(filter.eval(null));
}
use of com.hazelcast.map.impl.MapPartitionLostEventFilter in project hazelcast by hazelcast.
the class MapEventPublisherImpl method publishMapPartitionLostEvent.
@Override
public void publishMapPartitionLostEvent(Address caller, String mapName, int partitionId) {
Collection<EventRegistration> registrations = new LinkedList<EventRegistration>();
for (EventRegistration registration : getRegistrations(mapName)) {
if (registration.getFilter() instanceof MapPartitionLostEventFilter) {
registrations.add(registration);
}
}
if (registrations.isEmpty()) {
return;
}
String thisNodesAddress = getThisNodesAddress();
MapPartitionEventData eventData = new MapPartitionEventData(thisNodesAddress, mapName, caller, partitionId);
publishEventInternal(registrations, eventData, partitionId);
}
Aggregations