Skip to content

Commit c6f41b1

Browse files
committed
Update after internal poll
1 parent 4d3f21c commit c6f41b1

File tree

8 files changed

+93
-90
lines changed

8 files changed

+93
-90
lines changed

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

Lines changed: 59 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@
3131
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
3232

3333
/**
34-
* Configuration values for the BatchManager Implementation. All values are optional, and default values will be used if they
35-
* are not specified.
34+
* Configuration values for the BatchManager implementation used for controlling batch operations in Amazon SQS.
35+
* All values are optional, and default values will be used if they are not specified.
3636
*/
3737
@SdkPublicApi
3838
public final class BatchOverrideConfiguration implements ToCopyableBuilder<BatchOverrideConfiguration.Builder,
3939
BatchOverrideConfiguration> {
4040

4141
private final Integer maxBatchSize;
42-
private final Duration sendRequestFrequency;
42+
private final Duration sendMessageFrequency;
4343
private final Duration receiveMessageVisibilityTimeout;
44-
private final Duration receiveMessageMinWaitTime;
44+
private final Duration receiveMessageMinWaitDuration;
4545
private final List<MessageSystemAttributeName> receiveMessageSystemAttributeNames;
4646
private final List<String> receiveMessageAttributeNames;
4747

@@ -50,72 +50,73 @@ private BatchOverrideConfiguration(Builder builder) {
5050
this.maxBatchSize = Validate.isPositiveOrNull(builder.maxBatchSize,
5151
"maxBatchSize");
5252
Validate.isTrue(this.maxBatchSize == null || this.maxBatchSize <= 10,
53-
"A batch can contain up to 10 messages.");
53+
"The maxBatchSize must be less than or equal to 10. A batch can contain up to 10 messages.");
5454

55-
this.sendRequestFrequency = Validate.isPositiveOrNull(builder.sendRequestFrequency,
56-
"sendRequestFrequency");
55+
this.sendMessageFrequency = Validate.isPositiveOrNull(builder.sendMessageFrequency,
56+
"sendMessageFrequency");
5757
this.receiveMessageVisibilityTimeout = Validate.isPositiveOrNull(builder.receiveMessageVisibilityTimeout,
5858
"receiveMessageVisibilityTimeout");
59-
60-
this.receiveMessageMinWaitTime = Validate.isPositiveOrNull(builder.receiveMessageMinWaitTime,
61-
"receiveMessageMinWaitTime");
62-
63-
this.receiveMessageSystemAttributeNames = builder.receiveMessageSystemAttributeNames != null ?
64-
Collections.unmodifiableList(
65-
new ArrayList<>(builder.receiveMessageSystemAttributeNames)) :
66-
Collections.emptyList();
67-
68-
this.receiveMessageAttributeNames = builder.receiveMessageAttributeNames != null ?
69-
Collections.unmodifiableList(new ArrayList<>(builder.receiveMessageAttributeNames)) :
70-
Collections.emptyList();
59+
this.receiveMessageMinWaitDuration = Validate.isPositiveOrNull(builder.receiveMessageMinWaitDuration,
60+
"receiveMessageMinWaitDuration");
61+
this.receiveMessageSystemAttributeNames =
62+
builder.receiveMessageSystemAttributeNames == null ? Collections.emptyList() :
63+
Collections.unmodifiableList(builder.receiveMessageSystemAttributeNames);
64+
65+
this.receiveMessageAttributeNames =
66+
builder.receiveMessageAttributeNames == null ? Collections.emptyList() :
67+
Collections.unmodifiableList(builder.receiveMessageAttributeNames);
7168
}
7269

7370
public static Builder builder() {
7471
return new Builder();
7572
}
7673

7774
/**
78-
* @return the maximum number of items that are batched together in a single outbound request.
79-
* A batch can contain up to a maximum of 10 messages.
80-
* The default value is 10.
75+
* @return the maximum number of items that can be batched together in a single outbound SQS request
76+
* (e.g., for {@link SendMessageBatchRequest}, {@link ChangeMessageVisibilityBatchRequest}, or
77+
* {@link DeleteMessageBatchRequest}). A batch can contain up to a maximum of 10 messages.
78+
* The default value is 10.
8179
*/
8280
public Integer maxBatchSize() {
8381
return maxBatchSize;
8482
}
8583

