Skip to content

Commit 07cf6e0

Browse files
committed
Fix javadocs, add more tests, remove unncessary methods
1 parent ead3b78 commit 07cf6e0

File tree

12 files changed

+131
-70
lines changed

12 files changed

+131
-70
lines changed

codegen/src/main/java/software/amazon/awssdk/codegen/docs/WaiterDocs.java

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,21 @@ public static String waiterInterfaceJavadoc() {
3636

3737
public static CodeBlock waiterOperationJavadoc(ClassName className, Map.Entry<String, WaiterDefinition> waiterDefinition,
3838
OperationModel operationModel) {
39+
String returnStatement = "WaiterResponse containing either a response or an exception that has matched with the waiter "
40+
+ "success condition";
41+
42+
String asyncReturnStatement = "CompletableFuture containing the WaiterResponse. It completes successfully when the "
43+
+ "resource enters into a desired state or exceptionally when it is determined that the "
44+
+ "resource will never enter into the desired state.";
3945
String javadocs = new DocumentationBuilder().description("Polls {@link $T#$N} API until the desired condition "
4046
+ "{@code $N} is met, "
4147
+ "or until it is determined that the resource will never "
4248
+ "enter into the desired state")
4349
.param(operationModel.getInput().getVariableName(), "the request to be used"
4450
+ " for polling")
4551
.returns(className.simpleName().contains("Async") ?
46-
"CompletableFuture of the WaiterResponse containing either a "
47-
+ "response or an exception that has matched with the waiter "
48-
+ "success condition"
49-
: "WaiterResponse containing either a response or an exception that"
50-
+ " has matched with the waiter success condition")
52+
asyncReturnStatement :
53+
returnStatement)
5154
.build();
5255
return CodeBlock.builder()
5356
.add(javadocs, className, operationModel.getMethodName(), waiterDefinition.getKey())
@@ -65,7 +68,7 @@ public static CodeBlock waiterOperationConsumerBuilderJavadoc(ClassName clientCl
6568
+ "enter into the desired state. \n "
6669
+ "<p>This is a convenience method to create an instance of "
6770
+ "the request builder without the need "
68-
+ "to create one manually using {@link $T.builder()} ")
71+
+ "to create one manually using {@link $T#builder()} ")
6972
.param(operationModel.getInput().getVariableName(), "The consumer that will"
7073
+ " configure the "
7174
+ "request to be used"
@@ -94,14 +97,18 @@ public static CodeBlock waiterBuilderMethodJavadoc(ClassName className) {
9497
.build();
9598
}
9699

97-
public static CodeBlock waiterCreateMethodJavadoc(ClassName className) {
100+
public static CodeBlock waiterCreateMethodJavadoc(ClassName waiterClassName, ClassName clientClassName) {
98101
String javadocs = new DocumentationBuilder()
99-
.description("Create an instance of {@link $T} with the default configuration")
102+
.description("Create an instance of {@link $T} with the default configuration. \n"
103+
+ "<p><b>A default {@link $T} will be created to poll resources. It is recommended "
104+
+ "to share a single instance of the waiter created via this method. If it is not desirable "
105+
+ "to share a waiter instance, invoke {@link #close()} to release the resources once the waiter"
106+
+ " is not needed.</b>")
100107
.returns("an instance of {@link $T}")
101108
.build();
102109

103110
return CodeBlock.builder()
104-
.add(javadocs, className, className)
111+
.add(javadocs, waiterClassName, clientClassName, waiterClassName)
105112
.build();
106113
}
107114

@@ -121,7 +128,7 @@ public static CodeBlock waiterBuilderPollingStrategy() {
121128
public static CodeBlock waiterBuilderPollingStrategyConsumerBuilder() {
122129
String javadocs = new DocumentationBuilder()
123130
.description("This is a convenient method to pass the override configuration without the need to "
124-
+ "create an instance manually via {@link $T.builder()}")
131+
+ "create an instance manually via {@link $T#builder()}")
125132
.param("overrideConfiguration", "The consumer that will configure the overrideConfiguration")
126133
.see("#overrideConfiguration(WaiterOverrideConfiguration)")
127134
.returns("a reference to this object so that method calls can be chained together.")
@@ -149,7 +156,7 @@ public static CodeBlock waiterBuilderScheduledExecutorServiceJavadoc() {
149156
public static CodeBlock waiterBuilderClientJavadoc(ClassName className) {
150157
String javadocs = new DocumentationBuilder()
151158
.description("Defines the {@link $T} to use when polling a resource")
152-
.description("Sets a custom {@link $T} that will be used to pool the resource \n "
159+
.description("Sets a custom {@link $T} that will be used to poll the resource \n "
153160
+ "<p> This SDK client must be closed by the caller when it is ready to be disposed. The"
154161
+ " SDK will not close the client when the waiter is closed")
155162
.param("client", "the client to send the request")
@@ -216,4 +223,18 @@ public static CodeBlock waiterOperationWithOverrideConfig(ClassName clientClassN
216223
.add(javadocs, clientClassName, opModel.getMethodName(), waiterDefinition.getKey())
217224
.build();
218225
}
226+
227+
public static CodeBlock waiterMethodInClient(ClassName waiterClassName) {
228+
String javadocs = new DocumentationBuilder()
229+
.description("Create an instance of {@link $T} using this client. \n"
230+
+ "<p>Waiters created via this method are managed by the SDK and resources will be released "
231+
+ "when the service client is closed.")
232+
.returns("an instance of {@link $T}")
233+
.build();
234+
235+
return CodeBlock.builder()
236+
.add(javadocs, waiterClassName, waiterClassName)
237+
.build();
238+
}
239+
219240
}

codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/AsyncClientInterface.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import software.amazon.awssdk.codegen.docs.ClientType;
3737
import software.amazon.awssdk.codegen.docs.DocConfiguration;
3838
import software.amazon.awssdk.codegen.docs.SimpleMethodOverload;
39+
import software.amazon.awssdk.codegen.docs.WaiterDocs;
3940
import software.amazon.awssdk.codegen.model.config.customization.UtilitiesMethod;
4041
import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel;
4142
import software.amazon.awssdk.codegen.model.intermediate.OperationModel;
@@ -452,7 +453,7 @@ private MethodSpec waiterMethod() {
452453
.addModifiers(Modifier.PUBLIC, Modifier.DEFAULT)
453454
.returns(poetExtensions.getAsyncWaiterInterface())
454455
.addStatement("throw new $T()", UnsupportedOperationException.class)
455-
.addJavadoc("Creates an instance of {@link $T} object", poetExtensions.getAsyncWaiterInterface())
456+
.addJavadoc(WaiterDocs.waiterMethodInClient(poetExtensions.getAsyncWaiterInterface()))
456457
.build();
457458
}
458459
}

codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/SyncClientInterface.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import software.amazon.awssdk.codegen.docs.ClientType;
3737
import software.amazon.awssdk.codegen.docs.DocConfiguration;
3838
import software.amazon.awssdk.codegen.docs.SimpleMethodOverload;
39+
import software.amazon.awssdk.codegen.docs.WaiterDocs;
3940
import software.amazon.awssdk.codegen.model.config.customization.UtilitiesMethod;
4041
import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel;
4142
import software.amazon.awssdk.codegen.model.intermediate.OperationModel;
@@ -465,7 +466,7 @@ private MethodSpec waiterMethod() {
465466
.addModifiers(Modifier.PUBLIC, Modifier.DEFAULT)
466467
.addStatement("throw new $T()", UnsupportedOperationException.class)
467468
.returns(poetExtensions.getSyncWaiterInterface())
468-
.addJavadoc("Creates an instance of {@link $T} object", poetExtensions.getSyncWaiterInterface())
469+
.addJavadoc(WaiterDocs.waiterMethodInClient(poetExtensions.getSyncWaiterInterface()))
469470
.build();
470471
}
471472
}

codegen/src/main/java/software/amazon/awssdk/codegen/poet/waiters/BaseWaiterInterfaceSpec.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ public TypeSpec poetSpec() {
6767
.build());
6868
result.addMethod(MethodSpec.methodBuilder("create")
6969
.addModifiers(Modifier.PUBLIC, Modifier.STATIC)
70-
.addJavadoc(WaiterDocs.waiterCreateMethodJavadoc(className()))
70+
.addJavadoc(WaiterDocs.waiterCreateMethodJavadoc(className(),
71+
clientClassName()))
7172
.returns(className())
7273
.addStatement("return $T.builder().build()", waiterImplName())
7374
.build());

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/waiters/query-async-waiter-interface.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ public interface QueryAsyncWaiter extends SdkAutoCloseable {
2525
*
2626
* @param aPostOperationRequest
2727
* the request to be used for polling
28-
* @return CompletableFuture of the WaiterResponse containing either a response or an exception that has matched
29-
* with the waiter success condition
28+
* @return CompletableFuture containing the WaiterResponse. It completes successfully when the resource enters into
29+
* a desired state or exceptionally when it is determined that the resource will never enter into the
30+
* desired state.
3031
*/
3132
default CompletableFuture<WaiterResponse<APostOperationResponse>> waitUntilPostOperationSuccess(
3233
APostOperationRequest aPostOperationRequest) {
@@ -38,7 +39,7 @@ default CompletableFuture<WaiterResponse<APostOperationResponse>> waitUntilPostO
3839
* met, or until it is determined that the resource will never enter into the desired state.
3940
* <p>
4041
* This is a convenience method to create an instance of the request builder without the need to create one manually
41-
* using {@link APostOperationRequest.builder()}
42+
* using {@link APostOperationRequest#builder()}
4243
*
4344
* @param aPostOperationRequest
4445
* The consumer that will configure the request to be used for polling
@@ -97,7 +98,11 @@ static Builder builder() {
9798
}
9899

99100
/**
100-
* Create an instance of {@link QueryAsyncWaiter} with the default configuration
101+
* Create an instance of {@link QueryAsyncWaiter} with the default configuration.
102+
* <p>
103+
* <b>A default {@link QueryAsyncClient} will be created to poll resources. It is recommended to share a single
104+
* instance of the waiter created via this method. If it is not desirable to share a waiter instance, invoke
105+
* {@link #close()} to release the resources once the waiter is not needed.</b>
101106
*
102107
* @return an instance of {@link QueryAsyncWaiter}
103108
*/
@@ -130,7 +135,7 @@ interface Builder {
130135

131136
/**
132137
* This is a convenient method to pass the override configuration without the need to create an instance
133-
* manually via {@link WaiterOverrideConfiguration.builder()}
138+
* manually via {@link WaiterOverrideConfiguration#builder()}
134139
*
135140
* @param overrideConfiguration
136141
* The consumer that will configure the overrideConfiguration
@@ -144,7 +149,7 @@ default Builder overrideConfiguration(Consumer<WaiterOverrideConfiguration.Build
144149
}
145150

146151
/**
147-
* Sets a custom {@link QueryAsyncClient} that will be used to pool the resource
152+
* Sets a custom {@link QueryAsyncClient} that will be used to poll the resource
148153
* <p>
149154
* This SDK client must be closed by the caller when it is ready to be disposed. The SDK will not close the
150155
* client when the waiter is closed

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/waiters/query-sync-waiter-interface.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ default WaiterResponse<APostOperationResponse> waitUntilPostOperationSuccess(APo
3535
* until it is determined that the resource will never enter into the desired state.
3636
* <p>
3737
* This is a convenience method to create an instance of the request builder without the need to create one manually
38-
* using {@link APostOperationRequest.builder()}
38+
* using {@link APostOperationRequest#builder()}
3939
*
4040
* @param aPostOperationRequest
4141
* The consumer that will configure the request to be used for polling
@@ -94,7 +94,11 @@ static Builder builder() {
9494
}
9595

9696
/**
97-
* Create an instance of {@link QueryWaiter} with the default configuration
97+
* Create an instance of {@link QueryWaiter} with the default configuration.
98+
* <p>
99+
* <b>A default {@link QueryClient} will be created to poll resources. It is recommended to share a single instance
100+
* of the waiter created via this method. If it is not desirable to share a waiter instance, invoke {@link #close()}
101+
* to release the resources once the waiter is not needed.</b>
98102
*
99103
* @return an instance of {@link QueryWaiter}
100104
*/
@@ -115,7 +119,7 @@ interface Builder {
115119

116120
/**
117121
* This is a convenient method to pass the override configuration without the need to create an instance
118-
* manually via {@link WaiterOverrideConfiguration.builder()}
122+
* manually via {@link WaiterOverrideConfiguration#builder()}
119123
*
120124
* @param overrideConfiguration
121125
* The consumer that will configure the overrideConfiguration
@@ -129,7 +133,7 @@ default Builder overrideConfiguration(Consumer<WaiterOverrideConfiguration.Build
129133
}
130134

131135
/**
132-
* Sets a custom {@link QueryClient} that will be used to pool the resource
136+
* Sets a custom {@link QueryClient} that will be used to poll the resource
133137
* <p>
134138
* This SDK client must be closed by the caller when it is ready to be disposed. The SDK will not close the
135139
* client when the waiter is closed

core/sdk-core/src/main/java/software/amazon/awssdk/core/internal/waiters/DefaultWaiterResponse.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public final class DefaultWaiterResponse<T> implements WaiterResponse<T> {
3131
private final T result;
3232
private final Throwable exception;
3333
private final int attemptsExecuted;
34+
private final ResponseOrException<T> matched;
3435

3536
private DefaultWaiterResponse(Builder<T> builder) {
3637
mutuallyExclusive("response and exception are mutually exclusive, set only one on the Builder",
@@ -39,16 +40,18 @@ private DefaultWaiterResponse(Builder<T> builder) {
3940
this.exception = builder.exception;
4041
this.attemptsExecuted = Validate.paramNotNull(builder.attemptsExecuted, "attemptsExecuted");
4142
Validate.isPositive(builder.attemptsExecuted, "attemptsExecuted");
43+
matched = result != null ?
44+
ResponseOrException.response(result) :
45+
ResponseOrException.exception(exception);
4246
}
4347

44-
4548
public static <T> Builder<T> builder() {
4649
return new Builder<>();
4750
}
4851

4952
@Override
5053
public ResponseOrException<T> matched() {
51-
return result != null ? ResponseOrException.response(result) : ResponseOrException.exception(exception);
54+
return matched;
5255
}
5356

5457
@Override
@@ -89,7 +92,9 @@ public String toString() {
8992
ToString toString = ToString.builder("DefaultWaiterResponse")
9093
.add("attemptsExecuted", attemptsExecuted);
9194

92-
matched().apply(r -> toString.add("response", r), e -> toString.add("exception", e.getMessage()));
95+
matched.response().ifPresent(r -> toString.add("response", result));
96+
matched.exception().ifPresent(r -> toString.add("exception", exception));
97+
9398
return toString.build();
9499
}
95100

core/sdk-core/src/main/java/software/amazon/awssdk/core/internal/waiters/ResponseOrException.java

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,74 +16,53 @@
1616
package software.amazon.awssdk.core.internal.waiters;
1717

1818
import java.util.Optional;
19-
import java.util.function.Consumer;
20-
import java.util.function.Function;
21-
import software.amazon.awssdk.annotations.SdkProtectedApi;
19+
import software.amazon.awssdk.annotations.SdkPublicApi;
2220

2321
/**
2422
* Represents a value that can be either a response or a Throwable
2523
*
2624
* @param <R> response type
2725
*/
28-
@SdkProtectedApi
26+
@SdkPublicApi
2927
public final class ResponseOrException<R> {
3028

3129
private final Optional<R> response;
3230
private final Optional<Throwable> exception;
3331

34-
private ResponseOrException(Optional<R> l, Optional<Throwable> r) {
35-
response = l;
36-
exception = r;
32+
private ResponseOrException(Optional<R> response, Optional<Throwable> exception) {
33+
this.response = response;
34+
this.exception = exception;
3735
}
3836

3937
/**
40-
* Maps the Either to a type and returns the resolved value (which may be from the left or the right value).
41-
*
42-
* @param lFunc Function that maps the left value if present.
43-
* @param rFunc Function that maps the right value if present.
44-
* @param <T> Type that both the left and right should be mapped to.
45-
* @return Mapped value from either lFunc or rFunc depending on which value is present.
38+
* @return the optional response that has matched with the waiter success condition
4639
*/
47-
public <T> T map(
48-
Function<? super R, ? extends T> lFunc,
49-
Function<? super Throwable, ? extends T> rFunc) {
50-
return response.<T>map(lFunc).orElseGet(() -> exception.map(rFunc).get());
51-
}
52-
5340
public Optional<R> response() {
5441
return response;
5542
}
5643

57-
public Optional<Throwable> exception() {
58-
return exception;
59-
}
60-
6144
/**
62-
* Apply the consumers to the left or the right value depending on which is present.
63-
*
64-
* @param lFunc Consumer of left value, invoked if left value is present.
65-
* @param rFunc Consumer of right value, invoked if right value is present.
45+
* @return the optional exception that has matched with the waiter success condition
6646
*/
67-
public void apply(Consumer<? super R> lFunc, Consumer<? super Throwable> rFunc) {
68-
response.ifPresent(lFunc);
69-
exception.ifPresent(rFunc);
47+
public Optional<Throwable> exception() {
48+
return exception;
7049
}
7150

7251
/**
73-
* Create a new Either with the left type.
52+
* Create a new ResponseOrException with the response
7453
*
75-
* @param value Left value
76-
* @param <R> Left type
54+
* @param value response
55+
* @param <R> Response type
7756
*/
7857
public static <R> ResponseOrException<R> response(R value) {
7958
return new ResponseOrException<>(Optional.of(value), Optional.empty());
8059
}
8160

8261
/**
83-
* Create a new Either with the right type.
62+
* Create a new ResponseOrException with the exception
8463
*
85-
* @param value Right value
86-
* @param <R> Left type
64+
* @param value exception
65+
* @param <R> Response type
8766
*/
8867
public static <R> ResponseOrException<R> exception(Throwable value) {
8968
return new ResponseOrException<>(Optional.empty(), Optional.of(value));

0 commit comments

Comments
 (0)