Class BackpressureHelper
java.lang.Object
com.forgerock.rxjava3.intern.util.BackpressureHelper
Utility class to help with backpressure-related operations such as request aggregation.
-
Method Summary
Modifier and TypeMethodDescriptionstatic long
add
(@NonNull 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
addCap
(long a, long b) Adds two long values and caps the sum atLong.MAX_VALUE
.static long
produced
(@NonNull AtomicLong requested, long n) Atomically subtract the given number (positive, not validated) from the target field unless it containsLong.MAX_VALUE
.
-
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
-
add
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
-
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
-