Class BackpressureHelper
- java.lang.Object
-
- io.reactivex.rxjava3.internal.util.BackpressureHelper
-
public final class BackpressureHelper extends java.lang.Object
Utility class to help with backpressure-related operations such as request aggregation.
-
-
Constructor Summary
Constructors Modifier Constructor Description private
BackpressureHelper()
Utility class.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static long
add(@NonNull java.util.concurrent.atomic.AtomicLong requested, long n)
Atomically adds the positive value n to the requested value in theAtomicLong
and caps the result atLong.MAX_VALUE
and returns the previous value.static long
addCancel(@NonNull java.util.concurrent.atomic.AtomicLong requested, long n)
Atomically adds the positive value n to the requested value in theAtomicLong
and caps the result atLong.MAX_VALUE
and returns the previous value and considersLong.MIN_VALUE
as a cancel indication (no addition then).static long
addCap(long a, long b)
Adds two long values and caps the sum atLong.MAX_VALUE
.static long
multiplyCap(long a, long b)
Multiplies two long values and caps the product atLong.MAX_VALUE
.static long
produced(@NonNull java.util.concurrent.atomic.AtomicLong requested, long n)
Atomically subtract the given number (positive, not validated) from the target field unless it containsLong.MAX_VALUE
.static long
producedCancel(@NonNull java.util.concurrent.atomic.AtomicLong requested, long n)
Atomically subtract the given number (positive, not validated) from the target field if it doesn't containLong.MIN_VALUE
(indicating some cancelled state) orLong.MAX_VALUE
(unbounded mode).
-
-
-
Method Detail
-
addCap
public static long addCap(long a, long b)
Adds two long values and caps the sum atLong.MAX_VALUE
.- Parameters:
a
- the first valueb
- the second value- Returns:
- the sum capped at
Long.MAX_VALUE
-
multiplyCap
public static long multiplyCap(long a, long b)
Multiplies two long values and caps the product atLong.MAX_VALUE
.- Parameters:
a
- the first valueb
- the second value- Returns:
- the product capped at
Long.MAX_VALUE
-
add
public static long add(@NonNull @NonNull java.util.concurrent.atomic.AtomicLong requested, long n)
Atomically adds the positive value n to the requested value in theAtomicLong
and caps the result atLong.MAX_VALUE
and returns the previous value.- Parameters:
requested
- theAtomicLong
holding the current requested valuen
- the value to add, must be positive (not verified)- Returns:
- the original value before the add
-
addCancel
public static long addCancel(@NonNull @NonNull java.util.concurrent.atomic.AtomicLong requested, long n)
Atomically adds the positive value n to the requested value in theAtomicLong
and caps the result atLong.MAX_VALUE
and returns the previous value and considersLong.MIN_VALUE
as a cancel indication (no addition then).- Parameters:
requested
- theAtomicLong
holding the current requested valuen
- the value to add, must be positive (not verified)- Returns:
- the original value before the add
-
produced
public static long produced(@NonNull @NonNull java.util.concurrent.atomic.AtomicLong requested, long n)
Atomically subtract the given number (positive, not validated) from the target field unless it containsLong.MAX_VALUE
.- Parameters:
requested
- the target field holding the current requested amountn
- the produced element count, positive (not validated)- Returns:
- the new amount
-
producedCancel
public static long producedCancel(@NonNull @NonNull java.util.concurrent.atomic.AtomicLong requested, long n)
Atomically subtract the given number (positive, not validated) from the target field 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 element count, positive (not validated)- Returns:
- the new amount
-
-