Interface RetryStrategy
- All Superinterfaces:
AutoCloseable,SdkAutoCloseable
We do not recommend SDK users create their own retry strategies. We recommend refining an existing strategy:
- If you are using the strategy with a service, you can get the existing strategy
from that service via
[ServiceName]Client.defaults().retryStrategy(). RetryStrategiesfrom thesoftware.amazon.awssdk:retriesmodule.
Terminology:
- An attempt is a single invocation of an action.
- The attempt count is which attempt (starting with 1) the SDK is attempting to make.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceRetryStrategy.Builder<B extends RetryStrategy.Builder<B,T>, T extends RetryStrategy> Builder to create immutable instances ofRetryStrategy. -
Method Summary
Modifier and TypeMethodDescriptionAcquire a retry token synchronously.Acquire a retry token asynchronously.default voidclose()intReturns the maximum numbers attempts that this retry policy will allow.recordSuccess(RecordSuccessRequest request) Invoked after an attempt succeeds.Refresh a retry token synchronously.Refresh a retry token asynchronously.Create a newRetryStrategy.Builderwith the current configuration.default booleanReturns whether the retry strategy uses default retry predicates.
-
Method Details
-
acquireInitialToken
Acquire a retry token synchronously. Invoked before the first request attempt.Callers MUST wait for the
delayreturned by this call before making the first attempt. Callers that wish to retry a failed attempt MUST callrefreshRetryToken(software.amazon.awssdk.retries.api.RefreshRetryTokenRequest)before doing so.If the attempt was successful, callers MUST call
recordSuccess(software.amazon.awssdk.retries.api.RecordSuccessRequest).- Throws:
NullPointerException- if a required parameter is not specifiedTokenAcquisitionFailedException- if a token cannot be acquired
-
acquireInitialTokenAsync
default CompletableFuture<AcquireInitialTokenResponse> acquireInitialTokenAsync(AcquireInitialTokenRequest request) Acquire a retry token asynchronously. Invoked before the first request attempt.Callers MUST wait for the
delayreturned by this call before making the first attempt. Callers that wish to retry a failed attempt MUST callrefreshRetryToken(software.amazon.awssdk.retries.api.RefreshRetryTokenRequest)before doing so.If the attempt was successful, callers MUST call
recordSuccess(software.amazon.awssdk.retries.api.RecordSuccessRequest).The future is completed exceptionally with
NullPointerExceptionif a required parameter isnull.The future is completed exceptionally with
TokenAcquisitionFailedExceptionif a token cannot be acquired. -
refreshRetryToken
Refresh a retry token synchronously. Invoked before each subsequent (non-first) request attempt.Callers MUST wait for the
delayreturned by this call before making the next attempt. If the next attempt fails, callers MUST re-callrefreshRetryToken(software.amazon.awssdk.retries.api.RefreshRetryTokenRequest)before attempting another retry. This call invalidates the provided token, and returns a new one. Callers MUST use the new token.If the attempt was successful, callers MUST call
recordSuccess(software.amazon.awssdk.retries.api.RecordSuccessRequest).- Throws:
NullPointerException- if a required parameter is not specifiedIllegalArgumentException- if the provided token was not issued by this strategy or the provided token was already used for a previous refresh or success call.TokenAcquisitionFailedException- if a token cannot be acquired
-
refreshRetryTokenAsync
default CompletableFuture<RefreshRetryTokenResponse> refreshRetryTokenAsync(RefreshRetryTokenRequest request) Refresh a retry token asynchronously. Invoked before each subsequent (non-first) request attempt.Callers MUST wait for the
delayreturned by this call before making the next attempt. If the next attempt fails, callers MUST re-callrefreshRetryToken(software.amazon.awssdk.retries.api.RefreshRetryTokenRequest)before attempting another retry. This call invalidates the provided token, and returns a new one. Callers MUST use the new token.If the attempt was successful, callers MUST call
recordSuccess(software.amazon.awssdk.retries.api.RecordSuccessRequest).The future is completed exceptionally with
NullPointerExceptionif a required parameter is not specified.The future is completed exceptionally with
IllegalArgumentExceptionif the provided token was not issued by this strategy or the provided token was already used for a previous refresh or success call.The future is completed exceptionally with
TokenAcquisitionFailedExceptionif a token cannot be acquired. -
recordSuccess
Invoked after an attempt succeeds.- Throws:
NullPointerException- if a required parameter is not specifiedIllegalArgumentException- if the provided token was not issued by this strategy or the provided token was already used for a previous refresh or success call.
-
maxAttempts
int maxAttempts()Returns the maximum numbers attempts that this retry policy will allow.- Returns:
- the maximum numbers attempts that this retry policy will allow.
-
useClientDefaults
default boolean useClientDefaults()Returns whether the retry strategy uses default retry predicates.- Returns:
- true if this retry strategy should use the default retry predicates, false otherwise.
-
toBuilder
RetryStrategy.Builder<?,?> toBuilder()Create a newRetryStrategy.Builderwith the current configuration.This is useful for modifying the strategy's behavior, like conditions or max retries.
-
close
default void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceSdkAutoCloseable
-