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
Nested ClassesModifier and TypeClassDescriptionstatic final classConfigure and create aTokenBucketRetryCondition.static final classThe 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 TokenBucketRetryConditioncreate()Create a condition using theRetryMode.defaultRetryMode().booleanstatic TokenBucketRetryConditionforRetryMode(RetryMode retryMode) Create a condition using the configuredRetryMode.getCapacityForExecution(ExecutionAttributes attributes) IfshouldRetry(RetryPolicyContext)returned true for the provided execution, this method returns theTokenBucketRetryCondition.Capacityconsumed by the request.inthashCode()voidrequestSucceeded(RetryPolicyContext context) Called by the SDK to notify this condition that the provided request succeeded.voidCalled 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.booleanshouldRetry(RetryPolicyContext context) Determine whether a request should or should not be retried.intRetrieve 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.LEGACYdoes not subtract tokens from the token bucket when throttling exceptions are encountered. TheRetryMode.STANDARDtreats 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.Capacityconsumed 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:RetryConditionDetermine whether a request should or should not be retried.- Specified by:
shouldRetryin 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:RetryConditionCalled 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:
requestWillNotBeRetriedin interfaceRetryCondition
-
requestSucceeded
Description copied from interface:RetryConditionCalled 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:
requestSucceededin interfaceRetryCondition
-
toString
-
equals
-
hashCode
-