Skip to content

Commit 5006d03

Browse files
committed
Set longPoll ops for SQS,SWF,SFN
Add a customization to set the long polling trait for the following service operations: - SQS#ReceiveMessage - SFN#GetActivityTask - SWF#PollForActivityTask - SWF#PollForDecisionTask
1 parent 1e0e470 commit 5006d03

5 files changed

Lines changed: 123 additions & 2 deletions

File tree

‎codegen/src/main/java/software/amazon/awssdk/codegen/customization/processors/DefaultCustomizationProcessor.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ public static CodegenCustomizationProcessor getProcessorFor(
4242
new S3RemoveBucketFromUriProcessor(),
4343
new S3ControlRemoveAccountIdHostPrefixProcessor(),
4444
new ExplicitStringPayloadQueryProtocolProcessor(),
45-
new LowercaseShapeValidatorProcessor()
45+
new LowercaseShapeValidatorProcessor(),
46+
new LongPollingOperationProcessor()
4647
);
4748
}
4849
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.codegen.customization.processors;
17+
18+
import java.util.Arrays;
19+
import java.util.Collections;
20+
import java.util.HashMap;
21+
import java.util.List;
22+
import java.util.Map;
23+
import org.slf4j.Logger;
24+
import org.slf4j.LoggerFactory;
25+
import software.amazon.awssdk.codegen.customization.CodegenCustomizationProcessor;
26+
import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel;
27+
import software.amazon.awssdk.codegen.model.intermediate.OperationModel;
28+
import software.amazon.awssdk.codegen.model.service.ServiceModel;
29+
30+
// TODO: Remove this when the long polling trait is formalized as a c2j trait.
31+
/**
32+
* Marks specific service operations as having the long polling trait.
33+
*/
34+
public class LongPollingOperationProcessor implements CodegenCustomizationProcessor {
35+
private static final Logger log = LoggerFactory.getLogger(LongPollingOperationProcessor.class);
36+
37+
// Note: static mapping instead of exposed via CustomizationConfig to avoid exposing it for wider use unless necessary.
38+
private static final Map<String, List<String>> SERVICE_ID_TO_OPERATIONS_MAP;
39+
40+
static {
41+
Map<String, List<String>> serviceIdToOperationsMap = new HashMap<>();
42+
43+
serviceIdToOperationsMap.put("SQS", Collections.singletonList("ReceiveMessage"));
44+
serviceIdToOperationsMap.put("SFN", Collections.singletonList("GetActivityTask"));
45+
serviceIdToOperationsMap.put("SWF", Collections.unmodifiableList(Arrays.asList("PollForActivityTask",
46+
"PollForDecisionTask")));
47+
48+
SERVICE_ID_TO_OPERATIONS_MAP = Collections.unmodifiableMap(serviceIdToOperationsMap);
49+
}
50+
51+
@Override
52+
public void preprocess(ServiceModel serviceModel) {
53+
// no-op
54+
}
55+
56+
@Override
57+
public void postprocess(IntermediateModel intermediateModel) {
58+
String serviceId = intermediateModel.getMetadata().getServiceId();
59+
List<String> longPollingOperations = SERVICE_ID_TO_OPERATIONS_MAP.getOrDefault(serviceId, Collections.emptyList());
60+
61+
for (String longPollingOperation : longPollingOperations) {
62+
OperationModel opModel = intermediateModel.getOperation(longPollingOperation);
63+
if (opModel != null) {
64+
log.info("Setting the longPoll trait for {}#{}", serviceId, longPollingOperation);
65+
opModel.setLongPolling(true);
66+
} else {
67+
log.warn("Did not find operation {}#{}", serviceId, longPollingOperation);
68+
}
69+
}
70+
}
71+
}

