Top Description Inners Fields Constructors Methods
io.reactivex.internal.operators.flowable

public final Class FlowablePublish<T>

extends ConnectableFlowable<T>
implements HasUpstreamPublisher<T>, FlowablePublishClassic<T>
Class Inheritance
All Implemented Interfaces
io.reactivex.internal.operators.flowable.FlowablePublishClassic, io.reactivex.internal.fuseable.HasUpstreamPublisher
Type Parameters
<T>
the value type
Imports
java.util.concurrent.atomic.*, org.reactivestreams.*, io.reactivex.*, io.reactivex.disposables.Disposable, io.reactivex.exceptions.*, io.reactivex.flowables.ConnectableFlowable, io.reactivex.functions.Consumer, io.reactivex.internal.fuseable.*, io.reactivex.internal.queue.SpscArrayQueue, io.reactivex.internal.subscriptions.SubscriptionHelper, io.reactivex.internal.util.*, io.reactivex.plugins.RxJavaPlugins

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
pack-priv static class
FlowablePublish.InnerSubscriber<
the value type
T
>

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

pack-priv static class

Field Summary

Modifier and TypeField and Description
pack-priv final int
bufferSize

The size of the prefetch buffer.

pack-priv static final long
CANCELLED

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

pack-priv final AtomicReference<FlowablePublish.PublishSubscriber<T>>
current

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

pack-priv final Publisher<T>
pack-priv final Flowable<T>
source

The source observable.

Constructor Summary

AccessConstructor and Description
private
FlowablePublish(Publisher<T> onSubscribe, Flowable<T> source, final AtomicReference<FlowablePublish.PublishSubscriber<T>> current, int bufferSize)

Method Summary

