Class Subscriptions


  • public class Subscriptions
    extends Object
    • Constructor Summary

      Constructors 
      Constructor Description
      Subscriptions()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static long add​(long a, long b)
      Adds two long values and caps the sum at Long.MAX_VALUE.
      static long add​(AtomicLong requested, long requests)
      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.
      static long produced​(AtomicLong requested, long amount)
      Concurrent subtraction bound to 0, mostly used to decrement a request tracker by the amount produced by the operator.
      static long subOrZero​(long a, long b)
      Cap a subtraction to 0
    • Constructor Detail

      • Subscriptions

        public Subscriptions()
    • Method Detail

      • add

        public static long add​(AtomicLong requested,
                               long requests)
        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
        requests - the value to add, must be positive (not verified)
        Returns:
        the original value before the add
      • add

        public static long add​(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
      • produced

        public static long produced​(AtomicLong requested,
                                    long amount)
        Concurrent subtraction bound to 0, mostly used to decrement a request tracker by the amount produced by the operator.
        Parameters:
        requested - the atomic long keeping track of requests
        amount - delta to subtract
        Returns:
        value after subtraction or zero
      • subOrZero

        public static long subOrZero​(long a,
                                     long b)
        Cap a subtraction to 0
        Parameters:
        a - left operand
        b - right operand
        Returns:
        Subtraction result or 0 if overflow