sijie commented on a change in pull request #1809: Change LedgerManager to use CompletableFuture URL: https://github.com/apache/bookkeeper/pull/1809#discussion_r233123083
########## File path: bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/AbstractZkLedgerManager.java ########## @@ -100,34 +102,31 @@ public void run() { if (LOG.isDebugEnabled()) { LOG.debug("Re-read ledger metadata for {}.", ledgerId); } - readLedgerMetadata(ledgerId, this, AbstractZkLedgerManager.this); + readLedgerMetadata(ledgerId, AbstractZkLedgerManager.this) + .whenComplete((metadata, exception) -> handleMetadata(metadata, exception)); } else { if (LOG.isDebugEnabled()) { LOG.debug("Ledger metadata listener for ledger {} is already removed.", ledgerId); } } } - @Override - public void operationComplete(int rc, final Versioned<LedgerMetadata> result) { - if (BKException.Code.OK == rc) { + private void handleMetadata(Versioned<LedgerMetadata> result, Throwable exception) { + if (exception == null) { final Set<LedgerMetadataListener> listenerSet = listeners.get(ledgerId); if (null != listenerSet) { if (LOG.isDebugEnabled()) { LOG.debug("Ledger metadata is changed for {} : {}.", ledgerId, result); } - scheduler.submit(new Runnable() { - @Override - public void run() { + scheduler.submit(() -> { synchronized (listenerSet) { for (LedgerMetadataListener listener : listenerSet) { listener.onChanged(ledgerId, result); } } - } - }); + }); } - } else if (BKException.Code.NoSuchLedgerExistsException == rc) { + } else if (exception instanceof BKException.BKNoSuchLedgerExistsException) { Review comment: I will suggest not using `instanceof` here. We should just use `getExceptionCode(exception) == BKException.Code.NoSuchLedgerExistsException` ---------------------------------------------------------------- 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