Class RetryableStageHelper
- java.lang.Object
-
- software.amazon.awssdk.core.internal.http.pipeline.stages.utils.RetryableStageHelper
-
public final class RetryableStageHelper extends Object
Contains the logic shared byRetryableStageandAsyncRetryableStagewhen querying and interacting with aRetryStrategy.
-
-
Field Summary
Fields Modifier and Type Field Description static ExecutionAttribute<Duration>LAST_BACKOFF_DELAY_DURATIONstatic StringSDK_RETRY_INFO_HEADER
-
Constructor Summary
Constructors Constructor Description RetryableStageHelper(SdkHttpFullRequest request, RequestExecutionContext context, HttpClientDependencies dependencies)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DurationacquireInitialToken()Invoke when starting the first attempt.voidadjustClockIfClockSkew(Response<?> response)Adjust the client-side clock skew if the provided response indicates that there is a large skew between the client and service.intgetAttemptNumber()Retrieve the current attempt number, updated wheneverstartingAttempt()is invoked.SdkExceptiongetLastException()Retrieve the last call failure exception encountered by this execution, updated wheneversetLastException(java.lang.Throwable)is invoked.voidlogBackingOff(Duration backoffDelay)Log a message to the user at the debug level to indicate how long we will wait before retrying the request.voidlogSendingRequest()Log a message to the user at the debug level to indicate that we are sending the request to the service.voidrecordAttemptSucceeded()Notify the retry strategy that the request attempt succeeded.SdkHttpFullRequestrequestToSend()Retrieve the request to send to the service, including any detailed retry information headers.SdkExceptionretryPolicyDisallowedRetryException()Return the exception that should be thrown, because the retry strategy did not allow the request to be retried.voidsetLastException(Throwable lastException)Update thegetLastException()value for this helper.voidsetLastResponse(SdkHttpResponse lastResponse)Set the last HTTP response returned by the service.voidstartingAttempt()Invoke when starting a request attempt, before querying the retry policy.Optional<Duration>tryRefreshToken(Duration suggestedDelay)Invoked after a failed attempt and before retrying.
-
-
-
Field Detail
-
SDK_RETRY_INFO_HEADER
public static final String SDK_RETRY_INFO_HEADER
- See Also:
- Constant Field Values
-
LAST_BACKOFF_DELAY_DURATION
public static final ExecutionAttribute<Duration> LAST_BACKOFF_DELAY_DURATION
-
-
Constructor Detail
-
RetryableStageHelper
public RetryableStageHelper(SdkHttpFullRequest request, RequestExecutionContext context, HttpClientDependencies dependencies)
-
-
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 returnsDuration.ZEROif the calling code does not have to wait. As of today the only strategy that might return a non-zero value isAdaptiveRetryStrategy.
-
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.
-
getLastException
public SdkException getLastException()
Retrieve the last call failure exception encountered by this execution, updated wheneversetLastException(java.lang.Throwable)is invoked.
-
setLastException
public void setLastException(Throwable lastException)
Update thegetLastException()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 wheneverstartingAttempt()is invoked.
-
-