Class Backoff
- java.lang.Object
-
- org.apache.bookkeeper.common.util.Backoff
-
public class Backoff extends java.lang.Object
Implements various backoff strategies.Strategies are defined by a
Stream
of durations and are intended to determine the duration after which a task is to be retried.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Backoff.Constant
A constant backoff policy.static class
Backoff.Exponential
A exponential backoff policy.static class
Backoff.Jitter
A Jittered backoff policy.static interface
Backoff.Policy
Back off policy.
-
Field Summary
Fields Modifier and Type Field Description static Backoff.Policy
DEFAULT
-
Constructor Summary
Constructors Constructor Description Backoff()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.stream.Stream<java.lang.Long>
constant(long startMs)
Create a stream with constant backoffs.static java.util.stream.Stream<java.lang.Long>
decorrelatedJittered(long startMs, long maxMs)
Create an infinite backoffs that have jitter with a random distribution betweenstartMs
and 3 times the previously selected value, capped atmaxMs
.static java.util.stream.Stream<java.lang.Long>
equalJittered(long startMs, long maxMs)
Create infinite backoffs that keep half of the exponential growth, and jitter between 0 and that amount.static java.util.stream.Stream<java.lang.Long>
exponential(long startMs, int multiplier, long maxMs)
Create a stream with exponential backoffs.static java.util.stream.Stream<java.lang.Long>
exponentialJittered(long startMs, long maxMs)
Create a stream of exponential backoffs with jitters.
-
-
-
Field Detail
-
DEFAULT
public static final Backoff.Policy DEFAULT
-
-
Method Detail
-
constant
public static java.util.stream.Stream<java.lang.Long> constant(long startMs)
Create a stream with constant backoffs.- Parameters:
startMs
- initial backoff in milliseconds- Returns:
- a stream with constant backoff values.
-
exponential
public static java.util.stream.Stream<java.lang.Long> exponential(long startMs, int multiplier, long maxMs)
Create a stream with exponential backoffs.- Parameters:
startMs
- initial backoff in milliseconds.multiplier
- the multiplier for next backoff.maxMs
- max backoff in milliseconds.- Returns:
- a stream with exponential backoffs.
-
exponentialJittered
public static java.util.stream.Stream<java.lang.Long> exponentialJittered(long startMs, long maxMs)
Create a stream of exponential backoffs with jitters.This is "full jitter" via http://www.awsarchitectureblog.com/2015/03/backoff.html
- Parameters:
startMs
- initial backoff in milliseconds.maxMs
- max backoff in milliseconds.- Returns:
- a stream of exponential backoffs with jitters.
-
decorrelatedJittered
public static java.util.stream.Stream<java.lang.Long> decorrelatedJittered(long startMs, long maxMs)
Create an infinite backoffs that have jitter with a random distribution betweenstartMs
and 3 times the previously selected value, capped atmaxMs
.this is "decorrelated jitter" via http://www.awsarchitectureblog.com/2015/03/backoff.html
- Parameters:
startMs
- initial backoff in millisecondsmaxMs
- max backoff in milliseconds- Returns:
- a stream of jitter backoffs.
-
equalJittered
public static java.util.stream.Stream<java.lang.Long> equalJittered(long startMs, long maxMs)
Create infinite backoffs that keep half of the exponential growth, and jitter between 0 and that amount.this is "equal jitter" via http://www.awsarchitectureblog.com/2015/03/backoff.html
- Parameters:
startMs
- initial backoff in milliseconds.maxMs
- max backoff in milliseconds.- Returns:
- a stream of exponential backoffs with jitters.
-
-