private boolean shouldPublish(
     Data key, Data oldValue, Data value, EntryEventType eventType, EventFilter filter) {
   QueryEntry queryEntry = null;
   if (filter instanceof ReplicatedQueryEventFilter) {
     Data testValue;
     if (eventType == REMOVED) {
       testValue = oldValue;
     } else {
       testValue = value;
     }
     InternalSerializationService serializationService =
         (InternalSerializationService) nodeEngine.getSerializationService();
     queryEntry = new QueryEntry(serializationService, key, testValue, null);
   }
   return filter == null || filter.eval(queryEntry != null ? queryEntry : key);
 }
 public void publishEvent(
     Address caller,
     String mapName,
     EntryEventType eventType,
     final Data dataKey,
     Data dataOldValue,
     Data dataValue) {
   final Collection<EventRegistration> candidates = getCandidates(mapName);
   if (candidates.isEmpty()) {
     return;
   }
   final Set<EventRegistration> registrationsWithValue = new HashSet<EventRegistration>();
   final Set<EventRegistration> registrationsWithoutValue = new HashSet<EventRegistration>();
   // iterate on candidates.
   for (final EventRegistration candidate : candidates) {
     Result result = Result.NONE;
     final EventFilter filter = candidate.getFilter();
     if (emptyFilter(filter)) {
       result = processEmptyFilter();
     } else if (queryEventFilter(filter)) {
       result = processQueryEventFilter(filter, eventType, dataKey, dataOldValue, dataValue);
     } else if (filter.eval(dataKey)) {
       result = processEntryEventFilter(filter);
     }
     registerCandidate(result, candidate, registrationsWithValue, registrationsWithoutValue);
   }
   if (registrationsWithValue.isEmpty() && registrationsWithoutValue.isEmpty()) {
     return;
   }
   final EntryEventData eventData =
       createEntryEventData(
           mapName, caller, dataKey, dataValue, dataOldValue, eventType.getType());
   final int orderKey = pickOrderKey(dataKey);
   publishWithValue(registrationsWithValue, eventData, orderKey);
   publishWithoutValue(registrationsWithoutValue, eventData, orderKey);
 }
Beispiel #3
0
 public void publishEvent(
     Address caller,
     String mapName,
     EntryEventType eventType,
     Data dataKey,
     Data dataOldValue,
     Data dataValue) {
   Collection<EventRegistration> candidates =
       nodeEngine.getEventService().getRegistrations(SERVICE_NAME, mapName);
   Set<EventRegistration> registrationsWithValue = new HashSet<EventRegistration>();
   Set<EventRegistration> registrationsWithoutValue = new HashSet<EventRegistration>();
   if (candidates.isEmpty()) return;
   Object key = null;
   Object value = null;
   Object oldValue = null;
   for (EventRegistration candidate : candidates) {
     EventFilter filter = candidate.getFilter();
     if (filter instanceof EventServiceImpl.EmptyFilter) {
       registrationsWithValue.add(candidate);
     } else if (filter instanceof QueryEventFilter) {
       Object testValue;
       if (eventType == EntryEventType.REMOVED || eventType == EntryEventType.EVICTED) {
         oldValue = oldValue != null ? oldValue : toObject(dataOldValue);
         testValue = oldValue;
       } else {
         value = value != null ? value : toObject(dataValue);
         testValue = value;
       }
       key = key != null ? key : toObject(dataKey);
       QueryEventFilter queryEventFilter = (QueryEventFilter) filter;
       QueryEntry entry = new QueryEntry(getSerializationService(), dataKey, key, testValue);
       if (queryEventFilter.eval(entry)) {
         if (queryEventFilter.isIncludeValue()) {
           registrationsWithValue.add(candidate);
         } else {
           registrationsWithoutValue.add(candidate);
         }
       }
     } else if (filter.eval(dataKey)) {
       EntryEventFilter eventFilter = (EntryEventFilter) filter;
       if (eventFilter.isIncludeValue()) {
         registrationsWithValue.add(candidate);
       } else {
         registrationsWithoutValue.add(candidate);
       }
     }
   }
   if (registrationsWithValue.isEmpty() && registrationsWithoutValue.isEmpty()) return;
   String source = nodeEngine.getThisAddress().toString();
   if (eventType == EntryEventType.REMOVED || eventType == EntryEventType.EVICTED) {
     dataValue = dataValue != null ? dataValue : dataOldValue;
   }
   EventData event =
       new EventData(
           source, mapName, caller, dataKey, dataValue, dataOldValue, eventType.getType());
   int orderKey = dataKey.hashCode();
   nodeEngine
       .getEventService()
       .publishEvent(SERVICE_NAME, registrationsWithValue, event, orderKey);
   nodeEngine
       .getEventService()
       .publishEvent(
           SERVICE_NAME, registrationsWithoutValue, event.cloneWithoutValues(), orderKey);
 }