Skip to content

Commit

Permalink
Convert the long seconds into an int
Browse files Browse the repository at this point in the history
  • Loading branch information
joey committed Oct 3, 2024
1 parent 4bd8bf7 commit 3ec6b0a
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -602,11 +602,11 @@ private ReceiveMessageRequest doCreateReceiveMessageRequest(Duration pollTimeout
ReceiveMessageRequest.Builder builder = ReceiveMessageRequest.builder().queueUrl(attributes.getQueueUrl())
.maxNumberOfMessages(maxNumberOfMessages).messageAttributeNames(this.messageAttributeNames)
.attributeNamesWithStrings(this.messageSystemAttributeNames)
.waitTimeSeconds(pollTimeout.toSeconds());
.waitTimeSeconds(toInt(pollTimeout.toSeconds()));
if (additionalHeaders.containsKey(SqsHeaders.SQS_VISIBILITY_TIMEOUT_HEADER)) {
builder.visibilityTimeout(
getValueAs(additionalHeaders, SqsHeaders.SQS_VISIBILITY_TIMEOUT_HEADER, Duration.class)
.toSeconds());
toInt(getValueAs(additionalHeaders, SqsHeaders.SQS_VISIBILITY_TIMEOUT_HEADER, Duration.class)
.toSeconds()));
}
if (additionalHeaders.containsKey(SqsHeaders.SQS_RECEIVE_REQUEST_ATTEMPT_ID_HEADER)) {
builder.receiveRequestAttemptId(
Expand All @@ -616,6 +616,15 @@ private ReceiveMessageRequest doCreateReceiveMessageRequest(Duration pollTimeout
return builder.build();
}

// Convert a long value to an int. Values larger than Integer.MAX_VALUE are set to Integer.MAX_VALUE
private int toInt(long longValue) {
if (longValue > Integer.MAX_VALUE) {
return Integer.MAX_VALUE;
}

return (int) longValue;
}

private <V> V getValueAs(Map<String, Object> headers, String headerName, Class<V> valueClass) {
return valueClass.cast(headers.get(headerName));
}
Expand Down

0 comments on commit 3ec6b0a

Please sign in to comment.