public class BackOffPolicyBuilder extends Object
BackOffPolicy based on given attributes. The delay
values are expressed in milliseconds. If any provided value is less than one, the
resulting policy will set it to one. The default policy is a FixedBackOffPolicy
with a delay of 1000ms.
Examples:
// DefaultFixedBackOffPolicywith 1000ms delay BackOffPolicyBuilder .newDefaultPolicy(); //FixedBackOffPolicyBackOffPolicyBuilder .newBuilder() .delay(2000) .build(); //UniformRandomBackOffPolicyBackOffPolicyBuilder .newBuilder() .delay(500) .maxDelay(1000) .build(); //ExponentialBackOffPolicyBackOffPolicyBuilder .newBuilder() .delay(1000) .maxDelay(5000) .multiplier(2) .build(); //ExponentialRandomBackOffPolicywith providedSleeperBackOffPolicyBuilder .newBuilder() .delay(3000) .maxDelay(5000) .multiplier(1.5) .random(true) .sleeper(mySleeper) .build();
Not thread safe. Building should be performed in a single thread. The resulting
BackOffPolicy however is expected to be thread-safe and designed for moderate
load concurrent access.
| Modifier and Type | Method and Description |
|---|---|
BackOffPolicy |
build()
Builds the
BackOffPolicy with the given parameters. |
BackOffPolicyBuilder |
delay(long delay)
A canonical backoff period.
|
BackOffPolicyBuilder |
maxDelay(long maxDelay)
The maximum wait in milliseconds between retries.
|
BackOffPolicyBuilder |
multiplier(double multiplier)
If positive, then used as a multiplier for generating the next delay for backoff.
|
static BackOffPolicyBuilder |
newBuilder()
Creates a new
BackOffPolicyBuilder instance. |
static BackOffPolicy |
newDefaultPolicy()
Creates a new
FixedBackOffPolicy instance with a delay of 1000ms. |
BackOffPolicyBuilder |
random(boolean random)
In the exponential case (
multiplier > 0) set this to true to have the
backoff delays randomized, so that the maximum delay is multiplier times the
previous delay and the distribution is uniform between the two values. |
BackOffPolicyBuilder |
sleeper(Sleeper sleeper)
The
Sleeper instance to be used to back off. |
public static BackOffPolicyBuilder newBuilder()
BackOffPolicyBuilder instance.public static BackOffPolicy newDefaultPolicy()
FixedBackOffPolicy instance with a delay of 1000ms.public BackOffPolicyBuilder delay(long delay)
delay - the initial or canonical backoff period in millisecondspublic BackOffPolicyBuilder maxDelay(long maxDelay)
delay(long)
then a default value is applied depending on the resulting policy.maxDelay - the maximum wait between retries in millisecondspublic BackOffPolicyBuilder multiplier(double multiplier)
multiplier - a multiplier to use to calculate the next backoff delaypublic BackOffPolicyBuilder random(boolean random)
multiplier > 0) set this to true to have the
backoff delays randomized, so that the maximum delay is multiplier times the
previous delay and the distribution is uniform between the two values.random - the flag to signal randomization is requiredpublic BackOffPolicyBuilder sleeper(Sleeper sleeper)
Sleeper instance to be used to back off. Policies default to
ThreadWaitSleeper.sleeper - the Sleeper instancepublic BackOffPolicy build()
BackOffPolicy with the given parameters.BackOffPolicy instanceCopyright © 2022 SpringSource. All rights reserved.