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

The following examples show how to use org.apache.bookkeeper.client.LedgerHandle#readLastConfirmed() . 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: BkHelperLiveTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
void whenWriteAndReadEntries_thenSuccess() throws Exception {
    LedgerHandle lh = createLedger(bk, "myledger", ledgerPassword);
    long start = System.currentTimeMillis();
    for (int i = 0; i < 1000; i++) {
        byte[] data = new String("message-" + i).getBytes();
        lh.append(data);
    }
    lh.close();
    long elapsed = System.currentTimeMillis() - start;
    LOG.info("Entries added to ledgerId " + lh.getId() + ", elapsed=" + elapsed);

    Long ledgerId = findLedgerByName(bk, "myledger").orElse(null);
    assertNotNull(ledgerId);
    lh = bk.openLedger(ledgerId, BookKeeper.DigestType.MAC, ledgerPassword);
    long lastId = lh.readLastConfirmed();
    Enumeration<LedgerEntry> entries = lh.readEntries(0, lastId);
    while (entries.hasMoreElements()) {
        LedgerEntry entry = entries.nextElement();
        String msg = new String(entry.getEntry());
        LOG.info("Entry: id=" + entry.getEntryId() + ", data=" + msg);
    }
}
 
Example 2
Source File: DistributedLogTool.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
@Override
protected int runCmd() throws Exception {
    LedgerHandle lh = getBookKeeperClient().get().openLedgerNoRecovery(
            getLedgerID(), BookKeeper.DigestType.CRC32, dlConf.getBKDigestPW().getBytes(UTF_8));
    try {
        long lac = lh.readLastConfirmed();
        System.out.println("LastAddConfirmed: " + lac);
    } finally {
        lh.close();
    }
    return 0;
}
 
Example 3
Source File: DistributedLogTool.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
@Override
protected int runCmd() throws Exception {
    LedgerHandle lh = getBookKeeperClient().get()
            .openLedgerNoRecovery(getLedgerID(), BookKeeper.DigestType.CRC32,
                    dlConf.getBKDigestPW().getBytes(UTF_8));
    try {
        if (null == fromEntryId) {
            fromEntryId = 0L;
        }
        if (null == untilEntryId) {
            untilEntryId = lh.readLastConfirmed();
        }
        if (untilEntryId >= fromEntryId) {
            if (readAllBookies) {
                LedgerReader lr = new LedgerReader(getBookKeeperClient().get());
                if (readLac) {
                    readLacsFromAllBookies(lr, lh, fromEntryId, untilEntryId);
                } else {
                    readEntriesFromAllBookies(lr, lh, fromEntryId, untilEntryId);
                }
            } else {
                simpleReadEntries(lh, fromEntryId, untilEntryId);
            }
        } else {
            System.out.println("No entries.");
        }
    } finally {
        lh.close();
    }
    return 0;
}
 
Example 4
Source File: DistributedLogTool.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
@Override
protected int runCmd() throws Exception {
    LedgerHandle lh = getBookKeeperClient().get().openLedgerNoRecovery(
            getLedgerID(), BookKeeper.DigestType.CRC32, dlConf.getBKDigestPW().getBytes(UTF_8));
    try {
        long lac = lh.readLastConfirmed();
        System.out.println("LastAddConfirmed: " + lac);
    } finally {
        lh.close();
    }
    return 0;
}
 
Example 5
Source File: DistributedLogTool.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
@Override
protected int runCmd() throws Exception {
    LedgerHandle lh = getBookKeeperClient().get().openLedgerNoRecovery(getLedgerID(), BookKeeper.DigestType.CRC32,
            dlConf.getBKDigestPW().getBytes(UTF_8));
    try {
        if (null == fromEntryId) {
            fromEntryId = 0L;
        }
        if (null == untilEntryId) {
            untilEntryId = lh.readLastConfirmed();
        }
        if (untilEntryId >= fromEntryId) {
            if (readAllBookies) {
                LedgerReader lr = new LedgerReader(getBookKeeperClient().get());
                if (readLac) {
                    readLacsFromAllBookies(lr, lh, fromEntryId, untilEntryId);
                } else {
                    readEntriesFromAllBookies(lr, lh, fromEntryId, untilEntryId);
                }
            } else {
                simpleReadEntries(lh, fromEntryId, untilEntryId);
            }
        } else {
            System.out.println("No entries.");
        }
    } finally {
        lh.close();
    }
    return 0;
}