BewareMyPower commented on code in PR #24961:
URL: https://github.com/apache/pulsar/pull/24961#discussion_r2509358631


##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java:
##########
@@ -2318,6 +2319,170 @@ public void asyncReadEntry(Position position, 
ReadEntryCallback callback, Object
 
     }
 
+    @Override
+    public CompletableFuture<List<Entry>> asyncReadEntries(Position start, 
long numberOfEntriesToRead) {
+        CompletableFuture<List<Entry>> f = new CompletableFuture<>();
+        asyncReadEntries(start, numberOfEntriesToRead, new 
ReadEntriesCallback() {
+            @Override
+            public void readEntriesComplete(List<Entry> entries, Object ctx) {
+                f.complete(entries);
+            }
+
+            @Override
+            public void readEntriesFailed(ManagedLedgerException exception, 
Object ctx) {
+                f.completeExceptionally(exception);
+            }
+        }, null);
+        return f;
+    }
+
+    @Override
+    public void asyncReadEntries(Position start, long numberOfEntriesToRead, 
ReadEntriesCallback callback, Object ctx) {
+        if (!ledgers.containsKey(start.getLedgerId())) {
+            callback.readEntriesFailed(new ManagedLedgerException("Ledger not 
found"), ctx);
+            return;
+        }
+        if (start.getLedgerId() < 0) {
+            start = PositionFactory.create(start.getLedgerId(), 0L);
+        }
+        if (!isValidPosition(start)) {
+            callback.readEntriesFailed(new ManagedLedgerException("Invalid 
position"), ctx);
+            return;
+        }
+
+        Map<Long, Pair<Long, Long>> readerPositions = 
getReaderPositions(start, numberOfEntriesToRead);
+        if (readerPositions.isEmpty()) {
+            callback.readEntriesComplete(Collections.emptyList(), ctx);
+            return;
+        }
+
+        int actualReadEntries = getNumberOfEntries(readerPositions);
+        ReadEntriesCallback callback0 = new 
InternalReadEntriesCallback(actualReadEntries, callback);

Review Comment:
   Such callback is complicated, a better solution is to gather all futures of 
`asyncReadEntry` and wait for all of them



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to