Class EndConsumerHelper
- java.lang.Object
-
- io.reactivex.rxjava3.internal.util.EndConsumerHelper
-
public final class EndConsumerHelper extends java.lang.Object
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
Constructors Modifier Constructor Description private
EndConsumerHelper()
Utility class.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
composeMessage(java.lang.String consumer)
Builds the error message with the consumer class.static void
reportDoubleSubscription(java.lang.Class<?> consumer)
Report a ProtocolViolationException with a personalized message referencing the simple type name of the consumer class and report it via RxJavaPlugins.onError.static boolean
setOnce(java.util.concurrent.atomic.AtomicReference<Disposable> upstream, Disposable next, java.lang.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.static boolean
setOnce(java.util.concurrent.atomic.AtomicReference<org.reactivestreams.Subscription> upstream, org.reactivestreams.Subscription next, java.lang.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.static boolean
validate(Disposable upstream, Disposable next, java.lang.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.static boolean
validate(org.reactivestreams.Subscription upstream, org.reactivestreams.Subscription next, java.lang.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.
-
-
-
Method Detail
-
validate
public static boolean validate(Disposable upstream, Disposable next, java.lang.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
- the upstream current valuenext
- the Disposable to check for nullness and dispose if necessaryobserver
- the class of the consumer to have a personalized error message if the upstream already contains a non-cancelled Disposable.- Returns:
- true if successful, false if the upstream was non null
-
setOnce
public static boolean setOnce(java.util.concurrent.atomic.AtomicReference<Disposable> upstream, Disposable next, java.lang.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
- the target AtomicReference to updatenext
- the Disposable to set on it atomicallyobserver
- the class of the consumer to have a personalized error message if the upstream already contains a non-cancelled Disposable.- Returns:
- true if successful, false if the content of the AtomicReference was non null
-
validate
public static boolean validate(org.reactivestreams.Subscription upstream, org.reactivestreams.Subscription next, java.lang.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
- the upstream current valuenext
- the Subscription to check for nullness and cancel if necessarysubscriber
- the class of the consumer to have a personalized error message if the upstream already contains a non-cancelled Subscription.- Returns:
- true if successful, false if the upstream was non null
-
setOnce
public static boolean setOnce(java.util.concurrent.atomic.AtomicReference<org.reactivestreams.Subscription> upstream, org.reactivestreams.Subscription next, java.lang.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
- the target AtomicReference to updatenext
- the Subscription to set on it atomicallysubscriber
- the class of the consumer to have a personalized error message if the upstream already contains a non-cancelled Subscription.- Returns:
- true if successful, false if the content of the AtomicReference was non null
-
composeMessage
public static java.lang.String composeMessage(java.lang.String consumer)
Builds the error message with the consumer class.- Parameters:
consumer
- the class of the consumer- Returns:
- the error message string
-
reportDoubleSubscription
public static void reportDoubleSubscription(java.lang.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
- the class of the consumer
-
-