Class TokenBucketRetryCondition
java.lang.Object
software.amazon.awssdk.core.retry.conditions.TokenBucketRetryCondition
- All Implemented Interfaces:
RetryCondition
A
RetryCondition
that limits the number of retries made by the SDK using a token bucket algorithm. "Tokens" are
acquired from the bucket whenever shouldRetry(software.amazon.awssdk.core.retry.RetryPolicyContext)
returns true, and are released to the bucket whenever
requestSucceeded(software.amazon.awssdk.core.retry.RetryPolicyContext)
or requestWillNotBeRetried(software.amazon.awssdk.core.retry.RetryPolicyContext)
are invoked.
If "tokens" cannot be acquired from the bucket, it means too many requests have failed and the request will not be allowed
to retry until we start to see initial non-retried requests succeed via requestSucceeded(RetryPolicyContext)
.
This prevents the client from holding the calling thread to retry when it's likely that it will fail anyway.
This is currently included in the default RetryPolicy.aggregateRetryCondition()
, but can be disabled by setting the
RetryPolicy.Builder.retryCapacityCondition(software.amazon.awssdk.core.retry.conditions.RetryCondition)
to null.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
Configure and create aTokenBucketRetryCondition
.static final class
The number of tokens in the token bucket after a specific token acquisition succeeds. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()
Create a builder that allows fine-grained control over the token policy of this condition.static TokenBucketRetryCondition
create()
Create a condition using theRetryMode.defaultRetryMode()
.boolean
static TokenBucketRetryCondition
forRetryMode
(RetryMode retryMode) Create a condition using the configuredRetryMode
.getCapacityForExecution
(ExecutionAttributes attributes) IfshouldRetry(RetryPolicyContext)
returned true for the provided execution, this method returns theTokenBucketRetryCondition.Capacity
consumed by the request.int
hashCode()
void
requestSucceeded
(RetryPolicyContext context) Called by the SDK to notify this condition that the provided request succeeded.void
Called by the SDK to notify this condition that the provided request will not be retried, because some retry condition determined that it shouldn't be retried.boolean
shouldRetry
(RetryPolicyContext context) Determine whether a request should or should not be retried.int
Retrieve the number of tokens currently available in the token bucket.toString()
-
Method Details
-
create
Create a condition using theRetryMode.defaultRetryMode()
. This is equivalent toforRetryMode(RetryMode.defaultRetryMode())
.For more detailed control, see
builder()
. -
forRetryMode
Create a condition using the configuredRetryMode
. TheRetryMode.LEGACY
does not subtract tokens from the token bucket when throttling exceptions are encountered. TheRetryMode.STANDARD
treats throttling and non- throttling exceptions as the same cost.For more detailed control, see
builder()
. -
builder
Create a builder that allows fine-grained control over the token policy of this condition. -
getCapacityForExecution
public static Optional<TokenBucketRetryCondition.Capacity> getCapacityForExecution(ExecutionAttributes attributes) IfshouldRetry(RetryPolicyContext)
returned true for the provided execution, this method returns theTokenBucketRetryCondition.Capacity
consumed by the request. -
tokensAvailable
public int tokensAvailable()Retrieve the number of tokens currently available in the token bucket. This is a volatile snapshot of the current value. SeegetCapacityForExecution(ExecutionAttributes)
to see how much capacity was left in the bucket after a specific execution was considered. -
shouldRetry
Description copied from interface:RetryCondition
Determine whether a request should or should not be retried.- Specified by:
shouldRetry
in interfaceRetryCondition
- Parameters:
context
- Context about the state of the last request and information about the number of requests made.- Returns:
- True if the request should be retried, false if not.
-
requestWillNotBeRetried
Description copied from interface:RetryCondition
Called by the SDK to notify this condition that the provided request will not be retried, because some retry condition determined that it shouldn't be retried.- Specified by:
requestWillNotBeRetried
in interfaceRetryCondition
-
requestSucceeded
Description copied from interface:RetryCondition
Called by the SDK to notify this condition that the provided request succeeded. This method is invoked even if the execution never failed before (RetryPolicyContext.retriesAttempted()
is zero).- Specified by:
requestSucceeded
in interfaceRetryCondition
-
toString
-
equals
-
hashCode
public int hashCode()
-