Class RetryableStageHelper
- java.lang.Object
-
- software.amazon.awssdk.core.internal.http.pipeline.stages.utils.RetryableStageHelper
-
public class RetryableStageHelper extends Object
Contains the logic shared byRetryableStage
andAsyncRetryableStage
when querying and interacting with aRetryPolicy
.
-
-
Field Summary
Fields Modifier and Type Field Description static ExecutionAttribute<Duration>
LAST_BACKOFF_DELAY_DURATION
static String
SDK_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 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.void
attemptSucceeded()
Notify the retry policy that the request attempt succeeded.int
getAttemptNumber()
Retrieve the current attempt number, updated wheneverstartingAttempt()
is invoked.Duration
getBackoffDelay()
Get the amount of time that the request should be delayed before being sent.SdkException
getLastException()
Retrieve the last call failure exception encountered by this execution, updated wheneversetLastException(java.lang.Throwable)
is invoked.void
getSendToken()
Acquire a send token from the rate limiter.OptionalDouble
getSendTokenNonBlocking()
Acquire a send token from the rate limiter in a non blocking manner.boolean
isFastFailRateLimiting()
Whether rate limiting should fast fail.boolean
isLastExceptionThrottlingException()
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.void
logSendingRequest()
Log a message to the user at the debug level to indicate that we are sending the request to the service.SdkHttpFullRequest
requestToSend()
Retrieve the request to send to the service, including any detailed retry information headers.boolean
retryPolicyAllowsRetry()
Returns true if the retry policy allows this attempt.SdkException
retryPolicyDisallowedRetryException()
Return the exception that should be thrown, because the retry policy did not allow the request to be retried.void
setLastException(Throwable lastException)
Update thegetLastException()
value for this helper.void
setLastResponse(SdkHttpResponse lastResponse)
Set the last HTTP response returned by the service.void
startingAttempt()
Invoke when starting a request attempt, before querying the retry policy.void
updateClientSendingRateForErrorResponse()
Conditionally updates the sending rate of the rate limiter when an error response is received.void
updateClientSendingRateForSuccessResponse()
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.
-
-