Skip to content

Commit

Permalink
HTTP-42-BatchRequest - add support for batch request processing in HT…
Browse files Browse the repository at this point in the history
…TP sink #10 - changes after Code review - fix batch split

Signed-off-by: Krzysztof Chmielewski <[email protected]>
  • Loading branch information
kristoffSC committed Jul 3, 2023
1 parent 6d7de3e commit 224a164
Showing 1 changed file with 6 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,32 +58,22 @@ public List<CompletableFuture<JavaNetHttpResponseWrapper>> submit(
}

var responseFutures = new ArrayList<CompletableFuture<JavaNetHttpResponseWrapper>>();

int counter = 0;
String previousReqeustMethod = requestsToSubmit.get(0).method;
List<HttpSinkRequestEntry> reqeustBatch = new ArrayList<>(httpRequestBatchSize);

for (var entry : requestsToSubmit) {
if (!previousReqeustMethod.equalsIgnoreCase(entry.method)) {
if (reqeustBatch.size() == httpRequestBatchSize
|| !previousReqeustMethod.equalsIgnoreCase(entry.method)) {
// break batch and submit
responseFutures.add(sendBatch(endpointUrl, reqeustBatch));
reqeustBatch.clear();
// start a new batch for new HTTP method.
reqeustBatch.add(entry);
} else {
reqeustBatch.add(entry);
if (++counter % httpRequestBatchSize == 0) {
// batch is full, submit and start new batch.
responseFutures.add(sendBatch(endpointUrl, reqeustBatch));
reqeustBatch.clear();
}
}
reqeustBatch.add(entry);
previousReqeustMethod = entry.method;
}

if (!reqeustBatch.isEmpty()) {
// submit anything that left
responseFutures.add(sendBatch(endpointUrl, reqeustBatch));
}
// submit anything that left
responseFutures.add(sendBatch(endpointUrl, reqeustBatch));
return responseFutures;
}

Expand Down

0 comments on commit 224a164

Please sign in to comment.