From a23b2a24b99d10e05227df45112ae54228aa7f83 Mon Sep 17 00:00:00 2001 From: Dongie Agnir Date: Tue, 14 Jul 2026 11:09:26 -0700 Subject: [PATCH] Update RetryStrategy interface Add acquireInitialTokenAsync and refreshRetryTokenAsync methods to RetryStrategy interface to better support asynchronous workflows. --- .../awssdk/retries/api/RetryStrategy.java | 47 +++++++++++++++++-- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/core/retries-spi/src/main/java/software/amazon/awssdk/retries/api/RetryStrategy.java b/core/retries-spi/src/main/java/software/amazon/awssdk/retries/api/RetryStrategy.java index 491bab172e65..c7c89a26a0df 100644 --- a/core/retries-spi/src/main/java/software/amazon/awssdk/retries/api/RetryStrategy.java +++ b/core/retries-spi/src/main/java/software/amazon/awssdk/retries/api/RetryStrategy.java @@ -15,9 +15,11 @@ package software.amazon.awssdk.retries.api; +import java.util.concurrent.CompletableFuture; import java.util.function.Predicate; import software.amazon.awssdk.annotations.SdkPublicApi; import software.amazon.awssdk.annotations.ThreadSafe; +import software.amazon.awssdk.utils.SdkAutoCloseable; import software.amazon.awssdk.utils.builder.SdkBuilder; /** @@ -40,9 +42,9 @@ */ @ThreadSafe @SdkPublicApi -public interface RetryStrategy { +public interface RetryStrategy extends SdkAutoCloseable { /** - * Invoked before the first request attempt. + * Acquire a retry token synchronously. Invoked before the first request attempt. * *

Callers MUST wait for the {@code delay} returned by this call before making the first attempt. Callers that wish to * retry a failed attempt MUST call {@link #refreshRetryToken} before doing so. @@ -55,7 +57,23 @@ public interface RetryStrategy { AcquireInitialTokenResponse acquireInitialToken(AcquireInitialTokenRequest request); /** - * Invoked before each subsequent (non-first) request attempt. + * Acquire a retry token asynchronously. Invoked before the first request attempt. + * + *

Callers MUST wait for the {@code delay} returned by this call before making the first attempt. Callers that wish to + * retry a failed attempt MUST call {@link #refreshRetryToken} before doing so. + * + *

If the attempt was successful, callers MUST call {@link #recordSuccess}. + * + *

The future is completed exceptionally with {@link NullPointerException} if a required parameter is {@code null}. + *

The future is completed exceptionally with {@link TokenAcquisitionFailedException} if a token cannot be acquired. + */ + default CompletableFuture acquireInitialTokenAsync(AcquireInitialTokenRequest request) { + AcquireInitialTokenResponse response = acquireInitialToken(request); + return CompletableFuture.completedFuture(response); + } + + /** + * Refresh a retry token synchronously. Invoked before each subsequent (non-first) request attempt. * *

Callers MUST wait for the {@code delay} returned by this call before making the next attempt. If the next attempt * fails, callers MUST re-call {@link #refreshRetryToken} before attempting another retry. This call invalidates the provided @@ -70,6 +88,25 @@ public interface RetryStrategy { */ RefreshRetryTokenResponse refreshRetryToken(RefreshRetryTokenRequest request); + /** + * Refresh a retry token asynchronously. Invoked before each subsequent (non-first) request attempt. + * + *

Callers MUST wait for the {@code delay} returned by this call before making the next attempt. If the next attempt + * fails, callers MUST re-call {@link #refreshRetryToken} 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 {@link #recordSuccess}. + * + *

The future is completed exceptionally with {@link NullPointerException} if a required parameter is not specified. + *

The future is completed exceptionally with {@link IllegalArgumentException} if 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 {@link TokenAcquisitionFailedException} if a token cannot be acquired. + */ + default CompletableFuture refreshRetryTokenAsync(RefreshRetryTokenRequest request) { + RefreshRetryTokenResponse response = refreshRetryToken(request); + return CompletableFuture.completedFuture(response); + } + /** * Invoked after an attempt succeeds. * @@ -102,6 +139,10 @@ default boolean useClientDefaults() { */ Builder toBuilder(); + @Override + default void close() { + } + /** * Builder to create immutable instances of {@link RetryStrategy}. */