当前位置: 首页>>代码示例>>Java>>正文


Java LedgerHandle.getId方法代码示例

本文整理汇总了Java中org.apache.bookkeeper.client.LedgerHandle.getId方法的典型用法代码示例。如果您正苦于以下问题:Java LedgerHandle.getId方法的具体用法?Java LedgerHandle.getId怎么用?Java LedgerHandle.getId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.bookkeeper.client.LedgerHandle的用法示例。


在下文中一共展示了LedgerHandle.getId方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: asyncReadEntry

import org.apache.bookkeeper.client.LedgerHandle; //导入方法依赖的package包/类
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()) {
        LedgerHandle ledger = currentLedger;
        entryCache.asyncReadEntry(ledger, position, callback, ctx);
    } else {
        getLedgerHandle(position.getLedgerId()).thenAccept(ledger -> {
            entryCache.asyncReadEntry(ledger, position, callback, ctx);
        }).exceptionally(ex -> {
            log.error("[{}] Error opening ledger for reading at position {} - {}", name, position, ex.getMessage());
            callback.readEntryFailed(new ManagedLedgerException(ex), ctx);
            return null;
        });
    }

}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:20,代码来源:ManagedLedgerImpl.java

示例2: asyncReadEntries

import org.apache.bookkeeper.client.LedgerHandle; //导入方法依赖的package包/类
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 (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(new ManagedLedgerException(ex), opReadEntry.ctx);
            return null;
        });
    }
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:38,代码来源:ManagedLedgerImpl.java

示例3: invalidateLedgerHandle

