Class 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.
    • Method Detail

      • withFixedDelay

        public static RetryPolicy withFixedDelay​(int maxRetries,
                                                 org.threeten.bp.Duration delay)
        Get an instance of RetryPolicy 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 of RetryPolicy 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 of RetryPolicy 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 interface HttpPipelinePolicy
        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.