Top Description Inners Fields Constructors Methods
rx.internal.operators

public final Class OperatorPublish<T>

extends ConnectableObservable<T>
Class Inheritance
Type Parameters
<T>
the value type
Imports
java.util.Queue, java.util.concurrent.atomic.*, rx.*, rx.exceptions.*, rx.functions.*, rx.internal.util.RxRingBuffer, rx.internal.util.atomic.SpscAtomicArrayQueue, rx.internal.util.unsafe.*, rx.observables.ConnectableObservable, rx.subscriptions.Subscriptions

A connectable observable which shares an underlying source and dispatches source values to subscribers in a backpressure-aware manner.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
OperatorPublish.InnerProducer<
the value type
T
>

A Producer and Subscription that manages the request and unsubscription state of a child subscriber in thread-safe manner.

pack-priv static class

Field Summary

Modifier and TypeField and Description
pack-priv final AtomicReference<OperatorPublish.PublishSubscriber<T>>
current

Holds the current subscriber that is, will be or just was subscribed to the source observable.

pack-priv final Observable<? extends T>
source

The source observable.

Constructor Summary

AccessConstructor and Description
private
OperatorPublish(Observable.OnSubscribe<T> onSubscribe, Observable<? extends T> source, final AtomicReference<OperatorPublish.PublishSubscriber<T>> current)

Method Summary

Modifier and TypeMethod and Description
public void
connect(Action1<? super Subscription>
the action that receives the connection subscription before the subscription to source happens allowing the caller to synchronously disconnect a synchronous source
connection
)

Implements abstract rx.observables.ConnectableObservable.connect.

Instructs the ConnectableObservable to begin emitting the items from its underlying Observable to its Subscribers.
public static <
the value type
T
>
ConnectableObservable<T>

Returns:

the connectable observable
create
(Observable<? extends T>
the source observable
source
)

Creates a OperatorPublish instance to publish values of the given source observable.

public static <T, R> Observable<R>
create(final Observable<? extends T> source, final Func1<? super Observable<T>, ? extends Observable<R>> selector)

public static <T, R> Observable<R>
create(final Observable<? extends T> source, final Func1<? super Observable<T>, ? extends Observable<R>> selector, final boolean delayError)

Inherited from rx.observables.ConnectableObservable:
autoConnectautoConnectautoConnectconnectrefCount

Field Detail

currentback to summary
pack-priv final AtomicReference<OperatorPublish.PublishSubscriber<T>> current

Holds the current subscriber that is, will be or just was subscribed to the source observable.

sourceback to summary
pack-priv final Observable<? extends T> source

The source observable.

Constructor Detail

OperatorPublishback to summary
private OperatorPublish(Observable.OnSubscribe<T> onSubscribe, Observable<? extends T> source, final AtomicReference<OperatorPublish.PublishSubscriber<T>> current)

Method Detail

connectback to summary
public void connect(Action1<? super Subscription> connection)

Implements abstract rx.observables.ConnectableObservable.connect.

Doc from rx.observables.ConnectableObservable.connect.

Instructs the ConnectableObservable to begin emitting the items from its underlying Observable to its Subscribers.

Parameters
connection:Action1<? super Subscription>

the action that receives the connection subscription before the subscription to source happens allowing the caller to synchronously disconnect a synchronous source

Annotations
@Override
createback to summary
public static <T> ConnectableObservable<T> create(Observable<? extends T> source)

Creates a OperatorPublish instance to publish values of the given source observable.

Parameters
<T>
the value type
source:Observable<? extends T>

the source observable

Returns:ConnectableObservable<T>

the connectable observable

createback to summary
public static <T, R> Observable<R> create(final Observable<? extends T> source, final Func1<? super Observable<T>, ? extends Observable<R>> selector)
createback to summary
public static <T, R> Observable<R> create(final Observable<? extends T> source, final Func1<? super Observable<T>, ? extends Observable<R>> selector, final boolean delayError)
rx.internal.operators back to summary

