Java Code Examples for org.redisson.api.RPatternTopic#removeListener()

The following examples show how to use org.redisson.api.RPatternTopic#removeListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RedissonTopicPatternTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testUnsubscribe() throws InterruptedException {
    final CountDownLatch messageRecieved = new CountDownLatch(1);

    RPatternTopic topic1 = redisson.getPatternTopic("topic1.*");
    int listenerId = topic1.addListener(Message.class, (pattern, channel, msg) -> {
        Assert.fail();
    });
    topic1.addListener(Message.class, (pattern, channel, msg) -> {
        Assert.assertTrue(pattern.equals("topic1.*"));
        Assert.assertTrue(channel.equals("topic1.t3"));
        Assert.assertEquals(new Message("123"), msg);
        messageRecieved.countDown();
    });
    topic1.removeListener(listenerId);

    redisson.getTopic("topic1.t3").publish(new Message("123"));

    Assert.assertTrue(messageRecieved.await(5, TimeUnit.SECONDS));
}
 
Example 2
Source File: RedissonTopicPatternTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testListenerRemove() throws InterruptedException {
    RedissonClient redisson1 = BaseTest.createInstance();
    RPatternTopic topic1 = redisson1.getPatternTopic("topic.*");
    final CountDownLatch l = new CountDownLatch(1);
    topic1.addListener(new BasePatternStatusListener() {
        @Override
        public void onPUnsubscribe(String pattern) {
            Assert.assertEquals("topic.*", pattern);
            l.countDown();
        }
    });
    int id = topic1.addListener(Message.class, (pattern, channel, msg) -> {
        Assert.fail();
    });

    RedissonClient redisson2 = BaseTest.createInstance();
    RTopic topic2 = redisson2.getTopic("topic.t1");
    topic1.removeListener(id);
    topic2.publish(new Message("123"));

    redisson1.shutdown();
    redisson2.shutdown();
}
 
Example 3
Source File: RedissonObject.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public void removeListener(int listenerId) {
    RPatternTopic expiredTopic = new RedissonPatternTopic(StringCodec.INSTANCE, commandExecutor, "__keyevent@*:expired");
    expiredTopic.removeListener(listenerId);

    RPatternTopic deletedTopic = new RedissonPatternTopic(StringCodec.INSTANCE, commandExecutor, "__keyevent@*:del");
    deletedTopic.removeListener(listenerId);
}
 
Example 4
Source File: RedissonBucket.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public void removeListener(int listenerId) {
    RPatternTopic expiredTopic = new RedissonPatternTopic(StringCodec.INSTANCE, commandExecutor, "__keyevent@*:set");
    expiredTopic.removeListener(listenerId);

    super.removeListener(listenerId);
}
 
Example 5
Source File: RedissonTopicPatternTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testLazyUnsubscribe() throws InterruptedException {
    final CountDownLatch messageRecieved = new CountDownLatch(1);

    RedissonClient redisson1 = BaseTest.createInstance();
    RPatternTopic topic1 = redisson1.getPatternTopic("topic.*");
    int listenerId = topic1.addListener(Message.class, (pattern, channel, msg) -> {
        Assert.fail();
    });

    Thread.sleep(1000);
    topic1.removeListener(listenerId);
    Thread.sleep(1000);

    RedissonClient redisson2 = BaseTest.createInstance();
    RPatternTopic topic2 = redisson2.getPatternTopic("topic.*");
    topic2.addListener(Message.class, (pattern, channel, msg) -> {
        Assert.assertTrue(pattern.equals("topic.*"));
        Assert.assertTrue(channel.equals("topic.t1"));
        Assert.assertEquals(new Message("123"), msg);
        messageRecieved.countDown();
    });

    RTopic topic3 = redisson2.getTopic("topic.t1");
    topic3.publish(new Message("123"));

    Assert.assertTrue(messageRecieved.await(5, TimeUnit.SECONDS));

    redisson1.shutdown();
    redisson2.shutdown();
}