Package com.azure.core.http.policy
Class ExponentialBackoff
- java.lang.Object
-
- com.azure.core.http.policy.ExponentialBackoff
-
- All Implemented Interfaces:
RetryStrategy
public class ExponentialBackoff extends Object implements RetryStrategy
A truncated exponential backoff implementation ofRetryStrategythat has a delay duration that exponentially increases with each retry attempt until an upper bound is reached after which every retry attempt is delayed by the provided max delay duration.
-
-
Field Summary
-
Fields inherited from interface com.azure.core.http.policy.RetryStrategy
HTTP_STATUS_TOO_MANY_REQUESTS
-
-
Constructor Summary
Constructors Constructor Description ExponentialBackoff()Creates an instance ofExponentialBackoffwith a maximum number of retry attempts configured by the environment propertyConfiguration.PROPERTY_AZURE_REQUEST_RETRY_COUNT, or three if it isn't configured or is less than or equal to 0.ExponentialBackoff(int maxRetries, Duration baseDelay, Duration maxDelay)Creates an instance ofExponentialBackoff.ExponentialBackoff(ExponentialBackoffOptions options)Creates an instance ofExponentialBackoff.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DurationcalculateRetryDelay(int retryAttempts)Computes the delay between each retry.intgetMaxRetries()Max number of retry attempts to be make.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.azure.core.http.policy.RetryStrategy
shouldRetry, shouldRetryException
-
-
-
-
Constructor Detail
-
ExponentialBackoff
public ExponentialBackoff()
Creates an instance ofExponentialBackoffwith a maximum number of retry attempts configured by the environment propertyConfiguration.PROPERTY_AZURE_REQUEST_RETRY_COUNT, or three if it isn't configured or is less than or equal to 0. This strategy starts with a delay of 800 milliseconds and exponentially increases with each additional retry attempt to a maximum of 8 seconds.
-
ExponentialBackoff
public ExponentialBackoff(ExponentialBackoffOptions options)
Creates an instance ofExponentialBackoff.- Parameters:
options- TheExponentialBackoffOptions.- Throws:
NullPointerException- ifoptionsisnull.
-
ExponentialBackoff
public ExponentialBackoff(int maxRetries, Duration baseDelay, Duration maxDelay)Creates an instance ofExponentialBackoff.- Parameters:
maxRetries- The max retry attempts that can be made.baseDelay- The base delay duration for retry.maxDelay- The max delay duration for retry.- Throws:
IllegalArgumentException- ifmaxRetriesis less than 0 orbaseDelayis less than or equal to 0 ormaxDelayis less thanbaseDelay.
-
-
Method Detail
-
getMaxRetries
public int getMaxRetries()
Description copied from interface:RetryStrategyMax number of retry attempts to be make.- Specified by:
getMaxRetriesin interfaceRetryStrategy- Returns:
- The max number of retry attempts.
-
calculateRetryDelay
public Duration calculateRetryDelay(int retryAttempts)
Description copied from interface:RetryStrategyComputes the delay between each retry.- Specified by:
calculateRetryDelayin interfaceRetryStrategy- Parameters:
retryAttempts- The number of retry attempts completed so far.- Returns:
- The delay duration before the next retry.
-
-