Class BackpressureHelper
java.lang.Object
io.reactivex.rxjava3.internal.util.BackpressureHelper
Utility class to help with backpressure-related operations such as request aggregation.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic longadd(@NonNull 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.static longaddCancel(@NonNull 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 longaddCap(long a, long b) Adds two long values and caps the sum atLong.MAX_VALUE.static longmultiplyCap(long a, long b) Multiplies two long values and caps the product atLong.MAX_VALUE.static longproduced(@NonNull AtomicLong requested, long n) Atomically subtract the given number (positive, not validated) from the target field unless it containsLong.MAX_VALUE.static longproducedCancel(@NonNull 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).
-
Constructor Details
-
BackpressureHelper
private BackpressureHelper()Utility class.
-
-
Method Details
-
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
Atomically adds the positive value n to the requested value in theAtomicLongand caps the result atLong.MAX_VALUEand returns the previous value.- Parameters:
requested- theAtomicLongholding the current requested valuen- the value to add, must be positive (not verified)- Returns:
- the original value before the add
-
addCancel
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
-
produced
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
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
-