use of com.hazelcast.topic.MessageListener in project hazelcast by hazelcast.
the class TopicProxySupport method initialize.
private void initialize(ListenerConfig listenerConfig) {
NodeEngine nodeEngine = getNodeEngine();
MessageListener listener = loadListener(listenerConfig);
if (listener == null) {
return;
}
if (listener instanceof HazelcastInstanceAware) {
HazelcastInstanceAware hazelcastInstanceAware = (HazelcastInstanceAware) listener;
hazelcastInstanceAware.setHazelcastInstance(nodeEngine.getHazelcastInstance());
}
addMessageListenerInternal(listener);
}
use of com.hazelcast.topic.MessageListener in project hazelcast by hazelcast.
the class ClientReliableTopicTest method testListener.
@Test
public void testListener() throws InterruptedException {
ITopic topic = client.getReliableTopic(randomString());
int messageCount = 10;
final CountDownLatch latch = new CountDownLatch(messageCount);
MessageListener listener = new MessageListener() {
public void onMessage(Message message) {
latch.countDown();
}
};
topic.addMessageListener(listener);
for (int i = 0; i < messageCount; i++) {
topic.publish(i);
}
assertTrue(latch.await(20, TimeUnit.SECONDS));
}
use of com.hazelcast.topic.MessageListener in project hazelcast by hazelcast.
the class ClientTopicTest method testRemoveListener.
@Test
public void testRemoveListener() {
ITopic topic = client.getTopic(randomString());
MessageListener listener = new MessageListener() {
public void onMessage(Message message) {
}
};
UUID id = topic.addMessageListener(listener);
assertTrue(topic.removeMessageListener(id));
}
use of com.hazelcast.topic.MessageListener in project hazelcast by hazelcast.
the class AllTest method loadTopicOperations.
private List<Runnable> loadTopicOperations() {
ITopic topic = hazelcast.getTopic("myTopic");
topic.addMessageListener(new MessageListener() {
public void onMessage(Message message) {
messagesReceived.incrementAndGet();
}
});
List<Runnable> operations = new ArrayList<Runnable>();
addOperation(operations, new Runnable() {
public void run() {
ITopic topic = hazelcast.getTopic("myTopic");
topic.publish(String.valueOf(random.nextInt(100000000)));
messagesSend.incrementAndGet();
}
}, 10);
return operations;
}
Aggregations