Class RequestedCounter


  • public class RequestedCounter
    extends Object
    Requested event counter. This utility class helps to safely track and tryProcess the back-pressure of Flow.Subscribers.
    • Constructor Detail

      • RequestedCounter

        public RequestedCounter()
    • Method Detail

      • increment

        public void increment​(long increment,
                              Consumer<? super IllegalArgumentException> errorHandler)
        Increments safely a requested event counter to prevent Long.MAX_VALUE overflow.
        Parameters:
        increment - amount of additional events to request.
        errorHandler - a consumer of IllegalArgumentException to process errors
      • tryDecrement

        public boolean tryDecrement()
        Tries to safely decrement a positive requested counter value, making sure the value does not drop below zero.
        Returns:
        true if the initial positive value has been decremented successfully, false in case the initial counter value was already set to zero.
      • get

        public long get()
        Gets the current requested event counter value.
        Returns:
        current value of the requested event counter.
      • getAndReset

        public long getAndReset()
        Gets the current requested event counter value and resets it to 0.
        Returns:
        current value of the requested event counter.