use of com.hazelcast.map.MapEvent in project hazelcast by hazelcast.
the class EventPublisherHelper method createIMapEvent.
public static IMapEvent createIMapEvent(EventData eventData, EventFilter filter, Member member, SerializationService serializationService) {
String source = eventData.getSource();
int eventType = eventData.getEventType();
if (eventType == EventLostEvent.EVENT_TYPE) {
LocalEntryEventData localEventData = (LocalEntryEventData) eventData;
int partitionId = localEventData.getPartitionId();
return new EventLostEvent(source, null, partitionId);
}
if (eventType == EntryEventType.CLEAR_ALL.getType() || eventType == EntryEventType.EVICT_ALL.getType()) {
LocalCacheWideEventData localCacheWideEventData = (LocalCacheWideEventData) eventData;
int numberOfEntriesAffected = localCacheWideEventData.getNumberOfEntriesAffected();
return new MapEvent(source, null, eventType, numberOfEntriesAffected);
}
LocalEntryEventData localEntryEventData = (LocalEntryEventData) eventData;
Data dataKey = localEntryEventData.getKeyData();
Data dataNewValue = localEntryEventData.getValueData();
Data dataOldValue = localEntryEventData.getOldValueData();
boolean includeValue = isIncludeValue(filter);
return new DataAwareEntryEvent(member, eventType, source, dataKey, (includeValue ? dataNewValue : null), (includeValue ? dataOldValue : null), null, serializationService);
}
use of com.hazelcast.map.MapEvent in project hazelcast by hazelcast.
the class MultiMapEventsDispatcher method dispatchMapEventData.
private void dispatchMapEventData(EventData eventData, EntryListener listener) {
MapEventData mapEventData = (MapEventData) eventData;
Member member = getMemberOrNull(eventData);
if (member == null) {
return;
}
MapEvent event = createMapEvent(mapEventData, member);
dispatch0(event, listener);
incrementEventStats(event);
}
use of com.hazelcast.map.MapEvent in project hazelcast by hazelcast.
the class MapEventPublishingService method dispatchMapEventData.
private void dispatchMapEventData(MapEventData mapEventData, ListenerAdapter listener) {
Member member = getMember(mapEventData);
MapEvent event = createMapEvent(mapEventData, member);
callListener(listener, event);
}
use of com.hazelcast.map.MapEvent in project hazelcast by hazelcast.
the class QueryCacheListenerTest method listenerShouldReceive_CLEAR_ALL_Event_whenIMapCleared.
@Test
public void listenerShouldReceive_CLEAR_ALL_Event_whenIMapCleared() {
IMap<Integer, Employee> map = getIMapWithDefaultConfig(TRUE_PREDICATE, useNaturalFilteringStrategy);
int entryCount = 1000;
final AtomicInteger clearAllEventCount = new AtomicInteger();
final QueryCache<Integer, Employee> queryCache = map.getQueryCache(cacheName, new EntryAdapter() {
@Override
public void mapCleared(MapEvent e) {
clearAllEventCount.incrementAndGet();
}
}, TRUE_PREDICATE, false);
populateMap(map, entryCount);
assertQueryCacheSizeEventually(entryCount, queryCache);
map.clear();
assertTrueEventually(() -> {
// expecting at least 1 event
assertTrue(clearAllEventCount.get() >= 1);
assertEquals(0, queryCache.size());
});
}
use of com.hazelcast.map.MapEvent in project hazelcast by hazelcast.
the class MultiMapListenerTest method testMultiMapEntryListener.
@Test
public void testMultiMapEntryListener() {
HazelcastInstance instance = createHazelcastInstance();
MultiMap<String, String> multiMap = instance.getMultiMap("testMultiMapEntryListener");
final Set<String> expectedValues = new CopyOnWriteArraySet<String>();
expectedValues.add("hello");
expectedValues.add("world");
expectedValues.add("again");
final CountDownLatch latchAdded = new CountDownLatch(3);
final CountDownLatch latchRemoved = new CountDownLatch(1);
final CountDownLatch latchCleared = new CountDownLatch(1);
multiMap.addEntryListener(new EntryAdapter<String, String>() {
public void entryAdded(EntryEvent<String, String> event) {
String key = event.getKey();
String value = event.getValue();
if ("2".equals(key)) {
assertEquals("again", value);
} else {
assertEquals("1", key);
}
assertContains(expectedValues, value);
expectedValues.remove(value);
latchAdded.countDown();
}
public void entryRemoved(EntryEvent<String, String> event) {
assertEquals("2", event.getKey());
assertEquals("again", event.getOldValue());
latchRemoved.countDown();
}
public void entryUpdated(EntryEvent<String, String> event) {
throw new AssertionError("MultiMap cannot get update event!");
}
public void entryEvicted(EntryEvent<String, String> event) {
entryRemoved(event);
}
@Override
public void mapEvicted(MapEvent event) {
}
@Override
public void mapCleared(MapEvent event) {
latchCleared.countDown();
}
}, true);
multiMap.put("1", "hello");
multiMap.put("1", "world");
multiMap.put("2", "again");
Collection<String> values = multiMap.get("1");
assertEquals(2, values.size());
assertContains(values, "hello");
assertContains(values, "world");
assertEquals(1, multiMap.get("2").size());
assertEquals(3, multiMap.size());
multiMap.remove("2");
assertEquals(2, multiMap.size());
multiMap.clear();
assertOpenEventually(latchAdded);
assertOpenEventually(latchRemoved);
assertOpenEventually(latchCleared);
}
Aggregations