8684
/**
87-
* @return the maximum amount of time that an outgoing call waits to be batched with messages of the same type.
88-
* The default value is 200 milliseconds.
85+
* @return the maximum duration an outgoing call waits for additional messages of the same type before being sent.
86+
* If the {@link #maxBatchSize()} is reached before this duration, the batch will be sent immediately.
87+
* The default value is 200 milliseconds.
8988
*/
90-
public Duration sendRequestFrequency() {
91-
return sendRequestFrequency;
89+
public Duration sendMessageFrequency() {
90+
return sendMessageFrequency;
9291
}
9392

9493
/**
95-
* @return the custom visibility timeout to use when retrieving messages from SQS.
94+
* @return the custom visibility timeout to use when retrieving messages from SQS. If not set,
95+
* the default visibility timeout configured on the SQS queue will be used.
9696
*/
9797
public Duration receiveMessageVisibilityTimeout() {
9898
return receiveMessageVisibilityTimeout;
9999
}
100100

101101
/**
102-
* @return the minimum wait time for incoming receive message requests.
102+
* @return the minimum wait time for incoming receive message requests. Without a non-zero minimum wait time,
103+
* threads can waste CPU resources busy-waiting for messages. The default value is 50 milliseconds.
103104
*/
104-
public Duration receiveMessageMinWaitTime() {
105-
return receiveMessageMinWaitTime;
105+
public Duration receiveMessageMinWaitDuration() {
106+
return receiveMessageMinWaitDuration;
106107
}
107108

108109
/**
109-
* @return the system attribute names specific to the {@link ReceiveMessageRequest}
110-
* that will be requested via {@link ReceiveMessageRequest#messageSystemAttributeNames()}.
110+
* @return the system attribute names to request for {@link ReceiveMessageRequest}. Requests with differing
111+
* system attribute names will bypass the batch manager and make a direct call to SQS.
111112
*/
112113
public List<MessageSystemAttributeName> receiveMessageSystemAttributeNames() {
113114
return receiveMessageSystemAttributeNames;
114115
}
115116

116117
/**
117-
* @return the message attribute names that are specific to receive calls
118-
* and will be requested via {@link ReceiveMessageRequest#messageAttributeNames()}.
118+
* @return the message attribute names to request for {@link ReceiveMessageRequest}. Requests with different
119+
* message attribute names will bypass the batch manager and make a direct call to SQS.
119120
*/
120121
public List<String> receiveMessageAttributeNames() {
121122
return receiveMessageAttributeNames;
@@ -126,21 +127,20 @@ public List<String> receiveMessageAttributeNames() {
126127
public Builder toBuilder() {
127128
return new Builder()
128129
.maxBatchSize(maxBatchSize)
129-
.sendRequestFrequency(sendRequestFrequency)
130+
.sendMessageFrequency(sendMessageFrequency)
130131
.receiveMessageVisibilityTimeout(receiveMessageVisibilityTimeout)
131-
.receiveMessageMinWaitTime(receiveMessageMinWaitTime)
132+
.receiveMessageMinWaitDuration(receiveMessageMinWaitDuration)
132133
.receiveMessageSystemAttributeNames(receiveMessageSystemAttributeNames)
133134
.receiveMessageAttributeNames(receiveMessageAttributeNames);
134135
}
135136

136-
137137
@Override
138138
public String toString() {
139139
return ToString.builder("BatchOverrideConfiguration")
140140
.add("maxBatchSize", maxBatchSize)
141-
.add("sendRequestFrequency", sendRequestFrequency)
141+
.add("sendMessageFrequency", sendMessageFrequency)
142142
.add("receiveMessageVisibilityTimeout", receiveMessageVisibilityTimeout)
143-
.add("receiveMessageMinWaitTime", receiveMessageMinWaitTime)
143+
.add("receiveMessageMinWaitDuration", receiveMessageMinWaitDuration)
144144
.add("receiveMessageSystemAttributeNames", receiveMessageSystemAttributeNames)
145145
.add("receiveMessageAttributeNames", receiveMessageAttributeNames)
146146
.build();
@@ -160,20 +160,22 @@ public boolean equals(Object o) {
160160
if (maxBatchSize != null ? !maxBatchSize.equals(that.maxBatchSize) : that.maxBatchSize != null) {
161161
return false;
162162
}
163-
if (sendRequestFrequency != null ? !sendRequestFrequency.equals(that.sendRequestFrequency) :
164-
that.sendRequestFrequency != null) {
163+
if (sendMessageFrequency != null ? !sendMessageFrequency.equals(that.sendMessageFrequency) :
164+
that.sendMessageFrequency != null) {
165165
return false;
166166
}
167-
if (receiveMessageVisibilityTimeout != null ? !receiveMessageVisibilityTimeout.equals(that.receiveMessageVisibilityTimeout) :
167+
if (receiveMessageVisibilityTimeout != null
168+
? !receiveMessageVisibilityTimeout.equals(that.receiveMessageVisibilityTimeout) :
168169
that.receiveMessageVisibilityTimeout != null) {
169170
return false;
170171
}
171-
if (receiveMessageMinWaitTime != null ? !receiveMessageMinWaitTime.equals(that.receiveMessageMinWaitTime) :
172-
that.receiveMessageMinWaitTime != null) {
172+
if (receiveMessageMinWaitDuration != null ? !receiveMessageMinWaitDuration.equals(that.receiveMessageMinWaitDuration) :
173+
that.receiveMessageMinWaitDuration != null) {
173174
return false;
174175
}
175-
if (receiveMessageSystemAttributeNames != null ? !receiveMessageSystemAttributeNames.equals(that.receiveMessageSystemAttributeNames) :
176-
that.receiveMessageSystemAttributeNames != null) {
176+
if (receiveMessageSystemAttributeNames != null ?
177+
!receiveMessageSystemAttributeNames.equals(that.receiveMessageSystemAttributeNames)
178+
: that.receiveMessageSystemAttributeNames != null) {
177179
return false;
178180
}
179181
return receiveMessageAttributeNames != null ? receiveMessageAttributeNames.equals(that.receiveMessageAttributeNames) :
@@ -183,9 +185,9 @@ public boolean equals(Object o) {
183185
@Override
184186
public int hashCode() {
185187
int result = maxBatchSize != null ? maxBatchSize.hashCode() : 0;
186-
result = 31 * result + (sendRequestFrequency != null ? sendRequestFrequency.hashCode() : 0);
188+
result = 31 * result + (sendMessageFrequency != null ? sendMessageFrequency.hashCode() : 0);
187189
result = 31 * result + (receiveMessageVisibilityTimeout != null ? receiveMessageVisibilityTimeout.hashCode() : 0);
188-
result = 31 * result + (receiveMessageMinWaitTime != null ? receiveMessageMinWaitTime.hashCode() : 0);
190+
result = 31 * result + (receiveMessageMinWaitDuration != null ? receiveMessageMinWaitDuration.hashCode() : 0);
189191
result = 31 * result + (receiveMessageSystemAttributeNames != null ? receiveMessageSystemAttributeNames.hashCode() : 0);
190192
result = 31 * result + (receiveMessageAttributeNames != null ? receiveMessageAttributeNames.hashCode() : 0);
191193
return result;
@@ -194,9 +196,9 @@ public int hashCode() {
194196
public static final class Builder implements CopyableBuilder<Builder, BatchOverrideConfiguration> {
195197

196198
private Integer maxBatchSize = 10;
197-
private Duration sendRequestFrequency = Duration.ofMillis(200);
199+
private Duration sendMessageFrequency ;
198200
private Duration receiveMessageVisibilityTimeout;
199-
private Duration receiveMessageMinWaitTime = Duration.ofMillis(50);
201+
private Duration receiveMessageMinWaitDuration ;
200202
private List<MessageSystemAttributeName> receiveMessageSystemAttributeNames = Collections.emptyList();
201203
private List<String> receiveMessageAttributeNames = Collections.emptyList();
202204

@@ -224,15 +226,15 @@ public Builder maxBatchSize(Integer maxBatchSize) {
224226
* requests before being sent. Outbound requests include SendMessageBatchRequest,
225227
* ChangeMessageVisibilityBatchRequest, and DeleteMessageBatchRequest. If the maxBatchSize is reached
226228
* before this duration, the batch will be sent immediately.
227-
* Increasing the {@code sendRequestFrequency} gives more time for additional messages to be added to
229+
* Increasing the {@code sendMessageFrequency} gives more time for additional messages to be added to
228230
* the batch, which can reduce the number of requests and increase throughput. However, a higher
229231
* frequency may also result in increased average message latency. The default value is 200 milliseconds.
230232
*
231-
* @param sendRequestFrequency The new value for the frequency at which outbound requests are sent.
233+
* @param sendMessageFrequency The new value for the frequency at which outbound requests are sent.
232234
* @return This Builder object for method chaining.
233235
*/
234-
public Builder sendRequestFrequency(Duration sendRequestFrequency) {
235-
this.sendRequestFrequency = sendRequestFrequency;
236+
public Builder sendMessageFrequency(Duration sendMessageFrequency) {
237+
this.sendMessageFrequency = sendMessageFrequency;
236238
return this;
237239
}
238240

@@ -257,11 +259,11 @@ public Builder receiveMessageVisibilityTimeout(Duration receiveMessageVisibility
257259
* The call may return sooner than the configured `WaitTimeSeconds` if there are messages in the buffer.
258260
* If no messages are available and the wait time expires, the call will return an empty message list.
259261
*
260-
* @param receiveMessageMinWaitTime The new minimum wait time value.
262+
* @param receiveMessageMinWaitDuration The new minimum wait time value.
261263
* @return This Builder object for method chaining.
262264
*/
263-
public Builder receiveMessageMinWaitTime(Duration receiveMessageMinWaitTime) {
264-
this.receiveMessageMinWaitTime = receiveMessageMinWaitTime;
265+
public Builder receiveMessageMinWaitDuration(Duration receiveMessageMinWaitDuration) {
266+
this.receiveMessageMinWaitDuration = receiveMessageMinWaitDuration;
265267
return this;
266268
}
267269

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@
1717

1818
import static software.amazon.awssdk.services.sqs.internal.batchmanager.ResponseBatchConfiguration.MAX_SUPPORTED_SQS_RECEIVE_MSG;
1919

20-
import java.util.Optional;
2120
import java.util.concurrent.CompletableFuture;
2221
import java.util.concurrent.ScheduledExecutorService;
2322
import java.util.concurrent.TimeUnit;
2423
import java.util.function.Function;
2524
import software.amazon.awssdk.annotations.SdkInternalApi;
26-
import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration;
2725
import software.amazon.awssdk.services.sqs.SqsAsyncClient;
2826
import software.amazon.awssdk.services.sqs.model.ReceiveMessageRequest;
2927
import software.amazon.awssdk.services.sqs.model.ReceiveMessageResponse;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public ReceiveMessageBatchManager(SqsAsyncClient sqsClient,
4444
this.executor = executor;
4545
this.config = config != null
4646
? ResponseBatchConfiguration.builder()
47-
.minReceiveWaitTime(config.receiveMessageMinWaitTime())
47+
.minReceiveWaitTime(config.receiveMessageMinWaitDuration())
4848
.receiveMessageAttributeNames(config.receiveMessageAttributeNames())
4949
.messageSystemAttributeNames(config.receiveMessageSystemAttributeNames())
5050
.visibilityTimeout(config.receiveMessageVisibilityTimeout())

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,16 @@ public final class RequestBatchConfiguration {
3131
private final Integer maxBatchItems;
3232
private final Integer maxBatchKeys;
3333
private final Integer maxBufferSize;
34-
private final Duration maxOutboundBatchCollectionDuration;
34+
private final Duration sendMessageFrequency;
3535
private final Integer maxBatchBytesSize;
3636

3737
private RequestBatchConfiguration(Builder builder) {
3838

3939
this.maxBatchItems = builder.maxBatchItems != null ? builder.maxBatchItems : DEFAULT_MAX_BATCH_ITEMS;
4040
this.maxBatchKeys = builder.maxBatchKeys != null ? builder.maxBatchKeys : DEFAULT_MAX_BATCH_KEYS;
4141
this.maxBufferSize = builder.maxBufferSize != null ? builder.maxBufferSize : DEFAULT_MAX_BUFFER_SIZE;
42-
this.maxOutboundBatchCollectionDuration = builder.maxOutboundBatchCollectionDuration != null ? builder.maxOutboundBatchCollectionDuration :
42+
this.sendMessageFrequency = builder.sendMessageFrequency != null ?
43+
builder.sendMessageFrequency :
4344
DEFAULT_MAX_BATCH_OPEN_IN_MS;
4445
this.maxBatchBytesSize = builder.maxBatchBytesSize != null ? builder.maxBatchBytesSize : DEFAULT_MAX_BATCH_BYTES_SIZE;
4546

@@ -53,14 +54,14 @@ public static Builder builder(BatchOverrideConfiguration configuration) {
5354
if (configuration != null) {
5455
return new Builder()
5556
.maxBatchItems(configuration.maxBatchSize())
56-
.maxOutboundBatchCollectionDuration(configuration.sendRequestFrequency())
57+
.sendMessageFrequency(configuration.sendMessageFrequency())
5758
.maxBatchBytesSize(configuration.maxBatchSize());
5859
}
5960
return new Builder();
6061
}
6162

62-
public Duration maxOutboundBatchCollectionDuration() {
63-
return maxOutboundBatchCollectionDuration;
63+
public Duration sendMessageFrequency() {
64+
return sendMessageFrequency;
6465
}
6566

6667
public int maxBatchItems() {
@@ -84,7 +85,7 @@ public static final class Builder {
8485
private Integer maxBatchItems;
8586
private Integer maxBatchKeys;
8687
private Integer maxBufferSize;
87-
private Duration maxOutboundBatchCollectionDuration;
88+
private Duration sendMessageFrequency;
8889
private Integer maxBatchBytesSize;
8990

9091
private Builder() {
@@ -105,8 +106,8 @@ public Builder maxBufferSize(Integer maxBufferSize) {
105106
return this;
106107
}
107108

108-
public Builder maxOutboundBatchCollectionDuration(Duration maxOutboundBatchCollectionDuration) {
109-
this.maxOutboundBatchCollectionDuration = maxOutboundBatchCollectionDuration;
109+
public Builder sendMessageFrequency(Duration sendMessageFrequency) {
110+
this.sendMessageFrequency = sendMessageFrequency;
110111
return this;
111112
}
112113

0 commit comments

Comments
 (0)