Skip to content

Commit 02185c2

Browse files
author
Bennett Lynch
committed
Refactor & reorganize listener interfaces
1 parent 41a333e commit 02185c2

File tree

13 files changed

+440
-252
lines changed

13 files changed

+440
-252
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@
6666
import software.amazon.awssdk.codegen.poet.model.EventStreamSpecHelper;
6767
import software.amazon.awssdk.core.RequestOverrideConfiguration;
6868
import software.amazon.awssdk.core.async.AsyncResponseTransformer;
69-
import software.amazon.awssdk.core.async.NotifyingAsyncResponseTransformer;
7069
import software.amazon.awssdk.core.async.SdkPublisher;
70+
import software.amazon.awssdk.core.async.listen.TmpUtil;
7171
import software.amazon.awssdk.core.client.config.SdkAdvancedAsyncClientOption;
7272
import software.amazon.awssdk.core.client.config.SdkClientConfiguration;
7373
import software.amazon.awssdk.core.client.config.SdkClientOption;
@@ -259,7 +259,7 @@ protected MethodSpec.Builder operationBody(MethodSpec.Builder builder, Operation
259259
CompletableFuture.class,
260260
Void.class,
261261
"pair",
262-
NotifyingAsyncResponseTransformer.class,
262+
TmpUtil.class,
263263
"asyncResponseTransformer");
264264

