31
31
import software .amazon .awssdk .utils .builder .ToCopyableBuilder ;
32
32
33
33
/**
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.
36
36
*/
37
37
@ SdkPublicApi
38
38
public final class BatchOverrideConfiguration implements ToCopyableBuilder <BatchOverrideConfiguration .Builder ,
39
39
BatchOverrideConfiguration > {
40
40
41
41
private final Integer maxBatchSize ;
42
- private final Duration sendRequestFrequency ;
42
+ private final Duration sendMessageFrequency ;
43
43
private final Duration receiveMessageVisibilityTimeout ;
44
- private final Duration receiveMessageMinWaitTime ;
44
+ private final Duration receiveMessageMinWaitDuration ;
45
45
private final List <MessageSystemAttributeName > receiveMessageSystemAttributeNames ;
46
46
private final List <String > receiveMessageAttributeNames ;
47
47
@@ -50,72 +50,73 @@ private BatchOverrideConfiguration(Builder builder) {
50
50
this .maxBatchSize = Validate .isPositiveOrNull (builder .maxBatchSize ,
51
51
"maxBatchSize" );
52
52
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." );
54
54
55
- this .sendRequestFrequency = Validate .isPositiveOrNull (builder .sendRequestFrequency ,
56
- "sendRequestFrequency " );
55
+ this .sendMessageFrequency = Validate .isPositiveOrNull (builder .sendMessageFrequency ,
56
+ "sendMessageFrequency " );
57
57
this .receiveMessageVisibilityTimeout = Validate .isPositiveOrNull (builder .receiveMessageVisibilityTimeout ,
58
58
"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 );
71
68
}
72
69
73
70
public static Builder builder () {
74
71
return new Builder ();
75
72
}
76
73
77
74
/**
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.
81
79
*/
82
80
public Integer maxBatchSize () {
83
81
return maxBatchSize ;
84
82
}
85
83
86
84
/**
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.
89
88
*/
90
- public Duration sendRequestFrequency () {
91
- return sendRequestFrequency ;
89
+ public Duration sendMessageFrequency () {
90
+ return sendMessageFrequency ;
92
91
}
93
92
94
93
/**
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.
96
96
*/
97
97
public Duration receiveMessageVisibilityTimeout () {
98
98
return receiveMessageVisibilityTimeout ;
99
99
}
100
100
101
101
/**
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.
103
104
*/
104
- public Duration receiveMessageMinWaitTime () {
105
- return receiveMessageMinWaitTime ;
105
+ public Duration receiveMessageMinWaitDuration () {
106
+ return receiveMessageMinWaitDuration ;
106
107
}
107
108
108
109
/**
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 .
111
112
*/
112
113
public List <MessageSystemAttributeName > receiveMessageSystemAttributeNames () {
113
114
return receiveMessageSystemAttributeNames ;
114
115
}
115
116
116
117
/**
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 .
119
120
*/
120
121
public List <String > receiveMessageAttributeNames () {
121
122
return receiveMessageAttributeNames ;
@@ -126,21 +127,20 @@ public List<String> receiveMessageAttributeNames() {
126
127
public Builder toBuilder () {
127
128
return new Builder ()
128
129
.maxBatchSize (maxBatchSize )
129
- .sendRequestFrequency ( sendRequestFrequency )
130
+ .sendMessageFrequency ( sendMessageFrequency )
130
131
.receiveMessageVisibilityTimeout (receiveMessageVisibilityTimeout )
131
- .receiveMessageMinWaitTime ( receiveMessageMinWaitTime )
132
+ .receiveMessageMinWaitDuration ( receiveMessageMinWaitDuration )
132
133
.receiveMessageSystemAttributeNames (receiveMessageSystemAttributeNames )
133
134
.receiveMessageAttributeNames (receiveMessageAttributeNames );
134
135
}
135
136
136
-
137
137
@ Override
138
138
public String toString () {
139
139
return ToString .builder ("BatchOverrideConfiguration" )
140
140
.add ("maxBatchSize" , maxBatchSize )
141
- .add ("sendRequestFrequency " , sendRequestFrequency )
141
+ .add ("sendMessageFrequency " , sendMessageFrequency )
142
142
.add ("receiveMessageVisibilityTimeout" , receiveMessageVisibilityTimeout )
143
- .add ("receiveMessageMinWaitTime " , receiveMessageMinWaitTime )
143
+ .add ("receiveMessageMinWaitDuration " , receiveMessageMinWaitDuration )
144
144
.add ("receiveMessageSystemAttributeNames" , receiveMessageSystemAttributeNames )
145
145
.add ("receiveMessageAttributeNames" , receiveMessageAttributeNames )
146
146
.build ();
@@ -160,20 +160,22 @@ public boolean equals(Object o) {
160
160
if (maxBatchSize != null ? !maxBatchSize .equals (that .maxBatchSize ) : that .maxBatchSize != null ) {
161
161
return false ;
162
162
}
163
- if (sendRequestFrequency != null ? !sendRequestFrequency .equals (that .sendRequestFrequency ) :
164
- that .sendRequestFrequency != null ) {
163
+ if (sendMessageFrequency != null ? !sendMessageFrequency .equals (that .sendMessageFrequency ) :
164
+ that .sendMessageFrequency != null ) {
165
165
return false ;
166
166
}
167
- if (receiveMessageVisibilityTimeout != null ? !receiveMessageVisibilityTimeout .equals (that .receiveMessageVisibilityTimeout ) :
167
+ if (receiveMessageVisibilityTimeout != null
168
+ ? !receiveMessageVisibilityTimeout .equals (that .receiveMessageVisibilityTimeout ) :
168
169
that .receiveMessageVisibilityTimeout != null ) {
169
170
return false ;
170
171
}
171
- if (receiveMessageMinWaitTime != null ? !receiveMessageMinWaitTime .equals (that .receiveMessageMinWaitTime ) :
172
- that .receiveMessageMinWaitTime != null ) {
172
+ if (receiveMessageMinWaitDuration != null ? !receiveMessageMinWaitDuration .equals (that .receiveMessageMinWaitDuration ) :
173
+ that .receiveMessageMinWaitDuration != null ) {
173
174
return false ;
174
175
}
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 ) {
177
179
return false ;
178
180
}
179
181
return receiveMessageAttributeNames != null ? receiveMessageAttributeNames .equals (that .receiveMessageAttributeNames ) :
@@ -183,9 +185,9 @@ public boolean equals(Object o) {
183
185
@ Override
184
186
public int hashCode () {
185
187
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 );
187
189
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 );
189
191
result = 31 * result + (receiveMessageSystemAttributeNames != null ? receiveMessageSystemAttributeNames .hashCode () : 0 );
190
192
result = 31 * result + (receiveMessageAttributeNames != null ? receiveMessageAttributeNames .hashCode () : 0 );
191
193
return result ;
@@ -194,9 +196,9 @@ public int hashCode() {
194
196
public static final class Builder implements CopyableBuilder <Builder , BatchOverrideConfiguration > {
195
197
196
198
private Integer maxBatchSize = 10 ;
197
- private Duration sendRequestFrequency = Duration . ofMillis ( 200 ) ;
199
+ private Duration sendMessageFrequency ;
198
200
private Duration receiveMessageVisibilityTimeout ;
199
- private Duration receiveMessageMinWaitTime = Duration . ofMillis ( 50 ) ;
201
+ private Duration receiveMessageMinWaitDuration ;
200
202
private List <MessageSystemAttributeName > receiveMessageSystemAttributeNames = Collections .emptyList ();
201
203
private List <String > receiveMessageAttributeNames = Collections .emptyList ();
202
204
@@ -224,15 +226,15 @@ public Builder maxBatchSize(Integer maxBatchSize) {
224
226
* requests before being sent. Outbound requests include SendMessageBatchRequest,
225
227
* ChangeMessageVisibilityBatchRequest, and DeleteMessageBatchRequest. If the maxBatchSize is reached
226
228
* 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
228
230
* the batch, which can reduce the number of requests and increase throughput. However, a higher
229
231
* frequency may also result in increased average message latency. The default value is 200 milliseconds.
230
232
*
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.
232
234
* @return This Builder object for method chaining.
233
235
*/
234
- public Builder sendRequestFrequency (Duration sendRequestFrequency ) {
235
- this .sendRequestFrequency = sendRequestFrequency ;
236
+ public Builder sendMessageFrequency (Duration sendMessageFrequency ) {
237
+ this .sendMessageFrequency = sendMessageFrequency ;
236
238
return this ;
237
239
}
238
240
@@ -257,11 +259,11 @@ public Builder receiveMessageVisibilityTimeout(Duration receiveMessageVisibility
257
259
* The call may return sooner than the configured `WaitTimeSeconds` if there are messages in the buffer.
258
260
* If no messages are available and the wait time expires, the call will return an empty message list.
259
261
*
260
- * @param receiveMessageMinWaitTime The new minimum wait time value.
262
+ * @param receiveMessageMinWaitDuration The new minimum wait time value.
261
263
* @return This Builder object for method chaining.
262
264
*/
263
- public Builder receiveMessageMinWaitTime (Duration receiveMessageMinWaitTime ) {
264
- this .receiveMessageMinWaitTime = receiveMessageMinWaitTime ;
265
+ public Builder receiveMessageMinWaitDuration (Duration receiveMessageMinWaitDuration ) {
266
+ this .receiveMessageMinWaitDuration = receiveMessageMinWaitDuration ;
265
267
return this ;
266
268
}
267
269
0 commit comments