Search in sources :

Example 1 with ItemListenerConfig

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

the class QueueProxySupport method initialize.

@Override
public void initialize() {
    final NodeEngine nodeEngine = getNodeEngine();
    final List<ItemListenerConfig> itemListenerConfigs = config.getItemListenerConfigs();
    for (ItemListenerConfig itemListenerConfig : itemListenerConfigs) {
        ItemListener listener = itemListenerConfig.getImplementation();
        if (listener == null && itemListenerConfig.getClassName() != null) {
            try {
                listener = ClassLoaderUtil.newInstance(nodeEngine.getConfigClassLoader(), itemListenerConfig.getClassName());
            } catch (Exception e) {
                throw ExceptionUtil.rethrow(e);
            }
        }
        if (listener != null) {
            if (listener instanceof HazelcastInstanceAware) {
                ((HazelcastInstanceAware) listener).setHazelcastInstance(nodeEngine.getHazelcastInstance());
            }
            addItemListener(listener, itemListenerConfig.isIncludeValue());
        }
    }
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) ItemListenerConfig(com.hazelcast.config.ItemListenerConfig) ItemListener(com.hazelcast.core.ItemListener) HazelcastInstanceAware(com.hazelcast.core.HazelcastInstanceAware)

Example 2 with ItemListenerConfig

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

the class TestFullApplicationContext method testQueueConfig.

@Test
public void testQueueConfig() {
    QueueConfig testQConfig = config.getQueueConfig("testQ");
    assertNotNull(testQConfig);
    assertEquals("testQ", testQConfig.getName());
    assertEquals(1000, testQConfig.getMaxSize());
    assertEquals(1, testQConfig.getItemListenerConfigs().size());
    assertTrue(testQConfig.isStatisticsEnabled());
    ItemListenerConfig listenerConfig = testQConfig.getItemListenerConfigs().get(0);
    assertEquals("com.hazelcast.spring.DummyItemListener", listenerConfig.getClassName());
    assertTrue(listenerConfig.isIncludeValue());
    QueueConfig qConfig = config.getQueueConfig("q");
    assertNotNull(qConfig);
    assertEquals("q", qConfig.getName());
    assertEquals(2500, qConfig.getMaxSize());
    assertFalse(qConfig.isStatisticsEnabled());
    assertEquals(100, qConfig.getEmptyQueueTtl());
    assertEquals("my-quorum", qConfig.getQuorumName());
    QueueConfig queueWithStore1 = config.getQueueConfig("queueWithStore1");
    assertNotNull(queueWithStore1);
    QueueStoreConfig storeConfig1 = queueWithStore1.getQueueStoreConfig();
    assertNotNull(storeConfig1);
    assertEquals(DummyQueueStore.class.getName(), storeConfig1.getClassName());
    QueueConfig queueWithStore2 = config.getQueueConfig("queueWithStore2");
    assertNotNull(queueWithStore2);
    QueueStoreConfig storeConfig2 = queueWithStore2.getQueueStoreConfig();
    assertNotNull(storeConfig2);
    assertEquals(DummyQueueStoreFactory.class.getName(), storeConfig2.getFactoryClassName());
    QueueConfig queueWithStore3 = config.getQueueConfig("queueWithStore3");
    assertNotNull(queueWithStore3);
    QueueStoreConfig storeConfig3 = queueWithStore3.getQueueStoreConfig();
    assertNotNull(storeConfig3);
    assertEquals(dummyQueueStore, storeConfig3.getStoreImplementation());
    QueueConfig queueWithStore4 = config.getQueueConfig("queueWithStore4");
    assertNotNull(queueWithStore4);
    QueueStoreConfig storeConfig4 = queueWithStore4.getQueueStoreConfig();
    assertNotNull(storeConfig4);
    assertEquals(dummyQueueStoreFactory, storeConfig4.getFactoryImplementation());
}
Also used : QueueStoreConfig(com.hazelcast.config.QueueStoreConfig) QueueConfig(com.hazelcast.config.QueueConfig) ItemListenerConfig(com.hazelcast.config.ItemListenerConfig) Test(org.junit.Test) QuickTest(com.hazelcast.test.annotation.QuickTest)

Example 3 with ItemListenerConfig

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

the class AbstractCollectionProxyImpl method initialize.

@Override
public void initialize() {
    final NodeEngine nodeEngine = getNodeEngine();
    CollectionConfig config = getConfig(nodeEngine);
    final List<ItemListenerConfig> itemListenerConfigs = config.getItemListenerConfigs();
    for (ItemListenerConfig itemListenerConfig : itemListenerConfigs) {
        ItemListener listener = itemListenerConfig.getImplementation();
        if (listener == null && itemListenerConfig.getClassName() != null) {
            try {
                listener = ClassLoaderUtil.newInstance(nodeEngine.getConfigClassLoader(), itemListenerConfig.getClassName());
            } catch (Exception e) {
                throw ExceptionUtil.rethrow(e);
            }
        }
        if (listener != null) {
            if (listener instanceof HazelcastInstanceAware) {
                ((HazelcastInstanceAware) listener).setHazelcastInstance(nodeEngine.getHazelcastInstance());
            }
            addItemListener(listener, itemListenerConfig.isIncludeValue());
        }
    }
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) ItemListenerConfig(com.hazelcast.config.ItemListenerConfig) ItemListener(com.hazelcast.core.ItemListener) CollectionConfig(com.hazelcast.config.CollectionConfig) HazelcastInstanceAware(com.hazelcast.core.HazelcastInstanceAware)

Example 4 with ItemListenerConfig

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

the class QueueListenerTest method testConfigListenerRegistration.

@Test
public void testConfigListenerRegistration() throws Exception {
    Config config = new Config();
    String name = "queue";
    QueueConfig queueConfig = config.getQueueConfig(name);
    CountdownItemListener listener = new CountdownItemListener(1, 1);
    ItemListenerConfig itemListenerConfig = new ItemListenerConfig(listener, true);
    queueConfig.addItemListenerConfig(itemListenerConfig);
    HazelcastInstance instance = createHazelcastInstance(config);
    IQueue<String> queue = instance.getQueue(name);
    queue.offer("item");
    queue.poll();
    assertTrue(listener.added.await(10, TimeUnit.SECONDS));
}
Also used : QueueConfig(com.hazelcast.config.QueueConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) QueueConfig(com.hazelcast.config.QueueConfig) ItemListenerConfig(com.hazelcast.config.ItemListenerConfig) ItemListenerConfig(com.hazelcast.config.ItemListenerConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

ItemListenerConfig (com.hazelcast.config.ItemListenerConfig)4 QueueConfig (com.hazelcast.config.QueueConfig)2 HazelcastInstanceAware (com.hazelcast.core.HazelcastInstanceAware)2 ItemListener (com.hazelcast.core.ItemListener)2 NodeEngine (com.hazelcast.spi.NodeEngine)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 Test (org.junit.Test)2 CollectionConfig (com.hazelcast.config.CollectionConfig)1 Config (com.hazelcast.config.Config)1 QueueStoreConfig (com.hazelcast.config.QueueStoreConfig)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 ParallelTest (com.hazelcast.test.annotation.ParallelTest)1