Package io.helidon.common.reactive
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 tryProcess the back-pressure ofFlow.Subscriber
s.
-
-
Constructor Summary
Constructors Constructor Description RequestedCounter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
get()
Gets the current requested event counter value.long
getAndReset()
Gets the current requested event counter value and resets it to 0.void
increment(long increment, Consumer<? super IllegalArgumentException> errorHandler)
Increments safely a requested event counter to preventLong.MAX_VALUE
overflow.boolean
tryDecrement()
Tries to safely decrement a positive requested counter value, making sure the value does not drop below zero.
-
-
-
Method Detail
-
increment
public void increment(long increment, Consumer<? super IllegalArgumentException> errorHandler)
Increments safely a requested event counter to preventLong.MAX_VALUE
overflow.- Parameters:
increment
- amount of additional events to request.errorHandler
- a consumer ofIllegalArgumentException
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.
-
-