Search in sources :

Example 6 with MessageListener

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);
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) MessageListener(com.hazelcast.topic.MessageListener) HazelcastInstanceAware(com.hazelcast.core.HazelcastInstanceAware)

Example 7 with MessageListener

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));
}
Also used : ITopic(com.hazelcast.topic.ITopic) Message(com.hazelcast.topic.Message) MessageListener(com.hazelcast.topic.MessageListener) CountDownLatch(java.util.concurrent.CountDownLatch) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) DurableSubscriptionTest(com.hazelcast.topic.impl.reliable.DurableSubscriptionTest) Test(org.junit.Test)

Example 8 with MessageListener

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));
}
Also used : ITopic(com.hazelcast.topic.ITopic) Message(com.hazelcast.topic.Message) MessageListener(com.hazelcast.topic.MessageListener) UUID(java.util.UUID) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 9 with MessageListener

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;
}
Also used : ITopic(com.hazelcast.topic.ITopic) Message(com.hazelcast.topic.Message) MessageListener(com.hazelcast.topic.MessageListener) ArrayList(java.util.ArrayList)

Aggregations

MessageListener (com.hazelcast.topic.MessageListener)9 ITopic (com.hazelcast.topic.ITopic)5 Message (com.hazelcast.topic.Message)5 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 Test (org.junit.Test)4 UUID (java.util.UUID)3 HazelcastInstanceAware (com.hazelcast.core.HazelcastInstanceAware)2 NodeEngine (com.hazelcast.spi.impl.NodeEngine)2 ReliableMessageListener (com.hazelcast.topic.ReliableMessageListener)2 ClientConfig (com.hazelcast.client.config.ClientConfig)1 ClientSecurityConfig (com.hazelcast.client.config.ClientSecurityConfig)1 ConnectionRetryConfig (com.hazelcast.client.config.ConnectionRetryConfig)1 ClientExecutionServiceImpl (com.hazelcast.client.impl.spi.impl.ClientExecutionServiceImpl)1 ClientProperty (com.hazelcast.client.properties.ClientProperty)1 TestHazelcastFactory (com.hazelcast.client.test.TestHazelcastFactory)1 MemberImpl (com.hazelcast.cluster.impl.MemberImpl)1 Config (com.hazelcast.config.Config)1 EvictionConfig (com.hazelcast.config.EvictionConfig)1 ListenerConfig (com.hazelcast.config.ListenerConfig)1