Top Description Constructors Methods
io.reactivex.rxjava3.internal.util

public final Class EndConsumerHelper

extends Object
Class Inheritance
Imports
java.util.Objects, java.util.concurrent.atomic.AtomicReference, org.reactivestreams.Subscription, io.reactivex.rxjava3.disposables.Disposable, io.reactivex.rxjava3.exceptions.ProtocolViolationException, io.reactivex.rxjava3.internal.disposables.DisposableHelper, io.reactivex.rxjava3.internal.subscriptions.SubscriptionHelper, io.reactivex.rxjava3.plugins.RxJavaPlugins

Utility class to help report multiple subscriptions with the same consumer type instead of the internal "Disposable already set!" message that is practically reserved for internal operators and indicate bugs in them.

Constructor Summary

AccessConstructor and Description
private
EndConsumerHelper()

Utility class.

Method Summary

Modifier and TypeMethod and Description
public static String

Returns:

the error message string
composeMessage
(String
the class of the consumer
consumer
)

Builds the error message with the consumer class.

public static void
reportDoubleSubscription(Class<?>
the class of the consumer
consumer
)

Report a ProtocolViolationException with a personalized message referencing the simple type name of the consumer class and report it via RxJavaPlugins.onError.

public static boolean

Returns:

true if successful, false if the content of the AtomicReference was non null
setOnce
(AtomicReference<Disposable>
the target AtomicReference to update
upstream
,
Disposable
the Disposable to set on it atomically
next
,
Class<?>
the class of the consumer to have a personalized error message if the upstream already contains a non-cancelled Disposable.
observer
)

Atomically updates the target upstream AtomicReference from null to the non-null next Disposable, otherwise disposes next and reports a ProtocolViolationException if the AtomicReference doesn't contain the shared disposed indicator.

public static boolean

Returns:

true if successful, false if the content of the AtomicReference was non null
setOnce
(AtomicReference<Subscription>
the target AtomicReference to update
upstream
,
Subscription
the Subscription to set on it atomically
next
,
Class<?>
the class of the consumer to have a personalized error message if the upstream already contains a non-cancelled Subscription.
subscriber
)

Atomically updates the target upstream AtomicReference from null to the non-null next Subscription, otherwise cancels next and reports a ProtocolViolationException if the AtomicReference doesn't contain the shared cancelled indicator.

public static boolean

Returns:

true if successful, false if the upstream was non null
validate
(Disposable
the upstream current value
upstream
,
Disposable
the Disposable to check for nullness and dispose if necessary
next
,
Class<?>
the class of the consumer to have a personalized error message if the upstream already contains a non-cancelled Disposable.
observer
)

Ensures that the upstream Disposable is null and returns true, otherwise disposes the next Disposable and if the upstream is not the shared disposed instance, reports a ProtocolViolationException due to multiple subscribe attempts.

public static boolean

Returns:

true if successful, false if the upstream was non null
validate
(Subscription
the upstream current value
upstream
,
Subscription
the Subscription to check for nullness and cancel if necessary
next
,
Class<?>
the class of the consumer to have a personalized error message if the upstream already contains a non-cancelled Subscription.
subscriber
)

Ensures that the upstream Subscription is null and returns true, otherwise cancels the next Subscription and if the upstream is not the shared cancelled instance, reports a ProtocolViolationException due to multiple subscribe attempts.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

EndConsumerHelperback to summary
private EndConsumerHelper()

Utility class.

Method Detail

composeMessageback to summary
public static String composeMessage(String consumer)

Builds the error message with the consumer class.

Parameters
consumer:String

the class of the consumer

Returns:String

the error message string

reportDoubleSubscriptionback to summary
public static void reportDoubleSubscription(Class<?> consumer)

Report a ProtocolViolationException with a personalized message referencing the simple type name of the consumer class and report it via RxJavaPlugins.onError.

Parameters
consumer:Class<?>

the class of the consumer

setOnceback to summary
public static boolean setOnce(AtomicReference<Disposable> upstream, Disposable next, Class<?> observer)

Atomically updates the target upstream AtomicReference from null to the non-null next Disposable, otherwise disposes next and reports a ProtocolViolationException if the AtomicReference doesn't contain the shared disposed indicator.

Parameters
upstream:AtomicReference<Disposable>

the target AtomicReference to update

next:Disposable

the Disposable to set on it atomically

observer:Class<?>

the class of the consumer to have a personalized error message if the upstream already contains a non-cancelled Disposable.

Returns:boolean

true if successful, false if the content of the AtomicReference was non null

setOnceback to summary
public static boolean setOnce(AtomicReference<Subscription> upstream, Subscription next, Class<?> subscriber)

Atomically updates the target upstream AtomicReference from null to the non-null next Subscription, otherwise cancels next and reports a ProtocolViolationException if the AtomicReference doesn't contain the shared cancelled indicator.

Parameters
upstream:AtomicReference<Subscription>

the target AtomicReference to update

next:Subscription

the Subscription to set on it atomically

subscriber:Class<?>

the class of the consumer to have a personalized error message if the upstream already contains a non-cancelled Subscription.

Returns:boolean

true if successful, false if the content of the AtomicReference was non null

validateback to summary
public static boolean validate(Disposable upstream, Disposable next, Class<?> observer)

Ensures that the upstream Disposable is null and returns true, otherwise disposes the next Disposable and if the upstream is not the shared disposed instance, reports a ProtocolViolationException due to multiple subscribe attempts.

Parameters
upstream:Disposable

the upstream current value

next:Disposable

the Disposable to check for nullness and dispose if necessary

observer:Class<?>

the class of the consumer to have a personalized error message if the upstream already contains a non-cancelled Disposable.

Returns:boolean

true if successful, false if the upstream was non null

validateback to summary
public static boolean validate(Subscription upstream, Subscription next, Class<?> subscriber)

Ensures that the upstream Subscription is null and returns true, otherwise cancels the next Subscription and if the upstream is not the shared cancelled instance, reports a ProtocolViolationException due to multiple subscribe attempts.

Parameters
upstream:Subscription

the upstream current value

next:Subscription

the Subscription to check for nullness and cancel if necessary

subscriber:Class<?>

the class of the consumer to have a personalized error message if the upstream already contains a non-cancelled Subscription.

Returns:boolean

true if successful, false if the upstream was non null