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:
java.io.Serializable
,Action
,Action1<Subscriber<? super T>>
,Function
,Observable.OnSubscribe<T>
final class SubjectSubscriptionManager<T> extends java.util.concurrent.atomic.AtomicReference<SubjectSubscriptionManager.State<T>> implements Observable.OnSubscribe<T>
Represents the typical state and OnSubscribe logic for a Subject implementation.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
SubjectSubscriptionManager.State<T>
State-machine representing the termination state and active SubjectObservers.protected static class
SubjectSubscriptionManager.SubjectObserver<T>
Observer wrapping the actual Subscriber and providing various emission facilities.
-
Field Summary
Fields Modifier and Type Field Description (package private) boolean
active
Indicates that the subject is active (cheaper than checking the state).(package private) java.lang.Object
latest
Stores the latest value or the terminal value for some Subjects.NotificationLite<T>
nl
The notification lite.(package private) Action1<SubjectSubscriptionManager.SubjectObserver<T>>
onAdded
Action called after the subscriber has been added to the state.(package private) Action1<SubjectSubscriptionManager.SubjectObserver<T>>
onStart
Action called when a new subscriber subscribes but before it is added to the state.(package private) Action1<SubjectSubscriptionManager.SubjectObserver<T>>
onTerminated
Action called when the subscriber wants to subscribe to a terminal state.private static long
serialVersionUID
-
Constructor Summary
Constructors Constructor Description SubjectSubscriptionManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) boolean
add(SubjectSubscriptionManager.SubjectObserver<T> o)
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) java.lang.Object
getLatest()
(package private) SubjectSubscriptionManager.SubjectObserver<T>[]
next(java.lang.Object n)
Set a new latest NotificationLite value and return the active observers.(package private) SubjectSubscriptionManager.SubjectObserver<T>[]
observers()
(package private) void
remove(SubjectSubscriptionManager.SubjectObserver<T> o)
Atomically remove the specified SubjectObserver from the active observers.(package private) void
setLatest(java.lang.Object value)
Set the latest NotificationLite value.(package private) SubjectSubscriptionManager.SubjectObserver<T>[]
terminate(java.lang.Object n)
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 Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
latest
volatile java.lang.Object latest
Stores the latest value or the terminal value for some Subjects.
-
active
boolean active
Indicates that the subject is active (cheaper than checking the state).
-
onStart
Action1<SubjectSubscriptionManager.SubjectObserver<T>> onStart
Action called when a new subscriber subscribes but before it is added to the state.
-
onAdded
Action1<SubjectSubscriptionManager.SubjectObserver<T>> onAdded
Action called after the subscriber has been added to the state.
-
onTerminated
Action1<SubjectSubscriptionManager.SubjectObserver<T>> onTerminated
Action called when the subscriber wants to subscribe to a terminal state.
-
nl
public final NotificationLite<T> nl
The notification lite.
-
-
Method Detail
-
call
public void call(Subscriber<? super T> child)
-
addUnsubscriber
void addUnsubscriber(Subscriber<? super T> child, SubjectSubscriptionManager.SubjectObserver<T> bo)
Registers the unsubscribe action for the given subscriber.
-
setLatest
void setLatest(java.lang.Object value)
Set the latest NotificationLite value.
-
getLatest
java.lang.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
boolean add(SubjectSubscriptionManager.SubjectObserver<T> o)
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
void remove(SubjectSubscriptionManager.SubjectObserver<T> o)
Atomically remove the specified SubjectObserver from the active observers.- Parameters:
o
- the SubjectObserver to remove
-
next
SubjectSubscriptionManager.SubjectObserver<T>[] next(java.lang.Object n)
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
SubjectSubscriptionManager.SubjectObserver<T>[] terminate(java.lang.Object n)
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
-
-