use of com.hazelcast.spi.EventService in project hazelcast by hazelcast.
the class AbstractCacheService method addInvalidationListener.
/**
* Registers and {@link com.hazelcast.cache.impl.CacheEventListener} for specified <code>cacheName</code>.
*
* @param name the name of the cache that {@link com.hazelcast.cache.impl.CacheEventListener} will be registered for
* @param listener the {@link com.hazelcast.cache.impl.CacheEventListener} to be registered for specified <code>cache</code>
* @param localOnly true if only events originated from this member wants be listened, false if all invalidation events in the
* cluster wants to be listened
* @return the id which is unique for current registration
*/
@Override
public String addInvalidationListener(String name, CacheEventListener listener, boolean localOnly) {
EventService eventService = nodeEngine.getEventService();
EventRegistration registration;
if (localOnly) {
registration = eventService.registerLocalListener(SERVICE_NAME, name, listener);
} else {
registration = eventService.registerListener(SERVICE_NAME, name, listener);
}
return registration.getId();
}
use of com.hazelcast.spi.EventService in project hazelcast by hazelcast.
the class CacheEventHandler method publishEvent.
void publishEvent(CacheEventContext cacheEventContext) {
final EventService eventService = nodeEngine.getEventService();
final String cacheName = cacheEventContext.getCacheName();
final Collection<EventRegistration> candidates = eventService.getRegistrations(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(SERVICE_NAME, candidates, eventData, cacheEventContext.getOrderKey());
}
use of com.hazelcast.spi.EventService in project hazelcast by hazelcast.
the class CacheEventHandler method publishEvent.
void publishEvent(String cacheName, CacheEventSet eventSet, int orderKey) {
final EventService eventService = nodeEngine.getEventService();
final Collection<EventRegistration> candidates = eventService.getRegistrations(SERVICE_NAME, cacheName);
if (candidates.isEmpty()) {
return;
}
eventService.publishEvent(SERVICE_NAME, candidates, eventSet, orderKey);
}
use of com.hazelcast.spi.EventService in project hazelcast by hazelcast.
the class NodeQueryCacheEventService method getRegistrations.
private Collection<EventRegistration> getRegistrations(String mapName) {
MapServiceContext mapServiceContext = this.mapServiceContext;
NodeEngine nodeEngine = mapServiceContext.getNodeEngine();
EventService eventService = nodeEngine.getEventService();
return eventService.getRegistrations(MapService.SERVICE_NAME, mapName);
}
use of com.hazelcast.spi.EventService in project hazelcast by hazelcast.
the class NodeQueryCacheEventService method removeListener.
@Override
public boolean removeListener(String mapName, String cacheName, String id) {
String listenerName = generateListenerName(mapName, cacheName);
NodeEngine nodeEngine = mapServiceContext.getNodeEngine();
EventService eventService = nodeEngine.getEventService();
return eventService.deregisterListener(MapService.SERVICE_NAME, listenerName, id);
}
Aggregations