Search in sources :

Example 11 with EntryListenerConfig

use of com.hazelcast.config.EntryListenerConfig in project hazelcast by hazelcast.

the class ListenerTest method testConfigListenerRegistration.

@Test
public void testConfigListenerRegistration() throws InterruptedException {
    final CountDownLatch latch = new CountDownLatch(1);
    String name = randomString();
    Config config = getConfig();
    MapConfig mapConfig = config.getMapConfig(name);
    EntryListenerConfig entryListenerConfig = new EntryListenerConfig();
    entryListenerConfig.setImplementation(new EntryAdapter() {

        public void entryAdded(EntryEvent event) {
            latch.countDown();
        }
    });
    mapConfig.addEntryListenerConfig(entryListenerConfig);
    HazelcastInstance instance = createHazelcastInstance(config);
    IMap<Object, Object> map = instance.getMap(name);
    map.put(1, 1);
    assertTrue(latch.await(10, TimeUnit.SECONDS));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) Config(com.hazelcast.config.Config) MapPartitionLostListenerConfig(com.hazelcast.config.MapPartitionLostListenerConfig) EntryAdapter(com.hazelcast.core.EntryAdapter) EntryEvent(com.hazelcast.core.EntryEvent) MapConfig(com.hazelcast.config.MapConfig) CountDownLatch(java.util.concurrent.CountDownLatch) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 12 with EntryListenerConfig

use of com.hazelcast.config.EntryListenerConfig in project hazelcast by hazelcast.

the class ListenerTest method hazelcastAwareEntryListener_whenConfiguredViaClassName_thenInjectHazelcastInstance.

@Test
public void hazelcastAwareEntryListener_whenConfiguredViaClassName_thenInjectHazelcastInstance() throws InterruptedException {
    EntryListenerConfig listenerConfig = new EntryListenerConfig("com.hazelcast.map.ListenerTest$PingPongListener", false, true);
    hazelcastAwareEntryListener_injectHazelcastInstance(listenerConfig);
}
Also used : EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 13 with EntryListenerConfig

use of com.hazelcast.config.EntryListenerConfig in project hazelcast by hazelcast.

the class MultiMapListenerTest method testConfigListenerRegistration.

@Test
public void testConfigListenerRegistration() throws InterruptedException {
    Config config = new Config();
    final String name = "default";
    final CountDownLatch latch = new CountDownLatch(1);
    config.getMultiMapConfig(name).addEntryListenerConfig(new EntryListenerConfig().setImplementation(new EntryAdapter() {

        public void entryAdded(EntryEvent event) {
            latch.countDown();
        }
    }));
    final HazelcastInstance hz = createHazelcastInstance(config);
    hz.getMultiMap(name).put(1, 1);
    assertTrue(latch.await(10, TimeUnit.SECONDS));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MultiMapConfig(com.hazelcast.config.MultiMapConfig) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) Config(com.hazelcast.config.Config) EntryAdapter(com.hazelcast.core.EntryAdapter) EntryEvent(com.hazelcast.core.EntryEvent) CountDownLatch(java.util.concurrent.CountDownLatch) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 14 with EntryListenerConfig

use of com.hazelcast.config.EntryListenerConfig in project hazelcast by hazelcast.

the class TestFullApplicationContext method testMapConfig.

