Package io.camunda.zeebe.util
Class ExponentialBackoff
java.lang.Object
io.camunda.zeebe.util.ExponentialBackoff
- All Implemented Interfaces:
LongUnaryOperator
An simple implementation of exponential backoff, which multiples the previous delay with an
increasing multiplier and adding some jitter to avoid multiple clients polling at the same time
even with back off.
The next delay is calculated as:
max(min(maxDelay, currentDelay * backoffFactor), minDelay) + (rand(0.0, 1.0) * (currentDelay * jitterFactor) + (currentDelay * -jitterFactor))
-
Constructor Summary
ConstructorsConstructorDescriptionExponentialBackoff(long maxDelay, long minDelay) ExponentialBackoff(long maxDelay, long minDelay, double backoffFactor, double jitterFactor) -
Method Summary
Modifier and TypeMethodDescriptionlongapplyAsLong(long operand) longsupplyRetryDelay(long currentRetryDelay) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.function.LongUnaryOperator
andThen, compose
-
Constructor Details
-
ExponentialBackoff
public ExponentialBackoff() -
ExponentialBackoff
public ExponentialBackoff(long maxDelay, long minDelay) -
ExponentialBackoff
public ExponentialBackoff(long maxDelay, long minDelay, double backoffFactor, double jitterFactor)
-
-
Method Details
-
applyAsLong
public long applyAsLong(long operand) - Specified by:
applyAsLongin interfaceLongUnaryOperator
-
supplyRetryDelay
public long supplyRetryDelay(long currentRetryDelay)
-