Class RetryPolicy
- java.lang.Object
-
- com.azure.android.core.http.policy.RetryPolicy
-
- All Implemented Interfaces:
HttpPipelinePolicy
public class RetryPolicy extends java.lang.Object implements HttpPipelinePolicy
Pipeline interceptor that retries when a recoverable exception or HTTP error occurs.
-
-
Constructor Summary
Constructors Constructor Description RetryPolicy(RetryStrategy retryStrategy)
CreatesRetryPolicy
with the providedRetryStrategy
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description org.threeten.bp.Duration
calculateRetryDelay(HttpResponse response, java.lang.Throwable exception, int retryAttempts)
Determines the delay duration that should be waited before retrying.void
process(HttpPipelinePolicyChain chain)
Intercepts any exception in the pipeline or the HTTP response error and, if recoverable, retries sending the request.static RetryPolicy
withExponentialBackoff()
Get an instance ofRetryPolicy
that uses a default full jitter backoff retry strategy.static RetryPolicy
withExponentialBackoff(int maxRetries, org.threeten.bp.Duration baseDelay, org.threeten.bp.Duration maxDelay)
Get an instance ofRetryPolicy
that uses full jitter backoff retry strategy.static RetryPolicy
withFixedDelay(int maxRetries, org.threeten.bp.Duration delay)
Get an instance ofRetryPolicy
that uses fixed backoff delay retry strategy.
-
-
-
Constructor Detail
-
RetryPolicy
public RetryPolicy(RetryStrategy retryStrategy)
CreatesRetryPolicy
with the providedRetryStrategy
.- Parameters:
retryStrategy
- TheRetryStrategy
used for retries.
-
-
Method Detail
-
withFixedDelay
public static RetryPolicy withFixedDelay(int maxRetries, org.threeten.bp.Duration delay)
Get an instance ofRetryPolicy
that uses fixed backoff delay retry strategy.- Parameters:
maxRetries
- The maximum number of times to retry.delay
- The fixed backoff delay applied before every retry.- Returns:
- The retry interceptor.
-
withExponentialBackoff
public static RetryPolicy withExponentialBackoff()
Get an instance ofRetryPolicy
that uses a default full jitter backoff retry strategy.The retry strategy by default retries maximum 3 times, uses 800 milliseconds as the default base delay and uses 8 seconds as default maximum backoff delay before a retry.
- Returns:
- The retry interceptor.
-
withExponentialBackoff
public static RetryPolicy withExponentialBackoff(int maxRetries, org.threeten.bp.Duration baseDelay, org.threeten.bp.Duration maxDelay)
Get an instance ofRetryPolicy
that uses full jitter backoff retry strategy.- Parameters:
maxRetries
- The maximum number of times to retry.baseDelay
- The delay used as the coefficient for backoffs, also baseDelay will be the first backoff delay.maxDelay
- The maximum backoff delay before a retry.- Returns:
- The retry interceptor.
-
process
public void process(HttpPipelinePolicyChain chain)
Intercepts any exception in the pipeline or the HTTP response error and, if recoverable, retries sending the request.- Specified by:
process
in interfaceHttpPipelinePolicy
- Parameters:
chain
- Provides access to the request to send.
-
calculateRetryDelay
public org.threeten.bp.Duration calculateRetryDelay(HttpResponse response, java.lang.Throwable exception, int retryAttempts)
Determines the delay duration that should be waited before retrying.- Parameters:
response
- The HTTP response.exception
- The pipeline exception, if any.retryAttempts
- The number of retry attempts so far made.- Returns:
- The delay duration.
-
-