Top Description Fields Constructors Methods
rx.internal.producers

public final Class QueuedProducer<T>

extends AtomicLong
implements Producer, Observer<T>
Class Inheritance
All Implemented Interfaces
rx.Observer, rx.Producer
Type Parameters
<T>
the value type
Imports
java.util.Queue, java.util.concurrent.atomic.*, rx.*, rx.exceptions.*, rx.internal.operators.BackpressureUtils, rx.internal.util.atomic.SpscLinkedAtomicQueue, rx.internal.util.unsafe.*

Producer that holds an unbounded (or custom) queue, handles terminal events, enqueues values and relays them to a child subscriber on request.

Field Summary

Modifier and TypeField and Description
pack-priv final Subscriber<? super T>
pack-priv volatile boolean
pack-priv Throwable
pack-priv static final Object
pack-priv final Queue<Object>
private static final long
pack-priv final AtomicInteger

Constructor Summary

AccessConstructor and Description
public
QueuedProducer(Subscriber<? super T>
the target child subscriber
child
)

Constructs an instance with the target child subscriber and an Spsc Linked (Atomic) Queue as the queue implementation.

public
QueuedProducer(Subscriber<? super T>
the target child subscriber
child
,
Queue<Object>
the queue to use
queue
)

Constructs an instance with the target child subscriber and a custom queue implementation

Method Summary

Modifier and TypeMethod and Description
private boolean
checkTerminated(boolean isDone, boolean isEmpty)

private void
public boolean

Returns:

true if the queue accepted the offer, false otherwise
offer
(T
the value to enqueue and attempt to drain
value
)

Offers a value to this producer and tries to emit any queued values if the child requests allow it.

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
value
)

Implements rx.Observer.onNext.

Provides the Observer with a new item to observe.
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.
Inherited from java.util.concurrent.atomic.AtomicLong:
accumulateAndGetaddAndGetcompareAndExchangecompareAndExchangeAcquirecompareAndExchangeReleasecompareAndSetdecrementAndGetdoubleValuefloatValuegetgetAcquiregetAndAccumulategetAndAddgetAndDecrementgetAndIncrementgetAndSetgetAndUpdategetOpaquegetPlainincrementAndGetintValuelazySetlongValuesetsetOpaquesetPlainsetReleasetoStringupdateAndGetweakCompareAndSetweakCompareAndSetAcquireweakCompareAndSetPlainweakCompareAndSetReleaseweakCompareAndSetVolatile

Field Detail

childback to summary
pack-priv final Subscriber<? super T> child
doneback to summary
pack-priv volatile boolean done
errorback to summary
pack-priv Throwable error
NULL_SENTINELback to summary
pack-priv static final Object NULL_SENTINEL
queueback to summary
pack-priv final Queue<Object> queue
serialVersionUIDback to summary
private static final long serialVersionUID

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

wipback to summary
pack-priv final AtomicInteger wip

Constructor Detail

QueuedProducerback to summary
public QueuedProducer(Subscriber<? super T> child)

Constructs an instance with the target child subscriber and an Spsc Linked (Atomic) Queue as the queue implementation.

Parameters
child:Subscriber<? super T>

the target child subscriber

QueuedProducerback to summary
public QueuedProducer(Subscriber<? super T> child, Queue<Object> queue)

Constructs an instance with the target child subscriber and a custom queue implementation

Parameters
child:Subscriber<? super T>

the target child subscriber

queue:Queue<Object>

the queue to use

Method Detail

checkTerminatedback to summary
private boolean checkTerminated(boolean isDone, boolean isEmpty)
drainback to summary
private void drain()
offerback to summary
public boolean offer(T value)

Offers a value to this producer and tries to emit any queued values if the child requests allow it.

Parameters
value:T

the value to enqueue and attempt to drain

Returns:boolean

true if the queue accepted the offer, false otherwise

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 value)

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
value:T

the item emitted by the Observable

Annotations
@Override
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