Class RetryAlgorithm<ResponseT>

  • Type Parameters:
    ResponseT - response type
    Direct Known Subclasses:
    StreamingRetryAlgorithm

    public class RetryAlgorithm<ResponseT>
    extends java.lang.Object
    The retry algorithm, which makes decision based either on the thrown exception or the returned response, and the execution time settings of the previous attempt.

    This class is thread-safe.

    • Method Detail

      • createNextAttempt

        @Deprecated
        public TimedAttemptSettings createNextAttempt​(java.lang.Throwable previousThrowable,
                                                      ResponseT previousResponse,
                                                      TimedAttemptSettings previousSettings)
        Creates a next attempt TimedAttemptSettings. This method will return first non-null value, returned by either result or timed retry algorithms in that particular order.
        Parameters:
        previousThrowable - exception thrown by the previous attempt or null if a result was returned instead
        previousResponse - response returned by the previous attempt or null if an exception was thrown instead
        previousSettings - previous attempt settings
        Returns:
        next attempt settings, can be null, if no there should be no new attempt
      • createNextAttempt

        public TimedAttemptSettings createNextAttempt​(RetryingContext context,
                                                      java.lang.Throwable previousThrowable,
                                                      ResponseT previousResponse,
                                                      TimedAttemptSettings previousSettings)
        Creates a next attempt TimedAttemptSettings. This method will return first non-null value, returned by either result or timed retry algorithms in that particular order.
        Parameters:
        context - the RetryingContext that can be used to determine the RetrySettings for the next attempt
        previousThrowable - exception thrown by the previous attempt or null if a result was returned instead
        previousResponse - response returned by the previous attempt or null if an exception was thrown instead
        previousSettings - previous attempt settings
        Returns:
        next attempt settings, can be null, if there should be no new attempt
      • shouldRetry

        @Deprecated
        public boolean shouldRetry​(java.lang.Throwable previousThrowable,
                                   ResponseT previousResponse,
                                   TimedAttemptSettings nextAttemptSettings)
                            throws java.util.concurrent.CancellationException
        Returns true if another attempt should be made, or false otherwise.
        Parameters:
        previousThrowable - exception thrown by the previous attempt or null if a result was returned instead
        previousResponse - response returned by the previous attempt or null if an exception was thrown instead
        nextAttemptSettings - attempt settings, which will be used for the next attempt, if accepted
        Returns:
        true if another attempt should be made, or false otherwise
        Throws:
        java.util.concurrent.CancellationException - if the retrying process should be canceled
      • shouldRetry

        public boolean shouldRetry​(RetryingContext context,
                                   java.lang.Throwable previousThrowable,
                                   ResponseT previousResponse,
                                   TimedAttemptSettings nextAttemptSettings)
                            throws java.util.concurrent.CancellationException
        Returns true if another attempt should be made, or false otherwise.
        Parameters:
        context - the RetryingContext that can be used to determine whether another attempt should be made
        previousThrowable - exception thrown by the previous attempt or null if a result was returned instead
        previousResponse - response returned by the previous attempt or null if an exception was thrown instead
        nextAttemptSettings - attempt settings, which will be used for the next attempt, if accepted
        Returns:
        true if another attempt should be made, or false otherwise
        Throws:
        java.util.concurrent.CancellationException - if the retrying process should be cancelled
      • getResultAlgorithm

        @BetaApi("Surface for inspecting the a RetryAlgorithm is not yet stable")
        public ResultRetryAlgorithm<ResponseT> getResultAlgorithm()
      • getTimedAlgorithm

        @BetaApi("Surface for inspecting the a RetryAlgorithm is not yet stable")
        public TimedRetryAlgorithm getTimedAlgorithm()