Skip to content

Commit

Permalink
Use internal timeout in direct batch get, remove configuration (#1235)
Browse files Browse the repository at this point in the history
  • Loading branch information
MauriceVanVeen authored Oct 9, 2024
1 parent d263667 commit 30b264c
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 32 deletions.
25 changes: 0 additions & 25 deletions src/main/java/io/nats/client/api/MessageBatchGetRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
*/
public class MessageBatchGetRequest implements JsonSerializable {

private final Duration timeout;
private final int batch;
private final int maxBytes;
private final long sequence;
Expand All @@ -42,7 +41,6 @@ public class MessageBatchGetRequest implements JsonSerializable {
private final ZonedDateTime upToTime;

MessageBatchGetRequest(Builder b) {
this.timeout = b.timeout;
this.batch = b.batch;
this.maxBytes = b.maxBytes;
this.sequence = b.sequence;
Expand All @@ -53,15 +51,6 @@ public class MessageBatchGetRequest implements JsonSerializable {
this.upToTime = b.upToTime;
}

/**
* Timeout used for the request.
*
* @return Duration
*/
public Duration getTimeout() {
return timeout;
}

/**
* Maximum amount of messages to be returned for this request.
*
Expand Down Expand Up @@ -178,7 +167,6 @@ public static Builder builder(MessageBatchGetRequest req) {
* <p>{@code MessageBatchGetRequest.builder().build()} will create a default {@link MessageBatchGetRequest}.
*/
public static class Builder {
private Duration timeout = Duration.ofSeconds(5);
private int batch = -1;
private int maxBytes = -1;
private long sequence = -1;
Expand All @@ -201,7 +189,6 @@ public Builder() {
*/
public Builder(MessageBatchGetRequest req) {
if (req != null) {
this.timeout = req.timeout;
this.batch = req.batch;
this.maxBytes = req.maxBytes;
this.sequence = req.sequence;
Expand All @@ -213,18 +200,6 @@ public Builder(MessageBatchGetRequest req) {
}
}

/**
* Set the timeout used for the request.
*
* @param timeout the timeout
* @return Builder
*/
public Builder timeout(Duration timeout) {
validateDurationRequired(timeout);
this.timeout = timeout;
return this;
}

/**
* Set the maximum amount of messages to be returned for this request.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,9 @@ public void _requestMessageBatch(String streamName, MessageBatchGetRequest messa
String requestSubject = prependPrefix(String.format(JSAPI_DIRECT_GET, streamName));
conn.publish(requestSubject, replyTo, messageBatchGetRequest.serialize());

long start = System.currentTimeMillis();
long maxTimeMillis = messageBatchGetRequest.getTimeout().toMillis();
long maxTimeMillis = getTimeout().toMillis();
long timeLeft = maxTimeMillis;
long start = System.currentTimeMillis();
while (true) {
Message msg = sub.nextMessage(timeLeft);
if (msg == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1729,16 +1729,11 @@ public void testBatchDirectGetMultiLast() throws Exception {

@Test
public void testBatchDirectGetBuilder() {
// Default timeout
assertEquals(Duration.ofSeconds(5), MessageBatchGetRequest.builder().build().getTimeout());

// Request options.
MessageBatchGetRequest requestOptions = MessageBatchGetRequest.builder()
.timeout(Duration.ofSeconds(1))
.maxBytes(1234)
.batch(2)
.build();
assertEquals(Duration.ofSeconds(1), requestOptions.getTimeout());
assertEquals(1234, requestOptions.getMaxBytes());
assertEquals(2, requestOptions.getBatch());
assertEquals("{\"batch\":2,\"max_bytes\":1234}", requestOptions.toJson());
Expand Down

0 comments on commit 30b264c

Please sign in to comment.