import org.apache.bookkeeper.client.LedgerHandle; //导入方法依赖的package包/类
void invalidateLedgerHandle(LedgerHandle ledgerHandle, int rc) {
    long ledgerId = ledgerHandle.getId();
    if (ledgerId != currentLedger.getId()) {
        // remove handle from ledger cache since we got a (read) error
        ledgerCache.remove(ledgerId);
        if (log.isDebugEnabled()) {
            log.debug("[{}] Removed ledger {} from cache (after read error: {})", name, ledgerId, rc);
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("[{}] Ledger that encountered read error {} is current ledger", name, rc);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:15,代码来源:ManagedLedgerImpl.java

示例4: addComplete

import org.apache.bookkeeper.client.LedgerHandle; //导入方法依赖的package包/类
@Override
public void addComplete(int rc, final LedgerHandle lh, long entryId, Object ctx) {
    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());
    checkArgument(this.ctx == ctx);

    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) {
        // If we get a write error, we will try to create a new ledger and re-submit the pending writes. If the
        // ledger creation fails (persistent bk failure, another instanche owning the ML, ...), then the writes will
        // be marked as failed.
        ml.mbean.recordAddEntryError();

        ml.getExecutor().submitOrdered(ml.getName(), SafeRun.safeRun(() -> {
            // Force the creation of a new ledger. Doing it in a background thread to avoid acquiring ML lock
            // from a BK callback.
            ml.ledgerClosed(lh);
        }));
    } else {
        // Trigger addComplete callback in a thread hashed on the managed ledger name
        ml.getExecutor().submitOrdered(ml.getName(), this);
    }
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:32,代码来源:OpAddEntry.java

示例5: updateMetadata

import org.apache.bookkeeper.client.LedgerHandle; //导入方法依赖的package包/类
/**
 * Updates the metadata and persists it as a result of adding a new Ledger.
 *
 * @param currentMetadata   The current metadata.
 * @param newLedger         The newly added Ledger.
 * @param clearEmptyLedgers If true, the new metadata will not not contain any pointers to empty Ledgers. Setting this
 *                          to true will not remove a pointer to the last few ledgers in the Log (controlled by
 *                          Ledgers.MIN_FENCE_LEDGER_COUNT), even if they are indeed empty (this is so we don't interfere
 *                          with any ongoing fencing activities as another instance of this Log may not have yet been
 *                          fenced out).
 * @return A new instance of the LogMetadata, which includes the new ledger.
 * @throws DurableDataLogException If an Exception occurred.
 */
private LogMetadata updateMetadata(LogMetadata currentMetadata, LedgerHandle newLedger, boolean clearEmptyLedgers) throws DurableDataLogException {
    boolean create = currentMetadata == null;
    if (create) {
        // This is the first ledger ever in the metadata.
        currentMetadata = new LogMetadata(newLedger.getId());
    } else {
        currentMetadata = currentMetadata.addLedger(newLedger.getId());
        if (clearEmptyLedgers) {
            // Remove those ledgers from the metadata that are empty.
            currentMetadata = currentMetadata.removeEmptyLedgers(Ledgers.MIN_FENCE_LEDGER_COUNT);
        }
    }

    try {
        persistMetadata(currentMetadata, create);
    } catch (DurableDataLogException ex) {
        try {
            Ledgers.delete(newLedger.getId(), this.bookKeeper);
        } catch (Exception deleteEx) {
            log.warn("{}: Unable to delete newly created ledger {}.", this.traceObjectId, newLedger.getId(), deleteEx);
            ex.addSuppressed(deleteEx);
        }

        throw ex;
    }

    log.info("{} Metadata updated ({}).", this.traceObjectId, currentMetadata);
    return currentMetadata;
}
 
开发者ID:pravega,项目名称:pravega,代码行数:43,代码来源:BookKeeperLog.java

示例6: name

import org.apache.bookkeeper.client.LedgerHandle; //导入方法依赖的package包/类
@Test
public void name() throws Exception {
    // Create a client object for the local ensemble. This
    // operation throws multiple exceptions, so make sure to
    // use a try/catch block when instantiating client objects.
    BookKeeper bkc = new BookKeeper("localhost:2181");

    // A password for the new ledger
    byte[] ledgerPassword = "123456".getBytes();

    // Create a new ledger and fetch its identifier
    LedgerHandle lh = bkc.createLedger(BookKeeper.DigestType.MAC, ledgerPassword);
    long ledgerId = lh.getId();
    System.out.println("ledgerId: " + ledgerId);

    // Create a buffer for four-byte entries
    ByteBuffer entry = ByteBuffer.allocate(4);

    int numberOfEntries = 100;

    // Add entries to the ledger, then close it
    for (int i = 0; i < numberOfEntries; i++) {
        entry.putInt(i);
        entry.position(0);
        lh.addEntry(entry.array());
    }
    lh.close();

    // Open the ledger for reading
    lh = bkc.openLedger(ledgerId, BookKeeper.DigestType.MAC, ledgerPassword);

    // Read all available entries
    Enumeration<LedgerEntry> entries = lh.readEntries(0, numberOfEntries-1);

    while (entries.hasMoreElements()) {
        ByteBuffer result = ByteBuffer.wrap(entries.nextElement().getEntry());
        Integer retrEntry = result.getInt();

        // Print the integer stored in each entry
        System.out.println(String.format("Result: %s", retrEntry));
    }

    // Close the ledger and the client
    lh.close();
    bkc.close();
}
 
开发者ID:aCoder2013,项目名称:fastmq,代码行数:47,代码来源:BookKeeperTest.java

示例7: internalReadFromLedger

import org.apache.bookkeeper.client.LedgerHandle; //导入方法依赖的package包/类
private void internalReadFromLedger(LedgerHandle ledger, OpReadEntry opReadEntry) {

        // Perform the read
        long firstEntry = opReadEntry.readPosition.getEntryId();
        long lastEntryInLedger;
        final ManagedCursorImpl cursor = opReadEntry.cursor;

        PositionImpl lastPosition = lastConfirmedEntry;

        if (ledger.getId() == lastPosition.getLedgerId()) {
            // For the current ledger, we only give read visibility to the last entry we have received a confirmation in
            // the managed ledger layer
            lastEntryInLedger = lastPosition.getEntryId();
        } else {
            // For other ledgers, already closed the BK lastAddConfirmed is appropriate
            lastEntryInLedger = ledger.getLastAddConfirmed();
        }

        if (firstEntry > lastEntryInLedger) {
            if (log.isDebugEnabled()) {
                log.debug("[{}] No more messages to read from ledger={} lastEntry={} readEntry={}", name,
                        ledger.getId(), lastEntryInLedger, firstEntry);
            }

            if (ledger.getId() != currentLedger.getId()) {
                // Cursor was placed past the end of one ledger, move it to the
                // beginning of the next ledger
                Long nextLedgerId = ledgers.ceilingKey(ledger.getId() + 1);
                opReadEntry.updateReadPosition(new PositionImpl(nextLedgerId, 0));
            }

            opReadEntry.checkReadCompletion();
            return;
        }

        long lastEntry = min(firstEntry + opReadEntry.getNumberOfEntriesToRead() - 1, lastEntryInLedger);

        if (log.isDebugEnabled()) {
            log.debug("[{}] Reading entries from ledger {} - first={} last={}", name, ledger.getId(), firstEntry,
                    lastEntry);
        }
        entryCache.asyncReadEntry(ledger, firstEntry, lastEntry, false, opReadEntry, opReadEntry.ctx);

        if (updateCursorRateLimit.tryAcquire()) {
            if (isCursorActive(cursor)) {
                final PositionImpl lastReadPosition = PositionImpl.get(ledger.getId(), lastEntry);
                discardEntriesFromCache(cursor, lastReadPosition);
            }
        }
    }
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:51,代码来源:ManagedLedgerImpl.java

示例8: getCursorLedger

import org.apache.bookkeeper.client.LedgerHandle; //导入方法依赖的package包/类
public long getCursorLedger() {
    LedgerHandle lh = cursorLedger;
    return lh != null ? lh.getId() : -1;
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:5,代码来源:ManagedCursorImpl.java


注:本文中的org.apache.bookkeeper.client.LedgerHandle.getId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。