RetryStrategy Interface
public interface RetryStrategy
The interface for determining the retry strategy used in RetryPolicy.
Field Summary
| Modifier and Type | Field and Description |
|---|---|
| static final int |
HTTP_STATUS_TOO_MANY_REQUESTS
HTTP response status code for |
Method Summary
| Modifier and Type | Method and Description |
|---|---|
| abstract Duration |
calculateRetryDelay(int retryAttempts)
Computes the delay between each retry. |
| default Duration |
calculateRetryDelay(RequestRetryCondition requestRetryCondition)
Computes the delay between each retry based on the RequestRetryCondition. |
| abstract int |
getMaxRetries()
Max number of retry attempts to be made. |
| default boolean |
shouldRetry(HttpResponse httpResponse)
This method is consulted to determine if a retry attempt should be made for the given HttpResponse if the retry attempts are less than getMaxRetries(). |
| default boolean |
shouldRetryCondition(RequestRetryCondition requestRetryCondition)
This method is consulted to determine if a retry attempt should be made for the given RequestRetryCondition. |
| default boolean |
shouldRetryException(Throwable throwable)
This method is consulted to determine if a retry attempt should be made for the given Throwable propagated when the request failed to send. |
Field Details
HTTP_STATUS_TOO_MANY_REQUESTS
public static final int HTTP_STATUS_TOO_MANY_REQUESTS
HTTP response status code for Too Many Requests.
Method Details
calculateRetryDelay
public abstract Duration calculateRetryDelay(int retryAttempts)
Computes the delay between each retry.
If both this method and calculateRetryDelay(RequestRetryCondition requestRetryCondition) are overridden, this method is ignored.
Parameters:
Returns:
calculateRetryDelay
public default Duration calculateRetryDelay(RequestRetryCondition requestRetryCondition)
Computes the delay between each retry based on the RequestRetryCondition.
If this method is not overridden, the calculateRetryDelay(int retryAttempts) method is called with getTryCount().
If both this method and calculateRetryDelay(int retryAttempts) are overridden, this method is used.
Parameters:
Returns:
getMaxRetries
public abstract int getMaxRetries()
Max number of retry attempts to be made.
Returns:
shouldRetry
public default boolean shouldRetry(HttpResponse httpResponse)
This method is consulted to determine if a retry attempt should be made for the given HttpResponse if the retry attempts are less than getMaxRetries().
Parameters:
Returns:
shouldRetryCondition
public default boolean shouldRetryCondition(RequestRetryCondition requestRetryCondition)
This method is consulted to determine if a retry attempt should be made for the given RequestRetryCondition.
By default, if the RequestRetryCondition contains a non-null HttpResponse, then the shouldRetry(HttpResponse httpResponse) method is called, otherwise the shouldRetryException(Throwable throwable) method is called.
Parameters:
Returns:
shouldRetryException
public default boolean shouldRetryException(Throwable throwable)
This method is consulted to determine if a retry attempt should be made for the given Throwable propagated when the request failed to send.
Parameters:
Returns: