Search in sources :

Example 1 with PubSubMessage

use of com.corundumstudio.socketio.store.pubsub.PubSubMessage in project netty-socketio by mrniko.

the class RedissonPubSubStore method subscribe.

@Override
public <T extends PubSubMessage> void subscribe(PubSubType type, final PubSubListener<T> listener, Class<T> clazz) {
    String name = type.toString();
    RTopic topic = redissonSub.getTopic(name);
    int regId = topic.addListener(PubSubMessage.class, new MessageListener<PubSubMessage>() {

        @Override
        public void onMessage(CharSequence channel, PubSubMessage msg) {
            if (!nodeId.equals(msg.getNodeId())) {
                listener.onMessage((T) msg);
            }
        }
    });
    Queue<Integer> list = map.get(name);
    if (list == null) {
        list = new ConcurrentLinkedQueue<Integer>();
        Queue<Integer> oldList = map.putIfAbsent(name, list);
        if (oldList != null) {
            list = oldList;
        }
    }
    list.add(regId);
}
Also used : PubSubMessage(com.corundumstudio.socketio.store.pubsub.PubSubMessage) RTopic(org.redisson.api.RTopic)

Aggregations

PubSubMessage (com.corundumstudio.socketio.store.pubsub.PubSubMessage)1 RTopic (org.redisson.api.RTopic)1