Java Code Examples for org.apache.bookkeeper.client.BookKeeper#asyncOpenLedger()

The following examples show how to use org.apache.bookkeeper.client.BookKeeper#asyncOpenLedger() . 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: BKLogSegmentEntryStore.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<LogSegmentEntryReader> openReader(LogSegmentMetadata segment,
                                                long startEntryId) {
    BookKeeper bk;
    try {
        bk = this.bkc.get();
    } catch (IOException e) {
        return FutureUtils.exception(e);
    }
    OpenReaderRequest request = new OpenReaderRequest(segment, startEntryId);
    if (segment.isInProgress()) {
        bk.asyncOpenLedgerNoRecovery(
                segment.getLogSegmentId(),
                BookKeeper.DigestType.CRC32,
                passwd,
                this,
                request);
    } else {
        bk.asyncOpenLedger(
                segment.getLogSegmentId(),
                BookKeeper.DigestType.CRC32,
                passwd,
                this,
                request);
    }
    return request.openPromise;
}
 
Example 2
Source File: CompactedTopicImpl.java    From pulsar with Apache License 2.0 5 votes vote down vote up
private static CompletableFuture<CompactedTopicContext> openCompactedLedger(BookKeeper bk, long id) {
    CompletableFuture<LedgerHandle> promise = new CompletableFuture<>();
    bk.asyncOpenLedger(id,
                       Compactor.COMPACTED_TOPIC_LEDGER_DIGEST_TYPE,
                       Compactor.COMPACTED_TOPIC_LEDGER_PASSWORD,
                       (rc, ledger, ctx) -> {
                           if (rc != BKException.Code.OK) {
                               promise.completeExceptionally(BKException.create(rc));
                           } else {
                               promise.complete(ledger);
                           }
                       }, null);
    return promise.thenApply((ledger) -> new CompactedTopicContext(
                                     ledger, createCache(ledger, DEFAULT_STARTPOINT_CACHE_SIZE)));
}
 
Example 3
Source File: BKLogSegmentEntryStore.java    From distributedlog with Apache License 2.0 4 votes vote down vote up
@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;
}