Package io.smallrye.mutiny.helpers
Class Subscriptions
- java.lang.Object
-
- io.smallrye.mutiny.helpers.Subscriptions
-
public class Subscriptions extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSubscriptions.CancelledSubscriber<X>static classSubscriptions.DeferredSubscriptionstatic classSubscriptions.EmptySubscriptionstatic classSubscriptions.SingleItemSubscription<T>
-
Field Summary
Fields Modifier and Type Field Description static Subscriptions.EmptySubscriptionCANCELLEDThis instance must not be shared.static java.lang.ThrowableTERMINATED
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static longadd(long a, long b)Adds two long values and caps the sum at Long.MAX_VALUE.static longadd(java.util.concurrent.atomic.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 longaddAndHandledAlreadyCancelled(java.util.concurrent.atomic.AtomicLong requested, long n)Atomically adds the positive value n to the requested value in theAtomicLongand caps the result atLong.MAX_VALUEand returns the previous value and considersLong.MIN_VALUEas a cancel indication (no addition then).static booleanaddFailure(java.util.concurrent.atomic.AtomicReference<java.lang.Throwable> failures, java.lang.Throwable failure)static voidcancel(java.util.concurrent.atomic.AtomicReference<org.reactivestreams.Subscription> reference)static voidcomplete(org.reactivestreams.Subscriber<?> subscriber)InvokesonSubscribeon the givenSubscriberwith the cancelled subscription instance followed immediately by a call toonComplete.static org.reactivestreams.Subscriptionempty()static voidfail(org.reactivestreams.Subscriber<?> subscriber, java.lang.Throwable failure)InvokesonSubscribeon the givenSubscriberwith the cancelled subscription instance followed immediately by a call toonErrorwith the given failure.static voidfail(org.reactivestreams.Subscriber<?> subscriber, java.lang.Throwable failure, org.reactivestreams.Publisher<?> upstream)static java.lang.IllegalArgumentExceptiongetInvalidRequestException()static java.lang.ThrowablemarkFailureAsTerminated(java.util.concurrent.atomic.AtomicReference<java.lang.Throwable> failures)static longmultiply(long n, long times)Cap a multiplication to Long.MAX_VALUEstatic longproduced(java.util.concurrent.atomic.AtomicLong requested, long amount)Concurrent subtraction bound to 0, mostly used to decrement a request tracker by the amount produced by the operator.static longproducedAndHandleAlreadyCancelled(java.util.concurrent.atomic.AtomicLong requested, long n)Atomically subtract the given number from the target atomic long if it doesn't containLong.MIN_VALUE(indicating some cancelled state) orLong.MAX_VALUE(unbounded mode).static voidrequestIfNotNullOrAccumulate(java.util.concurrent.atomic.AtomicReference<org.reactivestreams.Subscription> field, java.util.concurrent.atomic.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 booleansetIfEmpty(java.util.concurrent.atomic.AtomicReference<org.reactivestreams.Subscription> container, org.reactivestreams.Subscription subscription)Atomically sets the subscription on the container if the content is stillnull.static booleansetIfEmptyAndRequest(java.util.concurrent.atomic.AtomicReference<org.reactivestreams.Subscription> container, java.util.concurrent.atomic.AtomicLong requested, org.reactivestreams.Subscription subscription)Atomically sets the newSubscriptionin the container and requests any accumulated amount from the requested counter.static <T> org.reactivestreams.Subscriptionsingle(org.reactivestreams.Subscriber<T> downstream, T item)static longsubOrZero(long a, long b)Cap a subtraction to 0static longsubtract(java.util.concurrent.atomic.AtomicLong requested, long emitted)Atomically subtract the given number (positive, not validated) from the target field unless it contains Long.MAX_VALUE.static java.lang.Throwableterminate(java.util.concurrent.atomic.AtomicReference<java.lang.Throwable> failure)static voidterminateAndPropagate(java.util.concurrent.atomic.AtomicReference<java.lang.Throwable> failures, org.reactivestreams.Subscriber<?> subscriber)static intunboundedOrLimit(int prefetch)static longunboundedOrRequests(int concurrency)
-
-
-
Field Detail
-
TERMINATED
public static final java.lang.Throwable TERMINATED
-
CANCELLED
public static final Subscriptions.EmptySubscription CANCELLED
This instance must not be shared. CallingSubscription.cancel()is a no-op.
-
-
Method Detail
-
getInvalidRequestException
public static java.lang.IllegalArgumentException getInvalidRequestException()
-
empty
public static org.reactivestreams.Subscription empty()
-
complete
public static void complete(org.reactivestreams.Subscriber<?> subscriber)
InvokesonSubscribeon the givenSubscriberwith the cancelled subscription instance followed immediately by a call toonComplete.- Parameters:
subscriber- the subscriber, must not benull
-
fail
public static void fail(org.reactivestreams.Subscriber<?> subscriber, java.lang.Throwable failure)InvokesonSubscribeon the givenSubscriberwith the cancelled subscription instance followed immediately by a call toonErrorwith the given failure.- Parameters:
subscriber- the subscriber, must not benullfailure- the failure, must not benull
-
fail
public static void fail(org.reactivestreams.Subscriber<?> subscriber, java.lang.Throwable failure, org.reactivestreams.Publisher<?> upstream)
-
add
public static long add(long a, long b)Adds two long values and caps the sum at Long.MAX_VALUE.- Parameters:
a- the first valueb- the second value- Returns:
- the sum capped at Long.MAX_VALUE
-
add
public static long add(java.util.concurrent.atomic.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.- Parameters:
requested- the AtomicLong holding the current requested valuerequests- the value to add, must be positive (not verified)- Returns:
- the original value before the add
-
subtract
public static long subtract(java.util.concurrent.atomic.AtomicLong requested, long emitted)Atomically subtract the given number (positive, not validated) from the target field unless it contains Long.MAX_VALUE.- Parameters:
requested- the target field holding the current requested amountemitted- the produced element count, positive (not validated)- Returns:
- the new amount
-
unboundedOrLimit
public static int unboundedOrLimit(int prefetch)
-
unboundedOrRequests
public static long unboundedOrRequests(int concurrency)
-
addFailure
public static boolean addFailure(java.util.concurrent.atomic.AtomicReference<java.lang.Throwable> failures, java.lang.Throwable failure)
-
cancel
public static void cancel(java.util.concurrent.atomic.AtomicReference<org.reactivestreams.Subscription> reference)
-
markFailureAsTerminated
public static java.lang.Throwable markFailureAsTerminated(java.util.concurrent.atomic.AtomicReference<java.lang.Throwable> failures)
-
terminateAndPropagate
public static void terminateAndPropagate(java.util.concurrent.atomic.AtomicReference<java.lang.Throwable> failures, org.reactivestreams.Subscriber<?> subscriber)
-
multiply
public static long multiply(long n, long times)Cap a multiplication to Long.MAX_VALUE- Parameters:
n- left operandtimes- right operand- Returns:
- n * times or Long.MAX_VALUE
-
requestIfNotNullOrAccumulate
public static void requestIfNotNullOrAccumulate(java.util.concurrent.atomic.AtomicReference<org.reactivestreams.Subscription> field, java.util.concurrent.atomic.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.- Parameters:
field- the target field that may already contain a Subscriptionrequested- the current requested amountrequests- the request amount, positive (verified)
-
setIfEmptyAndRequest
public static boolean setIfEmptyAndRequest(java.util.concurrent.atomic.AtomicReference<org.reactivestreams.Subscription> container, java.util.concurrent.atomic.AtomicLong requested, org.reactivestreams.Subscription subscription)Atomically sets the newSubscriptionin the container and requests any accumulated amount from the requested counter.- Parameters:
container- the target field for the new Subscriptionrequested- the current requested amountsubscription- the new Subscription, must not benull- Returns:
- true if the Subscription was set the first time
-
setIfEmpty
public static boolean setIfEmpty(java.util.concurrent.atomic.AtomicReference<org.reactivestreams.Subscription> container, org.reactivestreams.Subscription subscription)Atomically sets the subscription on the container if the content is stillnull. If not the passed subscription gets cancelled.- Parameters:
container- the target containersubscription- the new subscription to set- Returns:
trueif the operation succeeded,falseif the target container was already set.
-
terminate
public static java.lang.Throwable terminate(java.util.concurrent.atomic.AtomicReference<java.lang.Throwable> failure)
-
produced
public static long produced(java.util.concurrent.atomic.AtomicLong requested, long amount)Concurrent subtraction bound to 0, mostly used to decrement a request tracker by the amount produced by the operator.- Parameters:
requested- the atomic long keeping track of requestsamount- delta to subtract- Returns:
- value after subtraction or zero
-
subOrZero
public static long subOrZero(long a, long b)Cap a subtraction to 0- Parameters:
a- left operandb- right operand- Returns:
- Subtraction result or 0 if overflow
-
single
public static <T> org.reactivestreams.Subscription single(org.reactivestreams.Subscriber<T> downstream, T item)
-
producedAndHandleAlreadyCancelled
public static long producedAndHandleAlreadyCancelled(java.util.concurrent.atomic.AtomicLong requested, long n)Atomically subtract the given number from the target atomic long if it doesn't containLong.MIN_VALUE(indicating some cancelled state) orLong.MAX_VALUE(unbounded mode).- Parameters:
requested- the target field holding the current requested amountn- the produced item count, must be positive- Returns:
- the new amount
-
addAndHandledAlreadyCancelled
public static long addAndHandledAlreadyCancelled(java.util.concurrent.atomic.AtomicLong requested, long n)Atomically adds the positive value n to the requested value in theAtomicLongand caps the result atLong.MAX_VALUEand returns the previous value and considersLong.MIN_VALUEas a cancel indication (no addition then).- Parameters:
requested- theAtomicLongholding the current requested valuen- the value to add, must be positive (not verified)- Returns:
- the original value before the add
-
-