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
ConstructorsModifierConstructorDescriptionprotectedAbstractSubscription(MessageListener listener) protectedAbstractSubscription(MessageListener listener, byte[][] channels, byte[][] patterns) Constructs a newAbstractSubscriptioninstance. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Shutdown the subscription and free any resources held.protected abstract voiddoClose()Shutdown the subscription and free any resources held.protected abstract voiddoPsubscribe(byte[]... patterns) Subscribe to the given patternsprotected abstract voiddoPUnsubscribe(boolean all, byte[]... patterns) Pattern unsubscribe.protected abstract voiddoSubscribe(byte[]... channels) Subscribe to the given channels.protected abstract voiddoUnsubscribe(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.booleanisAlive()Indicates whether this subscription is still 'alive' or not.voidpSubscribe(byte[]... patterns) Adds the given channel patterns to the current subscription.voidCancels the subscription for all channels matched by patterns.voidpUnsubscribe(byte[]... patts) Cancels the subscription for all channels matching the given patterns.voidsubscribe(byte[]... channels) Adds the given channels to the current subscription.voidCancels the current subscription for all channels given by name.voidunsubscribe(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 newAbstractSubscriptioninstance. 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:SubscriptionShutdown the subscription and free any resources held.- Specified by:
closein interfaceSubscription
-
doClose
protected abstract void doClose()Shutdown the subscription and free any resources held. -
getListener
Description copied from interface:SubscriptionReturns the listener used for this subscription.- Specified by:
getListenerin interfaceSubscription- Returns:
- the listener used for this subscription.
-
getChannels
Description copied from interface:SubscriptionReturns the (named) channels for this subscription.- Specified by:
getChannelsin interfaceSubscription- Returns:
- collection of named channels
-
getPatterns
Description copied from interface:SubscriptionReturns the channel patters for this subscription.- Specified by:
getPatternsin interfaceSubscription- Returns:
- collection of channel patterns
-
pSubscribe
public void pSubscribe(byte[]... patterns) Description copied from interface:SubscriptionAdds the given channel patterns to the current subscription.- Specified by:
pSubscribein interfaceSubscription- Parameters:
patterns- channel patterns. Must not be empty.
-
pUnsubscribe
public void pUnsubscribe()Description copied from interface:SubscriptionCancels the subscription for all channels matched by patterns.- Specified by:
pUnsubscribein interfaceSubscription
-
subscribe
public void subscribe(byte[]... channels) Description copied from interface:SubscriptionAdds the given channels to the current subscription.- Specified by:
subscribein interfaceSubscription- Parameters:
channels- channel names. Must not be empty.
-
unsubscribe
public void unsubscribe()Description copied from interface:SubscriptionCancels the current subscription for all channels given by name.- Specified by:
unsubscribein interfaceSubscription
-
pUnsubscribe
Description copied from interface:SubscriptionCancels the subscription for all channels matching the given patterns.- Specified by:
pUnsubscribein interfaceSubscription- Parameters:
patts- must not be empty.
-
unsubscribe
Description copied from interface:SubscriptionCancels the current subscription for all given channels.- Specified by:
unsubscribein interfaceSubscription- Parameters:
chans- channel names. Must not be empty.
-
isAlive
public boolean isAlive()Description copied from interface:SubscriptionIndicates whether this subscription is still 'alive' or not.- Specified by:
isAlivein interfaceSubscription- Returns:
- true if the subscription still applies, false otherwise.
-