Class AbstractSubscription

java.lang.Object
org.springframework.data.redis.connection.util.AbstractSubscription
All Implemented Interfaces:
Subscription
Direct Known Subclasses:
LettuceSubscription

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.
Author:
Costin Leau, Christoph Strobl
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
     
    protected
    AbstractSubscription(MessageListener listener, byte[][] channels, byte[][] patterns)
    Constructs a new AbstractSubscription instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Shutdown the subscription and free any resources held.
    protected abstract void
    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[]>
    Returns the (named) channels for this subscription.
    Returns the listener used for this subscription.
    Collection<byte[]>
    Returns the channel patters for this subscription.
    boolean
    Indicates whether this subscription is still 'alive' or not.
    void
    pSubscribe(byte[]... patterns)
    Adds the given channel patterns to the current subscription.
    void
    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
    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 Details

    • AbstractSubscription

      protected AbstractSubscription(MessageListener listener)
    • AbstractSubscription

      protected AbstractSubscription(MessageListener listener, @Nullable byte[][] channels, @Nullable 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 - must not be null.
      channels - can be null.
      patterns - can be null.
  • Method Details

    • 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
    • close

      public void close()
      Description copied from interface: Subscription
      Shutdown the subscription and free any resources held.
      Specified by:
      close in interface Subscription
    • 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. Must not be empty.
    • 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. Must not be empty.
    • 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(@Nullable byte[]... patts)
      Description copied from interface: Subscription
      Cancels the subscription for all channels matching the given patterns.
      Specified by:
      pUnsubscribe in interface Subscription
      Parameters:
      patts - must not be empty.
    • unsubscribe

      public void unsubscribe(@Nullable 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. Must not be empty.
    • 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.