use of com.hazelcast.core.EntryEventType in project hazelcast by hazelcast.
the class InternalEntryListenerAdapter method onEvent.
@Override
public void onEvent(IMapEvent event) {
final EntryEventType eventType = event.getEventType();
final ListenerAdapter listenerAdapter = listenerAdapters[eventType.ordinal()];
if (listenerAdapter == null) {
return;
}
listenerAdapter.onEvent(event);
}
use of com.hazelcast.core.EntryEventType in project hazelcast by hazelcast.
the class EventQueuePlugin method sampleLocalDispatcherEvent.
private int sampleLocalDispatcherEvent(LocalEventDispatcher eventDispatcher) {
Object dispatcherEvent = eventDispatcher.getEvent();
if (dispatcherEvent instanceof EntryEventData) {
// IMap event
EntryEventData event = (EntryEventData) dispatcherEvent;
EntryEventType type = EntryEventType.getByType(event.getEventType());
String mapName = event.getMapName();
occurrenceMap.add(format("IMap '%s' %s", mapName, type), 1);
return 1;
} else if (dispatcherEvent instanceof CacheEventSet) {
// ICache event
CacheEventSet eventSet = (CacheEventSet) dispatcherEvent;
Set<CacheEventData> events = eventSet.getEvents();
for (CacheEventData event : events) {
occurrenceMap.add(format("ICache '%s' %s", event.getName(), event.getCacheEventType()), 1);
}
return events.size();
} else if (dispatcherEvent instanceof QueueEvent) {
// IQueue event
QueueEvent event = (QueueEvent) dispatcherEvent;
occurrenceMap.add(format("IQueue '%s' %s", event.getName(), event.getEventType()), 1);
return 1;
} else if (dispatcherEvent instanceof CollectionEvent) {
// ISet or IList event
CollectionEvent event = (CollectionEvent) dispatcherEvent;
String serviceName = eventDispatcher.getServiceName();
if (SetService.SERVICE_NAME.equals(serviceName)) {
serviceName = "ISet";
} else if (ListService.SERVICE_NAME.equals(serviceName)) {
serviceName = "IList";
}
occurrenceMap.add(format("%s '%s' %s", serviceName, event.getName(), event.getEventType()), 1);
return 1;
}
occurrenceMap.add(dispatcherEvent.getClass().getSimpleName(), 1);
return 1;
}
use of com.hazelcast.core.EntryEventType in project hazelcast by hazelcast.
the class MapListenerAdapterTest method ensure_map_listener_adapter_implements_listeners_for_all_entry_event_types_except_invalidation.
@Test
public void ensure_map_listener_adapter_implements_listeners_for_all_entry_event_types_except_invalidation() {
MapListenerAdapter mapListenerAdapterInstance = new MapListenerAdapter();
Map<EntryEventType, ConstructorFunction<MapListener, ListenerAdapter>> constructors = getConstructors();
for (Map.Entry<EntryEventType, ConstructorFunction<MapListener, ListenerAdapter>> entry : constructors.entrySet()) {
EntryEventType entryEventType = entry.getKey();
if (entryEventType == EntryEventType.INVALIDATION) {
// this event is used to listen near-cache invalidations.
continue;
}
assertNotNull("MapListenerAdapter misses an interface " + "to implement for entry-event-type=" + entryEventType, entry.getValue().createNew(mapListenerAdapterInstance));
}
}
use of com.hazelcast.core.EntryEventType in project hazelcast by hazelcast.
the class EventPublishOrderWithEvictionTest method assertEmittedEventsOrder.
private void assertEmittedEventsOrder(EventOrderAwareEntryListener entryListener) {
Map<Integer, List<EntryEventType>> eventsPerKey = new HashMap<Integer, List<EntryEventType>>();
List<EntryEvent> events = entryListener.getOrderedEvents();
for (EntryEvent event : events) {
Integer key = (Integer) event.getKey();
List<EntryEventType> eventTypes = eventsPerKey.get(key);
if (eventTypes == null) {
eventTypes = new ArrayList<EntryEventType>();
eventsPerKey.put(key, eventTypes);
}
EntryEventType eventType = event.getEventType();
eventTypes.add(eventType);
}
Set<Map.Entry<Integer, List<EntryEventType>>> entries = eventsPerKey.entrySet();
for (Map.Entry<Integer, List<EntryEventType>> entry : entries) {
List<EntryEventType> eventTypes = entry.getValue();
EntryEventType prev = null;
for (int i = 0; i < eventTypes.size(); i++) {
final EntryEventType eventType = eventTypes.get(i);
if (i == 0) {
assertEquals(EntryEventType.ADDED, eventType);
prev = eventType;
continue;
}
if (prev.equals(EntryEventType.ADDED)) {
assertEquals(EntryEventType.EVICTED, eventType);
} else if (prev.equals(EntryEventType.EVICTED)) {
assertEquals(EntryEventType.ADDED, eventType);
}
prev = eventType;
}
}
}
use of com.hazelcast.core.EntryEventType in project hazelcast by hazelcast.
the class MapListenerAdaptors method createListenerAdapters.
/**
* Creates a {@link com.hazelcast.map.impl.ListenerAdapter} array
* for all event types of {@link com.hazelcast.core.EntryEventType}.
*
* @param mapListener a {@link com.hazelcast.map.listener.MapListener} instance.
* @return an array of {@link com.hazelcast.map.impl.ListenerAdapter}
*/
public static ListenerAdapter[] createListenerAdapters(MapListener mapListener) {
EntryEventType[] values = EntryEventType.values();
ListenerAdapter[] listenerAdapters = new ListenerAdapter[values.length];
for (EntryEventType eventType : values) {
listenerAdapters[eventType.ordinal()] = createListenerAdapter(eventType, mapListener);
}
return listenerAdapters;
}
Aggregations