Top Description Fields Constructors Methods
io.reactivex.internal.subscriptions

public Class DeferredScalarSubscription<T>

extends BasicIntQueueSubscription<T>
Class Inheritance
Known Direct Subclasses
io.reactivex.processors.AsyncProcessor.AsyncSubscription, io.reactivex.internal.operators.flowable.FlowableAll.AllSubscriber, io.reactivex.internal.operators.flowable.FlowableAny.AnySubscriber, io.reactivex.internal.operators.flowable.FlowableCollect.CollectSubscriber, io.reactivex.internal.operators.flowable.FlowableSequenceEqual.EqualCoordinator, io.reactivex.internal.operators.flowable.FlowableSingle.SingleElementSubscriber, io.reactivex.internal.operators.flowable.FlowableTakeLastOne.TakeLastOneSubscriber, io.reactivex.internal.operators.flowable.FlowableElementAt.ElementAtSubscriber, io.reactivex.internal.operators.flowable.FlowableCount.CountSubscriber, io.reactivex.internal.operators.flowable.FlowableToList.ToListSubscriber, io.reactivex.internal.operators.flowable.FlowableReduce.ReduceSubscriber, io.reactivex.internal.operators.maybe.MaybeToFlowable.MaybeToFlowableSubscriber, io.reactivex.internal.operators.parallel.ParallelReduceFull.ParallelReduceFullMainSubscriber, io.reactivex.internal.operators.single.SingleToFlowable.SingleToFlowableObserver, io.reactivex.internal.subscribers.DeferredScalarSubscriber
Type Parameters
<T>
the value type
Imports
io.reactivex.annotations.Nullable, org.reactivestreams.Subscriber

A subscription that signals a single value eventually.

Note that the class leaks all methods of java.util.concurrent.atomic.AtomicLong. Use complete(Object) to signal the single value.

The this atomic integer stores a bit field:
bit 0: indicates that there is a value available
bit 1: indicates that there was a request made
bit 2: indicates there was a cancellation, exclusively set
bit 3: indicates in fusion mode but no value yet, exclusively set
bit 4: indicates in fusion mode and value is available, exclusively set
bit 5: indicates in fusion mode and value has been consumed, exclusively set
Where exclusively set means any other bits are 0 when that bit is set.

Field Summary

Modifier and TypeField and Description
pack-priv static final int
CANCELLED

Indicates the Subscription has been cancelled.

protected final Subscriber<? super T>
downstream

The Subscriber to emit the value to.

pack-priv static final int
FUSED_CONSUMED

Indicates this Subscription is in fusion mode and its value has been consumed.

pack-priv static final int
FUSED_EMPTY

Indicates this Subscription is in fusion mode and is currently empty.

pack-priv static final int
FUSED_READY

Indicates this Subscription is in fusion mode and has a value.

pack-priv static final int
HAS_REQUEST_HAS_VALUE

Indicates this Subscription has both request and value.

pack-priv static final int
HAS_REQUEST_NO_VALUE

Indicates this Subscription has been requested but there is no value yet.

pack-priv static final int
NO_REQUEST_HAS_VALUE

Indicates this Subscription has a value but not requested yet.

pack-priv static final int
NO_REQUEST_NO_VALUE

Indicates this Subscription has no value and not requested yet.

private static final long
protected T
value

Hides java.util.concurrent.atomic.AtomicInteger.value.

The value is stored here if there is no request yet or in fusion mode.

Constructor Summary

AccessConstructor and Description
public
DeferredScalarSubscription(Subscriber<? super T>
the Subscriber to wrap, not null (not verified)
downstream
)

Creates a DeferredScalarSubscription by wrapping the given Subscriber.

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 final void
clear()

Implements io.reactivex.internal.fuseable.SimpleQueue.clear.

Removes all enqueued items from this queue.
public final void
complete(T
the value to signal, not null (not validated)
v
)

Completes this subscription by indicating the given value should be emitted when the first request arrives.

public final boolean

Returns:

true if this Subscription has been cancelled
isCancelled
()

Returns true if this Subscription has been cancelled.

public final boolean
isEmpty()

Implements io.reactivex.internal.fuseable.SimpleQueue.isEmpty.

Returns true if the queue is empty.
public final T
poll()

Implements io.reactivex.internal.fuseable.SimpleQueue.poll.

Tries to dequeue a value (non-null) or returns null if the queue is empty.
public final 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.
public final int
requestFusion(int
the requested fusion mode, allowed values are SYNC, ASYNC, ANY combined with BOUNDARY (e.g., requestFusion(SYNC | BOUNDARY)).
mode
)

Implements io.reactivex.internal.fuseable.QueueFuseable.requestFusion.