pack-priv final Class OperatorPublish.InnerProducer<T>

extends AtomicLong
implements Producer, Subscription
Class Inheritance
All Implemented Interfaces
rx.Subscription, rx.Producer
Type Parameters
<T>
the value type

A Producer and Subscription that manages the request and unsubscription state of a child subscriber in thread-safe manner. We use AtomicLong as a base class to save on extra allocation of an AtomicLong and also save the overhead of the AtomicIntegerFieldUpdater.

Field Summary

Modifier and TypeField and Description
pack-priv final Subscriber<? super T>
child

The actual child subscriber.

pack-priv static final long
NOT_REQUESTED

Indicates this child has not yet requested any value.

pack-priv final OperatorPublish.PublishSubscriber<T>
parent

The parent subscriber-to-source used to allow removing the child in case of child unsubscription.

private static final long
pack-priv static final long
UNSUBSCRIBED

Indicates this child has been unsubscribed: the state is swapped in atomically and will prevent the dispatch() to emit (too many) values to a terminated child subscriber.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
isUnsubscribed()

Implements rx.Subscription.isUnsubscribed.

Indicates whether this Subscription is currently unsubscribed.
public long

Returns:

the updated request value (may indicate how much can be produced or a terminal state)
produced
(long
the number of items emitted
n
)

Indicate that values have been emitted to this child subscriber by the dispatch() method.

public void
request(long
the maximum number of items you want this Producer to produce, or Long.MAX_VALUE if you want the Producer to produce items at its own pace
n
)

Implements rx.Producer.request.

Request a certain maximum number of items from this Producer.
public void
unsubscribe()

Implements rx.Subscription.unsubscribe.

Stops the receipt of notifications on the Subscriber that was registered when this Subscription was received.
Inherited from java.util.concurrent.atomic.AtomicLong:
accumulateAndGetaddAndGetcompareAndExchangecompareAndExchangeAcquirecompareAndExchangeReleasecompareAndSetdecrementAndGetdoubleValuefloatValuegetgetAcquiregetAndAccumulategetAndAddgetAndDecrementgetAndIncrementgetAndSetgetAndUpdategetOpaquegetPlainincrementAndGetintValuelazySetlongValuesetsetOpaquesetPlainsetReleasetoStringupdateAndGetweakCompareAndSetweakCompareAndSetAcquireweakCompareAndSetPlainweakCompareAndSetReleaseweakCompareAndSetVolatile

Field Detail

childback to summary
pack-priv final Subscriber<? super T> child

The actual child subscriber.

NOT_REQUESTEDback to summary
pack-priv static final long NOT_REQUESTED

Indicates this child has not yet requested any value. We pretend we don't see such child subscribers in dispatch() to allow other child subscribers who have requested to make progress. In a concurrent subscription scenario, one can't be sure when a subscription happens exactly so this virtual shift should not cause any problems.

parentback to summary
pack-priv final OperatorPublish.PublishSubscriber<T> parent

The parent subscriber-to-source used to allow removing the child in case of child unsubscription.

serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.util.concurrent.atomic.AtomicLong.serialVersionUID.

UNSUBSCRIBEDback to summary
pack-priv static final long UNSUBSCRIBED

Indicates this child has been unsubscribed: the state is swapped in atomically and will prevent the dispatch() to emit (too many) values to a terminated child subscriber.

Constructor Detail

InnerProducerback to summary
public InnerProducer(OperatorPublish.PublishSubscriber<T> parent, Subscriber<? super T> child)

Method Detail

isUnsubscribedback to summary
public boolean isUnsubscribed()

Implements rx.Subscription.isUnsubscribed.

Doc from rx.Subscription.isUnsubscribed.

Indicates whether this Subscription is currently unsubscribed.

Returns:boolean

true if this Subscription is currently unsubscribed, false otherwise

Annotations
@Override
producedback to summary
public long produced(long n)

