@Override public void publishEvent( Address caller, String mapName, EntryEventType eventType, boolean syntheticEvent, final Data dataKey, Data dataOldValue, Data dataValue, Data dataMergingValue) { final Collection<EventRegistration> registrations = getRegistrations(mapName); if (registrations.isEmpty()) { return; } List<EventRegistration> registrationsWithValue = null; List<EventRegistration> registrationsWithoutValue = null; for (final EventRegistration candidate : registrations) { final EventFilter filter = candidate.getFilter(); final Result result = applyEventFilter(filter, syntheticEvent, dataKey, dataOldValue, dataValue, eventType); registrationsWithValue = initRegistrationsWithValue(registrationsWithValue, result); registrationsWithoutValue = initRegistrationsWithoutValue(registrationsWithoutValue, result); registerCandidate(result, candidate, registrationsWithValue, registrationsWithoutValue); } final boolean withValueRegistrationExists = isNotEmpty(registrationsWithValue); final boolean withoutValueRegistrationExists = isNotEmpty(registrationsWithoutValue); if (!withValueRegistrationExists && !withoutValueRegistrationExists) { return; } final EntryEventData eventData = createEntryEventData( mapName, caller, dataKey, dataValue, dataOldValue, dataMergingValue, eventType.getType()); final int orderKey = pickOrderKey(dataKey); if (withValueRegistrationExists) { publishEventInternal(registrationsWithValue, eventData, orderKey); } if (withoutValueRegistrationExists) { publishEventInternal(registrationsWithoutValue, eventData.cloneWithoutValues(), orderKey); } }
public void fireEntryListenerEvent( Data key, Data oldValue, Data value, EntryEventType eventType, String name, Address caller) { Collection<EventRegistration> registrations = eventService.getRegistrations(SERVICE_NAME, name); if (registrations.isEmpty()) { return; } EntryEventData eventData = new EntryEventData(name, name, caller, key, value, oldValue, eventType.getType()); for (EventRegistration registration : registrations) { if (!shouldPublish(key, oldValue, value, eventType, registration.getFilter())) { continue; } eventService.publishEvent(SERVICE_NAME, registration, eventData, key.hashCode()); } }
public void publishEvent(ItemEventType eventType, Data data) { EventService eventService = getNodeEngine().getEventService(); Collection<EventRegistration> registrations = eventService.getRegistrations(getServiceName(), name); for (EventRegistration registration : registrations) { QueueEventFilter filter = (QueueEventFilter) registration.getFilter(); QueueEvent event = new QueueEvent( name, filter.isIncludeValue() ? data : null, eventType, getNodeEngine().getThisAddress()); eventService.publishEvent(getServiceName(), registration, event, name.hashCode()); } }
@Override public void publishMapPartitionLostEvent(Address caller, String mapName, int partitionId) { final Collection<EventRegistration> registrations = new LinkedList<EventRegistration>(); for (EventRegistration registration : getRegistrations(mapName)) { if (registration.getFilter() instanceof MapPartitionLostEventFilter) { registrations.add(registration); } } if (registrations.isEmpty()) { return; } final String thisNodesAddress = getThisNodesAddress(); final MapPartitionEventData eventData = new MapPartitionEventData(thisNodesAddress, mapName, caller, partitionId); publishEventInternal(registrations, eventData, partitionId); }
@Override public void publishMapEvent( Address caller, String mapName, EntryEventType eventType, int numberOfEntriesAffected) { final Collection<EventRegistration> registrations = new LinkedList<EventRegistration>(); for (EventRegistration registration : getRegistrations(mapName)) { if (!(registration.getFilter() instanceof MapPartitionLostEventFilter)) { registrations.add(registration); } } if (registrations.isEmpty()) { return; } final String source = getThisNodesAddress(); final MapEventData mapEventData = new MapEventData(source, mapName, caller, eventType.getType(), numberOfEntriesAffected); publishEventInternal(registrations, mapEventData, mapName.hashCode()); }
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); }
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); }