Top Description Inners Fields Constructors Methods
rx.internal.util

public final Class BackpressureDrainManager

extends AtomicLong
implements Producer
Class Inheritance
All Implemented Interfaces
rx.Producer
Imports
java.util.concurrent.atomic.AtomicLong, rx.Producer

Manages the producer-backpressure-consumer interplay by matching up available elements with requested elements and/or terminal events.

History: 1.1.0 - experimental

Since
1.3

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
BackpressureDrainManager.BackpressureQueueCallback

Interface representing the minimal callbacks required to operate the drain part of a backpressure system.

Field Summary

Modifier and TypeField and Description
pack-priv final BackpressureDrainManager.BackpressureQueueCallback
actual

The callbacks to manage the drain.

pack-priv boolean
emitting

Indicates if one is in emitting phase, guarded by this.

pack-priv Throwable
exception

Indicates an error state, barrier is provided via terminated.

private static final long
pack-priv volatile boolean
terminated

Indicates a terminal state.

Constructor Summary

AccessConstructor and Description
public
BackpressureDrainManager(BackpressureDrainManager.BackpressureQueueCallback
he queue callback to check for new element availability
actual
)

Constructs a backpressure drain manager with 0 requestedCount, no terminal event and not emitting.

Method Summary

Modifier and TypeMethod and Description
public void
drain()

Try to drain the "queued" elements and terminal events by considering the available and requested event counts.

public boolean

Returns:

true if a terminal state has been reached
isTerminated
()

Checks if a terminal state has been reached.

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
terminate()

Move into a terminal state.

public void
terminate(Throwable
the exception to deliver
error
)

Move into a terminal state with an exception.

public void
terminateAndDrain()

Move into a terminal state and drain.

public void
terminateAndDrain(Throwable
the exception to deliver
error
)

Move into a terminal state with an exception and drain.

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

Field Detail

actualback to summary
pack-priv final BackpressureDrainManager.BackpressureQueueCallback actual

The callbacks to manage the drain.

emittingback to summary
pack-priv boolean emitting

Indicates if one is in emitting phase, guarded by this.

exceptionback to summary
pack-priv Throwable exception

Indicates an error state, barrier is provided via terminated.

serialVersionUIDback to summary
private static final long serialVersionUID

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

terminatedback to summary
pack-priv volatile boolean terminated

Indicates a terminal state.

Constructor Detail

BackpressureDrainManagerback to summary
public BackpressureDrainManager(BackpressureDrainManager.BackpressureQueueCallback actual)

Constructs a backpressure drain manager with 0 requestedCount, no terminal event and not emitting.

Parameters
actual:BackpressureDrainManager.BackpressureQueueCallback

he queue callback to check for new element availability

Method Detail

drainback to summary
public void drain()

Try to drain the "queued" elements and terminal events by considering the available and requested event counts.

isTerminatedback to summary
public boolean isTerminated()

Checks if a terminal state has been reached.

Returns:boolean

true if a terminal state has been reached

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
terminateback to summary
public void terminate()

Move into a terminal state. Call drain() anytime after.

terminateback to summary
public void terminate(Throwable error)

Move into a terminal state with an exception. Call drain() anytime after.

Serialized access is expected with respect to element emission.

Parameters
error:Throwable

the exception to deliver

terminateAndDrainback to summary
public void terminateAndDrain()

Move into a terminal state and drain.

terminateAndDrainback to summary
public void terminateAndDrain(Throwable error)

Move into a terminal state with an exception and drain.

Serialized access is expected with respect to element emission.

Parameters
error:Throwable

the exception to deliver

rx.internal.util back to summary

public Interface BackpressureDrainManager.BackpressureQueueCallback

Known Direct Implementers
rx.internal.operators.OperatorOnBackpressureBuffer.BufferSubscriber

Interface representing the minimal callbacks required to operate the drain part of a backpressure system.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true indicates that one should terminate the emission loop unconditionally and not deliver any further elements or terminal events.
accept
(Object
the value to deliver, not null
value
)

Override this method to deliver an element to downstream.

public void
complete(Throwable
if not null, contains the terminal exception
exception
)

Override this method to deliver a normal or exceptional terminal event.

public Object

Returns:

the next element or null if no next element available
peek
()

Override this method to peek for the next element, null meaning no next element available now.

public Object

Returns:

the next element or null if no next element available
poll
()

Override this method to poll (consume) the next element, null meaning no next element available now.

Method Detail

acceptback to summary
public boolean accept(Object value)

Override this method to deliver an element to downstream. The logic ensures that this happens only in the right conditions.

Parameters
value:Object

the value to deliver, not null

Returns:boolean

true indicates that one should terminate the emission loop unconditionally and not deliver any further elements or terminal events.

completeback to summary
public void complete(Throwable exception)

Override this method to deliver a normal or exceptional terminal event.

Parameters
exception:Throwable

if not null, contains the terminal exception

peekback to summary
public Object peek()

Override this method to peek for the next element, null meaning no next element available now.

It will be called plain and while holding this object's monitor.

Returns:Object

the next element or null if no next element available

pollback to summary
public Object poll()

Override this method to poll (consume) the next element, null meaning no next element available now.

Returns:Object

the next element or null if no next element available