private void publishWithValue( Set<EventRegistration> registrationsWithValue, EntryEventData event, int orderKey) { final NodeEngine nodeEngine = mapServiceContext.getNodeEngine(); nodeEngine .getEventService() .publishEvent(mapServiceContext.serviceName(), registrationsWithValue, event, orderKey); }
private void flushInvalidationMessages( String cacheName, InvalidationEventQueue invalidationMessageQueue) { // If still in progress, no need to another attempt. So just ignore. if (invalidationMessageQueue.tryAcquire()) { try { CacheBatchInvalidationMessage batchInvalidationMessage = new CacheBatchInvalidationMessage(cacheName, invalidationMessageQueue.size()); CacheSingleInvalidationMessage invalidationMessage; final int size = invalidationMessageQueue.size(); // At most, poll from the invalidation queue as the current size of the queue before start // to polling. // So skip new invalidation queue items offered while the polling in progress in this round. for (int i = 0; i < size; i++) { invalidationMessage = invalidationMessageQueue.poll(); if (invalidationMessage == null) { break; } batchInvalidationMessage.addInvalidationMessage(invalidationMessage); } EventService eventService = nodeEngine.getEventService(); Collection<EventRegistration> registrations = eventService.getRegistrations(ICacheService.SERVICE_NAME, cacheName); if (!registrations.isEmpty()) { eventService.publishEvent( ICacheService.SERVICE_NAME, registrations, batchInvalidationMessage, cacheName.hashCode()); } } finally { invalidationMessageQueue.release(); } } }
public void publishMapEvent( Address caller, String mapName, EntryEventType eventType, int numberOfEntriesAffected) { final NodeEngine nodeEngine = mapServiceContext.getNodeEngine(); final Collection<EventRegistration> registrations = nodeEngine.getEventService().getRegistrations(mapServiceContext.serviceName(), mapName); if (registrations.isEmpty()) { return; } final String source = nodeEngine.getThisAddress().toString(); final MapEventData mapEventData = new MapEventData(source, mapName, caller, eventType.getType(), numberOfEntriesAffected); nodeEngine .getEventService() .publishEvent( mapServiceContext.serviceName(), registrations, mapEventData, mapName.hashCode()); }
Collection<EventRegistration> getRegistrations(String mapName) { final MapServiceContext mapServiceContext = this.mapServiceContext; final NodeEngine nodeEngine = mapServiceContext.getNodeEngine(); final EventService eventService = nodeEngine.getEventService(); return eventService.getRegistrations(SERVICE_NAME, mapName); }
/** * - Sends eviction event. - Invalidates near cache. * * @param key the key to be processed. * @param value the value to be processed. */ @Override public void doPostEvictionOperations(Data key, Object value, boolean isExpired) { MapEventPublisher mapEventPublisher = mapServiceContext.getMapEventPublisher(); NodeEngine nodeEngine = mapServiceContext.getNodeEngine(); EventService eventService = nodeEngine.getEventService(); if (!eventService.hasEventRegistration(SERVICE_NAME, name)) { return; } Address thisAddress = nodeEngine.getThisAddress(); // Fire EVICTED event also in case of expiration because historically eviction-listener // listens all kind of eviction and expiration events and by firing EVICTED event we are // preserving // this behavior. mapEventPublisher.publishEvent(thisAddress, name, EVICTED, key, value, null); if (isExpired) { // We will be in this if in two cases: // 1. In case of TTL or max-idle-seconds expiration. // 2. When evicting due to the size-based eviction, we are also firing an EXPIRED event // because there is a possibility that evicted entry may be also an expired one. Trying to // catch // as much as possible expired entries. mapEventPublisher.publishEvent(thisAddress, name, EXPIRED, key, value, null); } }
public void destroyDistributedObject(String name) { for (MultiMapPartitionContainer container : partitionContainers) { if (container != null) { container.destroyCollection(name); } } nodeEngine.getEventService().deregisterAllListeners(SERVICE_NAME, name); }
void publishEventInternal( Collection<EventRegistration> registrations, Object eventData, int orderKey) { final MapServiceContext mapServiceContext = this.mapServiceContext; final NodeEngine nodeEngine = mapServiceContext.getNodeEngine(); final EventService eventService = nodeEngine.getEventService(); eventService.publishEvent(SERVICE_NAME, registrations, eventData, orderKey); }
public String addEventListener( EntryListener entryListener, EventFilter eventFilter, String mapName) { EventRegistration registration = nodeEngine .getEventService() .registerListener(SERVICE_NAME, mapName, eventFilter, entryListener); return registration.getId(); }
void publishEvent(String cacheName, CacheEventSet eventSet, int orderKey) { final EventService eventService = nodeEngine.getEventService(); final Collection<EventRegistration> candidates = eventService.getRegistrations(ICacheService.SERVICE_NAME, cacheName); if (candidates.isEmpty()) { return; } eventService.publishEvent(ICacheService.SERVICE_NAME, candidates, eventSet, orderKey); }
void publishEvent(CacheEventContext cacheEventContext) { final EventService eventService = nodeEngine.getEventService(); final String cacheName = cacheEventContext.getCacheName(); final Collection<EventRegistration> candidates = eventService.getRegistrations(ICacheService.SERVICE_NAME, cacheName); if (candidates.isEmpty()) { return; } final Object eventData; final CacheEventType eventType = cacheEventContext.getEventType(); switch (eventType) { case CREATED: case UPDATED: case REMOVED: case EXPIRED: final CacheEventData cacheEventData = new CacheEventDataImpl( cacheName, eventType, cacheEventContext.getDataKey(), cacheEventContext.getDataValue(), cacheEventContext.getDataOldValue(), cacheEventContext.isOldValueAvailable()); CacheEventSet eventSet = new CacheEventSet(eventType, cacheEventContext.getCompletionId()); eventSet.addEventData(cacheEventData); eventData = eventSet; break; case EVICTED: case INVALIDATED: eventData = new CacheEventDataImpl( cacheName, eventType, cacheEventContext.getDataKey(), null, null, false); break; case COMPLETED: CacheEventData completedEventData = new CacheEventDataImpl( cacheName, eventType, cacheEventContext.getDataKey(), cacheEventContext.getDataValue(), null, false); eventSet = new CacheEventSet(eventType, cacheEventContext.getCompletionId()); eventSet.addEventData(completedEventData); eventData = eventSet; break; default: throw new IllegalArgumentException( "Event Type not defined to create an eventData during publish : " + eventType.name()); } eventService.publishEvent( ICacheService.SERVICE_NAME, candidates, eventData, cacheEventContext.getOrderKey()); }
public String addListener( String name, EventListener listener, Data key, boolean includeValue, boolean local) { EventService eventService = nodeEngine.getEventService(); EventRegistration registration; final MultiMapEventFilter filter = new MultiMapEventFilter(includeValue, key); if (local) { registration = eventService.registerLocalListener(SERVICE_NAME, name, filter, listener); } else { registration = eventService.registerListener(SERVICE_NAME, name, filter, listener); } return registration.getId(); }
private void sendSingleInvalidationEvent(String name, Data key, String sourceUuid) { EventService eventService = nodeEngine.getEventService(); Collection<EventRegistration> registrations = eventService.getRegistrations(ICacheService.SERVICE_NAME, name); if (!registrations.isEmpty()) { eventService.publishEvent( ICacheService.SERVICE_NAME, registrations, new CacheSingleInvalidationMessage(name, key, sourceUuid), name.hashCode()); } }
public void fireMapClearedEvent(int deletedEntrySize, String name) { EventService eventService = nodeEngine.getEventService(); Collection<EventRegistration> registrations = eventService.getRegistrations(SERVICE_NAME, name); if (registrations.isEmpty()) { return; } MapEventData mapEventData = new MapEventData( name, name, nodeEngine.getThisAddress(), EntryEventType.CLEAR_ALL.getType(), deletedEntrySize); eventService.publishEvent(SERVICE_NAME, registrations, mapEventData, name.hashCode()); }
public void destroyDistributedObject(String name) { MapContainer mapContainer = mapContainers.remove(name); if (mapContainer != null) { if (mapContainer.isNearCacheEnabled()) { NearCache nearCache = nearCacheMap.remove(name); if (nearCache != null) { nearCache.clear(); } } mapContainer.shutDownMapStoreScheduledExecutor(); } final PartitionContainer[] containers = partitionContainers; for (PartitionContainer container : containers) { if (container != null) { container.destroyMap(name); } } nodeEngine.getEventService().deregisterAllListeners(SERVICE_NAME, name); }
private void sendBatchInvalidationEvent(String name, Data key, String sourceUuid) { EventService eventService = nodeEngine.getEventService(); Collection<EventRegistration> registrations = eventService.getRegistrations(ICacheService.SERVICE_NAME, name); if (registrations.isEmpty()) { return; } InvalidationEventQueue invalidationMessageQueue = invalidationMessageMap.get(name); if (invalidationMessageQueue == null) { InvalidationEventQueue newInvalidationMessageQueue = new InvalidationEventQueue(); invalidationMessageQueue = invalidationMessageMap.putIfAbsent(name, newInvalidationMessageQueue); if (invalidationMessageQueue == null) { invalidationMessageQueue = newInvalidationMessageQueue; } } CacheSingleInvalidationMessage invalidationMessage = new CacheSingleInvalidationMessage(name, key, sourceUuid); invalidationMessageQueue.offer(invalidationMessage); if (invalidationMessageQueue.size() >= invalidationMessageBatchSize) { flushInvalidationMessages(name, invalidationMessageQueue); } }
public ReplicatedMapEventPublishingService(ReplicatedMapService replicatedMapService) { this.replicatedMapService = replicatedMapService; this.nodeEngine = replicatedMapService.getNodeEngine(); this.config = nodeEngine.getConfig(); this.eventService = nodeEngine.getEventService(); }
public boolean removeEventListener(String mapName, String registrationId) { return nodeEngine.getEventService().deregisterListener(SERVICE_NAME, mapName, registrationId); }
private Collection<EventRegistration> getCandidates(String mapName) { final NodeEngine nodeEngine = mapServiceContext.getNodeEngine(); return nodeEngine.getEventService().getRegistrations(mapServiceContext.serviceName(), mapName); }
public boolean removeListener(String name, String registrationId) { EventService eventService = nodeEngine.getEventService(); return eventService.deregisterListener(SERVICE_NAME, name, registrationId); }
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); }