// CHECKSTYLE:OFF
  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }

    Registration that = (Registration) o;

    if (id != null ? !id.equals(that.id) : that.id != null) {
      return false;
    }
    if (serviceName != null ? !serviceName.equals(that.serviceName) : that.serviceName != null) {
      return false;
    }
    if (topic != null ? !topic.equals(that.topic) : that.topic != null) {
      return false;
    }
    if (filter != null ? !filter.equals(that.filter) : that.filter != null) {
      return false;
    }
    if (subscriber != null ? !subscriber.equals(that.subscriber) : that.subscriber != null) {
      return false;
    }

    return true;
  }
 @Override
 public int hashCode() {
   int result = id != null ? id.hashCode() : 0;
   result = 31 * result + (serviceName != null ? serviceName.hashCode() : 0);
   result = 31 * result + (topic != null ? topic.hashCode() : 0);
   result = 31 * result + (filter != null ? filter.hashCode() : 0);
   result = 31 * result + (subscriber != null ? subscriber.hashCode() : 0);
   return result;
 }
 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);
 }
 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);
 }
  protected Result applyEventFilter(
      EventFilter filter,
      boolean syntheticEvent,
      Data dataKey,
      Data dataOldValue,
      Data dataValue,
      EntryEventType eventType) {

    if (filter instanceof MapPartitionLostEventFilter) {
      return Result.NONE;
    }

    // below, order of ifs are important.
    // QueryEventFilter is instance of EntryEventFilter.
    // SyntheticEventFilter wraps an event filter.
    if (filter instanceof SyntheticEventFilter) {
      if (syntheticEvent) {
        return Result.NONE;
      }
      final SyntheticEventFilter syntheticEventFilter = (SyntheticEventFilter) filter;
      filter = syntheticEventFilter.getFilter();
    }

    if (filter instanceof EmptyFilter) {
      return Result.VALUE_INCLUDED;
    }

    if (filter instanceof QueryEventFilter) {
      return processQueryEventFilter(filter, eventType, dataKey, dataOldValue, dataValue);
    }

    if (filter instanceof EntryEventFilter) {
      return processEntryEventFilter(filter, dataKey);
    }

    throw new IllegalArgumentException(
        "Unknown EventFilter type = [" + filter.getClass().getCanonicalName() + "]");
  }
Beispiel #6
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);
 }