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());
}
}
}
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());
}
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());
}
}
}
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));
}
Aggregations