Class SubscriberUtils
java.lang.Object
io.servicetalk.concurrent.internal.SubscriberUtils
A set of utilities for common
PublisherSource.Subscriber
tasks.-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
checkDuplicateSubscription
(PublisherSource.Subscription existing, PublisherSource.Subscription next) Checks for an already existingPublisherSource.Subscription
and if one is given callsCancellable.cancel()
onnext
and returnsfalse
.static void
Deliver a terminal complete to aCompletableSource.Subscriber
that has not yet hadCompletableSource.Subscriber.onSubscribe(Cancellable)
called.static <T> void
deliverCompleteFromSource
(PublisherSource.Subscriber<T> subscriber) Deliver a terminal complete to aPublisherSource.Subscriber
that has not yet hadPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
called.static void
deliverErrorFromSource
(CompletableSource.Subscriber subscriber, Throwable cause) Deliver a terminal error to aCompletableSource.Subscriber
that has not yet hadCompletableSource.Subscriber.onSubscribe(Cancellable)
called.static <T> void
deliverErrorFromSource
(PublisherSource.Subscriber<T> subscriber, Throwable cause) Deliver a terminal error to aPublisherSource.Subscriber
that has not yet hadPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
called.static <T> void
deliverErrorFromSource
(SingleSource.Subscriber<T> subscriber, Throwable cause) Deliver a terminal error to aSingleSource.Subscriber
that has not yet hadSingleSource.Subscriber.onSubscribe(Cancellable)
called.static <T> void
deliverSuccessFromSource
(SingleSource.Subscriber<T> subscriber, T value) InvokesSingleSource.Subscriber.onSuccess(Object)
ignoring an occurred exception if any.static void
handleExceptionFromOnSubscribe
(CompletableSource.Subscriber subscriber, Throwable cause) Handle the case when a call toCompletableSource.Subscriber.onSubscribe(Cancellable)
throws from a source.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.static <T> void
handleExceptionFromOnSubscribe
(SingleSource.Subscriber<T> subscriber, Throwable cause) Handle the case when a call toSingleSource.Subscriber.onSubscribe(Cancellable)
throws from a source.static boolean
isRequestNValid
(long n) Returnsfalse
if the requested amount of elementsn
is not-positive,true
otherwise.static <T> void
logDuplicateTerminal
(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> 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.static <T> void
logDuplicateTerminal
(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> void
logDuplicateTerminal
(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> void
logDuplicateTerminalOnSuccess
(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 IllegalArgumentException
newExceptionForInvalidRequestN
(long n) Create a new exception for an invalid amount ofPublisherSource.Subscription.request(long)
according to Reactive Streams, Rule 3.9.static RuntimeException
Create a new exception when a subscriber throws when it doesn't return "normally" according to Reactive Streams, Rule 2.13.static void
safeCancel
(Cancellable cancellable) InvokesCancellable.cancel()
ignoring any exceptions that are thrown.static void
safeOnComplete
(CompletableSource.Subscriber subscriber) InvokesCompletableSource.Subscriber.onComplete()
ignoring an occurred exception if any.static <T> void
safeOnComplete
(PublisherSource.Subscriber<T> subscriber) InvokesPublisherSource.Subscriber.onComplete()
ignoring an occurred exception if any.static void
safeOnError
(CompletableSource.Subscriber subscriber, Throwable cause) InvokesCompletableSource.Subscriber.onError(Throwable)
ignoring an occurred exception if any.static <T> void
safeOnError
(PublisherSource.Subscriber<T> subscriber, Throwable cause) InvokesPublisherSource.Subscriber.onError(Throwable)
ignoring an occurred exception if any.static <T> void
safeOnError
(SingleSource.Subscriber<T> subscriber, Throwable cause) InvokesSingleSource.Subscriber.onError(Throwable)
ignoring an occurred exception if any.static <T> void
safeOnSuccess
(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.Subscription
and if one is given callsCancellable.cancel()
onnext
and returnsfalse
.- Parameters:
existing
- the existingPublisherSource.Subscription
ornull
if none exists.next
- the nextPublisherSource.Subscription
to use.- Returns:
true
if noPublisherSource.Subscription
exists,false
otherwise.
-
isRequestNValid
public static boolean isRequestNValid(long n) Returnsfalse
if the requested amount of elementsn
is not-positive,true
otherwise.- Parameters:
n
- the number of elements to request.- Returns:
false
if the requested amount of elementsn
is not-positive,true
otherwise.
-
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.Subscriber
that has not yet hadPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
called.- Type Parameters:
T
- The type ofPublisherSource.Subscriber
.- Parameters:
subscriber
- ThePublisherSource.Subscriber
to 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.Subscriber
that may throw an exception fromSingleSource.Subscriber.onSuccess(Object)
.value
- The value to pass toSingleSource.Subscriber.onSuccess(Object)
.
-
deliverCompleteFromSource
Deliver a terminal complete to aCompletableSource.Subscriber
that has not yet hadCompletableSource.Subscriber.onSubscribe(Cancellable)
called.- Parameters:
subscriber
- TheCompletableSource.Subscriber
to terminate.
-
deliverErrorFromSource
public static <T> void deliverErrorFromSource(PublisherSource.Subscriber<T> subscriber, Throwable cause) Deliver a terminal error to aPublisherSource.Subscriber
that has not yet hadPublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription)
called.- Type Parameters:
T
- The type ofPublisherSource.Subscriber
.- Parameters:
subscriber
- ThePublisherSource.Subscriber
to terminate.cause
- The terminal event.
-
deliverErrorFromSource
public static <T> void deliverErrorFromSource(SingleSource.Subscriber<T> subscriber, Throwable cause) Deliver a terminal error to aSingleSource.Subscriber
that has not yet hadSingleSource.Subscriber.onSubscribe(Cancellable)
called.- Type Parameters:
T
- The type ofSingleSource.Subscriber
.- Parameters:
subscriber
- TheSingleSource.Subscriber
to terminate.cause
- The terminal event.
-
deliverErrorFromSource
Deliver a terminal error to aCompletableSource.Subscriber
that has not yet hadCompletableSource.Subscriber.onSubscribe(Cancellable)
called.- Parameters:
subscriber
- TheCompletableSource.Subscriber
to 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.Subscriber
that 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.Subscriber
that 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.Subscriber
that 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.Subscriber
that may throw an exception fromCompletableSource.Subscriber.onError(Throwable)
.cause
- The occurredThrowable
forCompletableSource.Subscriber.onError(Throwable)
.
-
safeOnError
InvokesSingleSource.Subscriber.onError(Throwable)
ignoring an occurred exception if any.- Type Parameters:
T
- The type ofSingleSource.Subscriber
.- Parameters:
subscriber
- TheSingleSource.Subscriber
that may throw an exception fromSingleSource.Subscriber.onError(Throwable)
.cause
- The occurredThrowable
forSingleSource.Subscriber.onError(Throwable)
.
-
safeOnError
InvokesPublisherSource.Subscriber.onError(Throwable)
ignoring an occurred exception if any.- Type Parameters:
T
- The type ofPublisherSource.Subscriber
.- Parameters:
subscriber
- ThePublisherSource.Subscriber
that may throw an exception fromPublisherSource.Subscriber.onError(Throwable)
.cause
- The occurredThrowable
forPublisherSource.Subscriber.onError(Throwable)
.
-
safeOnComplete
InvokesPublisherSource.Subscriber.onComplete()
ignoring an occurred exception if any.- Type Parameters:
T
- The type ofPublisherSource.Subscriber
.- Parameters:
subscriber
- ThePublisherSource.Subscriber
that 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.Subscriber
that 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.Subscriber
that may throw an exception fromCompletableSource.Subscriber.onComplete()
.
-
safeCancel
InvokesCancellable.cancel()
ignoring any exceptions that are thrown.- Parameters:
cancellable
- TheCancellable
tocancel
.
-
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)
.
-