1515
1616package software .amazon .awssdk .retries .api ;
1717
18+ import java .util .concurrent .CompletableFuture ;
1819import java .util .function .Predicate ;
1920import software .amazon .awssdk .annotations .SdkPublicApi ;
2021import software .amazon .awssdk .annotations .ThreadSafe ;
22+ import software .amazon .awssdk .utils .SdkAutoCloseable ;
2123import software .amazon .awssdk .utils .builder .SdkBuilder ;
2224
2325/**
4042 */
4143@ ThreadSafe
4244@ SdkPublicApi
43- public interface RetryStrategy {
45+ public interface RetryStrategy extends SdkAutoCloseable {
4446 /**
45- * Invoked before the first request attempt.
47+ * Acquire a retry token synchronously. Invoked before the first request attempt.
4648 *
4749 * <p>Callers MUST wait for the {@code delay} returned by this call before making the first attempt. Callers that wish to
4850 * retry a failed attempt MUST call {@link #refreshRetryToken} before doing so.
@@ -55,7 +57,23 @@ public interface RetryStrategy {
5557 AcquireInitialTokenResponse acquireInitialToken (AcquireInitialTokenRequest request );
5658
5759 /**
58- * Invoked before each subsequent (non-first) request attempt.
60+ * Acquire a retry token asynchronously. Invoked before the first request attempt.
61+ *
62+ * <p>Callers MUST wait for the {@code delay} returned by this call before making the first attempt. Callers that wish to
63+ * retry a failed attempt MUST call {@link #refreshRetryToken} before doing so.
64+ *
65+ * <p>If the attempt was successful, callers MUST call {@link #recordSuccess}.
66+ *
67+ * <p>The future is completed exceptionally with {@link NullPointerException} if a required parameter is {@code null}.
68+ * <p>The future is completed exceptionally with {@link TokenAcquisitionFailedException} if a token cannot be acquired.
69+ */
70+ default CompletableFuture <AcquireInitialTokenResponse > acquireInitialTokenAsync (AcquireInitialTokenRequest request ) {
71+ AcquireInitialTokenResponse response = acquireInitialToken (request );
72+ return CompletableFuture .completedFuture (response );
73+ }
74+
75+ /**
76+ * Refresh a retry token synchronously. Invoked before each subsequent (non-first) request attempt.
5977 *
6078 * <p>Callers MUST wait for the {@code delay} returned by this call before making the next attempt. If the next attempt
6179 * fails, callers MUST re-call {@link #refreshRetryToken} before attempting another retry. This call invalidates the provided
@@ -70,6 +88,25 @@ public interface RetryStrategy {
7088 */
7189 RefreshRetryTokenResponse refreshRetryToken (RefreshRetryTokenRequest request );
7290
91+ /**
92+ * Refresh a retry token asynchronously. Invoked before each subsequent (non-first) request attempt.
93+ *
94+ * <p>Callers MUST wait for the {@code delay} returned by this call before making the next attempt. If the next attempt
95+ * fails, callers MUST re-call {@link #refreshRetryToken} before attempting another retry. This call invalidates the provided
96+ * token, and returns a new one. Callers MUST use the new token.
97+ *
98+ * <p>If the attempt was successful, callers MUST call {@link #recordSuccess}.
99+ *
100+ * <p>The future is completed exceptionally with {@link NullPointerException} if a required parameter is not specified.
101+ * <p>The future is completed exceptionally with {@link IllegalArgumentException} if the provided token was not issued by
102+ * this strategy or the provided token was already used for a previous refresh or success call.
103+ * <p>The future is completed exceptionally with {@link TokenAcquisitionFailedException} if a token cannot be acquired.
104+ */
105+ default CompletableFuture <RefreshRetryTokenResponse > refreshRetryTokenAsync (RefreshRetryTokenRequest request ) {
106+ RefreshRetryTokenResponse response = refreshRetryToken (request );
107+ return CompletableFuture .completedFuture (response );
108+ }
109+
73110 /**
74111 * Invoked after an attempt succeeds.
75112 *
@@ -102,6 +139,10 @@ default boolean useClientDefaults() {
102139 */
103140 Builder <?, ?> toBuilder ();
104141
142+ @ Override
143+ default void close () {
144+ }
145+
105146 /**
106147 * Builder to create immutable instances of {@link RetryStrategy}.
107148 */
0 commit comments