Skip to content

Commit 4d3f21c

Browse files
committed
Surface API review comments
2 parents 36bd1a1 + b04e5ad commit 4d3f21c

26 files changed

+630
-532
lines changed

services/sqs/src/main/java/software/amazon/awssdk/services/sqs/batchmanager/BatchOverrideConfiguration.java

Lines changed: 37 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,25 @@
3838
public final class BatchOverrideConfiguration implements ToCopyableBuilder<BatchOverrideConfiguration.Builder,
3939
BatchOverrideConfiguration> {
4040

41-
private final Integer outboundBatchSizeLimit;
42-
private final Duration outboundBatchWindowDuration;
41+
private final Integer maxBatchSize;
42+
private final Duration sendRequestFrequency;
4343
private final Duration receiveMessageVisibilityTimeout;
44-
private final Duration receiveMessageLongPollWaitDuration;
4544
private final Duration receiveMessageMinWaitTime;
4645
private final List<MessageSystemAttributeName> receiveMessageSystemAttributeNames;
4746
private final List<String> receiveMessageAttributeNames;
4847

4948

5049
private BatchOverrideConfiguration(Builder builder) {
51-
this.outboundBatchSizeLimit = Validate.isPositiveOrNull(builder.outboundBatchSizeLimit,
52-
"outboundBatchSizeLimit");
53-
Validate.isTrue(this.outboundBatchSizeLimit == null || this.outboundBatchSizeLimit <= 10,
50+
this.maxBatchSize = Validate.isPositiveOrNull(builder.maxBatchSize,
51+
"maxBatchSize");
52+
Validate.isTrue(this.maxBatchSize == null || this.maxBatchSize <= 10,
5453
"A batch can contain up to 10 messages.");
5554

56-
this.outboundBatchWindowDuration = Validate.isPositiveOrNull(builder.outboundBatchWindowDuration,
57-
"outboundBatchWindowDuration");
55+
this.sendRequestFrequency = Validate.isPositiveOrNull(builder.sendRequestFrequency,
56+
"sendRequestFrequency");
5857
this.receiveMessageVisibilityTimeout = Validate.isPositiveOrNull(builder.receiveMessageVisibilityTimeout,
5958
"receiveMessageVisibilityTimeout");
60-
this.receiveMessageLongPollWaitDuration = Validate.isPositiveOrNull(builder.receiveMessageLongPollWaitDuration,
61-
"receiveMessageLongPollWaitDuration");
59+
6260
this.receiveMessageMinWaitTime = Validate.isPositiveOrNull(builder.receiveMessageMinWaitTime,
6361
"receiveMessageMinWaitTime");
6462

@@ -81,16 +79,16 @@ public static Builder builder() {
8179
* A batch can contain up to a maximum of 10 messages.
8280
* The default value is 10.
8381
*/
84-
public Integer outboundBatchSizeLimit() {
85-
return outboundBatchSizeLimit;
82+
public Integer maxBatchSize() {
83+
return maxBatchSize;
8684
}
8785

8886
/**
8987
* @return the maximum amount of time that an outgoing call waits to be batched with messages of the same type.
9088
* The default value is 200 milliseconds.
9189
*/
92-
public Duration outboundBatchWindowDuration() {
93-
return outboundBatchWindowDuration;
90+
public Duration sendRequestFrequency() {
91+
return sendRequestFrequency;
9492
}
9593

9694
/**
@@ -100,14 +98,6 @@ public Duration receiveMessageVisibilityTimeout() {
10098
return receiveMessageVisibilityTimeout;
10199
}
102100

103-
/**
104-
* @return the amount of time the receive call will block on the server, waiting for messages to arrive if the
105-
* queue is empty when the call is initially made.
106-
*/
107-
public Duration receiveMessageLongPollWaitDuration() {
108-
return receiveMessageLongPollWaitDuration;
109-
}
110-
111101
/**
112102
* @return the minimum wait time for incoming receive message requests.
113103
*/
@@ -135,10 +125,9 @@ public List<String> receiveMessageAttributeNames() {
135125
@Override
136126
public Builder toBuilder() {
137127
return new Builder()
138-
.outboundBatchSizeLimit(outboundBatchSizeLimit)
139-
.outboundBatchWindowDuration(outboundBatchWindowDuration)
128+
.maxBatchSize(maxBatchSize)
129+
.sendRequestFrequency(sendRequestFrequency)
140130
.receiveMessageVisibilityTimeout(receiveMessageVisibilityTimeout)
141-
.receiveMessageLongPollWaitDuration(receiveMessageLongPollWaitDuration)
142131
.receiveMessageMinWaitTime(receiveMessageMinWaitTime)
143132
.receiveMessageSystemAttributeNames(receiveMessageSystemAttributeNames)
144133
.receiveMessageAttributeNames(receiveMessageAttributeNames);
@@ -148,10 +137,9 @@ public Builder toBuilder() {
148137
@Override
149138
public String toString() {
150139
return ToString.builder("BatchOverrideConfiguration")
151-
.add("outboundBatchSizeLimit", outboundBatchSizeLimit)
152-
.add("outboundBatchWindowDuration", outboundBatchWindowDuration)
140+
.add("maxBatchSize", maxBatchSize)
141+
.add("sendRequestFrequency", sendRequestFrequency)
153142
.add("receiveMessageVisibilityTimeout", receiveMessageVisibilityTimeout)
154-
.add("receiveMessageLongPollWaitDuration", receiveMessageLongPollWaitDuration)
155143
.add("receiveMessageMinWaitTime", receiveMessageMinWaitTime)
156144
.add("receiveMessageSystemAttributeNames", receiveMessageSystemAttributeNames)
157145
.add("receiveMessageAttributeNames", receiveMessageAttributeNames)
@@ -169,21 +157,17 @@ public boolean equals(Object o) {
169157

170158
BatchOverrideConfiguration that = (BatchOverrideConfiguration) o;
171159

172-
if (outboundBatchSizeLimit != null ? !outboundBatchSizeLimit.equals(that.outboundBatchSizeLimit) : that.outboundBatchSizeLimit != null) {
160+
if (maxBatchSize != null ? !maxBatchSize.equals(that.maxBatchSize) : that.maxBatchSize != null) {
173161
return false;
174162
}
175-
if (outboundBatchWindowDuration != null ? !outboundBatchWindowDuration.equals(that.outboundBatchWindowDuration) :
176-
that.outboundBatchWindowDuration != null) {
163+
if (sendRequestFrequency != null ? !sendRequestFrequency.equals(that.sendRequestFrequency) :
164+
that.sendRequestFrequency != null) {
177165
return false;
178166
}
179167
if (receiveMessageVisibilityTimeout != null ? !receiveMessageVisibilityTimeout.equals(that.receiveMessageVisibilityTimeout) :
180168
that.receiveMessageVisibilityTimeout != null) {
181169
return false;
182170
}
183-
if (receiveMessageLongPollWaitDuration != null ? !receiveMessageLongPollWaitDuration.equals(that.receiveMessageLongPollWaitDuration) :
184-
that.receiveMessageLongPollWaitDuration != null) {
185-
return false;
186-
}
187171
if (receiveMessageMinWaitTime != null ? !receiveMessageMinWaitTime.equals(that.receiveMessageMinWaitTime) :
188172
that.receiveMessageMinWaitTime != null) {
189173
return false;
@@ -198,10 +182,9 @@ public boolean equals(Object o) {
198182

199183
@Override
200184
public int hashCode() {
201-
int result = outboundBatchSizeLimit != null ? outboundBatchSizeLimit.hashCode() : 0;
202-
result = 31 * result + (outboundBatchWindowDuration != null ? outboundBatchWindowDuration.hashCode() : 0);
185+
int result = maxBatchSize != null ? maxBatchSize.hashCode() : 0;
186+
result = 31 * result + (sendRequestFrequency != null ? sendRequestFrequency.hashCode() : 0);
203187
result = 31 * result + (receiveMessageVisibilityTimeout != null ? receiveMessageVisibilityTimeout.hashCode() : 0);
204-
result = 31 * result + (receiveMessageLongPollWaitDuration != null ? receiveMessageLongPollWaitDuration.hashCode() : 0);
205188
result = 31 * result + (receiveMessageMinWaitTime != null ? receiveMessageMinWaitTime.hashCode() : 0);
206189
result = 31 * result + (receiveMessageSystemAttributeNames != null ? receiveMessageSystemAttributeNames.hashCode() : 0);
207190
result = 31 * result + (receiveMessageAttributeNames != null ? receiveMessageAttributeNames.hashCode() : 0);
@@ -210,10 +193,9 @@ public int hashCode() {
210193

211194
public static final class Builder implements CopyableBuilder<Builder, BatchOverrideConfiguration> {
212195

213-
private Integer outboundBatchSizeLimit = 10;
214-
private Duration outboundBatchWindowDuration = Duration.ofMillis(200);
196+
private Integer maxBatchSize = 10;
197+
private Duration sendRequestFrequency = Duration.ofMillis(200);
215198
private Duration receiveMessageVisibilityTimeout;
216-
private Duration receiveMessageLongPollWaitDuration;
217199
private Duration receiveMessageMinWaitTime = Duration.ofMillis(50);
218200
private List<MessageSystemAttributeName> receiveMessageSystemAttributeNames = Collections.emptyList();
219201
private List<String> receiveMessageAttributeNames = Collections.emptyList();
@@ -228,28 +210,29 @@ private Builder() {
228210
* and {@link DeleteMessageBatchRequest}.
229211
* A batch can contain up to a maximum of 10 messages. The default value is 10.
230212
*
231-
* @param outboundBatchSizeLimit The maximum number of items to be batched together in a single request.
213+
* @param maxBatchSize The maximum number of items to be batched together in a single request.
232214
* @return This Builder object for method chaining.
233215
*/
234-
public Builder outboundBatchSizeLimit(Integer outboundBatchSizeLimit) {
235-
this.outboundBatchSizeLimit = outboundBatchSizeLimit;
216+
public Builder maxBatchSize(Integer maxBatchSize) {
217+
this.maxBatchSize = maxBatchSize;
236218
return this;
237219
}
238220

239221
/**
240-
* Specifies the maximum duration that an outbound batch is held open for additional outbound requests
241-
* before being sent. Outbound requests include {@link SendMessageBatchRequest},
242-
* {@link ChangeMessageVisibilityBatchRequest}, and {@link DeleteMessageBatchRequest}. If the
243-
* {@link #outboundBatchSizeLimit} is reached before this duration, the batch will be sent immediately.
244-
* The longer this duration, the more time messages have to be added to the batch, which can reduce the
245-
* number of calls made and increase throughput, but it may also increase average message latency.
246-
* The default value is 200 milliseconds.
222+
* Specifies the frequency at which outbound batches are sent.
223+
* This defines the maximum duration that an outbound batch is held open for additional outbound
224+
* requests before being sent. Outbound requests include SendMessageBatchRequest,
225+
* ChangeMessageVisibilityBatchRequest, and DeleteMessageBatchRequest. If the maxBatchSize is reached
226+
* before this duration, the batch will be sent immediately.
227+
* Increasing the {@code sendRequestFrequency} gives more time for additional messages to be added to
228+
* the batch, which can reduce the number of requests and increase throughput. However, a higher
229+
* frequency may also result in increased average message latency. The default value is 200 milliseconds.
247230
*
248-
* @param outboundBatchWindowDuration The new outboundBatchWindowDuration value.
231+
* @param sendRequestFrequency The new value for the frequency at which outbound requests are sent.
249232
* @return This Builder object for method chaining.
250233
*/
251-
public Builder outboundBatchWindowDuration(Duration outboundBatchWindowDuration) {
252-
this.outboundBatchWindowDuration = outboundBatchWindowDuration;
234+
public Builder sendRequestFrequency(Duration sendRequestFrequency) {
235+
this.sendRequestFrequency = sendRequestFrequency;
253236
return this;
254237
}
255238

@@ -266,19 +249,6 @@ public Builder receiveMessageVisibilityTimeout(Duration receiveMessageVisibility
266249
return this;
267250
}
268251

269-
/**
270-
* Specifies the amount of time the receive call will block on the server waiting for messages to arrive if the
271-
* queue is empty when the receive call is first made. By default, this value is not set, meaning no long
272-
* polling wait time on the server side.
273-
*
274-
* @param receiveMessageLongPollWaitDuration The new longPollWaitTimeout value.
275-
* @return This Builder object for method chaining.
276-
*/
277-
public Builder receiveMessageLongPollWaitDuration(Duration receiveMessageLongPollWaitDuration) {
278-
this.receiveMessageLongPollWaitDuration = receiveMessageLongPollWaitDuration;
279-
return this;
280-
}
281-
282252
/**
283253
* Configures the minimum wait time for incoming receive message requests. The default value is 50 milliseconds.
284254
* Without a non-zero minimum wait time, threads can easily waste CPU time by busy-waiting against empty local buffers.

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

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,34 @@ protected ChangeMessageVisibilityBatchManager(RequestBatchConfiguration override
5151

5252
private static ChangeMessageVisibilityBatchRequest createChangeMessageVisibilityBatchRequest(
5353
List<IdentifiableMessage<ChangeMessageVisibilityRequest>> identifiedRequests, String batchKey) {
54-
List<ChangeMessageVisibilityBatchRequestEntry> entries = identifiedRequests
55-
.stream()
56-
.map(identifiedRequest -> createChangeMessageVisibilityBatchRequestEntry(identifiedRequest.id(),
57-
identifiedRequest.message()))
58-
.collect(Collectors.toList());
59-
// Since requests are batched together according to a combination of their queueUrl and overrideConfiguration,
60-
// all requests must have the same overrideConfiguration so it is sufficient to retrieve it from the first
61-
// request.
62-
Optional<AwsRequestOverrideConfiguration> overrideConfiguration = identifiedRequests.get(0).message()
54+
55+
List<ChangeMessageVisibilityBatchRequestEntry> entries =
56+
identifiedRequests.stream()
57+
.map(identifiedRequest -> createChangeMessageVisibilityBatchRequestEntry(
58+
identifiedRequest.id(),
59+
identifiedRequest.message()))
60+
.collect(Collectors.toList());
61+
62+
// All requests have the same overrideConfiguration, so it's sufficient to retrieve it from the first request.
63+
Optional<AwsRequestOverrideConfiguration> overrideConfiguration = identifiedRequests.get(0)
64+
.message()
6365
.overrideConfiguration();
64-
return overrideConfiguration.map(
65-
config -> ChangeMessageVisibilityBatchRequest.builder()
66-
.queueUrl(batchKey)
67-
.overrideConfiguration(config)
68-
.entries(entries)
69-
.build())
70-
.orElseGet(() -> ChangeMessageVisibilityBatchRequest.builder()
71-
.queueUrl(batchKey)
72-
.entries(entries)
73-
.build());
66+
67+
return overrideConfiguration
68+
.map(config -> ChangeMessageVisibilityBatchRequest.builder()
69+
.queueUrl(batchKey)
70+
.overrideConfiguration(config.toBuilder()
71+
.applyMutation(USER_AGENT_APPLIER)
72+
.build())
73+
.entries(entries)
74+
.build())
75+
.orElseGet(() -> ChangeMessageVisibilityBatchRequest.builder()
76+
.queueUrl(batchKey)
77+
.overrideConfiguration(o -> o
78+
.applyMutation(USER_AGENT_APPLIER)
79+
.build())
80+
.entries(entries)
81+
.build());
7482
}
7583

7684
private static ChangeMessageVisibilityBatchRequestEntry createChangeMessageVisibilityBatchRequestEntry(

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;

0 commit comments

Comments
 (0)