@Test
public void testMapConfig() {
    assertNotNull(config);
    assertEquals(26, config.getMapConfigs().size());
    MapConfig testMapConfig = config.getMapConfig("testMap");
    assertNotNull(testMapConfig);
    assertEquals("testMap", testMapConfig.getName());
    assertEquals(2, testMapConfig.getBackupCount());
    assertEquals(EvictionPolicy.NONE, testMapConfig.getEvictionPolicy());
    assertEquals(Integer.MAX_VALUE, testMapConfig.getMaxSizeConfig().getSize());
    assertEquals(30, testMapConfig.getEvictionPercentage());
    assertEquals(0, testMapConfig.getTimeToLiveSeconds());
    assertTrue(testMapConfig.getHotRestartConfig().isEnabled());
    assertTrue(testMapConfig.getHotRestartConfig().isFsync());
    assertEquals(1000, testMapConfig.getMinEvictionCheckMillis());
    assertEquals("PUT_IF_ABSENT", testMapConfig.getMergePolicy());
    assertTrue(testMapConfig.isReadBackupData());
    assertEquals(2, testMapConfig.getMapIndexConfigs().size());
    for (MapIndexConfig index : testMapConfig.getMapIndexConfigs()) {
        if ("name".equals(index.getAttribute())) {
            assertFalse(index.isOrdered());
        } else if ("age".equals(index.getAttribute())) {
            assertTrue(index.isOrdered());
        } else {
            fail("unknown index!");
        }
    }
    assertEquals(2, testMapConfig.getMapAttributeConfigs().size());
    for (MapAttributeConfig attribute : testMapConfig.getMapAttributeConfigs()) {
        if ("power".equals(attribute.getName())) {
            assertEquals("com.car.PowerExtractor", attribute.getExtractor());
        } else if ("weight".equals(attribute.getName())) {
            assertEquals("com.car.WeightExtractor", attribute.getExtractor());
        } else {
            fail("unknown attribute!");
        }
    }
    assertEquals("my-quorum", testMapConfig.getQuorumName());
    // test that the testMapConfig has a mapStoreConfig and it is correct
    MapStoreConfig testMapStoreConfig = testMapConfig.getMapStoreConfig();
    assertNotNull(testMapStoreConfig);
    assertEquals("com.hazelcast.spring.DummyStore", testMapStoreConfig.getClassName());
    assertTrue(testMapStoreConfig.isEnabled());
    assertEquals(0, testMapStoreConfig.getWriteDelaySeconds());
    assertEquals(10, testMapStoreConfig.getWriteBatchSize());
    assertTrue(testMapStoreConfig.isWriteCoalescing());
    assertEquals(MapStoreConfig.InitialLoadMode.EAGER, testMapStoreConfig.getInitialLoadMode());
    // test that the testMapConfig has a nearCacheConfig and it is correct
    NearCacheConfig testNearCacheConfig = testMapConfig.getNearCacheConfig();
    assertNotNull(testNearCacheConfig);
    assertEquals(0, testNearCacheConfig.getTimeToLiveSeconds());
    assertEquals(60, testNearCacheConfig.getMaxIdleSeconds());
    assertEquals(EvictionPolicy.LRU, testNearCacheConfig.getEvictionConfig().getEvictionPolicy());
    assertEquals(5000, testNearCacheConfig.getEvictionConfig().getSize());
    assertTrue(testNearCacheConfig.isInvalidateOnChange());
    // test that the testMapConfig2's mapStoreConfig implementation
    MapConfig testMapConfig2 = config.getMapConfig("testMap2");
    assertNotNull(testMapConfig2.getMapStoreConfig().getImplementation());
    assertEquals(dummyMapStore, testMapConfig2.getMapStoreConfig().getImplementation());
    assertEquals(MapStoreConfig.InitialLoadMode.LAZY, testMapConfig2.getMapStoreConfig().getInitialLoadMode());
    // test testMapConfig2's WanReplicationConfig
    WanReplicationRef wanReplicationRef = testMapConfig2.getWanReplicationRef();
    assertEquals("testWan", wanReplicationRef.getName());
    assertEquals("PUT_IF_ABSENT", wanReplicationRef.getMergePolicy());
    assertTrue(wanReplicationRef.isRepublishingEnabled());
    assertEquals(1000, testMapConfig2.getMaxSizeConfig().getSize());
    assertEquals(MaxSizeConfig.MaxSizePolicy.PER_NODE, testMapConfig2.getMaxSizeConfig().getMaxSizePolicy());
    assertEquals(2, testMapConfig2.getEntryListenerConfigs().size());
    for (EntryListenerConfig listener : testMapConfig2.getEntryListenerConfigs()) {
        if (listener.getClassName() != null) {
            assertNull(listener.getImplementation());
            assertTrue(listener.isIncludeValue());
            assertFalse(listener.isLocal());
        } else {
            assertNotNull(listener.getImplementation());
            assertEquals(entryListener, listener.getImplementation());
            assertTrue(listener.isLocal());
            assertTrue(listener.isIncludeValue());
        }
    }
    MapConfig simpleMapConfig = config.getMapConfig("simpleMap");
    assertNotNull(simpleMapConfig);
    assertEquals("simpleMap", simpleMapConfig.getName());
    assertEquals(3, simpleMapConfig.getBackupCount());
    assertEquals(1, simpleMapConfig.getAsyncBackupCount());
    assertEquals(EvictionPolicy.LRU, simpleMapConfig.getEvictionPolicy());
    assertEquals(10, simpleMapConfig.getMaxSizeConfig().getSize());
    assertEquals(50, simpleMapConfig.getEvictionPercentage());
    assertEquals(1, simpleMapConfig.getTimeToLiveSeconds());
    assertEquals("LATEST_UPDATE", simpleMapConfig.getMergePolicy());
    // test that the simpleMapConfig does NOT have a nearCacheConfig
    assertNull(simpleMapConfig.getNearCacheConfig());
    MapConfig testMapConfig3 = config.getMapConfig("testMap3");
    assertEquals("com.hazelcast.spring.DummyStoreFactory", testMapConfig3.getMapStoreConfig().getFactoryClassName());
    assertFalse(testMapConfig3.getMapStoreConfig().getProperties().isEmpty());
    assertEquals(testMapConfig3.getMapStoreConfig().getProperty("dummy.property"), "value");
    MapConfig testMapConfig4 = config.getMapConfig("testMap4");
    assertEquals(dummyMapStoreFactory, testMapConfig4.getMapStoreConfig().getFactoryImplementation());
    MapConfig mapWithOptimizedQueriesConfig = config.getMapConfig("mapWithOptimizedQueries");
    assertEquals(CacheDeserializedValues.ALWAYS, mapWithOptimizedQueriesConfig.getCacheDeserializedValues());
    MapConfig mapWithValueCachingSetToNever = config.getMapConfig("mapWithValueCachingSetToNever");
    assertEquals(CacheDeserializedValues.NEVER, mapWithValueCachingSetToNever.getCacheDeserializedValues());
    MapConfig mapWithValueCachingSetToAlways = config.getMapConfig("mapWithValueCachingSetToAlways");
    assertEquals(CacheDeserializedValues.ALWAYS, mapWithValueCachingSetToAlways.getCacheDeserializedValues());
    MapConfig mapWithNotOptimizedQueriesConfig = config.getMapConfig("mapWithNotOptimizedQueries");
    assertEquals(CacheDeserializedValues.INDEX_ONLY, mapWithNotOptimizedQueriesConfig.getCacheDeserializedValues());
    MapConfig mapWithDefaultOptimizedQueriesConfig = config.getMapConfig("mapWithDefaultOptimizedQueries");
    assertEquals(CacheDeserializedValues.INDEX_ONLY, mapWithDefaultOptimizedQueriesConfig.getCacheDeserializedValues());
    MapConfig testMapWithPartitionLostListenerConfig = config.getMapConfig("mapWithPartitionLostListener");
    List<MapPartitionLostListenerConfig> partitionLostListenerConfigs = testMapWithPartitionLostListenerConfig.getPartitionLostListenerConfigs();
    assertEquals(1, partitionLostListenerConfigs.size());
    assertEquals("DummyMapPartitionLostListenerImpl", partitionLostListenerConfigs.get(0).getClassName());
    MapConfig testMapWithPartitionStrategyConfig = config.getMapConfig("mapWithPartitionStrategy");
    assertEquals("com.hazelcast.spring.DummyPartitionStrategy", testMapWithPartitionStrategyConfig.getPartitioningStrategyConfig().getPartitioningStrategyClass());
}
Also used : MapAttributeConfig(com.hazelcast.config.MapAttributeConfig) MapIndexConfig(com.hazelcast.config.MapIndexConfig) MapPartitionLostListenerConfig(com.hazelcast.config.MapPartitionLostListenerConfig) WanReplicationRef(com.hazelcast.config.WanReplicationRef) NearCacheConfig(com.hazelcast.config.NearCacheConfig) MapConfig(com.hazelcast.config.MapConfig) ReplicatedMapConfig(com.hazelcast.config.ReplicatedMapConfig) MultiMapConfig(com.hazelcast.config.MultiMapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) Test(org.junit.Test) QuickTest(com.hazelcast.test.annotation.QuickTest)

