Class RequestedCounter

java.lang.Object
io.helidon.common.reactive.RequestedCounter

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

    Constructors
    Constructor
    Description
    Create new request counter with strict mode off.
    RequestedCounter(boolean strictMode)
    Create new request counter, with strict mode true are all operations with counter protected by lock.
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    get()
    Gets the current requested event counter value.
    void
    increment(long increment, Consumer<? super IllegalArgumentException> errorHandler)
    Increments safely a requested event counter to prevent Long.MAX_VALUE overflow.
    void
    Lock internal counter if strict mode is on.
    boolean
    Tries to safely decrement a positive requested counter value, making sure the value does not drop below zero.
    void
    Unlock internal counter.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • RequestedCounter

      public RequestedCounter()
      Create new request counter with strict mode off.
    • RequestedCounter

      public RequestedCounter(boolean strictMode)
      Create new request counter, with strict mode true are all operations with counter protected by lock.
      Parameters:
      strictMode - true for turning strict mode on
  • Method Details

    • 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.
    • lock

      public void lock()
      Lock internal counter if strict mode is on.
    • unlock

      public void unlock()
      Unlock internal counter.
    • get

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