Class RetryableStageHelper
- java.lang.Object
-
- software.amazon.awssdk.core.internal.http.pipeline.stages.utils.RetryableStageHelper
-
public class RetryableStageHelper extends Object
Contains the logic shared byRetryableStageandAsyncRetryableStagewhen querying and interacting with aRetryPolicy.
-
-
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, RateLimitingTokenBucket rateLimitingTokenBucket, HttpClientDependencies dependencies)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.voidattemptSucceeded()Notify the retry policy that the request attempt succeeded.intgetAttemptNumber()Retrieve the current attempt number, updated wheneverstartingAttempt()is invoked.DurationgetBackoffDelay()Get the amount of time that the request should be delayed before being sent.SdkExceptiongetLastException()Retrieve the last call failure exception encountered by this execution, updated wheneversetLastException(java.lang.Throwable)is invoked.voidgetSendToken()Acquire a send token from the rate limiter.OptionalDoublegetSendTokenNonBlocking()Acquire a send token from the rate limiter in a non blocking manner.booleanisFastFailRateLimiting()Whether rate limiting should fast fail.booleanisLastExceptionThrottlingException()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.SdkHttpFullRequestrequestToSend()Retrieve the request to send to the service, including any detailed retry information headers.booleanretryPolicyAllowsRetry()Returns true if the retry policy allows this attempt.SdkExceptionretryPolicyDisallowedRetryException()Return the exception that should be thrown, because the retry policy 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.voidupdateClientSendingRateForErrorResponse()Conditionally updates the sending rate of the rate limiter when an error response is received.voidupdateClientSendingRateForSuccessResponse()Conditionally updates the sending rate of the rate limiter when an error response is received.
-
-
-
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, RateLimitingTokenBucket rateLimitingTokenBucket, HttpClientDependencies dependencies)
-
-
Method Detail
-
startingAttempt
public void startingAttempt()
Invoke when starting a request attempt, before querying the retry policy.
-
retryPolicyAllowsRetry
public boolean retryPolicyAllowsRetry()
Returns true if the retry policy allows this attempt. This will always return true if the current attempt is not a retry (i.e. it's the first request in the execution).
-
retryPolicyDisallowedRetryException
public SdkException retryPolicyDisallowedRetryException()
Return the exception that should be thrown, because the retry policy did not allow the request to be retried.
-
getBackoffDelay
public Duration getBackoffDelay()
Get the amount of time that the request should be delayed before being sent. This may beDuration.ZERO, such as for the first request in the request series.
-
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.
-
attemptSucceeded
public void attemptSucceeded()
Notify the retry policy that the request attempt succeeded.
-
getAttemptNumber
public int getAttemptNumber()
Retrieve the current attempt number, updated wheneverstartingAttempt()is invoked.
-
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.
-
isFastFailRateLimiting
public boolean isFastFailRateLimiting()
Whether rate limiting should fast fail.
-
isLastExceptionThrottlingException
public boolean isLastExceptionThrottlingException()
-
getSendToken
public void getSendToken()
Acquire a send token from the rate limiter. Returns immediately if rate limiting is not enabled.
-
getSendTokenNonBlocking
public OptionalDouble getSendTokenNonBlocking()
Acquire a send token from the rate limiter in a non blocking manner. SeeRateLimitingTokenBucket.acquireNonBlocking(double, boolean)for documentation on how to interpret the returned value.
-
updateClientSendingRateForErrorResponse
public void updateClientSendingRateForErrorResponse()
Conditionally updates the sending rate of the rate limiter when an error response is received. This operation is a noop if rate limiting is not enabled.
-
updateClientSendingRateForSuccessResponse
public void updateClientSendingRateForSuccessResponse()
Conditionally updates the sending rate of the rate limiter when an error response is received. This operation is a noop if rate limiting is not enabled.
-
-