Search in sources :

Example 6 with BaseRedisPubSubListener

use of org.redisson.client.BaseRedisPubSubListener in project redisson by redisson.

the class MasterSlaveConnectionManager method punsubscribe.

public Codec punsubscribe(final String channelName, final AsyncSemaphore lock) {
    final PubSubConnectionEntry entry = name2PubSubConnection.remove(channelName);
    if (entry == null) {
        lock.release();
        return null;
    }
    Codec entryCodec = entry.getConnection().getPatternChannels().get(channelName);
    entry.punsubscribe(channelName, new BaseRedisPubSubListener() {

        @Override
        public boolean onStatus(PubSubType type, String channel) {
            if (type == PubSubType.PUNSUBSCRIBE && channel.equals(channelName)) {
                if (entry.release() == 1) {
                    freePubSubConnections.add(entry);
                }
                lock.release();
                return true;
            }
            return false;
        }
    });
    return entryCodec;
}
Also used : Codec(org.redisson.client.codec.Codec) BaseRedisPubSubListener(org.redisson.client.BaseRedisPubSubListener) PubSubType(org.redisson.client.protocol.pubsub.PubSubType)

Example 7 with BaseRedisPubSubListener

use of org.redisson.client.BaseRedisPubSubListener in project redisson by redisson.

the class PubSubConnectionEntry method punsubscribe.

public void punsubscribe(final String channel, final RedisPubSubListener<?> listener) {
    conn.addListener(new BaseRedisPubSubListener() {

        @Override
        public boolean onStatus(PubSubType type, String ch) {
            if (type == PubSubType.PUNSUBSCRIBE && channel.equals(ch)) {
                conn.removeListener(this);
                removeListeners(channel);
                if (listener != null) {
                    listener.onStatus(type, channel);
                }
                return true;
            }
            return false;
        }
    });
    conn.punsubscribe(channel);
}
Also used : BaseRedisPubSubListener(org.redisson.client.BaseRedisPubSubListener) PubSubType(org.redisson.client.protocol.pubsub.PubSubType)

Aggregations

BaseRedisPubSubListener (org.redisson.client.BaseRedisPubSubListener)7 PubSubType (org.redisson.client.protocol.pubsub.PubSubType)7 Codec (org.redisson.client.codec.Codec)4 RedisClient (org.redisson.client.RedisClient)1 RedisConnectionException (org.redisson.client.RedisConnectionException)1 RedisPubSubConnection (org.redisson.client.RedisPubSubConnection)1