ivankelly commented on a change in pull request #1809: Change LedgerManager to use CompletableFuture URL: https://github.com/apache/bookkeeper/pull/1809#discussion_r234228416
########## File path: bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieShell.java ########## @@ -1024,41 +1022,45 @@ public int runCmd(CommandLine cmdLine) throws Exception { final CountDownLatch processDone = new CountDownLatch(1); Processor<Long> ledgerProcessor = new Processor<Long>() { - @Override - public void process(Long ledgerId, VoidCallback cb) { - if (!printMeta && (bookieAddress == null)) { - printLedgerMetadata(ledgerId, null, false); - cb.processResult(BKException.Code.OK, null, null); - } else { - GenericCallback<Versioned<LedgerMetadata>> gencb = (rc, ledgerMetadata) -> { - if (rc == BKException.Code.OK) { - if ((bookieAddress == null) - || BookKeeperAdmin.areEntriesOfLedgerStoredInTheBookie( - ledgerId, bookieAddress, ledgerMetadata.getValue())) { - /* - * the print method has to be in - * synchronized scope, otherwise - * output of printLedgerMetadata - * could interleave since this - * callback for different - * ledgers can happen in - * different threads. - */ - synchronized (BookieShell.this) { - printLedgerMetadata(ledgerId, ledgerMetadata.getValue(), printMeta); - } - } - } else if (rc == BKException.Code.NoSuchLedgerExistsException) { - rc = BKException.Code.OK; - } else { - LOG.error("Unable to read the ledger: " + ledgerId + " information"); - } - cb.processResult(rc, null, null); - }; - ledgerManager.readLedgerMetadata(ledgerId, gencb); + @Override + public void process(Long ledgerId, VoidCallback cb) { + if (!printMeta && (bookieAddress == null)) { + printLedgerMetadata(ledgerId, null, false); + cb.processResult(BKException.Code.OK, null, null); + } else { + ledgerManager.readLedgerMetadata(ledgerId).whenComplete( + (metadata, exception) -> { Review comment: in this case, it would be a BKException, though when exceptions are wrapped and when they are not is not straightforward. If I have an future X and I call completeExceptionally on it, all handlers for that exception will get the raw exception. Any futures which have been created when installing the handlers will get the wrapped exception. In any case, I'm going remove all the instanceof and just pull the error codes out ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services