Request a fusion mode from the upstream.
public final boolean

Returns:

true if the current thread cancelled
tryCancel
()

Atomically sets a cancelled state and returns true if the current thread did it successfully.

Inherited from io.reactivex.internal.subscriptions.BasicIntQueueSubscription:
offeroffer

Field Detail

CANCELLEDback to summary
pack-priv static final int CANCELLED

Indicates the Subscription has been cancelled.

downstreamback to summary
protected final Subscriber<? super T> downstream

The Subscriber to emit the value to.

FUSED_CONSUMEDback to summary
pack-priv static final int FUSED_CONSUMED

Indicates this Subscription is in fusion mode and its value has been consumed.

FUSED_EMPTYback to summary
pack-priv static final int FUSED_EMPTY

Indicates this Subscription is in fusion mode and is currently empty.

FUSED_READYback to summary
pack-priv static final int FUSED_READY

Indicates this Subscription is in fusion mode and has a value.

HAS_REQUEST_HAS_VALUEback to summary
pack-priv static final int HAS_REQUEST_HAS_VALUE

Indicates this Subscription has both request and value.

HAS_REQUEST_NO_VALUEback to summary
pack-priv static final int HAS_REQUEST_NO_VALUE

Indicates this Subscription has been requested but there is no value yet.

NO_REQUEST_HAS_VALUEback to summary
pack-priv static final int NO_REQUEST_HAS_VALUE

Indicates this Subscription has a value but not requested yet.

NO_REQUEST_NO_VALUEback to summary
pack-priv static final int NO_REQUEST_NO_VALUE

Indicates this Subscription has no value and not requested yet.

serialVersionUIDback to summary
private static final long serialVersionUID

Hides io.reactivex.internal.subscriptions.BasicIntQueueSubscription.serialVersionUID.

valueback to summary
protected T value

Hides java.util.concurrent.atomic.AtomicInteger.value.

The value is stored here if there is no request yet or in fusion mode.

Constructor Detail

DeferredScalarSubscriptionback to summary
public DeferredScalarSubscription(Subscriber<? super T> downstream)

Creates a DeferredScalarSubscription by wrapping the given Subscriber.

Parameters
downstream:Subscriber<? super T>

the Subscriber to wrap, not null (not verified)

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
clearback to summary
public final void clear()

Implements io.reactivex.internal.fuseable.SimpleQueue.clear.

Doc from io.reactivex.internal.fuseable.SimpleQueue.clear.

Removes all enqueued items from this queue.

Annotations
@Override
completeback to summary
public final void complete(T v)

Completes this subscription by indicating the given value should be emitted when the first request arrives.

Make sure this is called exactly once.

Parameters
v:T

the value to signal, not null (not validated)

isCancelledback to summary
public final boolean isCancelled()

Returns true if this Subscription has been cancelled.

Returns:boolean

true if this Subscription has been cancelled

isEmptyback to summary
public final boolean isEmpty()

Implements io.reactivex.internal.fuseable.SimpleQueue.isEmpty.

Doc from io.reactivex.internal.fuseable.SimpleQueue.isEmpty.

Returns true if the queue is empty.

Note however that due to potential fused functions in poll() it is possible this method returns false but then poll() returns null because the fused function swallowed the available item(s).

Returns:boolean

true if the queue is empty

Annotations
@Override
pollback to summary
public final T poll()

Implements io.reactivex.internal.fuseable.SimpleQueue.poll.

Doc from io.reactivex.internal.fuseable.SimpleQueue.poll.

Tries to dequeue a value (non-null) or returns null if the queue is empty.

If the producer uses offer(Object, Object) and when polling in pairs, if the first poll() returns a non-null item, the second poll() is guaranteed to return a non-null item as well.

Returns:T

the item or null to indicate an empty queue

Annotations
@Nullable
@Override
requestback to summary
public final 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
requestFusionback to summary
public final int requestFusion(int mode)

Implements io.reactivex.internal.fuseable.QueueFuseable.requestFusion.

Doc from io.reactivex.internal.fuseable.QueueFuseable.requestFusion.

Request a fusion mode from the upstream.

This should be called before onSubscribe returns.

Calling this method multiple times or after onSubscribe finished is not allowed and may result in undefined behavior.

Parameters
mode:int

the requested fusion mode, allowed values are SYNC, ASYNC, ANY combined with BOUNDARY (e.g., requestFusion(SYNC | BOUNDARY)).

Returns:int

the established fusion mode: NONE, SYNC, ASYNC.

Annotations
@Override
tryCancelback to summary
public final boolean tryCancel()

Atomically sets a cancelled state and returns true if the current thread did it successfully.

Returns:boolean

true if the current thread cancelled