Class BackpressureUtils



  • public final class BackpressureUtils
    extends Object
    Utility functions for use with backpressure.
    • Method Summary

      Methods

      Modifier and Type Method and Description
      static long addCap(long a, long b)
      Adds two positive longs and caps the result at Long.MAX_VALUE.
      static <T> long getAndAddRequest(AtomicLongFieldUpdater<T> requested, T object, long n)
      Adds n to requested field and returns the value prior to addition once the addition is successful (uses CAS semantics).
      static long getAndAddRequest(AtomicLong requested, long n)
      Adds n to requested and returns the value prior to addition once the addition is successful (uses CAS semantics).
      static long multiplyCap(long a, long b)
      Multiplies two positive longs and caps the result at Long.MAX_VALUE.
    • Method Detail

      • getAndAddRequest

        public static <T> long getAndAddRequest(AtomicLongFieldUpdater<T> requested,
                                                T object,
                                                long n)
        Adds n to requested field and returns the value prior to addition once the addition is successful (uses CAS semantics). If overflows then sets requested field to Long.MAX_VALUE.
        Parameters:
        requested - atomic field updater for a request count
        object - contains the field updated by the updater
        n - the number of requests to add to the requested count
        Returns:
        requested value just prior to successful addition
      • getAndAddRequest

        public static long getAndAddRequest(AtomicLong requested,
                                            long n)
        Adds n to requested and returns the value prior to addition once the addition is successful (uses CAS semantics). If overflows then sets requested field to Long.MAX_VALUE.
        Parameters:
        requested - atomic long that should be updated
        n - the number of requests to add to the requested count
        Returns:
        requested value just prior to successful addition
      • multiplyCap

        public static long multiplyCap(long a,
                                       long b)
        Multiplies two positive longs and caps the result at Long.MAX_VALUE.
        Parameters:
        a - the first value
        b - the second value
        Returns:
        the capped product of a and b
      • addCap

        public static long addCap(long a,
                                  long b)
        Adds two positive longs and caps the result at Long.MAX_VALUE.
        Parameters:
        a - the first value
        b - the second value
        Returns:
        the capped sum of a and b