Java Code Examples for org.redisson.api.RTopic#removeListener()
The following examples show how to use
org.redisson.api.RTopic#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: RedisTopicEventChannel.java From jstarcraft-core with Apache License 2.0 | 6 votes |
@Override public void unregisterMonitor(Set<Class> types, EventMonitor monitor) { for (Class type : types) { EventManager manager = managers.get(type); if (manager != null) { manager.detachMonitor(monitor); if (manager.getSize() == 0) { managers.remove(type); // TODO 需要防止路径冲突 RTopic topic = getTopic(type); EventHandler handler = handlers.remove(type); topic.removeListener(handler); } } } }
Example 2
Source File: RedissonMapCache.java From redisson with Apache License 2.0 | 6 votes |
@Override public void removeListener(int listenerId) { super.removeListener(listenerId); RTopic removedTopic = redisson.getTopic(getRemovedChannelName()); removedTopic.removeListener(listenerId); RTopic createdTopic = redisson.getTopic(getCreatedChannelName()); createdTopic.removeListener(listenerId); RTopic updatedTopic = redisson.getTopic(getUpdatedChannelName()); updatedTopic.removeListener(listenerId); RTopic expiredTopic = redisson.getTopic(getExpiredChannelName()); expiredTopic.removeListener(listenerId); }
Example 3
Source File: RedissonTopicTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testCountListeners() { RedissonClient redisson = BaseTest.createInstance(); RTopic topic1 = redisson.getTopic("topic", LongCodec.INSTANCE); assertThat(topic1.countListeners()).isZero(); int id = topic1.addListener(Long.class, (channel, msg) -> { }); assertThat(topic1.countListeners()).isOne(); RTopic topic2 = redisson.getTopic("topic2", LongCodec.INSTANCE); assertThat(topic2.countListeners()).isZero(); int id2 = topic2.addListener(Long.class, (channel, msg) -> { }); assertThat(topic2.countListeners()).isOne(); topic1.removeListener(id); assertThat(topic1.countListeners()).isZero(); topic2.removeListener(id2); assertThat(topic2.countListeners()).isZero(); redisson.shutdown(); }
Example 4
Source File: RedissonTopicTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testUnsubscribe() throws InterruptedException { final CountDownLatch messageRecieved = new CountDownLatch(1); RedissonClient redisson = BaseTest.createInstance(); RTopic topic1 = redisson.getTopic("topic1"); int listenerId = topic1.addListener(Message.class, (channel, msg) -> { Assert.fail(); }); topic1.addListener(Message.class, (channel, msg) -> { Assert.assertEquals("topic1", channel.toString()); Assert.assertEquals(new Message("123"), msg); messageRecieved.countDown(); }); topic1.removeListener(listenerId); topic1 = redisson.getTopic("topic1"); topic1.publish(new Message("123")); Assert.assertTrue(messageRecieved.await(5, TimeUnit.SECONDS)); redisson.shutdown(); }
Example 5
Source File: RedissonTopicTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testRemoveByInstance() throws InterruptedException { RedissonClient redisson = BaseTest.createInstance(); RTopic topic1 = redisson.getTopic("topic1"); MessageListener listener = new MessageListener() { @Override public void onMessage(CharSequence channel, Object msg) { Assert.fail(); } }; topic1.addListener(Message.class, listener); topic1 = redisson.getTopic("topic1"); topic1.removeListener(listener); topic1.publish(new Message("123")); redisson.shutdown(); }
Example 6
Source File: RedissonTopicTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testLazyUnsubscribe() throws InterruptedException { final CountDownLatch messageRecieved = new CountDownLatch(1); RedissonClient redisson1 = BaseTest.createInstance(); RTopic topic1 = redisson1.getTopic("topic"); int listenerId = topic1.addListener(Message.class, (channel, msg) -> { Assert.fail(); }); Thread.sleep(1000); topic1.removeListener(listenerId); Thread.sleep(1000); RedissonClient redisson2 = BaseTest.createInstance(); RTopic topic2 = redisson2.getTopic("topic"); topic2.addListener(Message.class, (channel, msg) -> { Assert.assertEquals(new Message("123"), msg); messageRecieved.countDown(); }); topic2.publish(new Message("123")); Assert.assertTrue(messageRecieved.await(5, TimeUnit.SECONDS)); redisson1.shutdown(); redisson2.shutdown(); }
Example 7
Source File: RedissonTopicTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testListenerRemove() throws InterruptedException { RedissonClient redisson1 = BaseTest.createInstance(); RTopic topic1 = redisson1.getTopic("topic"); int id = topic1.addListener(Message.class, (channel, msg) -> { Assert.fail(); }); RedissonClient redisson2 = BaseTest.createInstance(); RTopic topic2 = redisson2.getTopic("topic"); topic1.removeListener(id); topic2.publish(new Message("123")); Thread.sleep(1000); redisson1.shutdown(); redisson2.shutdown(); }
Example 8
Source File: RedissonPubSubEventStore.java From j360-boot-app-all with Apache License 2.0 | 5 votes |
public void unsubscribe(PubSubType type) { String name = type.toString(); Queue<Integer> regIds = map.remove(name); RTopic topic = redissonSub.getTopic(name); for (Integer id : regIds) { topic.removeListener(id); } }
Example 9
Source File: RedissonTopicTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testCountSubscribers() { RedissonClient redisson = BaseTest.createInstance(); RTopic topic1 = redisson.getTopic("topic", LongCodec.INSTANCE); assertThat(topic1.countSubscribers()).isZero(); int id = topic1.addListener(Long.class, (channel, msg) -> { }); assertThat(topic1.countSubscribers()).isOne(); topic1.removeListener(id); assertThat(topic1.countSubscribers()).isZero(); redisson.shutdown(); }
Example 10
Source File: RedissonSessionManager.java From redisson with Apache License 2.0 | 5 votes |
@Override protected void stopInternal() throws LifecycleException { super.stopInternal(); setState(LifecycleState.STOPPING); Pipeline pipeline = getEngine().getPipeline(); synchronized (pipeline) { contextInUse.remove(getContext().getName()); //remove valves when all of the RedissonSessionManagers (web apps) are not in use anymore if (contextInUse.isEmpty()) { if (updateValve != null) { pipeline.removeValve(updateValve); updateValve = null; } } } if (messageListener != null) { RTopic updatesTopic = getTopic(); updatesTopic.removeListener(messageListener); } codecToUse = null; try { shutdownRedisson(); } catch (Exception e) { throw new LifecycleException(e); } }
Example 11
Source File: RedissonSessionManager.java From redisson with Apache License 2.0 | 5 votes |
@Override protected void stopInternal() throws LifecycleException { super.stopInternal(); setState(LifecycleState.STOPPING); Pipeline pipeline = getEngine().getPipeline(); synchronized (pipeline) { contextInUse.remove(getContext().getName()); //remove valves when all of the RedissonSessionManagers (web apps) are not in use anymore if (contextInUse.isEmpty()) { if (updateValve != null) { pipeline.removeValve(updateValve); updateValve = null; } } } if (messageListener != null) { RTopic updatesTopic = getTopic(); updatesTopic.removeListener(messageListener); } codecToUse = null; try { shutdownRedisson(); } catch (Exception e) { throw new LifecycleException(e); } }
Example 12
Source File: RedissonSessionManager.java From redisson with Apache License 2.0 | 5 votes |
@Override protected void stopInternal() throws LifecycleException { super.stopInternal(); setState(LifecycleState.STOPPING); Pipeline pipeline = getEngine().getPipeline(); synchronized (pipeline) { contextInUse.remove(((Context) getContainer()).getName()); //remove valves when all of the RedissonSessionManagers (web apps) are not in use anymore if (contextInUse.isEmpty()) { if (updateValve != null) { pipeline.removeValve(updateValve); updateValve = null; } } } if (messageListener != null) { RTopic updatesTopic = getTopic(); updatesTopic.removeListener(messageListener); } codecToUse = null; try { shutdownRedisson(); } catch (Exception e) { throw new LifecycleException(e); } }
Example 13
Source File: QueueTransferTask.java From redisson with Apache License 2.0 | 4 votes |
public void stop() { RTopic schedulerTopic = getTopic(); schedulerTopic.removeListener(messageListenerId); schedulerTopic.removeListener(statusListenerId); }