use of com.hazelcast.spi.EventRegistration 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.EventRegistration 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.EventRegistration in project hazelcast by hazelcast.
the class NodeQueryCacheEventService method sendEventToSubscriber.
@Override
public void sendEventToSubscriber(String name, Object eventData, int orderKey) {
Collection<EventRegistration> eventRegistrations = getRegistrations(name);
if (eventRegistrations.isEmpty()) {
return;
}
for (EventRegistration eventRegistration : eventRegistrations) {
Registration registration = (Registration) eventRegistration;
Object listener = registration.getListener();
if (listener instanceof QueryCacheListenerAdapter) {
continue;
}
publishEventInternal(registration, eventData, orderKey);
}
}
use of com.hazelcast.spi.EventRegistration in project hazelcast by hazelcast.
the class NodeQueryCacheEventService method hasListener.
@Override
public boolean hasListener(String mapName, String cacheName) {
String listenerName = generateListenerName(mapName, cacheName);
Collection<EventRegistration> eventRegistrations = getRegistrations(listenerName);
if (eventRegistrations.isEmpty()) {
return false;
}
for (EventRegistration eventRegistration : eventRegistrations) {
Registration registration = (Registration) eventRegistration;
Object listener = registration.getListener();
if (listener instanceof QueryCacheListenerAdapter) {
return true;
}
}
return false;
}
use of com.hazelcast.spi.EventRegistration in project hazelcast by hazelcast.
the class MultiMapEventsPublisher method publishMultiMapEvent.
public void publishMultiMapEvent(String mapName, EntryEventType eventType, int numberOfEntriesAffected) {
final EventService eventService = nodeEngine.getEventService();
final Collection<EventRegistration> registrations = eventService.getRegistrations(MultiMapService.SERVICE_NAME, mapName);
if (registrations.isEmpty()) {
return;
}
final Address caller = nodeEngine.getThisAddress();
final String source = caller.toString();
final MapEventData mapEventData = new MapEventData(source, mapName, caller, eventType.getType(), numberOfEntriesAffected);
eventService.publishEvent(MultiMapService.SERVICE_NAME, registrations, mapEventData, mapName.hashCode());
}
Aggregations