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

public final Enum SubscriptionHelper

extends Enum<SubscriptionHelper>
implements Subscription
Class Inheritance
All Implemented Interfaces
org.reactivestreams.Subscription
Imports
java.util.Objects, java.util.concurrent.atomic.*, org.reactivestreams.Subscription, io.reactivex.rxjava3.exceptions.ProtocolViolationException, io.reactivex.rxjava3.internal.util.BackpressureHelper, io.reactivex.rxjava3.plugins.RxJavaPlugins

Utility methods to validate Subscriptions in the various onSubscribe calls.

Field Summary

Modifier and TypeField and Description
public static final SubscriptionHelper
CANCELLED

Represents a cancelled Subscription.

Constructor Summary

AccessConstructor and Description
private

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 static boolean

Returns:

true if the swap from the non-cancelled instance to the common cancelled instance happened in the caller's thread (allows further one-time actions).
cancel
(AtomicReference<Subscription>
the target field to dispose the contents of
field
)

Atomically swaps in the common cancelled subscription instance and cancels the previous subscription if any.

public static void
deferredRequest(AtomicReference<Subscription>
the target field that may already contain a Subscription
field
,
AtomicLong
the current requested amount
requested
,
long
the request amount, positive (verified)
n
)

Atomically requests from the Subscription in the field if not null, otherwise accumulates the request amount in the requested field to be requested once the field is set to non-null.

public static boolean

Returns:

true if the Subscription was set the first time
deferredSetOnce
(AtomicReference<Subscription>
the target field for the new Subscription
field
,
AtomicLong
the current requested amount
requested
,
Subscription
the new Subscription, not null (verified)
s
)

Atomically sets the new Subscription on the field and requests any accumulated amount from the requested field.

public static boolean

Returns:

true if the operation succeeded, false if the target field holds the CANCELLED instance.
replace
(AtomicReference<Subscription>
the target field to set the new subscription on
field
,
Subscription
the new subscription
s
)

Atomically sets the subscription on the field but does not cancel the previous subscription.

public static void
reportMoreProduced(long
the overproduction amount
n
)

Reports to the plugin error handler that there were more values produced than requested, which is a sign of internal backpressure handling bug.

public static void
reportSubscriptionSet()

Reports that the subscription is already set to the RxJavaPlugins error handler, which is an indication of a onSubscribe management bug.

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.
public static boolean

Returns:

true if the operation succeeded, false if the target field holds the CANCELLED instance.
set
(AtomicReference<Subscription>
the target field to set the new subscription on
field
,
Subscription
the new subscription
s
)

Atomically sets the subscription on the field and cancels the previous subscription if any.

public static boolean

Returns:

true if the operation succeeded, false if the target field was not null.
setOnce
(AtomicReference<Subscription>
the target field
field
,
Subscription
the new subscription to set
s
)

Atomically sets the subscription on the field if it is still null.

public static boolean

Returns:

true if the operation succeeded, false if the target field was not null.
setOnce
(AtomicReference<Subscription>
the target field
field
,
Subscription
the new subscription to set
s
,
long
the amount to request, positive (not verified)
request
)

Atomically sets the subscription on the field if it is still null and issues a positive request to the given Subscription.

public static boolean

Returns:

true if the validation succeeded
validate
(Subscription
the current Subscription, expected to be null
current
,
Subscription
the next Subscription, expected to be non-null
next
)

Verifies that current is null, next is not null, otherwise signals errors to the RxJavaPlugins and returns false.

public static boolean

Returns:

false if n is non-positive.
validate
(long
the request amount
n
)

Validates that the n is positive.

