Skip to content

Commit b04e5ad

Browse files
authored
Update comments from PR 5488 (#5550)
* Update comments of PR 5488 * Update comments from PR 5488
1 parent e570e2b commit b04e5ad

16 files changed

+101
-125
lines changed

services/sqs/src/main/java/software/amazon/awssdk/services/sqs/internal/batchmanager/ChangeMessageVisibilityBatchManager.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
package software.amazon.awssdk.services.sqs.internal.batchmanager;
1717

18-
import static software.amazon.awssdk.services.sqs.internal.batchmanager.SqsMessageDefault.USER_AGENT_APPLIER;
19-
2018
import java.util.ArrayList;
2119
import java.util.List;
2220
import java.util.Optional;

services/sqs/src/main/java/software/amazon/awssdk/services/sqs/internal/batchmanager/DefaultSqsAsyncBatchManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515

1616
package software.amazon.awssdk.services.sqs.internal.batchmanager;
1717

18-
import static software.amazon.awssdk.services.sqs.internal.batchmanager.SqsMessageDefault.MAX_SEND_MESSAGE_PAYLOAD_SIZE_BYTES;
18+
19+
import static software.amazon.awssdk.services.sqs.internal.batchmanager.ResponseBatchConfiguration.MAX_SEND_MESSAGE_PAYLOAD_SIZE_BYTES;
1920

2021
import java.util.concurrent.CompletableFuture;
2122
import java.util.concurrent.ScheduledExecutorService;

services/sqs/src/main/java/software/amazon/awssdk/services/sqs/internal/batchmanager/DeleteMessageBatchManager.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
package software.amazon.awssdk.services.sqs.internal.batchmanager;
1717

18-
import static software.amazon.awssdk.services.sqs.internal.batchmanager.SqsMessageDefault.USER_AGENT_APPLIER;
19-
2018
import java.util.ArrayList;
2119
import java.util.List;
2220
import java.util.Optional;

services/sqs/src/main/java/software/amazon/awssdk/services/sqs/internal/batchmanager/QueueAttributesManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515

1616
package software.amazon.awssdk.services.sqs.internal.batchmanager;
1717

18-
import static software.amazon.awssdk.services.sqs.internal.batchmanager.SqsMessageDefault.USER_AGENT_APPLIER;
18+
19+
import static software.amazon.awssdk.services.sqs.internal.batchmanager.RequestBatchManager.USER_AGENT_APPLIER;
1920

2021
import java.time.Duration;
2122
import java.util.Arrays;

services/sqs/src/main/java/software/amazon/awssdk/services/sqs/internal/batchmanager/ReceiveBatchManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
package software.amazon.awssdk.services.sqs.internal.batchmanager;
1717

18-
import static software.amazon.awssdk.services.sqs.internal.batchmanager.SqsMessageDefault.MAX_SUPPORTED_SQS_RECEIVE_MSG;
18+
import static software.amazon.awssdk.services.sqs.internal.batchmanager.ResponseBatchConfiguration.MAX_SUPPORTED_SQS_RECEIVE_MSG;
1919

2020
import java.util.concurrent.CompletableFuture;
2121
import java.util.concurrent.ScheduledExecutorService;

services/sqs/src/main/java/software/amazon/awssdk/services/sqs/internal/batchmanager/ReceiveQueueBuffer.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,12 @@ public class ReceiveQueueBuffer implements SdkAutoCloseable {
4747

4848
private final AtomicBoolean processingFutures = new AtomicBoolean(false);
4949

50-
private ReceiveQueueBuffer(ScheduledExecutorService executor, SqsAsyncClient sqsClient,
51-
ResponseBatchConfiguration config, String queueUrl, QueueAttributesManager queueAttributesManager) {
52-
this.executor = executor;
53-
this.sqsClient = sqsClient;
54-
this.config = config;
55-
this.queueUrl = queueUrl;
56-
this.queueAttributesManager = queueAttributesManager;
50+
private ReceiveQueueBuffer(Builder builder) {
51+
this.executor = builder.executor;
52+
this.sqsClient = builder.sqsClient;
53+
this.config = builder.config;
54+
this.queueUrl = builder.queueUrl;
55+
this.queueAttributesManager = builder.queueAttributesManager;
5756
}
5857

5958
public static Builder builder() {
@@ -242,7 +241,7 @@ public Builder queueAttributesManager(QueueAttributesManager queueAttributesMana
242241
}
243242

244243
public ReceiveQueueBuffer build() {
245-
return new ReceiveQueueBuffer(executor, sqsClient, config, queueUrl, queueAttributesManager);
244+
return new ReceiveQueueBuffer(this);
246245
}
247246
}
248247
}

services/sqs/src/main/java/software/amazon/awssdk/services/sqs/internal/batchmanager/ReceiveSqsMessageHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
package software.amazon.awssdk.services.sqs.internal.batchmanager;
1717

1818

19-
import static software.amazon.awssdk.services.sqs.internal.batchmanager.SqsMessageDefault.USER_AGENT_APPLIER;
19+
import static software.amazon.awssdk.services.sqs.internal.batchmanager.RequestBatchManager.USER_AGENT_APPLIER;
2020

2121
import java.time.Duration;
2222
import java.util.List;

services/sqs/src/main/java/software/amazon/awssdk/services/sqs/internal/batchmanager/RequestBatchManager.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,21 @@
2727
import java.util.concurrent.ScheduledExecutorService;
2828
import java.util.concurrent.ScheduledFuture;
2929
import java.util.concurrent.TimeUnit;
30+
import java.util.function.Consumer;
3031
import software.amazon.awssdk.annotations.SdkInternalApi;
32+
import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration;
33+
import software.amazon.awssdk.core.ApiName;
3134
import software.amazon.awssdk.utils.Either;
3235
import software.amazon.awssdk.utils.Validate;
3336

3437
@SdkInternalApi
3538
public abstract class RequestBatchManager<RequestT, ResponseT, BatchResponseT> {
39+
40+
41+
// abm stands for Automatic Batching Manager
42+
public static final Consumer<AwsRequestOverrideConfiguration.Builder> USER_AGENT_APPLIER =
43+
b -> b.addApiName(ApiName.builder().version("abm").name("hll").build());
44+
3645
protected final RequestBatchConfiguration batchConfiguration ;
3746

3847
private final int maxBatchItems;

services/sqs/src/main/java/software/amazon/awssdk/services/sqs/internal/batchmanager/RequestPayloadCalculator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
package software.amazon.awssdk.services.sqs.internal.batchmanager;
1717

18-
import static software.amazon.awssdk.services.sqs.internal.batchmanager.SqsMessageDefault.ATTRIBUTE_MAPS_PAYLOAD_BYTES;
18+
import static software.amazon.awssdk.services.sqs.internal.batchmanager.ResponseBatchConfiguration.ATTRIBUTE_MAPS_PAYLOAD_BYTES;
1919

2020
import java.nio.charset.StandardCharsets;
2121
import java.util.Optional;

services/sqs/src/main/java/software/amazon/awssdk/services/sqs/internal/batchmanager/ResponseBatchConfiguration.java

Lines changed: 57 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515

1616
package software.amazon.awssdk.services.sqs.internal.batchmanager;
1717

18+
19+
1820
import java.time.Duration;
1921
import java.util.Collections;
2022
import java.util.List;
21-
import java.util.Optional;
2223
import software.amazon.awssdk.annotations.SdkInternalApi;
2324
import software.amazon.awssdk.services.sqs.batchmanager.BatchOverrideConfiguration;
2425
import software.amazon.awssdk.services.sqs.model.MessageSystemAttributeName;
@@ -33,10 +34,23 @@ public final class ResponseBatchConfiguration {
3334
public static final List<String> RECEIVE_MESSAGE_ATTRIBUTE_NAMES_DEFAULT = Collections.emptyList();
3435
public static final List<MessageSystemAttributeName> MESSAGE_SYSTEM_ATTRIBUTE_NAMES_DEFAULT = Collections.emptyList();
3536
public static final boolean ADAPTIVE_PREFETCHING_DEFAULT = false;
36-
public static final int MAX_BATCH_ITEMS_DEFAULT = 10;
3737
public static final int MAX_INFLIGHT_RECEIVE_BATCHES_DEFAULT = 10;
3838
public static final int MAX_DONE_RECEIVE_BATCHES_DEFAULT = 10;
3939

40+
public static final int MAX_SUPPORTED_SQS_RECEIVE_MSG = 10;
41+
42+
public static final int MAX_SEND_MESSAGE_PAYLOAD_SIZE_BYTES = 262_144; // 256 KiB
43+
44+
/**
45+
* <a href="https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-message-metadata.html#sqs-message-attributes">
46+
* AWS SQS Message Attributes Documentation</a>
47+
*
48+
* Rounding up max payload due to attribute maps.
49+
* This was not done in V1, thus an issue was reported where batch messages failed with payload size exceeding the maximum.
50+
*/
51+
public static final int ATTRIBUTE_MAPS_PAYLOAD_BYTES = 16 * 1024; // 16 KiB
52+
53+
4054
private final Duration visibilityTimeout;
4155
private final Duration longPollWaitTimeout;
4256
private final Duration minReceiveWaitTime;
@@ -48,47 +62,50 @@ public final class ResponseBatchConfiguration {
4862
private final Integer maxDoneReceiveBatches;
4963

5064
public ResponseBatchConfiguration(BatchOverrideConfiguration overrideConfiguration) {
51-
this.visibilityTimeout = Optional.ofNullable(overrideConfiguration)
52-
.map(BatchOverrideConfiguration::visibilityTimeout)
53-
.orElse(VISIBILITY_TIMEOUT_SECONDS_DEFAULT);
54-
55-
this.longPollWaitTimeout = Optional.ofNullable(overrideConfiguration)
56-
.map(BatchOverrideConfiguration::longPollWaitTimeout)
57-
.orElse(LONG_POLL_WAIT_TIMEOUT_DEFAULT);
58-
59-
this.minReceiveWaitTime = Optional.ofNullable(overrideConfiguration)
60-
.map(BatchOverrideConfiguration::minReceiveWaitTime)
61-
.orElse(MIN_RECEIVE_WAIT_TIME_MS_DEFAULT);
62-
63-
this.messageSystemAttributeValues = Optional.ofNullable(overrideConfiguration)
64-
.map(BatchOverrideConfiguration::messageSystemAttributeName)
65-
.filter(list -> !list.isEmpty())
66-
.orElse(MESSAGE_SYSTEM_ATTRIBUTE_NAMES_DEFAULT);
67-
68-
this.receiveMessageAttributeNames = Optional.ofNullable(overrideConfiguration)
69-
.map(BatchOverrideConfiguration::receiveMessageAttributeNames)
70-
.filter(list -> !list.isEmpty())
71-
.orElse(RECEIVE_MESSAGE_ATTRIBUTE_NAMES_DEFAULT);
72-
73-
this.adaptivePrefetching = Optional.ofNullable(overrideConfiguration)
74-
.map(BatchOverrideConfiguration::adaptivePrefetching)
75-
.orElse(ADAPTIVE_PREFETCHING_DEFAULT);
76-
77-
this.maxBatchItems = Optional.ofNullable(overrideConfiguration)
78-
.map(BatchOverrideConfiguration::maxBatchItems)
79-
.orElse(MAX_BATCH_ITEMS_DEFAULT);
80-
81-
82-
this.maxInflightReceiveBatches = Optional.ofNullable(overrideConfiguration)
83-
.map(BatchOverrideConfiguration::maxInflightReceiveBatches)
84-
.orElse(MAX_INFLIGHT_RECEIVE_BATCHES_DEFAULT);
85-
86-
this.maxDoneReceiveBatches = Optional.ofNullable(overrideConfiguration)
87-
.map(BatchOverrideConfiguration::maxDoneReceiveBatches)
88-
.orElse(MAX_DONE_RECEIVE_BATCHES_DEFAULT);
65+
this.visibilityTimeout = overrideConfiguration != null && overrideConfiguration.visibilityTimeout() != null
66+
? overrideConfiguration.visibilityTimeout()
67+
: VISIBILITY_TIMEOUT_SECONDS_DEFAULT;
68+
69+
this.longPollWaitTimeout = overrideConfiguration != null && overrideConfiguration.longPollWaitTimeout() != null
70+
? overrideConfiguration.longPollWaitTimeout()
71+
: LONG_POLL_WAIT_TIMEOUT_DEFAULT;
72+
73+
this.minReceiveWaitTime = overrideConfiguration != null && overrideConfiguration.minReceiveWaitTime() != null
74+
? overrideConfiguration.minReceiveWaitTime()
75+
: MIN_RECEIVE_WAIT_TIME_MS_DEFAULT;
76+
77+
this.messageSystemAttributeValues = overrideConfiguration != null
78+
&& overrideConfiguration.messageSystemAttributeName() != null
79+
&& !overrideConfiguration.messageSystemAttributeName().isEmpty()
80+
? overrideConfiguration.messageSystemAttributeName()
81+
: MESSAGE_SYSTEM_ATTRIBUTE_NAMES_DEFAULT;
82+
83+
this.receiveMessageAttributeNames = overrideConfiguration != null
84+
&& overrideConfiguration.receiveMessageAttributeNames() != null
85+
&& !overrideConfiguration.receiveMessageAttributeNames().isEmpty()
86+
? overrideConfiguration.receiveMessageAttributeNames()
87+
: RECEIVE_MESSAGE_ATTRIBUTE_NAMES_DEFAULT;
88+
89+
this.adaptivePrefetching = overrideConfiguration != null && overrideConfiguration.adaptivePrefetching() != null
90+
? overrideConfiguration.adaptivePrefetching()
91+
: ADAPTIVE_PREFETCHING_DEFAULT;
92+
93+
this.maxBatchItems = overrideConfiguration != null && overrideConfiguration.maxBatchItems() != null
94+
? overrideConfiguration.maxBatchItems()
95+
: MAX_SUPPORTED_SQS_RECEIVE_MSG;
96+
97+
this.maxInflightReceiveBatches = overrideConfiguration != null
98+
&& overrideConfiguration.maxInflightReceiveBatches() != null
99+
? overrideConfiguration.maxInflightReceiveBatches()
100+
: MAX_INFLIGHT_RECEIVE_BATCHES_DEFAULT;
101+
102+
this.maxDoneReceiveBatches = overrideConfiguration != null && overrideConfiguration.maxDoneReceiveBatches() != null
103+
? overrideConfiguration.maxDoneReceiveBatches()
104+
: MAX_DONE_RECEIVE_BATCHES_DEFAULT;
89105
}
90106

91107

108+
92109
public Duration visibilityTimeout() {
93110
return visibilityTimeout;
94111
}

services/sqs/src/main/java/software/amazon/awssdk/services/sqs/internal/batchmanager/SendMessageBatchManager.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
package software.amazon.awssdk.services.sqs.internal.batchmanager;
1717

18-
import static software.amazon.awssdk.services.sqs.internal.batchmanager.SqsMessageDefault.USER_AGENT_APPLIER;
19-
2018
import java.util.ArrayList;
2119
import java.util.List;
2220
import java.util.Optional;

services/sqs/src/main/java/software/amazon/awssdk/services/sqs/internal/batchmanager/SqsMessageDefault.java

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

services/sqs/src/test/java/software/amazon/awssdk/services/sqs/batchmanager/ReceiveSqsMessageHelperTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import static org.mockito.Mockito.times;
2828
import static org.mockito.Mockito.verify;
2929
import static org.mockito.Mockito.when;
30+
import static software.amazon.awssdk.services.sqs.internal.batchmanager.RequestBatchManager.USER_AGENT_APPLIER;
3031

3132
import java.time.Duration;
3233
import java.util.ArrayList;
@@ -48,7 +49,6 @@
4849
import software.amazon.awssdk.services.sqs.SqsAsyncClient;
4950
import software.amazon.awssdk.services.sqs.internal.batchmanager.ReceiveSqsMessageHelper;
5051
import software.amazon.awssdk.services.sqs.internal.batchmanager.ResponseBatchConfiguration;
51-
import software.amazon.awssdk.services.sqs.internal.batchmanager.SqsMessageDefault;
5252
import software.amazon.awssdk.services.sqs.model.ChangeMessageVisibilityBatchRequest;
5353
import software.amazon.awssdk.services.sqs.model.ChangeMessageVisibilityBatchResponse;
5454
import software.amazon.awssdk.services.sqs.model.Message;
@@ -293,7 +293,7 @@ public void asyncReceiveMessageArgs() throws Exception {
293293
.messageAttributeNames("custom1", "custom2")
294294
.visibilityTimeout(9)
295295
.waitTimeSeconds(15)
296-
.overrideConfiguration(o -> o.applyMutation(SqsMessageDefault.USER_AGENT_APPLIER))
296+
.overrideConfiguration(o -> o.applyMutation(USER_AGENT_APPLIER))
297297
.build();
298298

299299
verify(sqsClient, times(1)).receiveMessage(eq(expectedRequest));

0 commit comments

Comments
 (0)