The difference between this class and OperatorPublish is that this class doesn't consume the upstream if there are no child subscribers but waits for them to show up. Plus if the upstream source terminates, late subscribers will be immediately terminated with the same terminal event unlike OperatorPublish which just waits for the next connection.
The class extends AtomicInteger which is the work-in-progress gate for the drain-loop serializing subscriptions and child request changes.
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class | OnSubscribePublishMulticast.ParentSubscriber<
the input value type; T>The subscriber that must be used for subscribing to the upstream source. |
| pack-priv static class | OnSubscribePublishMulticast.PublishProducer<
the output value type T>A Producer and Subscription that wraps a child Subscriber and manages its backpressure requests along with its unsubscription from the parent class. |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final boolean | delayError
Delays the error delivery to happen only after all values have been consumed. |
| pack-priv volatile boolean | done
Indicates the upstream has completed. |
| pack-priv static final OnSubscribePublishMulticast. | EMPTY
Represents an empty array of subscriber wrapper, helps avoid allocating an empty array all the time. |
| pack-priv Throwable | error
Holds onto the upstream's exception if done is true and this field is non-null. |
| pack-priv final OnSubscribePublishMulticast. | parent
The subscriber that can be 'connected' to the upstream source. |
| pack-priv final int | prefetch
The number of items to prefetch from the upstreams source. |
| pack-priv volatile Producer | producer
Holds the upstream producer if any, set through the parent subscriber. |
| pack-priv final Queue | queue
The prefetch queue holding onto a fixed amount of items until all all child subscribers have requested something. |
| private static final long | |
| pack-priv volatile OnSubscribePublishMulticast. | subscribers
A copy-on-write array of currently subscribed child subscribers' wrapper structure. |
| pack-priv static final OnSubscribePublishMulticast. | TERMINATED
Represents a final state for this class that prevents new subscribers from subscribing to it. |
| Access | Constructor and Description |
|---|---|
| public | OnSubscribePublishMulticast(int
the prefetch amount, > 0 required prefetch, boolean delay the error delivery after the normal items? delayError)Constructor, initializes the fields |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv boolean | Returns: true if successful, false if the terminal state has been reached in the meantimethe wrapper innerAtomically adds the given wrapper of a child Subscriber to the subscribers array. |
| public void | |
| pack-priv boolean | Returns: true if the class reached its terminal statethe source-done indicator d, boolean the queue-emptiness indicator empty)Given the current source state, terminates all child subscribers. |
| pack-priv void | drain()
The serialization loop that determines the minimum request of all subscribers and tries to emit as many items from the queue if they are available. |
| public boolean | isUnsubscribed()
Implements rx. Subscription is currently unsubscribed.
|
| public void | onCompleted()
Implements rx. Observable has finished sending push-based notifications.
|
| public void | onError(Throwable
the exception encountered by the Observable e)Implements rx. Observable has experienced an error condition.
|
| public void | onNext(T
the item emitted by the Observable t)Implements rx. |
| pack-priv void | remove(OnSubscribePublishMulticast.
the wrapper to remove innerAtomically removes the given wrapper, if present, from the subscribers array. |
| pack-priv void | |
| public Subscriber | Returns: the subscriber instanceReturns the input subscriber of this class that must be subscribed to the upstream source. |
| pack-priv OnSubscribePublishMulticast. | Returns: the last set of subscribers before the state change or an empty arrayAtomically swaps in the terminated state. |
| public void | unsubscribe()
Implements rx. Subscriber that was registered when this Subscription
was received.
|
| delayError | back to summary |
|---|---|
| pack-priv final boolean delayError Delays the error delivery to happen only after all values have been consumed. | |
| done | back to summary |
|---|---|
| pack-priv volatile boolean done Indicates the upstream has completed. | |
| EMPTY | back to summary |
|---|---|
| pack-priv static final OnSubscribePublishMulticast. Represents an empty array of subscriber wrapper, helps avoid allocating an empty array all the time. | |
| error | back to summary |
|---|---|
| pack-priv Throwable error Holds onto the upstream's exception if done is true and this field is non-null. This field must be read after done or if subscribers == TERMINATED to establish a proper happens-before. | |
| parent | back to summary |
|---|---|
| pack-priv final OnSubscribePublishMulticast. The subscriber that can be 'connected' to the upstream source. | |
| prefetch | back to summary |
|---|---|
| pack-priv final int prefetch The number of items to prefetch from the upstreams source. | |
| producer | back to summary |
|---|---|
| pack-priv volatile Producer producer Holds the upstream producer if any, set through the parent subscriber. | |
| queue | back to summary |
|---|---|
| pack-priv final Queue<T> queue The prefetch queue holding onto a fixed amount of items until all all child subscribers have requested something. | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Hides java. | |
| subscribers | back to summary |
|---|---|
| pack-priv volatile OnSubscribePublishMulticast. A copy-on-write array of currently subscribed child subscribers' wrapper structure. | |
| TERMINATED | back to summary |
|---|---|
| pack-priv static final OnSubscribePublishMulticast. Represents a final state for this class that prevents new subscribers from subscribing to it. | |
| OnSubscribePublishMulticast | back to summary |
|---|---|
| public OnSubscribePublishMulticast(int prefetch, boolean delayError) Constructor, initializes the fields
| |
| add | back to summary |
|---|---|
| pack-priv boolean add(OnSubscribePublishMulticast. Atomically adds the given wrapper of a child Subscriber to the subscribers array.
| |
| call | back to summary |
|---|---|
| public void call(Subscriber<? super T> t) Implements rx.
| |
| checkTerminated | back to summary |
|---|---|
| pack-priv boolean checkTerminated(boolean d, boolean empty) Given the current source state, terminates all child subscribers.
| |
| drain | back to summary |
|---|---|
| pack-priv void drain() The serialization loop that determines the minimum request of all subscribers and tries to emit as many items from the queue if they are available. The execution of the drain-loop is guaranteed to be thread-safe. | |
| isUnsubscribed | back to summary |
|---|---|
| public boolean isUnsubscribed() Implements rx. Doc from rx. Indicates whether this
| |
| onCompleted | back to summary |
|---|---|
| public void onCompleted() Implements rx. Doc from rx. Notifies the Observer that the
The
| |
| onError | back to summary |
|---|---|
| public void onError(Throwable e) Implements rx. Doc from rx. Notifies the Observer that the
If the | |
| onNext | back to summary |
|---|---|
| public void onNext(T t) Implements rx. Doc from rx. Provides the Observer with a new item to observe.
The
The
| |
| remove | back to summary |
|---|---|
| pack-priv void remove(OnSubscribePublishMulticast. Atomically removes the given wrapper, if present, from the subscribers array.
| |
| setProducer | back to summary |
|---|---|
| pack-priv void setProducer(Producer p) Sets the main producer and issues the prefetch amount.
| |
| subscriber | back to summary |
|---|---|
| public Subscriber Returns the input subscriber of this class that must be subscribed to the upstream source.
| |
| terminate | back to summary |
|---|---|
| pack-priv OnSubscribePublishMulticast. Atomically swaps in the terminated state.
| |
| unsubscribe | back to summary |
|---|---|
| public void unsubscribe() Implements rx. Doc from rx. Stops the receipt of notifications on the
This allows deregistering an
| |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final OnSubscribePublishMulticast | state
The reference to the parent state where the events are forwarded to. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | onCompleted()
Implements rx. Observable has finished sending push-based notifications.
|
| public void | onError(Throwable
the exception encountered by the Observable e)Implements rx. Observable has experienced an error condition.
|
| public void | onNext(T
the item emitted by the Observable t)Implements rx. |
| public void | setProducer(Producer
producer to be used by this subscriber or the other subscriber
(or recursively its other subscriber) to make requests from p)Overrides rx. Subscriber(Subscriber) or
Subscriber(Subscriber, boolean)) then this method calls
setProducer on the other subscriber.
|
| state | back to summary |
|---|---|
| pack-priv final OnSubscribePublishMulticast<T> state The reference to the parent state where the events are forwarded to. | |
| ParentSubscriber | back to summary |
|---|---|
| public ParentSubscriber(OnSubscribePublishMulticast<T> state) | |
| onCompleted | back to summary |
|---|---|
| public void onCompleted() Implements rx. Doc from rx. Notifies the Observer that the
The
| |
| onError | back to summary |
|---|---|
| public void onError(Throwable e) Implements rx. Doc from rx. Notifies the Observer that the
If the | |
| onNext | back to summary |
|---|---|
| public void onNext(T t) Implements rx. Doc from rx. Provides the Observer with a new item to observe.
The
The
| |
| setProducer | back to summary |
|---|---|
| public void setProducer(Producer p) Overrides rx. Doc from rx. If other subscriber is set (by calling constructor
| |
The class extends AtomicLong that holds onto the child's requested amount.
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final Subscriber | actual
The actual subscriber to receive the events. |
| pack-priv final AtomicBoolean | once
Makes sure unsubscription happens only once. |
| pack-priv final OnSubscribePublishMulticast | parent
The parent object to request draining or removal. |
| private static final long |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | isUnsubscribed()
Implements rx. Subscription is currently unsubscribed.
|
| public void | request(long
the maximum number of items you want this Producer to produce, or n)Long.MAX_VALUE if you
want the Producer to produce items at its own paceImplements rx. |
| public void | unsubscribe()
Implements rx. Subscriber that was registered when this Subscription
was received.
|
| actual | back to summary |
|---|---|
| pack-priv final Subscriber<? super T> actual The actual subscriber to receive the events. | |
| once | back to summary |
|---|---|
| pack-priv final AtomicBoolean once Makes sure unsubscription happens only once. | |
| parent | back to summary |
|---|---|
| pack-priv final OnSubscribePublishMulticast<T> parent The parent object to request draining or removal. | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Hides java. | |
| PublishProducer | back to summary |
|---|---|
| public PublishProducer(Subscriber<? super T> actual, OnSubscribePublishMulticast<T> parent) | |
| isUnsubscribed | back to summary |
|---|---|
| public boolean isUnsubscribed() Implements rx. Doc from rx. Indicates whether this
| |
| request | back to summary |
|---|---|
| public void request(long n) Implements rx. Doc from rx. Request a certain maximum number of items from this Producer. This is a way of requesting backpressure.
To disable backpressure, pass
Requests are additive but if a sequence of requests totals more than request(100); request(Long.MAX_VALUE-1);
| |
| unsubscribe | back to summary |
|---|---|
| public void unsubscribe() Implements rx. Doc from rx. Stops the receipt of notifications on the
This allows deregistering an
| |