public static SubscriptionHelper
public static SubscriptionHelper[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

CANCELLEDback to summary
public static final SubscriptionHelper CANCELLED

Represents a cancelled Subscription.

Don't leak this instance!

Constructor Detail

SubscriptionHelperback to summary
private SubscriptionHelper()

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
cancelback to summary
public static boolean cancel(AtomicReference<Subscription> field)

Atomically swaps in the common cancelled subscription instance and cancels the previous subscription if any.

Parameters
field:AtomicReference<Subscription>

the target field to dispose the contents of

Returns:boolean

true if the swap from the non-cancelled instance to the common cancelled instance happened in the caller's thread (allows further one-time actions).

deferredRequestback to summary
public static void deferredRequest(AtomicReference<Subscription> field, AtomicLong requested, long n)

Atomically requests from the Subscription in the field if not null, otherwise accumulates the request amount in the requested field to be requested once the field is set to non-null.

Parameters
field:AtomicReference<Subscription>

the target field that may already contain a Subscription

requested:AtomicLong

the current requested amount

n:long

the request amount, positive (verified)

deferredSetOnceback to summary
public static boolean deferredSetOnce(AtomicReference<Subscription> field, AtomicLong requested, Subscription s)

Atomically sets the new Subscription on the field and requests any accumulated amount from the requested field.

Parameters
field:AtomicReference<Subscription>

the target field for the new Subscription

requested:AtomicLong

the current requested amount

s:Subscription

the new Subscription, not null (verified)

Returns:boolean

true if the Subscription was set the first time

replaceback to summary
public static boolean replace(AtomicReference<Subscription> field, Subscription s)

Atomically sets the subscription on the field but does not cancel the previous subscription.

Parameters
field:AtomicReference<Subscription>

the target field to set the new subscription on

s:Subscription

the new subscription

Returns:boolean

true if the operation succeeded, false if the target field holds the CANCELLED instance.

See Also
set(AtomicReference, Subscription)
reportMoreProducedback to summary
public static void reportMoreProduced(long n)

Reports to the plugin error handler that there were more values produced than requested, which is a sign of internal backpressure handling bug.

Parameters
n:long

the overproduction amount

reportSubscriptionSetback to summary
public static void reportSubscriptionSet()

Reports that the subscription is already set to the RxJavaPlugins error handler, which is an indication of a onSubscribe management bug.

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
setback to summary
public static boolean set(AtomicReference<Subscription> field, Subscription s)

Atomically sets the subscription on the field and cancels the previous subscription if any.

Parameters
field:AtomicReference<Subscription>

the target field to set the new subscription on

s:Subscription

the new subscription

Returns:boolean

true if the operation succeeded, false if the target field holds the CANCELLED instance.

See Also
replace(AtomicReference, Subscription)
setOnceback to summary
public static boolean setOnce(AtomicReference<Subscription> field, Subscription s)

Atomically sets the subscription on the field if it is still null.

If the field is not null and doesn't contain the CANCELLED instance, the reportSubscriptionSet() is called.

Parameters
field:AtomicReference<Subscription>

the target field

s:Subscription

the new subscription to set

Returns:boolean

true if the operation succeeded, false if the target field was not null.

setOnceback to summary
public static boolean setOnce(AtomicReference<Subscription> field, Subscription s, long request)

Atomically sets the subscription on the field if it is still null and issues a positive request to the given Subscription.

If the field is not null and doesn't contain the CANCELLED instance, the reportSubscriptionSet() is called.

Parameters
field:AtomicReference<Subscription>

the target field

s:Subscription

the new subscription to set

request:long

the amount to request, positive (not verified)

Returns:boolean

true if the operation succeeded, false if the target field was not null.

Since
2.1.11
validateback to summary
public static boolean validate(Subscription current, Subscription next)

Verifies that current is null, next is not null, otherwise signals errors to the RxJavaPlugins and returns false.

Parameters
current:Subscription

the current Subscription, expected to be null

next:Subscription

the next Subscription, expected to be non-null

Returns:boolean

true if the validation succeeded

validateback to summary
public static boolean validate(long n)

Validates that the n is positive.

Parameters
n:long

the request amount

Returns:boolean

false if n is non-positive.

valueOfback to summary
public static SubscriptionHelper valueOf(String name)
valuesback to summary
public static SubscriptionHelper[] values()