org.springframework.data.redis.connection.util
Class AbstractSubscription

java.lang.Object
  extended by org.springframework.data.redis.connection.util.AbstractSubscription
All Implemented Interfaces:
Subscription

public abstract class AbstractSubscription
extends Object
implements Subscription

Base implementation for a subscription handling the channel/pattern registration so subclasses only have to deal with the actual registration/unregistration.


Constructor Summary
protected AbstractSubscription(MessageListener listener)
           
protected AbstractSubscription(MessageListener listener, byte[][] channels, byte[][] patterns)
          Constructs a new AbstractSubscription instance.
 
Method Summary
protected abstract  void doClose()
          Shutdown the subscription and free any resources held.
protected abstract  void doPsubscribe(byte[]... patterns)
          Subscribe to the given patterns
protected abstract  void doPUnsubscribe(boolean all, byte[]... patterns)
          Pattern unsubscribe.
protected abstract  void doSubscribe(byte[]... channels)
          Subscribe to the given channels.
protected abstract  void doUnsubscribe(boolean all, byte[]... channels)
          Channel unsubscribe.
 Collection<byte[]> getChannels()
          Returns the (named) channels for this subscription.
 MessageListener getListener()
          Returns the listener used for this subscription.
 Collection<byte[]> getPatterns()
          Returns the channel patters for this subscription.
 boolean isAlive()
          Indicates whether this subscription is still 'alive' or not.
 void pSubscribe(byte[]... patterns)
          Adds the given channel patterns to the current subscription.
 void pUnsubscribe()
          Cancels the subscription for all channels matched by patterns.
 void pUnsubscribe(byte[]... patts)
          Cancels the subscription for all channels matching the given patterns.
 void subscribe(byte[]... channels)
          Adds the given channels to the current subscription.
 void unsubscribe()
          Cancels the current subscription for all channels given by name.
 void unsubscribe(byte[]... chans)
          Cancels the current subscription for all given channels.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractSubscription

protected AbstractSubscription(MessageListener listener)

AbstractSubscription

protected AbstractSubscription(MessageListener listener,
                               byte[][] channels,
                               byte[][] patterns)
Constructs a new AbstractSubscription instance. Allows channels and patterns to be added to the subscription w/o triggering a subscription action (as some clients (Jedis) require an initial call before entering into listening mode).

Parameters:
listener -
channels -
patterns -
Method Detail

doSubscribe

protected abstract void doSubscribe(byte[]... channels)
Subscribe to the given channels.

Parameters:
channels - channels to subscribe to

doUnsubscribe

protected abstract void doUnsubscribe(boolean all,
                                      byte[]... channels)
Channel unsubscribe.

Parameters:
all - true if all the channels are unsubscribed (used as a hint for the underlying implementation).
channels - channels to be unsubscribed

doPsubscribe

protected abstract void doPsubscribe(byte[]... patterns)
Subscribe to the given patterns

Parameters:
patterns - patterns to subscribe to

doPUnsubscribe

protected abstract void doPUnsubscribe(boolean all,
                                       byte[]... patterns)
Pattern unsubscribe.

Parameters:
all - true if all the patterns are unsubscribed (used as a hint for the underlying implementation).
patterns - patterns to be unsubscribed

doClose

protected abstract void doClose()
Shutdown the subscription and free any resources held.


getListener

public MessageListener getListener()
Description copied from interface: Subscription
Returns the listener used for this subscription.

Specified by:
getListener in interface Subscription
Returns:
the listener used for this subscription.

getChannels

public Collection<byte[]> getChannels()
Description copied from interface: Subscription
Returns the (named) channels for this subscription.

Specified by:
getChannels in interface Subscription
Returns:
collection of named channels

getPatterns

public Collection<byte[]> getPatterns()
Description copied from interface: Subscription
Returns the channel patters for this subscription.

Specified by:
getPatterns in interface Subscription
Returns:
collection of channel patterns

pSubscribe

public void pSubscribe(byte[]... patterns)
Description copied from interface: Subscription
Adds the given channel patterns to the current subscription.

Specified by:
pSubscribe in interface Subscription
Parameters:
patterns - channel patterns

pUnsubscribe

public void pUnsubscribe()
Description copied from interface: Subscription
Cancels the subscription for all channels matched by patterns.

Specified by:
pUnsubscribe in interface Subscription

subscribe

public void subscribe(byte[]... channels)
Description copied from interface: Subscription
Adds the given channels to the current subscription.

Specified by:
subscribe in interface Subscription
Parameters:
channels - channel names

unsubscribe

public void unsubscribe()
Description copied from interface: Subscription
Cancels the current subscription for all channels given by name.

Specified by:
unsubscribe in interface Subscription

pUnsubscribe

public void pUnsubscribe(byte[]... patts)
Description copied from interface: Subscription
Cancels the subscription for all channels matching the given patterns.

Specified by:
pUnsubscribe in interface Subscription

unsubscribe

public void unsubscribe(byte[]... chans)
Description copied from interface: Subscription
Cancels the current subscription for all given channels.

Specified by:
unsubscribe in interface Subscription
Parameters:
chans - channel names

isAlive

public boolean isAlive()
Description copied from interface: Subscription
Indicates whether this subscription is still 'alive' or not.

Specified by:
isAlive in interface Subscription
Returns:
true if the subscription still applies, false otherwise.