Java Code Examples for org.apache.bookkeeper.client.AsyncCallback#OpenCallback
The following examples show how to use
org.apache.bookkeeper.client.AsyncCallback#OpenCallback .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LedgerHandleCache.java From distributedlog with Apache License 2.0 | 5 votes |
/** * Open the given ledger <i>ledgerDesc</i>. * * @param ledgerDesc * ledger description * @param callback * open callback. * @param ctx * callback context */ private void asyncOpenLedger(LedgerDescriptor ledgerDesc, AsyncCallback.OpenCallback callback, Object ctx) { try { if (!ledgerDesc.isFenced()) { bkc.get().asyncOpenLedgerNoRecovery(ledgerDesc.getLedgerId(), BookKeeper.DigestType.CRC32, digestpw.getBytes(UTF_8), callback, ctx); } else { bkc.get().asyncOpenLedger(ledgerDesc.getLedgerId(), BookKeeper.DigestType.CRC32, digestpw.getBytes(UTF_8), callback, ctx); } } catch (IOException ace) { // :) when we can't get bkc, it means bookie handle not available callback.openComplete(BKException.Code.BookieHandleNotAvailableException, null, ctx); } }
Example 2
Source File: BKLogSegmentEntryStore.java From distributedlog with Apache License 2.0 | 4 votes |
@Override public CompletableFuture<LogSegmentRandomAccessEntryReader> openRandomAccessReader(final LogSegmentMetadata segment, final boolean fence) { final BookKeeper bk; try { bk = this.bkc.get(); } catch (IOException e) { return FutureUtils.exception(e); } final CompletableFuture<LogSegmentRandomAccessEntryReader> openPromise = new CompletableFuture<LogSegmentRandomAccessEntryReader>(); AsyncCallback.OpenCallback openCallback = new AsyncCallback.OpenCallback() { @Override public void openComplete(int rc, LedgerHandle lh, Object ctx) { if (BKException.Code.OK != rc) { FutureUtils.completeExceptionally( openPromise, new BKTransmitException("Failed to open ledger handle for log segment " + segment, rc)); return; } LogSegmentRandomAccessEntryReader reader = new BKLogSegmentRandomAccessEntryReader( segment, lh, conf); FutureUtils.complete(openPromise, reader); } }; if (segment.isInProgress() && !fence) { bk.asyncOpenLedgerNoRecovery( segment.getLogSegmentId(), BookKeeper.DigestType.CRC32, passwd, openCallback, null); } else { bk.asyncOpenLedger( segment.getLogSegmentId(), BookKeeper.DigestType.CRC32, passwd, openCallback, null); } return openPromise; }