Search in sources :

Example 1 with EntryListener

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

the class ClusterListener method simulateCacheInserts.

private void simulateCacheInserts(Cache cache) {
    EntryListener EntryListener = EntryListeners.get(cache);
    if (EntryListener != null) {
        if (cache instanceof CacheWrapper) {
            Cache wrapped = ((CacheWrapper) cache).getWrappedCache();
            if (wrapped instanceof ClusteredCache) {
                ClusteredCache clusteredCache = (ClusteredCache) wrapped;
                for (Map.Entry entry : (Set<Map.Entry>) cache.entrySet()) {
                    EntryEvent event = new EntryEvent(clusteredCache.map.getName(), cluster.getLocalMember(), EntryEventType.ADDED.getType(), entry.getKey(), null, entry.getValue());
                    EntryListener.entryAdded(event);
                }
            }
        }
    }
}
Also used : CacheWrapper(org.jivesoftware.util.cache.CacheWrapper) HashSet(java.util.HashSet) Set(java.util.Set) EntryEvent(com.hazelcast.core.EntryEvent) EntryListener(com.hazelcast.core.EntryListener) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Cache(org.jivesoftware.util.cache.Cache)

Example 2 with EntryListener

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

the class ClientMapTest method testPredicateListenerWithPortableKey.

@Test
@SuppressWarnings("deprecation")
public void testPredicateListenerWithPortableKey() throws InterruptedException {
    IMap<Portable, Integer> tradeMap = createMap();
    final AtomicInteger atomicInteger = new AtomicInteger(0);
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    EntryListener listener = new EntryAdapter() {

        @Override
        public void entryAdded(EntryEvent event) {
            atomicInteger.incrementAndGet();
            countDownLatch.countDown();
        }
    };
    NamedPortable key = new NamedPortable("a", 1);
    tradeMap.addEntryListener(listener, key, true);
    NamedPortable key2 = new NamedPortable("b", 2);
    tradeMap.put(key2, 1);
    assertFalse(countDownLatch.await(5, TimeUnit.SECONDS));
    assertEquals(0, atomicInteger.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Portable(com.hazelcast.nio.serialization.Portable) NamedPortable(com.hazelcast.nio.serialization.NamedPortable) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EntryAdapter(com.hazelcast.core.EntryAdapter) EntryEvent(com.hazelcast.core.EntryEvent) CountDownLatch(java.util.concurrent.CountDownLatch) EntryListener(com.hazelcast.core.EntryListener) NamedPortable(com.hazelcast.nio.serialization.NamedPortable) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 3 with EntryListener

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

the class ClientMapTest method testEntryListener.

/**
     * Issue #996
     */
@Test
@SuppressWarnings({ "deprecation", "unchecked" })
public void testEntryListener() throws InterruptedException {
    CountDownLatch gateAdd = new CountDownLatch(3);
    CountDownLatch gateRemove = new CountDownLatch(1);
    CountDownLatch gateEvict = new CountDownLatch(1);
    CountDownLatch gateUpdate = new CountDownLatch(1);
    CountDownLatch gateClearAll = new CountDownLatch(1);
    CountDownLatch gateEvictAll = new CountDownLatch(1);
    String mapName = randomString();
    IMap<Integer, Deal> serverMap = server.getMap(mapName);
    serverMap.put(3, new Deal(3));
    IMap<Integer, Deal> clientMap = client.getMap(mapName);
    assertEquals(1, clientMap.size());
    EntryListener listener = new IntegerDealEntryListener(gateAdd, gateRemove, gateEvict, gateUpdate, gateClearAll, gateEvictAll);
    clientMap.addEntryListener(listener, new SqlPredicate("id=1"), 2, true);
    clientMap.put(2, new Deal(1));
    clientMap.put(2, new Deal(1));
    clientMap.remove(2);
    clientMap.put(2, new Deal(1));
    clientMap.evict(2);
    clientMap.clear();
    clientMap.put(2, new Deal(1));
    clientMap.evictAll();
    assertTrue(gateAdd.await(10, TimeUnit.SECONDS));
    assertTrue(gateRemove.await(10, TimeUnit.SECONDS));
    assertTrue(gateEvict.await(10, TimeUnit.SECONDS));
    assertTrue(gateUpdate.await(10, TimeUnit.SECONDS));
    assertTrue(gateClearAll.await(10, TimeUnit.SECONDS));
    assertTrue(gateEvictAll.await(10, TimeUnit.SECONDS));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SqlPredicate(com.hazelcast.query.SqlPredicate) CountDownLatch(java.util.concurrent.CountDownLatch) EntryListener(com.hazelcast.core.EntryListener) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 4 with EntryListener

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

the class MapPreconditionsTest method testAddLocalEntryListenerWithEntryListenerAndPredicate_NullListener.

@Test(expected = UnsupportedOperationException.class)
public void testAddLocalEntryListenerWithEntryListenerAndPredicate_NullListener() throws Exception {
    EntryListener entryListener = null;
    Predicate predicate = new TruePredicate();
    map.addLocalEntryListener(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 5 with EntryListener

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

the class MapPreconditionsTest method testAddEntryListenerWithEntryListener.

@Test(expected = NullPointerException.class)
public void testAddEntryListenerWithEntryListener() throws Exception {
    EntryListener entryListener = null;
    map.addEntryListener(entryListener, false);
}
Also used : EntryListener(com.hazelcast.core.EntryListener) 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