Java Code Examples for org.apache.bookkeeper.client.LedgerHandle#getId()

The following examples show how to use org.apache.bookkeeper.client.LedgerHandle#getId() . 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: ManagedLedgerImpl.java    From pulsar with Apache License 2.0 6 votes vote down vote up
public void asyncReadEntry(PositionImpl position, ReadEntryCallback callback, Object ctx) {
    LedgerHandle currentLedger = this.currentLedger;
    if (log.isDebugEnabled()) {
        log.debug("[{}] Reading entry ledger {}: {}", name, position.getLedgerId(), position.getEntryId());
    }
    if (position.getLedgerId() == currentLedger.getId()) {
        asyncReadEntry(currentLedger, position, callback, ctx);
    } else {
        getLedgerHandle(position.getLedgerId()).thenAccept(ledger -> asyncReadEntry(ledger, position, callback, ctx)).exceptionally(ex -> {
            log.error("[{}] Error opening ledger for reading at position {} - {}", name, position, ex.getMessage());
            callback.readEntryFailed(ManagedLedgerException.getManagedLedgerException(ex.getCause()), ctx);
            return null;
        });
    }

}
 
Example 2
Source File: ManagedLedgerImpl.java    From pulsar with Apache License 2.0 5 votes vote down vote up
void asyncReadEntries(OpReadEntry opReadEntry) {
    final State state = STATE_UPDATER.get(this);
    if (state == State.Fenced || state == State.Closed) {
        opReadEntry.readEntriesFailed(new ManagedLedgerFencedException(), opReadEntry.ctx);
        return;
    }

    long ledgerId = opReadEntry.readPosition.getLedgerId();

    LedgerHandle currentLedger = this.currentLedger;

    if (currentLedger != null && ledgerId == currentLedger.getId()) {
        // Current writing ledger is not in the cache (since we don't want
        // it to be automatically evicted), and we cannot use 2 different
        // ledger handles (read & write)for the same ledger.
        internalReadFromLedger(currentLedger, opReadEntry);
    } else {
        LedgerInfo ledgerInfo = ledgers.get(ledgerId);
        if (ledgerInfo == null || ledgerInfo.getEntries() == 0) {
            // Cursor is pointing to a empty ledger, there's no need to try opening it. Skip this ledger and
            // move to the next one
            opReadEntry.updateReadPosition(new PositionImpl(opReadEntry.readPosition.getLedgerId() + 1, 0));
            opReadEntry.checkReadCompletion();
            return;
        }

        // Get a ledger handle to read from
        getLedgerHandle(ledgerId).thenAccept(ledger -> internalReadFromLedger(ledger, opReadEntry)).exceptionally(ex -> {
            log.error("[{}] Error opening ledger for reading at position {} - {}", name, opReadEntry.readPosition,
                    ex.getMessage());
            opReadEntry.readEntriesFailed(ManagedLedgerException.getManagedLedgerException(ex.getCause()),
                    opReadEntry.ctx);
            return null;
        });
    }
}
 
Example 3
Source File: OpAddEntry.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@Override
public void addComplete(int rc, final LedgerHandle lh, long entryId, Object ctx) {

    if (!STATE_UPDATER.compareAndSet(OpAddEntry.this, State.INITIATED, State.COMPLETED)) {
        log.warn("[{}] The add op is terminal legacy callback for entry {}-{} adding.", ml.getName(), lh.getId(), entryId);
        OpAddEntry.this.recycle();
        return;
    }

    if (ledger.getId() != lh.getId()) {
        log.warn("[{}] ledgerId {} doesn't match with acked ledgerId {}", ml.getName(), ledger.getId(), lh.getId());
    }
    checkArgument(ledger.getId() == lh.getId(), "ledgerId %s doesn't match with acked ledgerId %s", ledger.getId(),
            lh.getId());
    
    if (!checkAndCompleteOp(ctx)) {
        // means callback might have been completed by different thread (timeout task thread).. so do nothing
        return;
    }

    this.entryId = entryId;
    if (log.isDebugEnabled()) {
        log.debug("[{}] [{}] write-complete: ledger-id={} entry-id={} size={} rc={}", this, ml.getName(),
                lh.getId(), entryId, dataLength, rc);
    }

    if (rc != BKException.Code.OK) {
        handleAddFailure(lh);
    } else {
        // Trigger addComplete callback in a thread hashed on the managed ledger name
        ml.getExecutor().executeOrdered(ml.getName(), this);
    }
}
 
Example 4
Source File: ManagedCursorImpl.java    From pulsar with Apache License 2.0 4 votes vote down vote up
public long getCursorLedger() {
    LedgerHandle lh = cursorLedger;
    return lh != null ? lh.getId() : -1;
}