Package rx.subjects
Class SubjectSubscriptionManager<T>
java.lang.Object
java.util.concurrent.atomic.AtomicReference<SubjectSubscriptionManager.State<T>>
rx.subjects.SubjectSubscriptionManager<T>
- Type Parameters:
T
- the source and return value type
- All Implemented Interfaces:
Serializable
,Action
,Action1<Subscriber<? super T>>
,Function
,Observable.OnSubscribe<T>
final class SubjectSubscriptionManager<T>
extends AtomicReference<SubjectSubscriptionManager.State<T>>
implements Observable.OnSubscribe<T>
Represents the typical state and OnSubscribe logic for a Subject implementation.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static final class
State-machine representing the termination state and active SubjectObservers.protected static final class
Observer wrapping the actual Subscriber and providing various emission facilities. -
Field Summary
FieldsModifier and TypeFieldDescription(package private) boolean
Indicates that the subject is active (cheaper than checking the state).(package private) Object
Stores the latest value or the terminal value for some Subjects.final NotificationLite
<T> The notification lite.(package private) Action1
<SubjectSubscriptionManager.SubjectObserver<T>> Action called after the subscriber has been added to the state.(package private) Action1
<SubjectSubscriptionManager.SubjectObserver<T>> Action called when a new subscriber subscribes but before it is added to the state.(package private) Action1
<SubjectSubscriptionManager.SubjectObserver<T>> Action called when the subscriber wants to subscribe to a terminal state.private static final long
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) boolean
Try to atomically add a SubjectObserver to the active state.(package private) void
addUnsubscriber
(Subscriber<? super T> child, SubjectSubscriptionManager.SubjectObserver<T> bo) Registers the unsubscribe action for the given subscriber.void
call
(Subscriber<? super T> child) (package private) Object
(package private) SubjectSubscriptionManager.SubjectObserver<T>[]
Set a new latest NotificationLite value and return the active observers.(package private) SubjectSubscriptionManager.SubjectObserver<T>[]
(package private) void
Atomically remove the specified SubjectObserver from the active observers.(package private) void
Set the latest NotificationLite value.(package private) SubjectSubscriptionManager.SubjectObserver<T>[]
Atomically set the terminal NotificationLite value (which could be any of the 3), clear the active observers and return the last active observers.Methods inherited from class java.util.concurrent.atomic.AtomicReference
accumulateAndGet, compareAndExchange, compareAndExchangeAcquire, compareAndExchangeRelease, compareAndSet, get, getAcquire, getAndAccumulate, getAndSet, getAndUpdate, getOpaque, getPlain, lazySet, set, setOpaque, setPlain, setRelease, toString, updateAndGet, weakCompareAndSet, weakCompareAndSetAcquire, weakCompareAndSetPlain, weakCompareAndSetRelease, weakCompareAndSetVolatile
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
latest
Stores the latest value or the terminal value for some Subjects. -
active
boolean activeIndicates that the subject is active (cheaper than checking the state). -
onStart
Action called when a new subscriber subscribes but before it is added to the state. -
onAdded
Action called after the subscriber has been added to the state. -
onTerminated
Action1<SubjectSubscriptionManager.SubjectObserver<T>> onTerminatedAction called when the subscriber wants to subscribe to a terminal state. -
nl
The notification lite.
-
-
Constructor Details
-
SubjectSubscriptionManager
public SubjectSubscriptionManager()
-
-
Method Details
-
call
-
addUnsubscriber
Registers the unsubscribe action for the given subscriber. -
setLatest
Set the latest NotificationLite value. -
getLatest
Object getLatest()- Returns:
- Retrieve the latest NotificationLite value
-
observers
SubjectSubscriptionManager.SubjectObserver<T>[] observers()- Returns:
- the array of active subscribers, don't write into the array!
-
add
Try to atomically add a SubjectObserver to the active state.- Parameters:
o
- the SubjectObserver to add- Returns:
- false if the subject is already in its terminal state
-
remove
Atomically remove the specified SubjectObserver from the active observers.- Parameters:
o
- the SubjectObserver to remove
-
next
Set a new latest NotificationLite value and return the active observers.- Parameters:
n
- the new latest value- Returns:
- the array of SubjectObservers, don't write into the array!
-
terminate
Atomically set the terminal NotificationLite value (which could be any of the 3), clear the active observers and return the last active observers.- Parameters:
n
- the terminal value- Returns:
- the last active SubjectObservers
-