public final class SubscriberUtils
extends java.lang.Object
PublisherSource.Subscriber tasks.| Modifier and Type | Method and Description |
|---|---|
static <T> int |
calculateSourceRequested(java.util.concurrent.atomic.AtomicLongFieldUpdater<T> requestNUpdater,
java.util.concurrent.atomic.AtomicLongFieldUpdater<T> sourceRequestedUpdater,
java.util.concurrent.atomic.AtomicLongFieldUpdater<T> emittedUpdater,
int limit,
T owner)
Attempts to increment
sourceRequestedUpdater in order to make it the same as requestNUpdater
while not exceeding the limit. |
static boolean |
checkDuplicateSubscription(PublisherSource.Subscription existing,
PublisherSource.Subscription next)
Checks for an already existing
PublisherSource.Subscription and if one is given calls Cancellable.cancel() on
next and returns false. |
static void |
deliverTerminalFromSource(CompletableSource.Subscriber subscriber,
java.lang.Throwable cause)
Deliver a terminal error to a
CompletableSource.Subscriber that has not yet had
CompletableSource.Subscriber#onSubscribe(Cancellable) called. |
static <T> void |
deliverTerminalFromSource(PublisherSource.Subscriber<T> subscriber)
Deliver a terminal complete to a
PublisherSource.Subscriber that has not yet had
PublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription) called. |
static <T> void |
deliverTerminalFromSource(PublisherSource.Subscriber<T> subscriber,
java.lang.Throwable cause)
Deliver a terminal error to a
PublisherSource.Subscriber that has not yet had
PublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription) called. |
static <T> void |
deliverTerminalFromSource(SingleSource.Subscriber<T> subscriber,
java.lang.Throwable cause)
Deliver a terminal error to a
SingleSource.Subscriber that has not yet had
SingleSource.Subscriber#onSubscribe(Cancellable) called. |
static void |
handleExceptionFromOnSubscribe(CompletableSource.Subscriber subscriber,
java.lang.Throwable cause)
Handle the case when a call to
CompletableSource.Subscriber#onSubscribe(Cancellable) throws from a
source. |
static <T> void |
handleExceptionFromOnSubscribe(PublisherSource.Subscriber<T> subscriber,
java.lang.Throwable cause)
Handle the case when a call to
PublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription) throws from a source. |
static <T> void |
handleExceptionFromOnSubscribe(SingleSource.Subscriber<T> subscriber,
java.lang.Throwable cause)
Handle the case when a call to
SingleSource.Subscriber#onSubscribe(Cancellable) throws from a source. |
static boolean |
isRequestNValid(long n)
Returns
false if the requested amount of elements n is not-positive, true otherwise. |
static java.lang.IllegalArgumentException |
newExceptionForInvalidRequestN(long n)
Create a new exception for an invalid amount of
PublisherSource.Subscription.request(long) according to
Reactive Streams,
Rule 3.9. |
static <T> void |
safeOnError(SingleSource.Subscriber<T> subscriber,
java.lang.Throwable cause)
Invokes
SingleSource.Subscriber#onError(Throwable) ignoring an occurred exception if any. |
static <R> boolean |
trySetTerminal(TerminalNotification toSet,
boolean overrideComplete,
java.util.concurrent.atomic.AtomicReferenceFieldUpdater<R,TerminalNotification> terminalNotificationUpdater,
R flagOwner)
There are some scenarios where a completion
TerminalNotification can be overridden with an error if
errors are produced asynchronously. |
public static boolean checkDuplicateSubscription(@Nullable
PublisherSource.Subscription existing,
PublisherSource.Subscription next)
PublisherSource.Subscription and if one is given calls Cancellable.cancel() on
next and returns false.existing - the existing PublisherSource.Subscription or null if none exists.next - the next PublisherSource.Subscription to use.true if no PublisherSource.Subscription exists, false otherwise.public static boolean isRequestNValid(long n)
false if the requested amount of elements n is not-positive, true otherwise.n - the number of elements to request.false if the requested amount of elements n is not-positive, true otherwise.public static java.lang.IllegalArgumentException newExceptionForInvalidRequestN(long n)
PublisherSource.Subscription.request(long) according to
Reactive Streams,
Rule 3.9.n - the invalid request count.public static <T> int calculateSourceRequested(java.util.concurrent.atomic.AtomicLongFieldUpdater<T> requestNUpdater,
java.util.concurrent.atomic.AtomicLongFieldUpdater<T> sourceRequestedUpdater,
java.util.concurrent.atomic.AtomicLongFieldUpdater<T> emittedUpdater,
int limit,
T owner)
sourceRequestedUpdater in order to make it the same as requestNUpdater
while not exceeding the limit.T - The type of object which owns the atomic updater parameters.requestNUpdater - The total number which has been requested (typically from
PublisherSource.Subscription.request(long)).sourceRequestedUpdater - The total number which has actually been passed to
PublisherSource.Subscription.request(long). This outstanding count
sourceRequestedUpdater() - emittedUpdater.get() should never exceed limit.emittedUpdater - The amount of data that has been emitted/delivered by the source.limit - The maximum outstanding demand from the source at any given time.owner - The object which all atomic updater parameters are associated with.sourceRequestedUpdater was increased by. This value is typically used to call
PublisherSource.Subscription.request(long).public static <R> boolean trySetTerminal(TerminalNotification toSet, boolean overrideComplete, java.util.concurrent.atomic.AtomicReferenceFieldUpdater<R,TerminalNotification> terminalNotificationUpdater, R flagOwner)
TerminalNotification can be overridden with an error if
errors are produced asynchronously.
This method helps set TerminalNotification atomically providing such an override.
R - Type of flagOwner.toSet - TerminalNotification to set.overrideComplete - Whether exisiting TerminalNotification.complete() should be overridden with the
toSet.terminalNotificationUpdater - AtomicReferenceFieldUpdater to access the current
TerminalNotification.flagOwner - instance of R that owns the current TerminalNotification field referenced by
terminalNotificationUpdater.true if toSet is updated as the current TerminalNotification.public static <T> void deliverTerminalFromSource(PublisherSource.Subscriber<T> subscriber, java.lang.Throwable cause)
PublisherSource.Subscriber that has not yet had
PublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription) called.T - The type of PublisherSource.Subscriber.subscriber - The PublisherSource.Subscriber to terminate.cause - The terminal event.public static <T> void deliverTerminalFromSource(PublisherSource.Subscriber<T> subscriber)
PublisherSource.Subscriber that has not yet had
PublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription) called.T - The type of PublisherSource.Subscriber.subscriber - The PublisherSource.Subscriber to terminate.public static <T> void deliverTerminalFromSource(SingleSource.Subscriber<T> subscriber, java.lang.Throwable cause)
SingleSource.Subscriber that has not yet had
SingleSource.Subscriber#onSubscribe(Cancellable) called.T - The type of SingleSource.Subscriber.subscriber - The SingleSource.Subscriber to terminate.cause - The terminal event.public static void deliverTerminalFromSource(CompletableSource.Subscriber subscriber, java.lang.Throwable cause)
CompletableSource.Subscriber that has not yet had
CompletableSource.Subscriber#onSubscribe(Cancellable) called.subscriber - The CompletableSource.Subscriber to terminate.cause - The terminal event.public static <T> void handleExceptionFromOnSubscribe(PublisherSource.Subscriber<T> subscriber, java.lang.Throwable cause)
PublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription) throws from a source.T - The type of PublisherSource.Subscriber.subscriber - The PublisherSource.Subscriber that threw an exception from
PublisherSource.Subscriber.onSubscribe(PublisherSource.Subscription).cause - The exception thrown by subscriber.public static <T> void handleExceptionFromOnSubscribe(SingleSource.Subscriber<T> subscriber, java.lang.Throwable cause)
SingleSource.Subscriber#onSubscribe(Cancellable) throws from a source.T - The type of SingleSource.Subscriber.subscriber - The SingleSource.Subscriber that threw an exception from
SingleSource.Subscriber#onSubscribe(Cancellable).cause - The exception thrown by subscriber.public static void handleExceptionFromOnSubscribe(CompletableSource.Subscriber subscriber, java.lang.Throwable cause)
CompletableSource.Subscriber#onSubscribe(Cancellable) throws from a
source.subscriber - The CompletableSource.Subscriber that threw an exception from
CompletableSource.Subscriber#onSubscribe(Cancellable).cause - The exception thrown by subscriber.public static <T> void safeOnError(SingleSource.Subscriber<T> subscriber, java.lang.Throwable cause)
SingleSource.Subscriber#onError(Throwable) ignoring an occurred exception if any.T - The type of SingleSource.Subscriber.subscriber - The SingleSource.Subscriber that may threw an exception from
SingleSource.Subscriber#onError(Throwable).cause - The occurred Throwable for SingleSource.Subscriber#onError(Throwable).