Modifier and TypeMethod and Description
public void
connect(Consumer<? super Disposable>
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 io.reactivex.flowables.ConnectableFlowable.connect.

Instructs the ConnectableFlowable to begin emitting the items from its underlying Flowable to its Subscribers.
public static <
the source value type
T
>
ConnectableFlowable<T>

Returns:

the connectable observable
create
(Flowable<T>
the source observable
source
,
final int
the size of the prefetch buffer
bufferSize
)

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

public int

Returns:

The internal buffer size of this FloawblePublish operator.
publishBufferSize
()

Implements io.reactivex.internal.operators.flowable.FlowablePublishClassic.publishBufferSize.

The internal buffer size of this FloawblePublish operator.
public Publisher<T>
publishSource()

Implements io.reactivex.internal.operators.flowable.FlowablePublishClassic.publishSource.

The upstream source of this publish operator.
public Publisher<T>
source()

Implements io.reactivex.internal.fuseable.HasUpstreamPublisher.source.

Returns the source Publisher.
protected void
subscribeActual(Subscriber<? super T>
the incoming Subscriber, never null
s
)

Implements abstract io.reactivex.Flowable.subscribeActual.

Operator implementations (both source and intermediate) should implement this method that performs the necessary business logic and handles the incoming Subscribers.
Inherited from io.reactivex.flowables.ConnectableFlowable:
autoConnectautoConnectautoConnectconnectrefCountrefCountrefCountrefCountrefCountrefCount

Field Detail

bufferSizeback to summary
pack-priv final int bufferSize

The size of the prefetch buffer.

CANCELLEDback to summary
pack-priv static final long CANCELLED

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

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

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

onSubscribeback to summary
pack-priv final Publisher<T> onSubscribe
sourceback to summary
pack-priv final Flowable<T> source

The source observable.

Constructor Detail

FlowablePublishback to summary
private FlowablePublish(Publisher<T> onSubscribe, Flowable<T> source, final AtomicReference<FlowablePublish.PublishSubscriber<T>> current, int bufferSize)

Method Detail

connectback to summary
public void connect(Consumer<? super Disposable> connection)

Implements abstract io.reactivex.flowables.ConnectableFlowable.connect.

Doc from io.reactivex.flowables.ConnectableFlowable.connect.

Instructs the ConnectableFlowable to begin emitting the items from its underlying Flowable to its Subscribers.

Parameters
connection:Consumer<? super Disposable>

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> ConnectableFlowable<T> create(Flowable<T> source, final int bufferSize)

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

Parameters
<T>
the source value type
source:Flowable<T>

the source observable

bufferSize:int

the size of the prefetch buffer

Returns:ConnectableFlowable<T>

the connectable observable

publishBufferSizeback to summary
public int publishBufferSize()

Implements io.reactivex.internal.operators.flowable.FlowablePublishClassic.publishBufferSize.

The internal buffer size of this FloawblePublish operator.

Returns:int

The internal buffer size of this FloawblePublish operator.

Annotations
@Override
publishSourceback to summary
public Publisher<T> publishSource()

Implements io.reactivex.internal.operators.flowable.FlowablePublishClassic.publishSource.

Doc from io.reactivex.internal.operators.flowable.FlowablePublishClassic.publishSource.

The upstream source of this publish operator.

Returns:Publisher<T>

the upstream source of this publish operator

Annotations
@Override
sourceback to summary
public Publisher<T> source()

Implements io.reactivex.internal.fuseable.HasUpstreamPublisher.source.

Doc from io.reactivex.internal.fuseable.HasUpstreamPublisher.source.

Returns the source Publisher.

This method is intended to discover the assembly graph of sequences.

Returns:Publisher<T>

the source Publisher

Annotations
@Override
subscribeActualback to summary
protected void subscribeActual(Subscriber<? super T> s)

Implements abstract io.reactivex.Flowable.subscribeActual.

Doc from io.reactivex.Flowable.subscribeActual.

Operator implementations (both source and intermediate) should implement this method that performs the necessary business logic and handles the incoming Subscribers.

There is no need to call any of the plugin hooks on the current Flowable instance or the Subscriber; all hooks and basic safeguards have been applied by subscribe(Subscriber) before this method gets called.

Parameters
s:Subscriber<? super T>

the incoming Subscriber, never null

Annotations
@Override
io.reactivex.internal.operators.flowable back to summary

pack-priv final Class FlowablePublish.FlowablePublisher<T>

extends Object
implements Publisher<T>
Class Inheritance
  • java.lang.Object
  • io.reactivex.internal.operators.flowable.FlowablePublish.FlowablePublisher
All Implemented Interfaces
org.reactivestreams.Publisher

Field Summary

Modifier and TypeField and Description
private final int
private final AtomicReference<FlowablePublish.PublishSubscriber<T>>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
subscribe(Subscriber<? super T>
the Subscriber that will consume signals from this Publisher
child
)

Implements org.reactivestreams.Publisher.subscribe.

Request Publisher to start streaming data.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bufferSizeback to summary
private final int bufferSize
currback to summary
private final AtomicReference<FlowablePublish.PublishSubscriber<T>> curr

Constructor Detail

FlowablePublisherback to summary
pack-priv FlowablePublisher(AtomicReference<FlowablePublish.PublishSubscriber<T>> curr, int bufferSize)

Method Detail

subscribeback to summary
public void subscribe(Subscriber<? super T> child)

Implements org.reactivestreams.Publisher.subscribe.

Doc from org.reactivestreams.Publisher.subscribe.

Request Publisher to start streaming data.

This is a "factory method" and can be called multiple times, each time starting a new Subscription.

Each Subscription will work for only a single Subscriber.

A Subscriber should only subscribe once to a single Publisher.

If the Publisher rejects the subscription attempt or otherwise fails it will signal the error via Subscriber#onError(Throwable).

Parameters
child:Subscriber<? super T>

the Subscriber that will consume signals from this Publisher

Annotations
@Override
io.reactivex.internal.operators.flowable back to summary

pack-priv final Class FlowablePublish.InnerSubscriber<T>

extends AtomicLong
implements Subscription
Class Inheritance
All Implemented Interfaces
org.reactivestreams.Subscription
Type Parameters
<T>
the value type

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

Field Summary

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

The actual child subscriber.

pack-priv long
emitted

Track the number of emitted items (avoids decrementing the request counter).

pack-priv volatile FlowablePublish.PublishSubscriber<T>
parent

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

private static final long

Constructor Summary

AccessConstructor and Description
pack-priv
InnerSubscriber(Subscriber<? super T> child)

Method Summary

Modifier and TypeMethod and Description
public void
cancel()

Implements org.reactivestreams.Subscription.cancel.

Request the Publisher to stop sending data and clean up resources.
public void
request(long
the strictly positive number of elements to requests to the upstream Publisher
n
)

Implements org.reactivestreams.Subscription.request.

No events will be sent by a Publisher until demand is signaled via this method.
Inherited from java.util.concurrent.atomic.AtomicLong:
accumulateAndGetaddAndGetcompareAndExchangecompareAndExchangeAcquirecompareAndExchangeReleasecompareAndSetdecrementAndGetdoubleValuefloatValuegetgetAcquiregetAndAccumulategetAndAddgetAndDecrementgetAndIncrementgetAndSetgetAndUpdategetOpaquegetPlainincrementAndGetintValuelazySetlongValuesetsetOpaquesetPlainsetReleasetoStringupdateAndGetweakCompareAndSetweakCompareAndSetAcquireweakCompareAndSetPlainweakCompareAndSetReleaseweakCompareAndSetVolatile

Field Detail

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

The actual child subscriber.

emittedback to summary
pack-priv long emitted

Track the number of emitted items (avoids decrementing the request counter).

parentback to summary
pack-priv volatile FlowablePublish.PublishSubscriber<T> parent

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

serialVersionUIDback to summary
private static final long serialVersionUID

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

Constructor Detail

InnerSubscriberback to summary
pack-priv InnerSubscriber(Subscriber<? super T> child)

Method Detail

cancelback to summary
public void cancel()

Implements org.reactivestreams.Subscription.cancel.

Doc from org.reactivestreams.Subscription.cancel.

Request the Publisher to stop sending data and clean up resources.

Data may still be sent to meet previously signalled demand after calling cancel.

Annotations
@Override
requestback to summary
public void request(long n)

Implements org.reactivestreams.Subscription.request.

Doc from org.reactivestreams.Subscription.request.

No events will be sent by a Publisher until demand is signaled via this method.

It can be called however often and whenever needed—but if the outstanding cumulative demand ever becomes Long.MAX_VALUE or more, it may be treated by the Publisher as "effectively unbounded".

Whatever has been requested can be sent by the Publisher so only signal demand for what can be safely handled.

A Publisher can send less than is requested if the stream ends but then must emit either Subscriber#onError(Throwable) or Subscriber#onComplete().

Parameters
n:long

the strictly positive number of elements to requests to the upstream Publisher

Annotations
@Override
io.reactivex.internal.operators.flowable back to summary

pack-priv final Class FlowablePublish.PublishSubscriber<T>

extends AtomicInteger
implements FlowableSubscriber<T>, Disposable
Class Inheritance
All Implemented Interfaces
io.reactivex.disposables.Disposable, io.reactivex.FlowableSubscriber, org.reactivestreams.Subscriber
Annotations
@SuppressWarnings:rawtypes

Field Summary

Modifier and TypeField and Description
pack-priv final int
bufferSize

The prefetch buffer size.

pack-priv final AtomicReference<FlowablePublish.PublishSubscriber<T>>
current

Holds onto the current connected PublishSubscriber.

pack-priv static final FlowablePublish.InnerSubscriber<T>[]
EMPTY

Indicates an empty array of inner subscribers.

pack-priv volatile SimpleQueue<T>
queue

Holds notifications from upstream.

private static final long
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 int
pack-priv final AtomicReference<FlowablePublish.InnerSubscriber<T>[]>
subscribers

Tracks the subscribed InnerSubscribers.

pack-priv volatile Object
terminalEvent

Contains either an onComplete or an onError token from upstream.

pack-priv static final FlowablePublish.InnerSubscriber<T>[]
TERMINATED

Indicates a terminated PublishSubscriber.

pack-priv final AtomicReference<Subscription>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv boolean

Returns:

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

Atomically try adding a new InnerSubscriber 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.

public void
dispose()

Implements io.reactivex.disposables.Disposable.dispose.

Dispose the resource, the operation should be idempotent.
public boolean
isDisposed()

Implements io.reactivex.disposables.Disposable.isDisposed.

Returns true if this resource has been disposed.
public void
onComplete()

Implements org.reactivestreams.Subscriber.onComplete.

Successful terminal state.
public void
onError(Throwable
the throwable signaled
e
)

Implements org.reactivestreams.Subscriber.onError.

Failed terminal state.
public void
onNext(T
the element signaled
t
)

Implements org.reactivestreams.Subscriber.onNext.

Data notification sent by the Publisher in response to requests to Subscription#request(long).
public void
onSubscribe(Subscription
the Subscription that allows requesting data via Subscription#request(long)
s
)

Implements io.reactivex.FlowableSubscriber.onSubscribe.

Implementors of this method should make sure everything that needs to be visible in onNext(Object) is established before calling Subscription#request(long).
pack-priv void
remove(FlowablePublish.InnerSubscriber<T>
the producer to remove
producer
)

Atomically removes the given InnerSubscriber from the subscribers array.

Inherited from java.util.concurrent.atomic.AtomicInteger:
accumulateAndGetaddAndGetcompareAndExchangecompareAndExchangeAcquirecompareAndExchangeReleasecompareAndSetdecrementAndGetdoubleValuefloatValuegetgetAcquiregetAndAccumulategetAndAddgetAndDecrementgetAndIncrementgetAndSetgetAndUpdategetOpaquegetPlainincrementAndGetintValuelazySetlongValuesetsetOpaquesetPlainsetReleasetoStringupdateAndGetweakCompareAndSetweakCompareAndSetAcquireweakCompareAndSetPlainweakCompareAndSetReleaseweakCompareAndSetVolatile

Field Detail

bufferSizeback to summary
pack-priv final int bufferSize

The prefetch buffer size.

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

Holds onto the current connected PublishSubscriber.

EMPTYback to summary
pack-priv static final FlowablePublish.InnerSubscriber<T>[] EMPTY

Indicates an empty array of inner subscribers.

queueback to summary
pack-priv volatile SimpleQueue<T> queue

Holds notifications from upstream.

serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.util.concurrent.atomic.AtomicInteger.serialVersionUID.

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.

sourceModeback to summary
pack-priv int sourceMode
subscribersback to summary
pack-priv final AtomicReference<FlowablePublish.InnerSubscriber<T>[]> subscribers

Tracks the subscribed InnerSubscribers.

terminalEventback to summary
pack-priv volatile Object terminalEvent

Contains either an onComplete or an onError token from upstream.

TERMINATEDback to summary
pack-priv static final FlowablePublish.InnerSubscriber<T>[] TERMINATED

Indicates a terminated PublishSubscriber.

upstreamback to summary
pack-priv final AtomicReference<Subscription> upstream

Constructor Detail

PublishSubscriberback to summary
pack-priv PublishSubscriber(AtomicReference<FlowablePublish.PublishSubscriber<T>> current, int bufferSize)
Annotations
@SuppressWarnings:unchecked

Method Detail

addback to summary
pack-priv boolean add(FlowablePublish.InnerSubscriber<T> producer)

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

Parameters
producer:FlowablePublish.InnerSubscriber<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

Annotations
@SuppressWarnings:unchecked
dispatchback to summary
pack-priv void dispatch()

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

disposeback to summary
public void dispose()

Implements io.reactivex.disposables.Disposable.dispose.

Doc from io.reactivex.disposables.Disposable.dispose.

Dispose the resource, the operation should be idempotent.

Annotations
@Override
isDisposedback to summary
public boolean isDisposed()

Implements io.reactivex.disposables.Disposable.isDisposed.

Doc from io.reactivex.disposables.Disposable.isDisposed.

Returns true if this resource has been disposed.

Returns:boolean

true if this resource has been disposed

Annotations
@Override
onCompleteback to summary
public void onComplete()

Implements org.reactivestreams.Subscriber.onComplete.

Doc from org.reactivestreams.Subscriber.onComplete.

Successful terminal state.

No further events will be sent even if Subscription#request(long) is invoked again.

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

Implements org.reactivestreams.Subscriber.onError.

Doc from org.reactivestreams.Subscriber.onError.

Failed terminal state.

No further events will be sent even if Subscription#request(long) is invoked again.

Parameters
e:Throwable

the throwable signaled

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

Implements org.reactivestreams.Subscriber.onNext.

Doc from org.reactivestreams.Subscriber.onNext.

Data notification sent by the Publisher in response to requests to Subscription#request(long).

Parameters
t:T

the element signaled

Annotations
@Override
onSubscribeback to summary
public void onSubscribe(Subscription s)

Implements io.reactivex.FlowableSubscriber.onSubscribe.

Doc from io.reactivex.FlowableSubscriber.onSubscribe.

Implementors of this method should make sure everything that needs to be visible in onNext(Object) is established before calling Subscription#request(long). In practice this means no initialization should happen after the request() call and additional behavior is thread safe in respect to onNext. Invoked after calling Publisher#subscribe(Subscriber).

No data will start flowing until Subscription#request(long) is invoked.

It is the responsibility of this Subscriber instance to call Subscription#request(long) whenever more data is wanted.

The Publisher will send notifications only in response to Subscription#request(long).

Parameters
s:Subscription

Doc from org.reactivestreams.Subscriber.onSubscribe.

the Subscription that allows requesting data via Subscription#request(long)

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

Atomically removes the given InnerSubscriber from the subscribers array.

Parameters
producer:FlowablePublish.InnerSubscriber<T>

the producer to remove

Annotations
@SuppressWarnings:unchecked