Indicate that values have been emitted to this child subscriber by the dispatch() method.

Parameters
n:long

the number of items emitted

Returns:long

the updated request value (may indicate how much can be produced or a terminal state)

requestback to summary
public void request(long n)

Implements rx.Producer.request.

Doc from rx.Producer.request.

Request a certain maximum number of items from this Producer. This is a way of requesting backpressure. To disable backpressure, pass Long.MAX_VALUE to this method.

Requests are additive but if a sequence of requests totals more than Long.MAX_VALUE then Long.MAX_VALUE requests will be actioned and the extras may be ignored. Arriving at Long.MAX_VALUE by addition of requests cannot be assumed to disable backpressure. For example, the code below may result in Long.MAX_VALUE requests being actioned only.

request(100);
request(Long.MAX_VALUE-1);
Parameters
n:long

the maximum number of items you want this Producer to produce, or Long.MAX_VALUE if you want the Producer to produce items at its own pace

Annotations
@Override
unsubscribeback to summary
public void unsubscribe()

Implements rx.Subscription.unsubscribe.

Doc from rx.Subscription.unsubscribe.

Stops the receipt of notifications on the Subscriber that was registered when this Subscription was received.

This allows deregistering an Subscriber before it has finished receiving all events (i.e. before onCompleted is called).

Annotations
@Override
rx.internal.operators back to summary

pack-priv final Class OperatorPublish.PublishSubscriber<T>

extends Subscriber<T>
implements Subscription
Class Inheritance
All Implemented Interfaces
rx.Subscription
Annotations
@SuppressWarnings:rawtypes

Field Summary

Modifier and TypeField and Description
pack-priv final AtomicReference<OperatorPublish.PublishSubscriber<T>>
current

Holds onto the current connected PublishSubscriber.

pack-priv boolean
emitting

Guarded by this.

pack-priv static final OperatorPublish.InnerProducer<T>[]
EMPTY

Indicates an empty array of inner producers.

pack-priv boolean
missed

Guarded by this.

pack-priv final AtomicReference<OperatorPublish.InnerProducer<T>[]>
producers

Tracks the subscribed producers.

pack-priv final Queue<Object>
queue

Holds notifications from upstream.

pack-priv final AtomicBoolean
shouldConnect

Atomically changed from false to true by connect to make sure the connection is only performed by one thread.

pack-priv volatile Object
terminalEvent

Contains either an onCompleted or an onError token from upstream.

pack-priv static final OperatorPublish.InnerProducer<T>[]
TERMINATED

Indicates a terminated PublishSubscriber.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
pack-priv boolean

Returns:

true if succeeded, false otherwise
add
(OperatorPublish.InnerProducer<T>
the producer to add
producer
)

Atomically try adding a new InnerProducer to this Subscriber or return false if this Subscriber was terminated.

pack-priv boolean

Returns:

true if there is indeed a terminal condition
checkTerminated
(Object
the terminal event (a NotificationLite.error or completed)
term
,
boolean
set to true if the queue is empty
empty
)

Perform termination actions in case the source has terminated in some way and the queue has also become empty.

pack-priv void
dispatch()

The common serialization point of events arriving from upstream and child-subscribers requesting more.

pack-priv void
init()

Should be called after the constructor finished to setup nulling-out the current reference.

public void
onCompleted()

Implements rx.Observer.onCompleted.

Notifies the Observer that the Observable has finished sending push-based notifications.
public void
onError(Throwable
the exception encountered by the Observable
e
)

Implements rx.Observer.onError.

Notifies the Observer that the Observable has experienced an error condition.
public void
onNext(T
the item emitted by the Observable
t
)

Implements rx.Observer.onNext.

Provides the Observer with a new item to observe.
public void
onStart()

Overrides rx.Subscriber.onStart.

This method is invoked when the Subscriber and Observable have been connected but the Observable has not yet begun to emit items or send notifications to the Subscriber.
pack-priv void
remove(OperatorPublish.InnerProducer<T>
the producer to remove
producer
)

