Package io.temporal.internal
Class AsyncBackoffThrottler
- java.lang.Object
-
- io.temporal.internal.AsyncBackoffThrottler
-
public final class AsyncBackoffThrottler extends java.lang.Object
Used to throttle code execution in presence of failures using exponential backoff logic. The formula used to calculate the next sleep interval is:min(pow(backoffCoefficient, failureCount - 1) * initialSleep, maxSleep);
Example usage:
BackoffThrottler throttler = new BackoffThrottler(1000, 60000, 2); while(!stopped) { try { Future<Void> t = throttler.throttle(); t.get(); // some code that can fail and should be throttled ... throttler.success(); } catch (Exception e) { throttler.failure(); } }
-
-
Constructor Summary
Constructors Constructor Description AsyncBackoffThrottler(java.time.Duration initialSleep, java.time.Duration maxSleep, double backoffCoefficient)
Construct an instance of the throttler.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
failure()
Increment failure count.void
success()
Resent failure count to 0.java.util.concurrent.CompletableFuture<java.lang.Void>
throttle()
Result future is done after a delay if there were failures since the last success call.
-
-
-
Constructor Detail
-
AsyncBackoffThrottler
public AsyncBackoffThrottler(java.time.Duration initialSleep, java.time.Duration maxSleep, double backoffCoefficient)
Construct an instance of the throttler.- Parameters:
initialSleep
- time to sleep on the first failuremaxSleep
- maximum time to sleep independently of number of failuresbackoffCoefficient
- coefficient used to calculate the next time to sleep.
-
-