use of com.hazelcast.cache.CacheEventType in project hazelcast by hazelcast.
the class CacheEventListenerAdaptor method handleEvent.
private void handleEvent(int type, Collection<CacheEventData> keys) {
final Iterable<CacheEntryEvent<? extends K, ? extends V>> cacheEntryEvent = createCacheEntryEvent(keys);
CacheEventType eventType = CacheEventType.getByType(type);
switch(eventType) {
case CREATED:
if (this.cacheEntryCreatedListener != null) {
this.cacheEntryCreatedListener.onCreated(cacheEntryEvent);
}
break;
case UPDATED:
if (this.cacheEntryUpdatedListener != null) {
this.cacheEntryUpdatedListener.onUpdated(cacheEntryEvent);
}
break;
case REMOVED:
if (this.cacheEntryRemovedListener != null) {
this.cacheEntryRemovedListener.onRemoved(cacheEntryEvent);
}
break;
case EXPIRED:
if (this.cacheEntryExpiredListener != null) {
this.cacheEntryExpiredListener.onExpired(cacheEntryEvent);
}
break;
default:
throw new IllegalArgumentException("Invalid event type: " + eventType.name());
}
}
use of com.hazelcast.cache.CacheEventType 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());
}
Aggregations