265265
builder.addStatement("$N = $N.left()",

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-async-client-class.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
import software.amazon.awssdk.core.SdkResponse;
3131
import software.amazon.awssdk.core.async.AsyncRequestBody;
3232
import software.amazon.awssdk.core.async.AsyncResponseTransformer;
33-
import software.amazon.awssdk.core.async.NotifyingAsyncResponseTransformer;
3433
import software.amazon.awssdk.core.async.SdkPublisher;
34+
import software.amazon.awssdk.core.async.listen.TmpUtil;
3535
import software.amazon.awssdk.core.client.config.SdkAdvancedAsyncClientOption;
3636
import software.amazon.awssdk.core.client.config.SdkClientConfiguration;
3737
import software.amazon.awssdk.core.client.config.SdkClientOption;
@@ -1000,7 +1000,7 @@ public <ReturnT> CompletableFuture<ReturnT> streamingInputOutputOperation(
10001000
try {
10011001
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service");
10021002
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "StreamingInputOutputOperation");
1003-
Pair<AsyncResponseTransformer<StreamingInputOutputOperationResponse, ReturnT>, CompletableFuture<Void>> pair = NotifyingAsyncResponseTransformer
1003+
Pair<AsyncResponseTransformer<StreamingInputOutputOperationResponse, ReturnT>, CompletableFuture<Void>> pair = TmpUtil
10041004
.wrapWithEndOfStreamFuture(asyncResponseTransformer);
10051005
asyncResponseTransformer = pair.left();
10061006
CompletableFuture<Void> endOfStreamFuture = pair.right();
@@ -1082,7 +1082,7 @@ public <ReturnT> CompletableFuture<ReturnT> streamingOutputOperation(
10821082
try {
10831083
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service");
10841084
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "StreamingOutputOperation");
1085-
Pair<AsyncResponseTransformer<StreamingOutputOperationResponse, ReturnT>, CompletableFuture<Void>> pair = NotifyingAsyncResponseTransformer
1085+
Pair<AsyncResponseTransformer<StreamingOutputOperationResponse, ReturnT>, CompletableFuture<Void>> pair = TmpUtil
10861086
.wrapWithEndOfStreamFuture(asyncResponseTransformer);
10871087
asyncResponseTransformer = pair.left();
10881088
CompletableFuture<Void> endOfStreamFuture = pair.right();

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-aws-json-async-client-class.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
import software.amazon.awssdk.core.SdkResponse;
3030
import software.amazon.awssdk.core.async.AsyncRequestBody;
3131
import software.amazon.awssdk.core.async.AsyncResponseTransformer;
32-
import software.amazon.awssdk.core.async.NotifyingAsyncResponseTransformer;
3332
import software.amazon.awssdk.core.async.SdkPublisher;
33+
import software.amazon.awssdk.core.async.listen.TmpUtil;
3434
import software.amazon.awssdk.core.client.config.SdkAdvancedAsyncClientOption;
3535
import software.amazon.awssdk.core.client.config.SdkClientConfiguration;
3636
import software.amazon.awssdk.core.client.config.SdkClientOption;
@@ -990,7 +990,7 @@ public <ReturnT> CompletableFuture<ReturnT> streamingInputOutputOperation(
990990
try {
991991
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service");
992992
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "StreamingInputOutputOperation");
993-
Pair<AsyncResponseTransformer<StreamingInputOutputOperationResponse, ReturnT>, CompletableFuture<Void>> pair = NotifyingAsyncResponseTransformer
993+
Pair<AsyncResponseTransformer<StreamingInputOutputOperationResponse, ReturnT>, CompletableFuture<Void>> pair = TmpUtil
994994
.wrapWithEndOfStreamFuture(asyncResponseTransformer);
995995
asyncResponseTransformer = pair.left();
996996
CompletableFuture<Void> endOfStreamFuture = pair.right();
@@ -1072,7 +1072,7 @@ public <ReturnT> CompletableFuture<ReturnT> streamingOutputOperation(
10721072
try {
10731073
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service");
10741074
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "StreamingOutputOperation");
1075-
Pair<AsyncResponseTransformer<StreamingOutputOperationResponse, ReturnT>, CompletableFuture<Void>> pair = NotifyingAsyncResponseTransformer
1075+
Pair<AsyncResponseTransformer<StreamingOutputOperationResponse, ReturnT>, CompletableFuture<Void>> pair = TmpUtil
10761076
.wrapWithEndOfStreamFuture(asyncResponseTransformer);
10771077
asyncResponseTransformer = pair.left();
10781078
CompletableFuture<Void> endOfStreamFuture = pair.right();

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-query-async-client-class.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import software.amazon.awssdk.core.RequestOverrideConfiguration;
1919
import software.amazon.awssdk.core.async.AsyncRequestBody;
2020
import software.amazon.awssdk.core.async.AsyncResponseTransformer;
21-
import software.amazon.awssdk.core.async.NotifyingAsyncResponseTransformer;
21+
import software.amazon.awssdk.core.async.listen.TmpUtil;
2222
import software.amazon.awssdk.core.client.config.SdkClientConfiguration;
2323
import software.amazon.awssdk.core.client.config.SdkClientOption;
2424
import software.amazon.awssdk.core.client.handler.AsyncClientHandler;
@@ -354,7 +354,7 @@ public <ReturnT> CompletableFuture<ReturnT> streamingOutputOperation(
354354
try {
355355
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service");
356356
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "StreamingOutputOperation");
357-
Pair<AsyncResponseTransformer<StreamingOutputOperationResponse, ReturnT>, CompletableFuture<Void>> pair = NotifyingAsyncResponseTransformer
357+
Pair<AsyncResponseTransformer<StreamingOutputOperationResponse, ReturnT>, CompletableFuture<Void>> pair = TmpUtil
358358
.wrapWithEndOfStreamFuture(asyncResponseTransformer);
359359
asyncResponseTransformer = pair.left();
360360
CompletableFuture<Void> endOfStreamFuture = pair.right();

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-xml-async-client-class.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import software.amazon.awssdk.core.SdkPojoBuilder;
2424
import software.amazon.awssdk.core.async.AsyncRequestBody;
2525
import software.amazon.awssdk.core.async.AsyncResponseTransformer;
26-
import software.amazon.awssdk.core.async.NotifyingAsyncResponseTransformer;
26+
import software.amazon.awssdk.core.async.listen.TmpUtil;
2727
import software.amazon.awssdk.core.client.config.SdkAdvancedAsyncClientOption;
2828
import software.amazon.awssdk.core.client.config.SdkClientConfiguration;
2929
import software.amazon.awssdk.core.client.config.SdkClientOption;
@@ -440,7 +440,7 @@ public <ReturnT> CompletableFuture<ReturnT> streamingOutputOperation(
440440
try {
441441
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Xml Service");
442442
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "StreamingOutputOperation");
443-
Pair<AsyncResponseTransformer<StreamingOutputOperationResponse, ReturnT>, CompletableFuture<Void>> pair = NotifyingAsyncResponseTransformer
443+
Pair<AsyncResponseTransformer<StreamingOutputOperationResponse, ReturnT>, CompletableFuture<Void>> pair = TmpUtil
444444
.wrapWithEndOfStreamFuture(asyncResponseTransformer);
445445
asyncResponseTransformer = pair.left();
446446
CompletableFuture<Void> endOfStreamFuture = pair.right();

core/sdk-core/src/main/java/software/amazon/awssdk/core/async/AsyncResponseTransformer.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import software.amazon.awssdk.annotations.SdkPublicApi;
2323
import software.amazon.awssdk.core.ResponseBytes;
2424
import software.amazon.awssdk.core.SdkResponse;
25+
import software.amazon.awssdk.core.async.listen.AsyncResponseTransformerListener;
2526
import software.amazon.awssdk.core.internal.async.ByteArrayAsyncResponseTransformer;
2627
import software.amazon.awssdk.core.internal.async.FileAsyncResponseTransformer;
2728
import software.amazon.awssdk.core.internal.async.PublisherAsyncResponseTransformer;
@@ -108,6 +109,14 @@ public interface AsyncResponseTransformer<ResponseT, ResultT> {
108109
*/
109110
void exceptionOccurred(Throwable error);
110111

112+
/**
113+
* Wrap this {@link AsyncResponseTransformer} with a new one that will notify a {@link AsyncResponseTransformerListener} of
114+
* important events occurring.
115+
*/
116+
default AsyncResponseTransformer<ResponseT, ResultT> wrapWithListener(AsyncResponseTransformerListener<ResponseT> listener) {
117+
return AsyncResponseTransformerListener.wrap(this, listener);
118+
}
119+
111120
/**
112121
* Creates an {@link AsyncResponseTransformer} that writes all the content to the given file. In the event of an error,
113122
* the SDK will attempt to delete the file (whatever has been written to it so far). If the file already exists, an

core/sdk-core/src/main/java/software/amazon/awssdk/core/async/NotifyingAsyncResponseTransformer.java

Lines changed: 0 additions & 198 deletions
This file was deleted.

0 commit comments

Comments
 (0)