com.lambdaworks.redis.pubsub
Class RedisPubSubConnection<K,V>

java.lang.Object
  extended by org.jboss.netty.channel.SimpleChannelUpstreamHandler
      extended by com.lambdaworks.redis.RedisAsyncConnection<K,V>
          extended by com.lambdaworks.redis.pubsub.RedisPubSubConnection<K,V>
All Implemented Interfaces:
ChannelHandler, ChannelUpstreamHandler

public class RedisPubSubConnection<K,V>
extends RedisAsyncConnection<K,V>

An asynchronous thread-safe pub/sub connection to a redis server. After one or more channels are subscribed to only pub/sub related commands or RedisAsyncConnection.quit() may be called. Incoming messages and results of the subscribe(K...)/unsubscribe(K...) calls will be passed to all registered RedisPubSubListeners. A ConnectionWatchdog monitors each connection and reconnects automatically until RedisAsyncConnection.close() is called. Channel and pattern subscriptions are renewed after reconnecting.

Author:
Will Glozer

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.jboss.netty.channel.ChannelHandler
ChannelHandler.Sharable
 
Field Summary
 
Fields inherited from class com.lambdaworks.redis.RedisAsyncConnection
channel, codec, multi, queue, timeout, unit
 
Constructor Summary
RedisPubSubConnection(BlockingQueue<Command<K,V,?>> queue, RedisCodec<K,V> codec, long timeout, TimeUnit unit)
          Initialize a new connection.
 
Method Summary
 void addListener(RedisPubSubListener<K,V> listener)
          Add a new listener.
 void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e)
           
 void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
           
 void psubscribe(K... patterns)
           
 void punsubscribe(K... patterns)
           
 void removeListener(RedisPubSubListener<K,V> listener)
          Remove an existing listener.
 void subscribe(K... channels)
           
 void unsubscribe(K... channels)
           
 
Methods inherited from class com.lambdaworks.redis.RedisAsyncConnection
append, auth, await, awaitAll, awaitAll, bgrewriteaof, bgsave, bitcount, bitcount, bitopAnd, bitopNot, bitopOr, bitopXor, blpop, brpop, brpoplpush, channelClosed, clientGetname, clientKill, clientList, clientSetname, close, configGet, configResetstat, configSet, dbsize, debugObject, decr, decrby, del, digest, discard, dispatch, dispatch, dispatch, dispatch, dispatch, dump, echo, eval, evalsha, exec, exists, expire, expireat, expireat, flushall, flushdb, get, getbit, getrange, getset, hdel, hexists, hget, hgetall, hincrby, hincrbyfloat, hkeys, hlen, hmget, hmset, hset, hsetnx, hvals, incr, incrby, incrbyfloat, info, info, keys, lastsave, lindex, linsert, llen, lpop, lpush, lpushx, lrange, lrem, lset, ltrim, mget, migrate, move, mset, msetnx, multi, newScriptOutput, objectEncoding, objectIdletime, objectRefcount, persist, pexpire, pexpireat, pexpireat, ping, pttl, publish, quit, randomkey, rename, renamenx, restore, rpop, rpoplpush, rpush, rpushx, sadd, save, scard, scriptExists, scriptFlush, scriptKill, scriptLoad, sdiff, sdiffstore, select, set, setbit, setex, setnx, setrange, setTimeout, shutdown, shutdown, sinter, sinterstore, sismember, slaveof, slaveofNoOne, slowlogGet, slowlogGet, slowlogLen, slowlogReset, smembers, smove, sort, sort, sortStore, spop, srandmember, srandmember, srem, string, strlen, sunion, sunionstore, sync, ttl, type, unwatch, watch, zadd, zadd, zcard, zcount, zcount, zincrby, zinterstore, zinterstore, zrange, zrangebyscore, zrangebyscore, zrangebyscore, zrangebyscore, zrangebyscoreWithScores, zrangebyscoreWithScores, zrangebyscoreWithScores, zrangebyscoreWithScores, zrangeWithScores, zrank, zrem, zremrangebyrank, zremrangebyscore, zremrangebyscore, zrevrange, zrevrangebyscore, zrevrangebyscore, zrevrangebyscore, zrevrangebyscore, zrevrangebyscoreWithScores, zrevrangebyscoreWithScores, zrevrangebyscoreWithScores, zrevrangebyscoreWithScores, zrevrangeWithScores, zrevrank, zscore, zunionstore, zunionstore
 
Methods inherited from class org.jboss.netty.channel.SimpleChannelUpstreamHandler
channelBound, channelDisconnected, channelInterestChanged, channelOpen, channelUnbound, childChannelClosed, childChannelOpen, exceptionCaught, handleUpstream, writeComplete
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RedisPubSubConnection

public RedisPubSubConnection(BlockingQueue<Command<K,V,?>> queue,
                             RedisCodec<K,V> codec,
                             long timeout,
                             TimeUnit unit)
Initialize a new connection.

Parameters:
queue - Command queue.
codec - Codec used to encode/decode keys and values.
timeout - Maximum time to wait for a responses.
unit - Unit of time for the timeout.
Method Detail

addListener

public void addListener(RedisPubSubListener<K,V> listener)
Add a new listener.

Parameters:
listener - Listener.

removeListener

public void removeListener(RedisPubSubListener<K,V> listener)
Remove an existing listener.

Parameters:
listener - Listener.

psubscribe

public void psubscribe(K... patterns)

punsubscribe

public void punsubscribe(K... patterns)

subscribe

public void subscribe(K... channels)

unsubscribe

public void unsubscribe(K... channels)

channelConnected

public void channelConnected(ChannelHandlerContext ctx,
                             ChannelStateEvent e)
                      throws Exception
Overrides:
channelConnected in class RedisAsyncConnection<K,V>
Throws:
Exception

messageReceived

public void messageReceived(ChannelHandlerContext ctx,
                            MessageEvent e)
                     throws Exception
Overrides:
messageReceived in class SimpleChannelUpstreamHandler
Throws:
Exception


Copyright © 2013. All Rights Reserved.