public class Subscriptions extends Object
Modifier and Type | Class and Description |
---|---|
static class |
Subscriptions.CancelledSubscriber<X> |
static class |
Subscriptions.DeferredSubscription |
static class |
Subscriptions.EmptySubscription |
static class |
Subscriptions.SingleItemSubscription<T> |
Modifier and Type | Field and Description |
---|---|
static Subscriptions.EmptySubscription |
CANCELLED
This instance must not be shared.
|
static Throwable |
TERMINATED |
Modifier and Type | Method and Description |
---|---|
static long |
add(AtomicLong requested,
long requests)
Atomically adds the positive value n to the requested value in the AtomicLong and
caps the result at Long.MAX_VALUE and returns the previous value.
|
static long |
add(long a,
long b)
Adds two long values and caps the sum at Long.MAX_VALUE.
|
static long |
addAndHandledAlreadyCancelled(AtomicLong requested,
long n)
Atomically adds the positive value n to the requested value in the
AtomicLong and
caps the result at Long.MAX_VALUE and returns the previous value and
considers Long.MIN_VALUE as a cancel indication (no addition then). |
static boolean |
addFailure(AtomicReference<Throwable> failures,
Throwable failure) |
static void |
cancel(AtomicReference<org.reactivestreams.Subscription> reference) |
static void |
complete(org.reactivestreams.Subscriber<?> subscriber)
Invokes
onSubscribe on the given Subscriber with the cancelled subscription instance
followed immediately by a call to onComplete . |
static org.reactivestreams.Subscription |
empty() |
static void |
fail(org.reactivestreams.Subscriber<?> subscriber,
Throwable failure)
Invokes
onSubscribe on the given Subscriber with the cancelled subscription instance
followed immediately by a call to onError with the given failure. |
static void |
fail(org.reactivestreams.Subscriber<?> subscriber,
Throwable failure,
org.reactivestreams.Publisher<?> upstream) |
static IllegalArgumentException |
getInvalidRequestException() |
static Throwable |
markFailureAsTerminated(AtomicReference<Throwable> failures) |
static long |
multiply(long n,
long times)
Cap a multiplication to Long.MAX_VALUE
|
static long |
produced(AtomicLong requested,
long amount)
Concurrent subtraction bound to 0, mostly used to decrement a request tracker by
the amount produced by the operator.
|
static long |
producedAndHandleAlreadyCancelled(AtomicLong requested,
long n)
Atomically subtract the given number from the target atomic long if it doesn't contain
Long.MIN_VALUE
(indicating some cancelled state) or Long.MAX_VALUE (unbounded mode). |
static void |
requestIfNotNullOrAccumulate(AtomicReference<org.reactivestreams.Subscription> field,
AtomicLong requested,
long requests)
Atomically requests from the Subscription in the field if not null, otherwise accumulates
the request amount in the requested field to be requested once the field is set to non-null.
|
static boolean |
setIfEmpty(AtomicReference<org.reactivestreams.Subscription> container,
org.reactivestreams.Subscription subscription)
Atomically sets the subscription on the container if the content is still
null . |
static boolean |
setIfEmptyAndRequest(AtomicReference<org.reactivestreams.Subscription> container,
AtomicLong requested,
org.reactivestreams.Subscription subscription)
Atomically sets the new
Subscription in the container and requests any accumulated amount
from the requested counter. |
static <T> org.reactivestreams.Subscription |
single(org.reactivestreams.Subscriber<T> downstream,
T item) |
static long |
subOrZero(long a,
long b)
Cap a subtraction to 0
|
static long |
subtract(AtomicLong requested,
long emitted)
Atomically subtract the given number (positive, not validated) from the target field unless it contains Long.MAX_VALUE.
|
static Throwable |
terminate(AtomicReference<Throwable> failure) |
static void |
terminateAndPropagate(AtomicReference<Throwable> failures,
org.reactivestreams.Subscriber<?> subscriber) |
static int |
unboundedOrLimit(int prefetch) |
static long |
unboundedOrRequests(int concurrency) |
public static final Throwable TERMINATED
public static final Subscriptions.EmptySubscription CANCELLED
Subscription.cancel()
is a no-op.public static IllegalArgumentException getInvalidRequestException()
public static org.reactivestreams.Subscription empty()
public static void complete(org.reactivestreams.Subscriber<?> subscriber)
onSubscribe
on the given Subscriber
with the cancelled subscription instance
followed immediately by a call to onComplete
.subscriber
- the subscriber, must not be null
public static void fail(org.reactivestreams.Subscriber<?> subscriber, Throwable failure)
onSubscribe
on the given Subscriber
with the cancelled subscription instance
followed immediately by a call to onError
with the given failure.subscriber
- the subscriber, must not be null
failure
- the failure, must not be null
public static void fail(org.reactivestreams.Subscriber<?> subscriber, Throwable failure, org.reactivestreams.Publisher<?> upstream)
public static long add(long a, long b)
a
- the first valueb
- the second valuepublic static long add(AtomicLong requested, long requests)
requested
- the AtomicLong holding the current requested valuerequests
- the value to add, must be positive (not verified)public static long subtract(AtomicLong requested, long emitted)
requested
- the target field holding the current requested amountemitted
- the produced element count, positive (not validated)public static int unboundedOrLimit(int prefetch)
public static long unboundedOrRequests(int concurrency)
public static boolean addFailure(AtomicReference<Throwable> failures, Throwable failure)
public static void cancel(AtomicReference<org.reactivestreams.Subscription> reference)
public static Throwable markFailureAsTerminated(AtomicReference<Throwable> failures)
public static void terminateAndPropagate(AtomicReference<Throwable> failures, org.reactivestreams.Subscriber<?> subscriber)
public static long multiply(long n, long times)
n
- left operandtimes
- right operandpublic static void requestIfNotNullOrAccumulate(AtomicReference<org.reactivestreams.Subscription> field, AtomicLong requested, long requests)
field
- the target field that may already contain a Subscriptionrequested
- the current requested amountrequests
- the request amount, positive (verified)public static boolean setIfEmptyAndRequest(AtomicReference<org.reactivestreams.Subscription> container, AtomicLong requested, org.reactivestreams.Subscription subscription)
Subscription
in the container and requests any accumulated amount
from the requested counter.container
- the target field for the new Subscriptionrequested
- the current requested amountsubscription
- the new Subscription, must not be null
public static boolean setIfEmpty(AtomicReference<org.reactivestreams.Subscription> container, org.reactivestreams.Subscription subscription)
null
.
If not the passed subscription gets cancelled.container
- the target containersubscription
- the new subscription to settrue
if the operation succeeded, false
if the target container was already set.public static Throwable terminate(AtomicReference<Throwable> failure)
public static long produced(AtomicLong requested, long amount)
requested
- the atomic long keeping track of requestsamount
- delta to subtractpublic static long subOrZero(long a, long b)
a
- left operandb
- right operandpublic static <T> org.reactivestreams.Subscription single(org.reactivestreams.Subscriber<T> downstream, T item)
public static long producedAndHandleAlreadyCancelled(AtomicLong requested, long n)
Long.MIN_VALUE
(indicating some cancelled state) or Long.MAX_VALUE
(unbounded mode).requested
- the target field holding the current requested amountn
- the produced item count, must be positivepublic static long addAndHandledAlreadyCancelled(AtomicLong requested, long n)
AtomicLong
and
caps the result at Long.MAX_VALUE
and returns the previous value and
considers Long.MIN_VALUE
as a cancel indication (no addition then).requested
- the AtomicLong
holding the current requested valuen
- the value to add, must be positive (not verified)Copyright © 2019–2020 SmallRye. All rights reserved.