Class StreamingRetryAlgorithm<ResponseT>


  • @InternalApi("For internal use only")
    public final class StreamingRetryAlgorithm<ResponseT>
    extends RetryAlgorithm<ResponseT>
    The streaming retry algorithm, which makes decision based either on the thrown exception and the execution time settings of the previous attempt. This extends RetryAlgorithm to take additional information (provided by ServerStreamingAttemptCallable) into account.

    This class is thread-safe.

    Internal use only - public for technical reasons.

    • Method Detail

      • createNextAttempt

        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.

        The attempt settings will be reset if the stream attempt produced any messages.

        Overrides:
        createNextAttempt in class RetryAlgorithm<ResponseT>
        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.

        The attempt settings will be reset if the stream attempt produced any messages.

        Overrides:
        createNextAttempt in class RetryAlgorithm<ResponseT>
        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

        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.

        Ensures retries are only scheduled if the StreamResumptionStrategy in the ServerStreamingAttemptCallable supports it.

        Overrides:
        shouldRetry in class RetryAlgorithm<ResponseT>
        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.

        Schedules retries only if the StreamResumptionStrategy in the ServerStreamingAttemptCallable supports it.

        Overrides:
        shouldRetry in class RetryAlgorithm<ResponseT>
        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