Class RetryableStageHelper


  • public final class RetryableStageHelper
    extends Object
    Contains the logic shared by RetryableStage and AsyncRetryableStage when querying and interacting with a RetryStrategy.
    • Method Detail

      • startingAttempt

        public void startingAttempt()
        Invoke when starting a request attempt, before querying the retry policy.
      • acquireInitialToken

        public Duration acquireInitialToken()
        Invoke when starting the first attempt. This method will acquire the initial token and store it as an execution attribute. This method returns a delay that the caller have to wait before attempting the first request. If this method returns Duration.ZERO if the calling code does not have to wait. As of today the only strategy that might return a non-zero value is AdaptiveRetryStrategy.
      • recordAttemptSucceeded

        public void recordAttemptSucceeded()
        Notify the retry strategy that the request attempt succeeded.
      • tryRefreshToken

        public Optional<Duration> tryRefreshToken​(Duration suggestedDelay)
        Invoked after a failed attempt and before retrying. The returned optional will be non-empty if the client can retry or empty if the retry-strategy disallows the retry. The calling code is expected to wait the delay represented in the duration if present before retrying the request.
        Parameters:
        suggestedDelay - A suggested delay, presumably coming from the server response. The response when present will be at least this amount.
        Returns:
        An optional time to wait. If the value is not present the retry strategy disallowed the retry and the calling code should not retry.
      • retryPolicyDisallowedRetryException

        public SdkException retryPolicyDisallowedRetryException()
        Return the exception that should be thrown, because the retry strategy did not allow the request to be retried.
      • logBackingOff

        public void logBackingOff​(Duration backoffDelay)
        Log a message to the user at the debug level to indicate how long we will wait before retrying the request.
      • requestToSend

        public SdkHttpFullRequest requestToSend()
        Retrieve the request to send to the service, including any detailed retry information headers.
      • logSendingRequest

        public void logSendingRequest()
        Log a message to the user at the debug level to indicate that we are sending the request to the service.
      • adjustClockIfClockSkew

        public void adjustClockIfClockSkew​(Response<?> response)
        Adjust the client-side clock skew if the provided response indicates that there is a large skew between the client and service. This will allow a retried request to be signed with what is likely to be a more accurate time.
      • setLastException

        public void setLastException​(Throwable lastException)
        Update the getLastException() value for this helper. This will be used to determine whether the request should be retried.
      • setLastResponse

        public void setLastResponse​(SdkHttpResponse lastResponse)
        Set the last HTTP response returned by the service. This will be used to determine whether the request should be retried.
      • getAttemptNumber

        public int getAttemptNumber()
        Retrieve the current attempt number, updated whenever startingAttempt() is invoked.