Example 15 with EntryListenerConfig

use of com.hazelcast.config.EntryListenerConfig 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)

Aggregations

EntryListenerConfig (com.hazelcast.config.EntryListenerConfig)17 QuickTest (com.hazelcast.test.annotation.QuickTest)12 Test (org.junit.Test)12 ParallelTest (com.hazelcast.test.annotation.ParallelTest)6 Config (com.hazelcast.config.Config)5 MapConfig (com.hazelcast.config.MapConfig)5 HazelcastInstance (com.hazelcast.core.HazelcastInstance)5 MultiMapConfig (com.hazelcast.config.MultiMapConfig)4 EntryAdapter (com.hazelcast.core.EntryAdapter)4 EntryEvent (com.hazelcast.core.EntryEvent)4 MapPartitionLostListenerConfig (com.hazelcast.config.MapPartitionLostListenerConfig)3 QueryCacheConfig (com.hazelcast.config.QueryCacheConfig)3 ReplicatedMapConfig (com.hazelcast.config.ReplicatedMapConfig)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 MapIndexConfig (com.hazelcast.config.MapIndexConfig)2 NearCacheConfig (com.hazelcast.config.NearCacheConfig)2 AssertTask (com.hazelcast.test.AssertTask)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ClientConfig (com.hazelcast.client.config.ClientConfig)1 MapAttributeConfig (com.hazelcast.config.MapAttributeConfig)1