use of com.hazelcast.map.listener.MapListener in project hazelcast by hazelcast.
the class MapListenerTest method main.
public static void main(String[] args) throws InterruptedException {
// create Hazelcast instance
Config config = new Config();
config.setInstanceName("hz-maplistener");
config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
config.getNetworkConfig().getInterfaces().setInterfaces(Arrays.asList(new String[] { "127.0.0.1" }));
HazelcastInstance hz = Hazelcast.newHazelcastInstance(config);
IMap<String, Person> map = hz.getMap("map");
MapListener listener = new AllListener();
map.addEntryListener(listener, new SqlPredicate("age > " + AGE_THRESHOLD), true);
MapRandomizer mapRandomizer = new MapRandomizer(map);
Thread t = new Thread(mapRandomizer);
t.start();
// let it run for 1 minute
Thread.sleep(60000);
mapRandomizer.setRunning(false);
// assertions
assertCount(ENTRIES, ENTRIES_OBSERVED, "entries");
assertCount(EXITS, EXITS_OBSERVED, "exits");
// dumpMap(map);
hz.shutdown();
}
use of com.hazelcast.map.listener.MapListener in project hazelcast by hazelcast.
the class AbstractQueryCacheEndToEndConstructor method addListener.
private String addListener(QueryCacheRequest request) {
MapListener listener = request.getListener();
if (listener == null) {
return null;
}
QueryCacheEventService eventService = subscriberContext.getEventService();
return eventService.addListener(request.getMapName(), request.getCacheName(), listener);
}
use of com.hazelcast.map.listener.MapListener in project hazelcast by hazelcast.
the class AbstractQueryCacheConfigurator method setEntryListener.
protected void setEntryListener(String mapName, String cacheId, QueryCacheConfig config) {
for (EntryListenerConfig listenerConfig : config.getEntryListenerConfigs()) {
MapListener listener = getListener(listenerConfig);
if (listener != null) {
EventFilter filter = new EntryEventFilter(null, listenerConfig.isIncludeValue());
eventService.addListener(mapName, cacheId, listener, filter);
}
}
}
use of com.hazelcast.map.listener.MapListener in project hazelcast by hazelcast.
the class ListenerConfigHolder method asListenerConfig.
public <T extends ListenerConfig> T asListenerConfig(SerializationService serializationService) {
validate();
ListenerConfig listenerConfig = null;
if (className != null) {
switch(listenerType) {
case GENERIC:
listenerConfig = new ListenerConfig(className);
break;
case ITEM:
listenerConfig = new ItemListenerConfig(className, includeValue);
break;
case ENTRY:
listenerConfig = new EntryListenerConfig(className, local, includeValue);
break;
case SPLIT_BRAIN_PROTECTION:
listenerConfig = new SplitBrainProtectionListenerConfig(className);
break;
case CACHE_PARTITION_LOST:
listenerConfig = new CachePartitionLostListenerConfig(className);
break;
case MAP_PARTITION_LOST:
listenerConfig = new MapPartitionLostListenerConfig(className);
break;
default:
}
} else {
EventListener eventListener = serializationService.toObject(listenerImplementation);
switch(listenerType) {
case GENERIC:
listenerConfig = new ListenerConfig(eventListener);
break;
case ITEM:
listenerConfig = new ItemListenerConfig((ItemListener) eventListener, includeValue);
break;
case ENTRY:
listenerConfig = new EntryListenerConfig((MapListener) eventListener, local, includeValue);
break;
case SPLIT_BRAIN_PROTECTION:
listenerConfig = new SplitBrainProtectionListenerConfig((SplitBrainProtectionListener) eventListener);
break;
case CACHE_PARTITION_LOST:
listenerConfig = new CachePartitionLostListenerConfig((CachePartitionLostListener) eventListener);
break;
case MAP_PARTITION_LOST:
listenerConfig = new MapPartitionLostListenerConfig((MapPartitionLostListener) eventListener);
break;
default:
}
}
return (T) listenerConfig;
}
use of com.hazelcast.map.listener.MapListener in project hazelcast by hazelcast.
the class AbstractMapNullTest method testNullability.
@Test
public void testNullability() {
EntryAddedListener sampleMapListener = event -> {
};
Predicate<Object, Object> samplePredicate = Predicates.alwaysTrue();
TimeUnit sampleTimeUnit = TimeUnit.SECONDS;
assertThrowsNPE(m -> m.putAll(null));
assertThrowsNPE(m -> m.containsKey(null));
assertThrowsNPE(m -> m.containsValue(null));
assertThrowsNPE(m -> m.get(null));
assertThrowsNPE(m -> m.put(null, ""));
assertThrowsNPE(m -> m.put("", null));
assertThrowsNPE(m -> m.remove(null));
assertThrowsNPE(m -> m.remove(null, ""));
assertThrowsNPE(m -> m.remove("", null));
assertThrowsNPE(m -> m.removeAll(null));
assertThrowsNPE(m -> m.delete(null));
assertThrowsNPE(m -> m.loadAll(null, true));
assertThrowsNPE(m -> m.getAsync(null));
assertThrowsNPE(m -> m.putAsync(null, ""));
assertThrowsNPE(m -> m.putAsync("", null));
assertThrowsNPE(m -> m.putAsync(null, "", -1, sampleTimeUnit));
assertThrowsNPE(m -> m.putAsync("", null, -1, sampleTimeUnit));
assertThrowsNPE(m -> m.putAsync("", "", -1, null));
assertThrowsNPE(m -> m.putAsync(null, "", -1, sampleTimeUnit, -1, sampleTimeUnit));
assertThrowsNPE(m -> m.putAsync("", null, -1, sampleTimeUnit, -1, sampleTimeUnit));
assertThrowsNPE(m -> m.putAsync("", "", -1, null, -1, sampleTimeUnit));
assertThrowsNPE(m -> m.putAsync("", "", -1, sampleTimeUnit, -1, null));
assertThrowsNPE(m -> m.setAsync(null, ""));
assertThrowsNPE(m -> m.setAsync("", null));
assertThrowsNPE(m -> m.setAsync(null, "", -1, sampleTimeUnit));
assertThrowsNPE(m -> m.setAsync("", null, -1, sampleTimeUnit));
assertThrowsNPE(m -> m.setAsync("", "", -1, null));
assertThrowsNPE(m -> m.setAsync(null, "", -1, sampleTimeUnit, -1, sampleTimeUnit));
assertThrowsNPE(m -> m.setAsync("", null, -1, sampleTimeUnit, -1, sampleTimeUnit));
assertThrowsNPE(m -> m.setAsync("", "", -1, null, -1, sampleTimeUnit));
assertThrowsNPE(m -> m.setAsync("", "", -1, sampleTimeUnit, -1, null));
assertThrowsNPE(m -> m.tryRemove(null, -1, sampleTimeUnit));
assertThrowsNPE(m -> m.tryRemove("", -1, null));
assertThrowsNPE(m -> m.tryPut(null, "", -1, sampleTimeUnit));
assertThrowsNPE(m -> m.tryPut("", null, -1, sampleTimeUnit));
assertThrowsNPE(m -> m.tryPut("", "", -1, null));
assertThrowsNPE(m -> m.put(null, "", -1, sampleTimeUnit));
assertThrowsNPE(m -> m.put("", null, -1, sampleTimeUnit));
assertThrowsNPE(m -> m.put("", "", -1, null));
assertThrowsNPE(m -> m.putTransient(null, "", -1, sampleTimeUnit));
assertThrowsNPE(m -> m.putTransient("", null, -1, sampleTimeUnit));
assertThrowsNPE(m -> m.putTransient("", "", -1, null));
assertThrowsNPE(m -> m.putTransient(null, "", -1, sampleTimeUnit, -1, sampleTimeUnit));
assertThrowsNPE(m -> m.putTransient("", null, -1, sampleTimeUnit, -1, sampleTimeUnit));
assertThrowsNPE(m -> m.putTransient("", "", -1, null, -1, sampleTimeUnit));
assertThrowsNPE(m -> m.putTransient("", "", -1, sampleTimeUnit, -1, null));
assertThrowsNPE(m -> m.putIfAbsent(null, ""));
assertThrowsNPE(m -> m.putIfAbsent("", null));
assertThrowsNPE(m -> m.putIfAbsent(null, "", -1, sampleTimeUnit));
assertThrowsNPE(m -> m.putIfAbsent("", null, -1, sampleTimeUnit));
assertThrowsNPE(m -> m.putIfAbsent("", "", -1, null));
assertThrowsNPE(m -> m.putIfAbsent(null, "", -1, sampleTimeUnit, -1, sampleTimeUnit));
assertThrowsNPE(m -> m.putIfAbsent("", null, -1, sampleTimeUnit, -1, sampleTimeUnit));
assertThrowsNPE(m -> m.putIfAbsent("", "", -1, null, -1, sampleTimeUnit));
assertThrowsNPE(m -> m.putIfAbsent("", "", -1, sampleTimeUnit, -1, null));
assertThrowsNPE(m -> m.replace(null, "", ""));
assertThrowsNPE(m -> m.replace("", null, ""));
assertThrowsNPE(m -> m.replace("", "", null));
assertThrowsNPE(m -> m.replace(null, ""));
assertThrowsNPE(m -> m.replace("", null));
assertThrowsNPE(m -> m.set(null, ""));
assertThrowsNPE(m -> m.set("", null));
assertThrowsNPE(m -> m.set(null, "", -1, sampleTimeUnit));
assertThrowsNPE(m -> m.set("", null, -1, sampleTimeUnit));
assertThrowsNPE(m -> m.set("", "", -1, null));
assertThrowsNPE(m -> m.set(null, "", -1, sampleTimeUnit, -1, sampleTimeUnit));
assertThrowsNPE(m -> m.set("", null, -1, sampleTimeUnit, -1, sampleTimeUnit));
assertThrowsNPE(m -> m.set("", "", -1, null, -1, sampleTimeUnit));
assertThrowsNPE(m -> m.set("", "", -1, sampleTimeUnit, -1, null));
assertThrowsNPE(m -> m.setAll(null));
assertThrowsNPE(m -> m.setAllAsync(null));
assertThrowsNPE(m -> m.lock(null));
assertThrowsNPE(m -> m.lock(null, -1, sampleTimeUnit));
assertThrowsNPE(m -> m.tryLock(null));
assertThrowsNPE(m -> m.tryLock(null, -1, sampleTimeUnit));
assertThrowsNPE(m -> m.tryLock(null, -1, sampleTimeUnit, -1, sampleTimeUnit));
assertThrowsNPE(m -> m.unlock(null));
assertThrowsNPE(m -> m.forceUnlock(null));
if (isNotClient()) {
assertThrowsNPE(m -> m.addLocalEntryListener((MapListener) null));
assertThrowsNPE(m -> m.addLocalEntryListener((MapListener) null, samplePredicate, true));
assertThrowsNPE(m -> m.addLocalEntryListener(sampleMapListener, null, true));
assertThrowsNPE(m -> m.addLocalEntryListener(sampleMapListener, null, "", true));
assertThrowsNPE(m -> m.localKeySet(null));
}
assertThrowsNPE(m -> m.addInterceptor(null));
assertThrowsNPE(m -> m.removeInterceptor(null));
assertThrowsNPE(m -> m.addEntryListener((MapListener) null, "", true));
assertThrowsNPE(m -> m.addEntryListener((MapListener) null, (Object) null, true));
assertThrowsNPE(m -> m.addEntryListener((MapListener) null, samplePredicate, true));
assertThrowsNPE(m -> m.addEntryListener(sampleMapListener, null, true));
assertThrowsNPE(m -> m.addEntryListener((MapListener) null, samplePredicate, "", true));
assertThrowsNPE(m -> m.addEntryListener(sampleMapListener, null, "", true));
assertThrowsNPE(m -> m.removeEntryListener(null));
assertThrowsNPE(m -> m.addPartitionLostListener(null));
assertThrowsNPE(m -> m.removePartitionLostListener(null));
assertThrowsNPE(m -> m.getEntryView(null));
assertThrowsNPE(m -> m.evict(null));
assertThrowsNPE(m -> m.keySet(null));
assertThrowsNPE(m -> m.entrySet(null));
assertThrowsNPE(m -> m.values(null));
assertThrows(NullPointerException.class, m -> m.addIndex(null, "attribute"));
assertThrows(NullPointerException.class, m -> m.addIndex(IndexType.SORTED, null));
assertThrows(NullPointerException.class, m -> m.addIndex(null));
assertThrowsNPE(m -> m.aggregate(null));
assertThrowsNPE(m -> m.aggregate(null, samplePredicate));
assertThrowsNPE(m -> m.aggregate(new CountAggregator<>(), null));
assertThrowsNPE(m -> m.project(null, samplePredicate));
assertThrowsNPE(m -> m.project(Projections.identity(), null));
assertThrowsNPE(m -> m.getQueryCache(null));
assertThrowsNPE(m -> m.getQueryCache(null, samplePredicate, true));
assertThrowsNPE(m -> m.getQueryCache("cache", null, true));
assertThrowsNPE(m -> m.getQueryCache(null, sampleMapListener, samplePredicate, true));
assertThrowsNPE(m -> m.getQueryCache("cache", null, samplePredicate, true));
assertThrowsNPE(m -> m.getQueryCache("cache", sampleMapListener, null, true));
assertThrowsNPE(m -> m.setTtl(null, -1, sampleTimeUnit));
assertThrowsNPE(m -> m.setTtl("", -1, null));
}
Aggregations