-
- All Implemented Interfaces:
-
com.tds.common.reactor.Subscription
,java.io.Serializable
public final class SequentialSubscription extends AtomicReference<Subscription> implements Subscription
A container of a Subscription that supports operations of SerialSubscription and MultipleAssignmentSubscription via methods (update, replace) and extends AtomicReference to reduce allocation count (beware the API leak of AtomicReference!).
-
-
Constructor Summary
Constructors Constructor Description SequentialSubscription()
Create an empty SequentialSubscription. SequentialSubscription(Subscription initial)
Create a SequentialSubscription with the given initial Subscription.
-
Method Summary
Modifier and Type Method Description Subscription
current()
Returns the current contained Subscription (may be null). boolean
update(Subscription next)
Atomically sets the contained Subscription to the provided next value and unsubscribesthe previous value or unsubscribes the next value if this container is unsubscribed. boolean
replace(Subscription next)
Atomically replaces the contained Subscription to the provided next value butdoes not unsubscribe the previous value or unsubscribes the next value if thiscontainer is unsubscribed. boolean
updateWeak(Subscription next)
Atomically tries to set the contained Subscription to the provided next value and unsubscribesthe previous value or unsubscribes the next value if this container is unsubscribed. boolean
replaceWeak(Subscription next)
Atomically tries to replace the contained Subscription to the provided next value butdoes not unsubscribe the previous value or unsubscribes the next value if this containeris unsubscribed. void
unsubscribe()
Stops the receipt of notifications on the Subscriber that was registered when this Subscriptionwas received. boolean
isUnsubscribed()
Indicates whether this {@code Subscription}
is currently unsubscribed.-
Methods inherited from class java.util.concurrent.atomic.AtomicReference
accumulateAndGet, compareAndSet, get, getAndAccumulate, getAndSet, getAndUpdate, lazySet, set, toString, updateAndGet, weakCompareAndSet
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
SequentialSubscription
SequentialSubscription()
Create an empty SequentialSubscription.
-
SequentialSubscription
SequentialSubscription(Subscription initial)
Create a SequentialSubscription with the given initial Subscription.- Parameters:
initial
- the initial Subscription, may be null
-
-
Method Detail
-
current
Subscription current()
Returns the current contained Subscription (may be null).
(Remark: named as such because get() is final).
-
update
boolean update(Subscription next)
Atomically sets the contained Subscription to the provided next value and unsubscribesthe previous value or unsubscribes the next value if this container is unsubscribed.
(Remark: named as such because set() is final).
- Parameters:
next
- the next Subscription to contain, may be null
-
replace
boolean replace(Subscription next)
Atomically replaces the contained Subscription to the provided next value butdoes not unsubscribe the previous value or unsubscribes the next value if thiscontainer is unsubscribed.
- Parameters:
next
- the next Subscription to contain, may be null
-
updateWeak
boolean updateWeak(Subscription next)
Atomically tries to set the contained Subscription to the provided next value and unsubscribesthe previous value or unsubscribes the next value if this container is unsubscribed.
Unlike update, this doesn't retry if the replace failedbecause a concurrent operation changed the underlying contained object.
- Parameters:
next
- the next Subscription to contain, may be null
-
replaceWeak
boolean replaceWeak(Subscription next)
Atomically tries to replace the contained Subscription to the provided next value butdoes not unsubscribe the previous value or unsubscribes the next value if this containeris unsubscribed.
Unlike replace, this doesn't retry if the replace failedbecause a concurrent operation changed the underlying contained object.
- Parameters:
next
- the next Subscription to contain, may be null
-
unsubscribe
void unsubscribe()
Stops the receipt of notifications on the Subscriber that was registered when this Subscriptionwas received.
This allows deregistering an Subscriber before it has finished receiving all events (i.e. beforeonCompleted is called).
-
isUnsubscribed
boolean isUnsubscribed()
Indicates whether this
{@code Subscription}
is currently unsubscribed.
-
-
-
-