Skip to content

Commit

Permalink
Update comments from PR 5488 (#5550)
Browse files Browse the repository at this point in the history
* Update comments of PR 5488

* Update comments from  PR 5488
  • Loading branch information
joviegas authored Sep 3, 2024
1 parent e570e2b commit b04e5ad
Show file tree
Hide file tree
Showing 16 changed files with 101 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

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

import static software.amazon.awssdk.services.sqs.internal.batchmanager.SqsMessageDefault.USER_AGENT_APPLIER;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

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

import static software.amazon.awssdk.services.sqs.internal.batchmanager.SqsMessageDefault.MAX_SEND_MESSAGE_PAYLOAD_SIZE_BYTES;

import static software.amazon.awssdk.services.sqs.internal.batchmanager.ResponseBatchConfiguration.MAX_SEND_MESSAGE_PAYLOAD_SIZE_BYTES;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ScheduledExecutorService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

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

import static software.amazon.awssdk.services.sqs.internal.batchmanager.SqsMessageDefault.USER_AGENT_APPLIER;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

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

import static software.amazon.awssdk.services.sqs.internal.batchmanager.SqsMessageDefault.USER_AGENT_APPLIER;

import static software.amazon.awssdk.services.sqs.internal.batchmanager.RequestBatchManager.USER_AGENT_APPLIER;

import java.time.Duration;
import java.util.Arrays;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

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

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

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ScheduledExecutorService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,12 @@ public class ReceiveQueueBuffer implements SdkAutoCloseable {

private final AtomicBoolean processingFutures = new AtomicBoolean(false);

private ReceiveQueueBuffer(ScheduledExecutorService executor, SqsAsyncClient sqsClient,
ResponseBatchConfiguration config, String queueUrl, QueueAttributesManager queueAttributesManager) {
this.executor = executor;
this.sqsClient = sqsClient;
this.config = config;
this.queueUrl = queueUrl;
this.queueAttributesManager = queueAttributesManager;
private ReceiveQueueBuffer(Builder builder) {
this.executor = builder.executor;
this.sqsClient = builder.sqsClient;
this.config = builder.config;
this.queueUrl = builder.queueUrl;
this.queueAttributesManager = builder.queueAttributesManager;
}

public static Builder builder() {
Expand Down Expand Up @@ -242,7 +241,7 @@ public Builder queueAttributesManager(QueueAttributesManager queueAttributesMana
}

public ReceiveQueueBuffer build() {
return new ReceiveQueueBuffer(executor, sqsClient, config, queueUrl, queueAttributesManager);
return new ReceiveQueueBuffer(this);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package software.amazon.awssdk.services.sqs.internal.batchmanager;


import static software.amazon.awssdk.services.sqs.internal.batchmanager.SqsMessageDefault.USER_AGENT_APPLIER;
import static software.amazon.awssdk.services.sqs.internal.batchmanager.RequestBatchManager.USER_AGENT_APPLIER;

import java.time.Duration;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,21 @@
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration;
import software.amazon.awssdk.core.ApiName;
import software.amazon.awssdk.utils.Either;
import software.amazon.awssdk.utils.Validate;

@SdkInternalApi
public abstract class RequestBatchManager<RequestT, ResponseT, BatchResponseT> {


// abm stands for Automatic Batching Manager
public static final Consumer<AwsRequestOverrideConfiguration.Builder> USER_AGENT_APPLIER =
b -> b.addApiName(ApiName.builder().version("abm").name("hll").build());

protected final RequestBatchConfiguration batchConfiguration ;

private final int maxBatchItems;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

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

import static software.amazon.awssdk.services.sqs.internal.batchmanager.SqsMessageDefault.ATTRIBUTE_MAPS_PAYLOAD_BYTES;
import static software.amazon.awssdk.services.sqs.internal.batchmanager.ResponseBatchConfiguration.ATTRIBUTE_MAPS_PAYLOAD_BYTES;

import java.nio.charset.StandardCharsets;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@

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



import java.time.Duration;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.services.sqs.batchmanager.BatchOverrideConfiguration;
import software.amazon.awssdk.services.sqs.model.MessageSystemAttributeName;
Expand All @@ -33,10 +34,23 @@ public final class ResponseBatchConfiguration {
public static final List<String> RECEIVE_MESSAGE_ATTRIBUTE_NAMES_DEFAULT = Collections.emptyList();
public static final List<MessageSystemAttributeName> MESSAGE_SYSTEM_ATTRIBUTE_NAMES_DEFAULT = Collections.emptyList();
public static final boolean ADAPTIVE_PREFETCHING_DEFAULT = false;
public static final int MAX_BATCH_ITEMS_DEFAULT = 10;
public static final int MAX_INFLIGHT_RECEIVE_BATCHES_DEFAULT = 10;
public static final int MAX_DONE_RECEIVE_BATCHES_DEFAULT = 10;

public static final int MAX_SUPPORTED_SQS_RECEIVE_MSG = 10;

public static final int MAX_SEND_MESSAGE_PAYLOAD_SIZE_BYTES = 262_144; // 256 KiB

/**
* <a href="https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-message-metadata.html#sqs-message-attributes">
* AWS SQS Message Attributes Documentation</a>
*
* Rounding up max payload due to attribute maps.
* This was not done in V1, thus an issue was reported where batch messages failed with payload size exceeding the maximum.
*/
public static final int ATTRIBUTE_MAPS_PAYLOAD_BYTES = 16 * 1024; // 16 KiB


private final Duration visibilityTimeout;
private final Duration longPollWaitTimeout;
private final Duration minReceiveWaitTime;
Expand All @@ -48,47 +62,50 @@ public final class ResponseBatchConfiguration {
private final Integer maxDoneReceiveBatches;

public ResponseBatchConfiguration(BatchOverrideConfiguration overrideConfiguration) {
this.visibilityTimeout = Optional.ofNullable(overrideConfiguration)
.map(BatchOverrideConfiguration::visibilityTimeout)
.orElse(VISIBILITY_TIMEOUT_SECONDS_DEFAULT);

this.longPollWaitTimeout = Optional.ofNullable(overrideConfiguration)
.map(BatchOverrideConfiguration::longPollWaitTimeout)
.orElse(LONG_POLL_WAIT_TIMEOUT_DEFAULT);

this.minReceiveWaitTime = Optional.ofNullable(overrideConfiguration)
.map(BatchOverrideConfiguration::minReceiveWaitTime)
.orElse(MIN_RECEIVE_WAIT_TIME_MS_DEFAULT);

this.messageSystemAttributeValues = Optional.ofNullable(overrideConfiguration)
.map(BatchOverrideConfiguration::messageSystemAttributeName)
.filter(list -> !list.isEmpty())
.orElse(MESSAGE_SYSTEM_ATTRIBUTE_NAMES_DEFAULT);

this.receiveMessageAttributeNames = Optional.ofNullable(overrideConfiguration)
.map(BatchOverrideConfiguration::receiveMessageAttributeNames)
.filter(list -> !list.isEmpty())
.orElse(RECEIVE_MESSAGE_ATTRIBUTE_NAMES_DEFAULT);

this.adaptivePrefetching = Optional.ofNullable(overrideConfiguration)
.map(BatchOverrideConfiguration::adaptivePrefetching)
.orElse(ADAPTIVE_PREFETCHING_DEFAULT);

this.maxBatchItems = Optional.ofNullable(overrideConfiguration)
.map(BatchOverrideConfiguration::maxBatchItems)
.orElse(MAX_BATCH_ITEMS_DEFAULT);


this.maxInflightReceiveBatches = Optional.ofNullable(overrideConfiguration)
.map(BatchOverrideConfiguration::maxInflightReceiveBatches)
.orElse(MAX_INFLIGHT_RECEIVE_BATCHES_DEFAULT);

this.maxDoneReceiveBatches = Optional.ofNullable(overrideConfiguration)
.map(BatchOverrideConfiguration::maxDoneReceiveBatches)
.orElse(MAX_DONE_RECEIVE_BATCHES_DEFAULT);
this.visibilityTimeout = overrideConfiguration != null && overrideConfiguration.visibilityTimeout() != null
? overrideConfiguration.visibilityTimeout()
: VISIBILITY_TIMEOUT_SECONDS_DEFAULT;

this.longPollWaitTimeout = overrideConfiguration != null && overrideConfiguration.longPollWaitTimeout() != null
? overrideConfiguration.longPollWaitTimeout()
: LONG_POLL_WAIT_TIMEOUT_DEFAULT;

this.minReceiveWaitTime = overrideConfiguration != null && overrideConfiguration.minReceiveWaitTime() != null
? overrideConfiguration.minReceiveWaitTime()
: MIN_RECEIVE_WAIT_TIME_MS_DEFAULT;

this.messageSystemAttributeValues = overrideConfiguration != null
&& overrideConfiguration.messageSystemAttributeName() != null
&& !overrideConfiguration.messageSystemAttributeName().isEmpty()
? overrideConfiguration.messageSystemAttributeName()
: MESSAGE_SYSTEM_ATTRIBUTE_NAMES_DEFAULT;

this.receiveMessageAttributeNames = overrideConfiguration != null
&& overrideConfiguration.receiveMessageAttributeNames() != null
&& !overrideConfiguration.receiveMessageAttributeNames().isEmpty()
? overrideConfiguration.receiveMessageAttributeNames()
: RECEIVE_MESSAGE_ATTRIBUTE_NAMES_DEFAULT;

this.adaptivePrefetching = overrideConfiguration != null && overrideConfiguration.adaptivePrefetching() != null
? overrideConfiguration.adaptivePrefetching()
: ADAPTIVE_PREFETCHING_DEFAULT;

this.maxBatchItems = overrideConfiguration != null && overrideConfiguration.maxBatchItems() != null
? overrideConfiguration.maxBatchItems()
: MAX_SUPPORTED_SQS_RECEIVE_MSG;

this.maxInflightReceiveBatches = overrideConfiguration != null
&& overrideConfiguration.maxInflightReceiveBatches() != null
? overrideConfiguration.maxInflightReceiveBatches()
: MAX_INFLIGHT_RECEIVE_BATCHES_DEFAULT;

this.maxDoneReceiveBatches = overrideConfiguration != null && overrideConfiguration.maxDoneReceiveBatches() != null
? overrideConfiguration.maxDoneReceiveBatches()
: MAX_DONE_RECEIVE_BATCHES_DEFAULT;
}



public Duration visibilityTimeout() {
return visibilityTimeout;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

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

import static software.amazon.awssdk.services.sqs.internal.batchmanager.SqsMessageDefault.USER_AGENT_APPLIER;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static software.amazon.awssdk.services.sqs.internal.batchmanager.RequestBatchManager.USER_AGENT_APPLIER;

import java.time.Duration;
import java.util.ArrayList;
Expand All @@ -48,7 +49,6 @@
import software.amazon.awssdk.services.sqs.SqsAsyncClient;
import software.amazon.awssdk.services.sqs.internal.batchmanager.ReceiveSqsMessageHelper;
import software.amazon.awssdk.services.sqs.internal.batchmanager.ResponseBatchConfiguration;
import software.amazon.awssdk.services.sqs.internal.batchmanager.SqsMessageDefault;
import software.amazon.awssdk.services.sqs.model.ChangeMessageVisibilityBatchRequest;
import software.amazon.awssdk.services.sqs.model.ChangeMessageVisibilityBatchResponse;
import software.amazon.awssdk.services.sqs.model.Message;
Expand Down Expand Up @@ -293,7 +293,7 @@ public void asyncReceiveMessageArgs() throws Exception {
.messageAttributeNames("custom1", "custom2")
.visibilityTimeout(9)
.waitTimeSeconds(15)
.overrideConfiguration(o -> o.applyMutation(SqsMessageDefault.USER_AGENT_APPLIER))
.overrideConfiguration(o -> o.applyMutation(USER_AGENT_APPLIER))
.build();

verify(sqsClient, times(1)).receiveMessage(eq(expectedRequest));
Expand Down
Loading

0 comments on commit b04e5ad

Please sign in to comment.