use of io.pravega.client.BatchClientFactory in project pravega by pravega.
the class BatchClientSimpleTest method readFromRanges.
// Start utils region
private int readFromRanges(List<SegmentRange> ranges, BatchClientFactory batchClient) {
List<CompletableFuture<Integer>> eventCounts = ranges.parallelStream().map(range -> CompletableFuture.supplyAsync(() -> batchClient.readSegment(range, new JavaSerializer<>())).thenApplyAsync(segmentIterator -> {
log.debug("Thread " + Thread.currentThread().getId() + " reading events.");
int numEvents = Lists.newArrayList(segmentIterator).size();
segmentIterator.close();
return numEvents;
})).collect(Collectors.toList());
return eventCounts.stream().map(CompletableFuture::join).mapToInt(Integer::intValue).sum();
}
Aggregations