Search in sources :

Example 26 with EntryListener

use of com.hazelcast.core.EntryListener in project hazelcast by hazelcast.

the class MapPreconditionsTest method testAddLocalEntryListenerWithEntryListenerAndPredicateAndKey_NullPredicate.

@Test(expected = UnsupportedOperationException.class)
public void testAddLocalEntryListenerWithEntryListenerAndPredicateAndKey_NullPredicate() throws Exception {
    EntryListener entryListener = new TestEntryListener();
    Predicate predicate = null;
    map.addLocalEntryListener(entryListener, predicate, null, true);
}
Also used : EntryListener(com.hazelcast.core.EntryListener) Predicate(com.hazelcast.query.Predicate) TruePredicate(com.hazelcast.query.TruePredicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 27 with EntryListener

use of com.hazelcast.core.EntryListener in project hazelcast by hazelcast.

the class ReplicatedMapEventPublishingService method dispatchEvent.

@Override
public void dispatchEvent(Object event, Object listener) {
    if ((event instanceof EntryEventData)) {
        EntryEventData entryEventData = (EntryEventData) event;
        Member member = getMember(entryEventData);
        EntryEvent entryEvent = createDataAwareEntryEvent(entryEventData, member);
        EntryListener entryListener = (EntryListener) listener;
        switch(entryEvent.getEventType()) {
            case ADDED:
                entryListener.entryAdded(entryEvent);
                break;
            case EVICTED:
                entryListener.entryEvicted(entryEvent);
                break;
            case UPDATED:
                entryListener.entryUpdated(entryEvent);
                break;
            case REMOVED:
                entryListener.entryRemoved(entryEvent);
                break;
            default:
                throw new IllegalArgumentException("event type " + entryEvent.getEventType() + " not supported");
        }
        String mapName = ((EntryEventData) event).getMapName();
        Boolean statisticsEnabled = statisticsMap.get(mapName);
        if (statisticsEnabled == null) {
            ReplicatedMapConfig mapConfig = config.findReplicatedMapConfig(mapName);
            statisticsEnabled = mapConfig.isStatisticsEnabled();
            statisticsMap.put(mapName, statisticsEnabled);
        }
        if (statisticsEnabled) {
            int partitionId = nodeEngine.getPartitionService().getPartitionId(entryEventData.getDataKey());
            ReplicatedRecordStore recordStore = replicatedMapService.getPartitionContainer(partitionId).getRecordStore(mapName);
            if (recordStore instanceof AbstractReplicatedRecordStore) {
                LocalReplicatedMapStatsImpl stats = ((AbstractReplicatedRecordStore) recordStore).getStats();
                stats.incrementReceivedEvents();
            }
        }
    } else if (event instanceof MapEventData) {
        MapEventData mapEventData = (MapEventData) event;
        Member member = getMember(mapEventData);
        MapEvent mapEvent = new MapEvent(mapEventData.getMapName(), member, mapEventData.getEventType(), mapEventData.getNumberOfEntries());
        EntryListener entryListener = (EntryListener) listener;
        EntryEventType type = EntryEventType.getByType(mapEventData.getEventType());
        switch(type) {
            case CLEAR_ALL:
                entryListener.mapCleared(mapEvent);
                break;
            default:
                throw new IllegalArgumentException("event type " + type + " not supported");
        }
    }
}
Also used : AbstractReplicatedRecordStore(com.hazelcast.replicatedmap.impl.record.AbstractReplicatedRecordStore) MapEvent(com.hazelcast.core.MapEvent) MapEventData(com.hazelcast.map.impl.event.MapEventData) EntryListener(com.hazelcast.core.EntryListener) EntryEventType(com.hazelcast.core.EntryEventType) LocalReplicatedMapStatsImpl(com.hazelcast.monitor.impl.LocalReplicatedMapStatsImpl) AbstractReplicatedRecordStore(com.hazelcast.replicatedmap.impl.record.AbstractReplicatedRecordStore) ReplicatedRecordStore(com.hazelcast.replicatedmap.impl.record.ReplicatedRecordStore) DataAwareEntryEvent(com.hazelcast.map.impl.DataAwareEntryEvent) EntryEvent(com.hazelcast.core.EntryEvent) ReplicatedMapConfig(com.hazelcast.config.ReplicatedMapConfig) EntryEventData(com.hazelcast.map.impl.event.EntryEventData) Member(com.hazelcast.core.Member)

Example 28 with EntryListener

use of com.hazelcast.core.EntryListener in project hazelcast by hazelcast.

the class ObjectMultiMapProxy method initialize.

@Override
public void initialize() {
    final NodeEngine nodeEngine = getNodeEngine();
    List<EntryListenerConfig> listenerConfigs = config.getEntryListenerConfigs();
    for (EntryListenerConfig listenerConfig : listenerConfigs) {
        EntryListener listener = null;
        if (listenerConfig.getImplementation() != null) {
            listener = listenerConfig.getImplementation();
        } else if (listenerConfig.getClassName() != null) {
            try {
                listener = ClassLoaderUtil.newInstance(nodeEngine.getConfigClassLoader(), listenerConfig.getClassName());
            } catch (Exception e) {
                throw ExceptionUtil.rethrow(e);
            }
        }
        if (listener != null) {
            if (listener instanceof HazelcastInstanceAware) {
                ((HazelcastInstanceAware) listener).setHazelcastInstance(nodeEngine.getHazelcastInstance());
            }
            if (listenerConfig.isLocal()) {
                addLocalEntryListener(listener);
            } else {
                addEntryListener(listener, listenerConfig.isIncludeValue());
            }
        }
    }
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) EntryListener(com.hazelcast.core.EntryListener) HazelcastInstanceAware(com.hazelcast.core.HazelcastInstanceAware) HazelcastException(com.hazelcast.core.HazelcastException)

Example 29 with EntryListener

use of com.hazelcast.core.EntryListener in project hazelcast by hazelcast.

the class MapPreconditionsTest method testAddEntryListenerWithEntryListenerAndPredicate_NullListener.

@Test(expected = NullPointerException.class)
public void testAddEntryListenerWithEntryListenerAndPredicate_NullListener() throws Exception {
    EntryListener entryListener = null;
    Predicate predicate = new TruePredicate();
    map.addEntryListener(entryListener, predicate, false);
}
Also used : TruePredicate(com.hazelcast.query.TruePredicate) EntryListener(com.hazelcast.core.EntryListener) Predicate(com.hazelcast.query.Predicate) TruePredicate(com.hazelcast.query.TruePredicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 30 with EntryListener

use of com.hazelcast.core.EntryListener in project hazelcast by hazelcast.

the class MapPreconditionsTest method testAddEntryListenerWithEntryListenerAndPredicateAndKey_NullPredicate.

@Test(expected = NullPointerException.class)
public void testAddEntryListenerWithEntryListenerAndPredicateAndKey_NullPredicate() throws Exception {
    EntryListener entryListener = new TestEntryListener();
    Predicate predicate = null;
    map.addEntryListener(entryListener, predicate, null, true);
}
Also used : EntryListener(com.hazelcast.core.EntryListener) Predicate(com.hazelcast.query.Predicate) TruePredicate(com.hazelcast.query.TruePredicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

EntryListener (com.hazelcast.core.EntryListener)30 ParallelTest (com.hazelcast.test.annotation.ParallelTest)26 QuickTest (com.hazelcast.test.annotation.QuickTest)26 Test (org.junit.Test)26 Predicate (com.hazelcast.query.Predicate)16 TruePredicate (com.hazelcast.query.TruePredicate)16 EntryEvent (com.hazelcast.core.EntryEvent)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 EntryAdapter (com.hazelcast.core.EntryAdapter)2 SqlPredicate (com.hazelcast.query.SqlPredicate)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 EntryListenerConfig (com.hazelcast.config.EntryListenerConfig)1 ReplicatedMapConfig (com.hazelcast.config.ReplicatedMapConfig)1 EntryEventType (com.hazelcast.core.EntryEventType)1 HazelcastException (com.hazelcast.core.HazelcastException)1 HazelcastInstanceAware (com.hazelcast.core.HazelcastInstanceAware)1 IMap (com.hazelcast.core.IMap)1 MapEvent (com.hazelcast.core.MapEvent)1