Class SubscriberUtils
java.lang.Object
io.servicetalk.concurrent.internal.SubscriberUtils
A set of utilities for common
PublisherSource.Subscriber tasks.-
Method Summary
Modifier and TypeMethodDescriptionstatic booleancheckDuplicateSubscription(PublisherSource.Subscription existing, PublisherSource.Subscription next) Checks for an already existingPublisherSource.Subscriptionand if one is given callsCancellable.cancel()onnextand returnsfalse.static voidDeliver a terminal complete to aCompletableSource.Subscriberthat has not yet hadCompletableSource.Subscriber.onSubscribe(Cancellable)called.static <T> voiddeliverCompleteFromSource(PublisherSource.Subscriber<T> subscriber) Deliver a terminal complete to aPublisherSource.Subscriberthat has not yet hadPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)called.static voiddeliverErrorFromSource(CompletableSource.Subscriber subscriber, Throwable cause) Deliver a terminal error to aCompletableSource.Subscriberthat has not yet hadCompletableSource.Subscriber.onSubscribe(Cancellable)called.static <T> voiddeliverErrorFromSource(PublisherSource.Subscriber<T> subscriber, Throwable cause) Deliver a terminal error to aPublisherSource.Subscriberthat has not yet hadPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)called.static <T> voiddeliverErrorFromSource(SingleSource.Subscriber<T> subscriber, Throwable cause) Deliver a terminal error to aSingleSource.Subscriberthat has not yet hadSingleSource.Subscriber.onSubscribe(Cancellable)called.static <T> voiddeliverSuccessFromSource(SingleSource.Subscriber<T> subscriber, T value) InvokesSingleSource.Subscriber.onSuccess(Object)ignoring an occurred exception if any.static voidhandleExceptionFromOnSubscribe(CompletableSource.Subscriber subscriber, Throwable cause) Handle the case when a call toCompletableSource.Subscriber.onSubscribe(Cancellable)throws from a source.static <T> voidhandleExceptionFromOnSubscribe(PublisherSource.Subscriber<T> subscriber, Throwable cause) Handle the case when a call toPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)throws from a source.static <T> voidhandleExceptionFromOnSubscribe(SingleSource.Subscriber<T> subscriber, Throwable cause) Handle the case when a call toSingleSource.Subscriber.onSubscribe(Cancellable)throws from a source.static booleanisRequestNValid(long n) Returnsfalseif the requested amount of elementsnis not-positive,trueotherwise.static <T> voidlogDuplicateTerminal(PublisherSource.Subscriber<T> subscriber) Log if the ReactiveStreams specification has been violated related to out of orderPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)or duplicate terminal signals.static <T> voidlogDuplicateTerminal(PublisherSource.Subscriber<T> subscriber, Throwable cause) Log if the ReactiveStreams specification has been violated related to out of orderPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)or duplicate terminal signals.static <T> voidlogDuplicateTerminal(SingleSource.Subscriber<T> subscriber) Log if the ReactiveStreams specification has been violated related to out of orderSingleSource.Subscriber.onSubscribe(Cancellable)or duplicate terminal signals.static <T> voidlogDuplicateTerminal(SingleSource.Subscriber<T> subscriber, Throwable cause) Log if the ReactiveStreams specification has been violated related to out of orderSingleSource.Subscriber.onSubscribe(Cancellable)or duplicate terminal signals.static <T> voidlogDuplicateTerminalOnSuccess(SingleSource.Subscriber<T> subscriber, T onSuccess) Log if the ReactiveStreams specification has been violated related to out of orderSingleSource.Subscriber.onSubscribe(Cancellable)or duplicate terminal signals.static IllegalArgumentExceptionnewExceptionForInvalidRequestN(long n) Create a new exception for an invalid amount ofPublisherSource.Subscription.request(long)according to Reactive Streams, Rule 3.9.static RuntimeExceptionCreate a new exception when a subscriber throws when it doesn't return "normally" according to Reactive Streams, Rule 2.13.static voidsafeCancel(Cancellable cancellable) InvokesCancellable.cancel()ignoring any exceptions that are thrown.static voidsafeOnComplete(CompletableSource.Subscriber subscriber) InvokesCompletableSource.Subscriber.onComplete()ignoring an occurred exception if any.static <T> voidsafeOnComplete(PublisherSource.Subscriber<T> subscriber) InvokesPublisherSource.Subscriber.onComplete()ignoring an occurred exception if any.static voidsafeOnError(CompletableSource.Subscriber subscriber, Throwable cause) InvokesCompletableSource.Subscriber.onError(Throwable)ignoring an occurred exception if any.static <T> voidsafeOnError(PublisherSource.Subscriber<T> subscriber, Throwable cause) InvokesPublisherSource.Subscriber.onError(Throwable)ignoring an occurred exception if any.static <T> voidsafeOnError(SingleSource.Subscriber<T> subscriber, Throwable cause) InvokesSingleSource.Subscriber.onError(Throwable)ignoring an occurred exception if any.static <T> voidsafeOnSuccess(SingleSource.Subscriber<T> subscriber, T value) InvokesSingleSource.Subscriber.onSuccess(Object)ignoring an occurred exception if any.
-
Method Details
-
checkDuplicateSubscription
public static boolean checkDuplicateSubscription(@Nullable PublisherSource.Subscription existing, PublisherSource.Subscription next) Checks for an already existingPublisherSource.Subscriptionand if one is given callsCancellable.cancel()onnextand returnsfalse.- Parameters:
existing- the existingPublisherSource.Subscriptionornullif none exists.next- the nextPublisherSource.Subscriptionto use.- Returns:
trueif noPublisherSource.Subscriptionexists,falseotherwise.
-
isRequestNValid
public static boolean isRequestNValid(long n) Returnsfalseif the requested amount of elementsnis not-positive,trueotherwise.- Parameters:
n- the number of elements to request.- Returns:
falseif the requested amount of elementsnis not-positive,trueotherwise.
-
newExceptionForInvalidRequestN
Create a new exception for an invalid amount ofPublisherSource.Subscription.request(long)according to Reactive Streams, Rule 3.9.- Parameters:
n- the invalid request count.- Returns:
- The exception which clarifies the invalid behavior.
-
newExceptionNormalReturn
Create a new exception when a subscriber throws when it doesn't return "normally" according to Reactive Streams, Rule 2.13.- Parameters:
cause- The original cause that was thrown.- Returns:
- The exception which clarifies the invalid behavior.
-
deliverCompleteFromSource
Deliver a terminal complete to aPublisherSource.Subscriberthat has not yet hadPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)called.- Type Parameters:
T- The type ofPublisherSource.Subscriber.- Parameters:
subscriber- ThePublisherSource.Subscriberto terminate.
-
deliverSuccessFromSource
public static <T> void deliverSuccessFromSource(SingleSource.Subscriber<T> subscriber, @Nullable T value) InvokesSingleSource.Subscriber.onSuccess(Object)ignoring an occurred exception if any.- Type Parameters:
T- The type ofSingleSource.Subscriber.- Parameters:
subscriber- TheSingleSource.Subscriberthat may throw an exception fromSingleSource.Subscriber.onSuccess(Object).value- The value to pass toSingleSource.Subscriber.onSuccess(Object).
-
deliverCompleteFromSource
Deliver a terminal complete to aCompletableSource.Subscriberthat has not yet hadCompletableSource.Subscriber.onSubscribe(Cancellable)called.- Parameters:
subscriber- TheCompletableSource.Subscriberto terminate.
-
deliverErrorFromSource
public static <T> void deliverErrorFromSource(PublisherSource.Subscriber<T> subscriber, Throwable cause) Deliver a terminal error to aPublisherSource.Subscriberthat has not yet hadPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)called.- Type Parameters:
T- The type ofPublisherSource.Subscriber.- Parameters:
subscriber- ThePublisherSource.Subscriberto terminate.cause- The terminal event.
-
deliverErrorFromSource
public static <T> void deliverErrorFromSource(SingleSource.Subscriber<T> subscriber, Throwable cause) Deliver a terminal error to aSingleSource.Subscriberthat has not yet hadSingleSource.Subscriber.onSubscribe(Cancellable)called.- Type Parameters:
T- The type ofSingleSource.Subscriber.- Parameters:
subscriber- TheSingleSource.Subscriberto terminate.cause- The terminal event.
-
deliverErrorFromSource
Deliver a terminal error to aCompletableSource.Subscriberthat has not yet hadCompletableSource.Subscriber.onSubscribe(Cancellable)called.- Parameters:
subscriber- TheCompletableSource.Subscriberto terminate.cause- The terminal event.
-
handleExceptionFromOnSubscribe
public static <T> void handleExceptionFromOnSubscribe(PublisherSource.Subscriber<T> subscriber, Throwable cause) Handle the case when a call toPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)throws from a source.- Type Parameters:
T- The type ofPublisherSource.Subscriber.- Parameters:
subscriber- ThePublisherSource.Subscriberthat threw an exception fromPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription).cause- The exception thrown bysubscriber.
-
handleExceptionFromOnSubscribe
public static <T> void handleExceptionFromOnSubscribe(SingleSource.Subscriber<T> subscriber, Throwable cause) Handle the case when a call toSingleSource.Subscriber.onSubscribe(Cancellable)throws from a source.- Type Parameters:
T- The type ofSingleSource.Subscriber.- Parameters:
subscriber- TheSingleSource.Subscriberthat threw an exception fromSingleSource.Subscriber.onSubscribe(Cancellable).cause- The exception thrown bysubscriber.
-
handleExceptionFromOnSubscribe
public static void handleExceptionFromOnSubscribe(CompletableSource.Subscriber subscriber, Throwable cause) Handle the case when a call toCompletableSource.Subscriber.onSubscribe(Cancellable)throws from a source.- Parameters:
subscriber- TheCompletableSource.Subscriberthat threw an exception fromCompletableSource.Subscriber.onSubscribe(Cancellable).cause- The exception thrown bysubscriber.
-
safeOnError
InvokesCompletableSource.Subscriber.onError(Throwable)ignoring an occurred exception if any.- Parameters:
subscriber- TheCompletableSource.Subscriberthat may throw an exception fromCompletableSource.Subscriber.onError(Throwable).cause- The occurredThrowableforCompletableSource.Subscriber.onError(Throwable).
-
safeOnError
InvokesSingleSource.Subscriber.onError(Throwable)ignoring an occurred exception if any.- Type Parameters:
T- The type ofSingleSource.Subscriber.- Parameters:
subscriber- TheSingleSource.Subscriberthat may throw an exception fromSingleSource.Subscriber.onError(Throwable).cause- The occurredThrowableforSingleSource.Subscriber.onError(Throwable).
-
safeOnError
InvokesPublisherSource.Subscriber.onError(Throwable)ignoring an occurred exception if any.- Type Parameters:
T- The type ofPublisherSource.Subscriber.- Parameters:
subscriber- ThePublisherSource.Subscriberthat may throw an exception fromPublisherSource.Subscriber.onError(Throwable).cause- The occurredThrowableforPublisherSource.Subscriber.onError(Throwable).
-
safeOnComplete
InvokesPublisherSource.Subscriber.onComplete()ignoring an occurred exception if any.- Type Parameters:
T- The type ofPublisherSource.Subscriber.- Parameters:
subscriber- ThePublisherSource.Subscriberthat may throw an exception fromPublisherSource.Subscriber.onComplete().
-
safeOnSuccess
InvokesSingleSource.Subscriber.onSuccess(Object)ignoring an occurred exception if any.- Type Parameters:
T- The type ofSingleSource.Subscriber.- Parameters:
subscriber- TheSingleSource.Subscriberthat may throw an exception fromSingleSource.Subscriber.onSuccess(Object).value- The value to pass toSingleSource.Subscriber.onSuccess(Object).
-
safeOnComplete
InvokesCompletableSource.Subscriber.onComplete()ignoring an occurred exception if any.- Parameters:
subscriber- TheCompletableSource.Subscriberthat may throw an exception fromCompletableSource.Subscriber.onComplete().
-
safeCancel
InvokesCancellable.cancel()ignoring any exceptions that are thrown.- Parameters:
cancellable- TheCancellabletocancel.
-
logDuplicateTerminal
Log if the ReactiveStreams specification has been violated related to out of orderPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)or duplicate terminal signals.- Type Parameters:
T- The type ofPublisherSource.Subscriber.- Parameters:
subscriber- ThePublisherSource.Subscriber.
-
logDuplicateTerminal
public static <T> void logDuplicateTerminal(PublisherSource.Subscriber<T> subscriber, Throwable cause) Log if the ReactiveStreams specification has been violated related to out of orderPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)or duplicate terminal signals.- Type Parameters:
T- The type ofPublisherSource.Subscriber.- Parameters:
subscriber- ThePublisherSource.Subscriber.cause- The cause fromPublisherSource.Subscriber.onError(Throwable).
-
logDuplicateTerminal
Log if the ReactiveStreams specification has been violated related to out of orderSingleSource.Subscriber.onSubscribe(Cancellable)or duplicate terminal signals.- Type Parameters:
T- The type ofSingleSource.Subscriber.- Parameters:
subscriber- TheSingleSource.Subscriber.
-
logDuplicateTerminalOnSuccess
public static <T> void logDuplicateTerminalOnSuccess(SingleSource.Subscriber<T> subscriber, @Nullable T onSuccess) Log if the ReactiveStreams specification has been violated related to out of orderSingleSource.Subscriber.onSubscribe(Cancellable)or duplicate terminal signals.- Type Parameters:
T- The type ofSingleSource.Subscriber.- Parameters:
subscriber- TheSingleSource.Subscriber.onSuccess- The signal delivered toSingleSource.Subscriber.onSuccess(Object).
-
logDuplicateTerminal
Log if the ReactiveStreams specification has been violated related to out of orderSingleSource.Subscriber.onSubscribe(Cancellable)or duplicate terminal signals.- Type Parameters:
T- The type ofSingleSource.Subscriber.- Parameters:
subscriber- TheSingleSource.Subscriber.cause- The cause fromSingleSource.Subscriber.onError(Throwable).
-