Class BackpressureHelper

java.lang.Object
io.reactivex.rxjava3.internal.util.BackpressureHelper

public final class BackpressureHelper extends Object
Utility class to help with backpressure-related operations such as request aggregation.
  • 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 at Long.MAX_VALUE.
      Parameters:
      a - the first value
      b - 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 at Long.MAX_VALUE.
      Parameters:
      a - the first value
      b - the second value
      Returns:
      the product capped at Long.MAX_VALUE
    • add

      public static long add(@NonNull @NonNull 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.
      Parameters:
      requested - the AtomicLong holding the current requested value
      n - the value to add, must be positive (not verified)
      Returns:
      the original value before the add
    • addCancel

      public static long addCancel(@NonNull @NonNull 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).
      Parameters:
      requested - the AtomicLong holding the current requested value
      n - the value to add, must be positive (not verified)
      Returns:
      the original value before the add
    • produced

      public static long produced(@NonNull @NonNull AtomicLong requested, long n)
      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 amount
      n - the produced element count, positive (not validated)
      Returns:
      the new amount
    • producedCancel

      public static long producedCancel(@NonNull @NonNull AtomicLong requested, long n)
      Atomically subtract the given number (positive, not validated) from the target field if it doesn't contain Long.MIN_VALUE (indicating some cancelled state) or Long.MAX_VALUE (unbounded mode).
      Parameters:
      requested - the target field holding the current requested amount
      n - the produced element count, positive (not validated)
      Returns:
      the new amount