/** * Async try read last confirmed. * * @param ledgerDesc * ledger descriptor * @return future presenting read last confirmed result. */ public Future<Long> asyncTryReadLastConfirmed(LedgerDescriptor ledgerDesc) { RefCountedLedgerHandle refHandle = handlesMap.get(ledgerDesc); if (null == refHandle) { LOG.error("Accessing ledger {} without opening.", ledgerDesc); return Future.exception(BKException.create(BKException.Code.UnexpectedConditionException)); } final Promise<Long> promise = new Promise<Long>(); refHandle.handle.asyncTryReadLastConfirmed(new AsyncCallback.ReadLastConfirmedCallback() { @Override public void readLastConfirmedComplete(int rc, long lastAddConfirmed, Object ctx) { if (BKException.Code.OK == rc) { promise.setValue(lastAddConfirmed); } else { promise.setException(BKException.create(rc)); } } }, null); return promise; }
/** * {@inheritDoc} */ @Override public CompletableFuture<Long> tryReadLastAddConfirmedAsync() { FutureReadLastConfirmed result = new FutureReadLastConfirmed(); asyncTryReadLastConfirmed(result, null); return result; }
/** * Obtains synchronously the last confirmed write from a quorum of bookies. * It is similar as {@link #readLastConfirmed()}, but it doesn't wait all the responses * from the quorum. It would callback immediately if it received a LAC which is larger * than current LAC. * * @see #readLastConfirmed() * * @return The entry id of the last confirmed write or {@link #INVALID_ENTRY_ID INVALID_ENTRY_ID} * if no entry has been confirmed * @throws InterruptedException * @throws BKException */ public long tryReadLastConfirmed() throws InterruptedException, BKException { LastConfirmedCtx ctx = new LastConfirmedCtx(); asyncTryReadLastConfirmed(new SyncReadLastConfirmedCallback(), ctx); synchronized (ctx) { while (!ctx.ready()) { ctx.wait(); } } if (ctx.getRC() != BKException.Code.OK) { throw BKException.create(ctx.getRC()); } return ctx.getlastConfirmed(); }