Interface RetryStrategy

All Known Implementing Classes:
ExponentialBackoff, FixedDelay

public interface RetryStrategy
The interface for determining the retry strategy used in RetryPolicy.
  • Field Details

    • HTTP_STATUS_TOO_MANY_REQUESTS

      static final int HTTP_STATUS_TOO_MANY_REQUESTS
      HTTP response status code for Too Many Requests.
      See Also:
  • Method Details

    • getMaxRetries

      int getMaxRetries()
      Max number of retry attempts to be make.
      Returns:
      The max number of retry attempts.
    • calculateRetryDelay

      Duration calculateRetryDelay(int retryAttempts)
      Computes the delay between each retry.
      Parameters:
      retryAttempts - The number of retry attempts completed so far.
      Returns:
      The delay duration before the next retry.
    • shouldRetry

      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:
      httpResponse - The response from the previous attempt.
      Returns:
      Whether a retry should be attempted.
    • shouldRetryException

      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:
      throwable - The Throwable thrown during the previous attempt.
      Returns:
      Whether a retry should be attempted.
    • shouldRetryCondition

      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) method is called, otherwise the shouldRetryException(Throwable) method is called.

      Parameters:
      requestRetryCondition - The RequestRetryCondition containing information that can be used to determine if the request should be retried.
      Returns:
      Whether a retry should be attempted.