‎codegen/src/main/java/software/amazon/awssdk/codegen/model/intermediate/OperationModel.java‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ public class OperationModel extends DocumentationModel {
9090

9191
private boolean unsignedPayload;
9292

93+
private boolean longPolling;
94+
9395
public String getOperationName() {
9496
return operationName;
9597
}
@@ -381,6 +383,14 @@ public void setUnsignedPayload(boolean unsignedPayload) {
381383
this.unsignedPayload = unsignedPayload;
382384
}
383385

386+
public boolean isLongPolling() {
387+
return longPolling;
388+
}
389+
390+
public void setLongPolling(boolean longPolling) {
391+
this.longPolling = longPolling;
392+
}
393+
384394
@Override
385395
public boolean equals(Object o) {
386396
if (o == null || getClass() != o.getClass()) {
@@ -395,7 +405,8 @@ public boolean equals(Object o) {
395405
&& hasStringMemberAsPayload == that.hasStringMemberAsPayload && isAuthenticated == that.isAuthenticated
396406
&& isPaginated == that.isPaginated && endpointOperation == that.endpointOperation
397407
&& endpointCacheRequired == that.endpointCacheRequired && httpChecksumRequired == that.httpChecksumRequired
398-
&& unsignedPayload == that.unsignedPayload && Objects.equals(operationName, that.operationName)
408+
&& unsignedPayload == that.unsignedPayload && longPolling == that.longPolling
409+
&& Objects.equals(operationName, that.operationName)
399410
&& Objects.equals(serviceProtocol, that.serviceProtocol)
400411
&& Objects.equals(deprecatedMessage, that.deprecatedMessage) && Objects.equals(input, that.input)
401412
&& Objects.equals(returnType, that.returnType) && Objects.equals(exceptions, that.exceptions)
@@ -437,6 +448,7 @@ public int hashCode() {
437448
result = 31 * result + Objects.hashCode(staticContextParams);
438449
result = 31 * result + Objects.hashCode(operationContextParams);
439450
result = 31 * result + Boolean.hashCode(unsignedPayload);
451+
result = 31 * result + Boolean.hashCode(longPolling);
440452
return result;
441453
}
442454
}

‎codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/specs/JsonProtocolSpec.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import software.amazon.awssdk.codegen.poet.PoetExtension;
4444
import software.amazon.awssdk.codegen.poet.client.traits.HttpChecksumRequiredTrait;
4545
import software.amazon.awssdk.codegen.poet.client.traits.HttpChecksumTrait;
46+
import software.amazon.awssdk.codegen.poet.client.traits.LongPollTrait;
4647
import software.amazon.awssdk.codegen.poet.client.traits.RequestCompressionTrait;
4748
import software.amazon.awssdk.codegen.poet.eventstream.EventStreamUtils;
4849
import software.amazon.awssdk.codegen.poet.model.EventStreamSpecHelper;
@@ -219,6 +220,7 @@ public CodeBlock executionHandler(OperationModel opModel) {
219220
.add(hostPrefixExpression(opModel))
220221
.add(discoveredEndpoint(opModel))
221222
.add(credentialType(opModel, model))
223+
.add(LongPollTrait.executionParamSetter(opModel))
222224
.add(".withRequestConfiguration(clientConfiguration)")
223225
.add(".withInput($L)\n", opModel.getInput().getVariableName())
224226
.add(".withMetricCollector(apiCallMetricCollector)")
@@ -290,6 +292,7 @@ public CodeBlock asyncExecutionHandler(IntermediateModel intermediateModel, Oper
290292
.add(".withMarshaller($L)\n", asyncMarshaller(model, opModel, marshaller, protocolFactory))
291293
.add(asyncRequestBody(opModel))
292294
.add(fullDuplex(opModel))
295+
.add(LongPollTrait.executionParamSetter(opModel))
293296
.add(hasInitialRequestEvent(opModel, isRestJson))
294297
.add(".withResponseHandler($L)\n", responseHandlerName(opModel, isRestJson))
295298
.add(".withErrorResponseHandler(errorResponseHandler)\n")
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.codegen.poet.client.traits;
17+
18+
import com.squareup.javapoet.CodeBlock;
19+
import software.amazon.awssdk.codegen.model.intermediate.OperationModel;
20+
21+
/**
22+
* Helper methods for working with the long poll trait for operations.
23+
*/
24+
public final class LongPollTrait {
25+
private LongPollTrait() {
26+
}
27+
public static CodeBlock executionParamSetter(OperationModel operationModel) {
28+
if (operationModel.isLongPolling()) {
29+
return CodeBlock.of(".withLongPolling(true)");
30+
}
31+
return CodeBlock.of("");
32+
}
33+
34+
}

0 commit comments

Comments
 (0)