Atomically removes the given producer from the producers array.

Inherited from rx.Subscriber:
addisUnsubscribedrequestsetProducerunsubscribe

Field Detail

currentback to summary
pack-priv final AtomicReference<OperatorPublish.PublishSubscriber<T>> current

Holds onto the current connected PublishSubscriber.

emittingback to summary
pack-priv boolean emitting

Guarded by this.

EMPTYback to summary
pack-priv static final OperatorPublish.InnerProducer<T>[] EMPTY

Indicates an empty array of inner producers.

missedback to summary
pack-priv boolean missed

Guarded by this.

producersback to summary
pack-priv final AtomicReference<OperatorPublish.InnerProducer<T>[]> producers

Tracks the subscribed producers.

queueback to summary
pack-priv final Queue<Object> queue

Holds notifications from upstream.

shouldConnectback to summary
pack-priv final AtomicBoolean shouldConnect

Atomically changed from false to true by connect to make sure the connection is only performed by one thread.

terminalEventback to summary
pack-priv volatile Object terminalEvent

Contains either an onCompleted or an onError token from upstream.

TERMINATEDback to summary
pack-priv static final OperatorPublish.InnerProducer<T>[] TERMINATED

Indicates a terminated PublishSubscriber.

Constructor Detail

PublishSubscriberback to summary
public PublishSubscriber(AtomicReference<OperatorPublish.PublishSubscriber<T>> current)

Method Detail

addback to summary
pack-priv boolean add(OperatorPublish.InnerProducer<T> producer)

Atomically try adding a new InnerProducer to this Subscriber or return false if this Subscriber was terminated.

Parameters
producer:OperatorPublish.InnerProducer<T>

the producer to add

Returns:boolean

true if succeeded, false otherwise

checkTerminatedback to summary
pack-priv boolean checkTerminated(Object term, boolean empty)

Perform termination actions in case the source has terminated in some way and the queue has also become empty.

Parameters
term:Object

the terminal event (a NotificationLite.error or completed)

empty:boolean

set to true if the queue is empty

Returns:boolean

true if there is indeed a terminal condition

dispatchback to summary
pack-priv void dispatch()

The common serialization point of events arriving from upstream and child-subscribers requesting more.

initback to summary
pack-priv void init()

Should be called after the constructor finished to setup nulling-out the current reference.

onCompletedback to summary
public void onCompleted()

Implements rx.Observer.onCompleted.

Doc from rx.Observer.onCompleted.

Notifies the Observer that the Observable has finished sending push-based notifications.

The Observable will not call this method if it calls onError.

Annotations
@Override
onErrorback to summary
public void onError(Throwable e)

Implements rx.Observer.onError.

Doc from rx.Observer.onError.

Notifies the Observer that the Observable has experienced an error condition.

If the Observable calls this method, it will not thereafter call onNext or onCompleted.

Parameters
e:Throwable

the exception encountered by the Observable

Annotations
@Override
onNextback to summary
public void onNext(T t)

Implements rx.Observer.onNext.

Doc from rx.Observer.onNext.

Provides the Observer with a new item to observe.

The Observable may call this method 0 or more times.

The Observable will not call this method again after it calls either onCompleted or onError.

Parameters
t:T

the item emitted by the Observable

Annotations
@Override
onStartback to summary
public void onStart()

Overrides rx.Subscriber.onStart.

Doc from rx.Subscriber.onStart.

This method is invoked when the Subscriber and Observable have been connected but the Observable has not yet begun to emit items or send notifications to the Subscriber. Override this method to add any useful initialization to your subscription, for instance to initiate backpressure.

Annotations
@Override
removeback to summary
pack-priv void remove(OperatorPublish.InnerProducer<T> producer)

Atomically removes the given producer from the producers array.

Parameters
producer:OperatorPublish.InnerProducer<T>

the producer to remove