Class ExponentialBackoffOptions
The ExponentialBackoffOptions class provides configuration options for the ExponentialBackoff
retry strategy. This strategy uses a delay duration that exponentially increases with each retry attempt until an
upper bound is reached. After reaching the upper bound, every retry attempt is delayed by the provided max delay
duration.
This class is useful when you need to customize the behavior of the exponential backoff strategy. It allows you to specify the maximum number of retry attempts, the base delay duration, and the maximum delay duration.
Code sample:
In this example, an ExponentialBackoffOptions is created and used to configure an
ExponentialBackoff retry strategy. The strategy is then used in a RetryPolicy which can then be added to
a pipeline. For a request then sent by the pipeline, if the server responds with a transient error, the request
will be retried with an exponentially increasing delay.
ExponentialBackoffOptions options = new ExponentialBackoffOptions().setMaxRetries(5)
.setBaseDelay(Duration.ofSeconds(1))
.setMaxDelay(Duration.ofSeconds(10));
ExponentialBackoff retryStrategy = new ExponentialBackoff(options);
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGets the base delay duration for retry.Gets the max delay duration for retry.Gets the max retry attempts that can be made.setBaseDelay(Duration baseDelay) Sets the base delay duration for retry.setMaxDelay(Duration maxDelay) Sets the max delay duration for retry.setMaxRetries(Integer maxRetries) Sets the max retry attempts that can be made.
-
Constructor Details
-
ExponentialBackoffOptions
public ExponentialBackoffOptions()Creates a new instance ofExponentialBackoffOptions.
-
-
Method Details
-
getMaxRetries
Gets the max retry attempts that can be made.- Returns:
- The max retry attempts that can be made.
-
setMaxRetries
Sets the max retry attempts that can be made.- Parameters:
maxRetries- the max retry attempts that can be made.- Returns:
- The updated
ExponentialBackoffOptions - Throws:
IllegalArgumentException- ifmaxRetriesis less than 0.
-
getBaseDelay
Gets the base delay duration for retry.- Returns:
- The base delay duration for retry.
-
setBaseDelay
Sets the base delay duration for retry.- Parameters:
baseDelay- the base delay duration for retry.- Returns:
- The updated
ExponentialBackoffOptions - Throws:
IllegalArgumentException- ifbaseDelayis less than or equal to 0 ormaxDelayhas been set and is less thanbaseDelay.
-
getMaxDelay
Gets the max delay duration for retry.- Returns:
- The max delay duration for retry.
-
setMaxDelay
Sets the max delay duration for retry.- Parameters:
maxDelay- the max delay duration for retry.- Returns:
- The updated
ExponentialBackoffOptions - Throws:
IllegalArgumentException- ifmaxDelayis less than or equal to 0 orbaseDelayhas been set and is more thanmaxDelay.
-