Class AbstractSubscription
java.lang.Object
org.springframework.data.redis.connection.util.AbstractSubscription
- All Implemented Interfaces:
Subscription
- Direct Known Subclasses:
LettuceSubscription
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
ModifierConstructorDescriptionprotected
AbstractSubscription
(MessageListener listener) protected
AbstractSubscription
(MessageListener listener, byte[][] channels, byte[][] patterns) Constructs a newAbstractSubscription
instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Shutdown the subscription and free any resources held.protected abstract void
doClose()
Shutdown the subscription and free any resources held.protected abstract void
doPsubscribe
(byte[]... patterns) Subscribe to the given patternsprotected 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
isAlive()
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.
-
Constructor Details
-
AbstractSubscription
-
AbstractSubscription
protected AbstractSubscription(MessageListener listener, @Nullable byte[][] channels, @Nullable byte[][] patterns) Constructs a newAbstractSubscription
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 interfaceSubscription
-
doClose
protected abstract void doClose()Shutdown the subscription and free any resources held. -
getListener
Description copied from interface:Subscription
Returns the listener used for this subscription.- Specified by:
getListener
in interfaceSubscription
- Returns:
- the listener used for this subscription.
-
getChannels
Description copied from interface:Subscription
Returns the (named) channels for this subscription.- Specified by:
getChannels
in interfaceSubscription
- Returns:
- collection of named channels
-
getPatterns
Description copied from interface:Subscription
Returns the channel patters for this subscription.- Specified by:
getPatterns
in interfaceSubscription
- 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 interfaceSubscription
- 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 interfaceSubscription
-
subscribe
public void subscribe(byte[]... channels) Description copied from interface:Subscription
Adds the given channels to the current subscription.- Specified by:
subscribe
in interfaceSubscription
- 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 interfaceSubscription
-
pUnsubscribe
Description copied from interface:Subscription
Cancels the subscription for all channels matching the given patterns.- Specified by:
pUnsubscribe
in interfaceSubscription
- Parameters:
patts
- must not be empty.
-
unsubscribe
Description copied from interface:Subscription
Cancels the current subscription for all given channels.- Specified by:
unsubscribe
in interfaceSubscription
- 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 interfaceSubscription
- Returns:
- true if the subscription still applies, false otherwise.
-