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


Java LedgerHandle.readEntries方法代码示例

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


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

示例1: createLedgers

import org.apache.bookkeeper.client.LedgerHandle; //导入方法依赖的package包/类
@Test
public void createLedgers() throws Exception {
    try {
        BookKeeper bookKeeperClient = getKeeper();
        LedgerHandle ledger = bookKeeperClient.createLedger(BookKeeper.DigestType.MAC, "123456".getBytes(Charsets.UTF_8));
        long entryId = ledger.addEntry("Hello World".getBytes());
        System.out.println(entryId);
        Enumeration<LedgerEntry> enumeration = ledger.readEntries(0, 99);
        while (enumeration.hasMoreElements()) {
            LedgerEntry entry = enumeration.nextElement();
            System.out.println(entry.getEntryId());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:aCoder2013,项目名称:fastmq,代码行数:17,代码来源:BookKeeperTest.java

示例2: verifyRecoveredLedgers

import org.apache.bookkeeper.client.LedgerHandle; //导入方法依赖的package包/类
/**
 * Helper method to verify that we can read the recovered ledger entries.
 * 
 * @param numLedgers
 *            Number of ledgers to verify
 * @param startEntryId
 *            Start Entry Id to read
 * @param endEntryId
 *            End Entry Id to read
 * @throws BKException
 * @throws InterruptedException
 */
private void verifyRecoveredLedgers(int numLedgers, long startEntryId, long endEntryId) throws BKException,
        InterruptedException {
    // Get a set of LedgerHandles for all of the ledgers to verify
    List<LedgerHandle> lhs = new ArrayList<LedgerHandle>();
    for (int i = 0; i < numLedgers; i++) {
        lhs.add(bkc.openLedger(i + 1, digestType, System.getProperty("passwd").getBytes()));
    }
    // Read the ledger entries to verify that they are all present and
    // correct in the new bookie.
    for (LedgerHandle lh : lhs) {
        Enumeration<LedgerEntry> entries = lh.readEntries(startEntryId, endEntryId);
        while (entries.hasMoreElements()) {
            LedgerEntry entry = entries.nextElement();
            assertTrue(new String(entry.getEntry()).equals("LedgerId: " + entry.getLedgerId() + ", EntryId: "
                    + entry.getEntryId()));
        }
    }

}
 
开发者ID:gerritjvv,项目名称:bigstreams,代码行数:32,代码来源:BookieRecoveryTest.java

示例3: simpleReadEntries

import org.apache.bookkeeper.client.LedgerHandle; //导入方法依赖的package包/类
private void simpleReadEntries(LedgerHandle lh, long fromEntryId, long untilEntryId) throws Exception {
    Enumeration<LedgerEntry> entries = lh.readEntries(fromEntryId, untilEntryId);
    long i = fromEntryId;
    System.out.println("Entries:");
    while (entries.hasMoreElements()) {
        LedgerEntry entry = entries.nextElement();
        System.out.println("\t" + i  + "(eid=" + entry.getEntryId() + ")\t: ");
        Entry.Reader reader = Entry.newBuilder()
                .setLogSegmentInfo(0L, 0L)
                .setEntryId(entry.getEntryId())
                .setInputStream(entry.getEntryInputStream())
                .setEnvelopeEntry(LogSegmentMetadata.supportsEnvelopedEntries(metadataVersion))
                .buildReader();
        printEntry(reader);
        ++i;
    }
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:18,代码来源:DistributedLogTool.java

示例4: readEntry

import org.apache.bookkeeper.client.LedgerHandle; //导入方法依赖的package包/类
@Test
    public void readEntry() throws Exception {
        BookKeeper keeper = getKeeper();
        LedgerHandle ledgerHandle = keeper.openLedger(55L, BookKeeper.DigestType.MAC, "".getBytes(Charsets.UTF_8));
//        ledgerHandle.addEntry("Hello World".getBytes());
        Enumeration<LedgerEntry> enumeration = ledgerHandle.readEntries(1, 99);
        while (enumeration.hasMoreElements()) {
            LedgerEntry ledgerEntry = enumeration.nextElement();
            System.out.println(ledgerEntry.getEntryId());
        }
    }
 
开发者ID:aCoder2013,项目名称:fastmq,代码行数:12,代码来源:BookKeeperTest.java

示例5: LedgerInputStream

import org.apache.bookkeeper.client.LedgerHandle; //导入方法依赖的package包/类
/**
 * construct a outputstream from a ledger handle
 * 
 * @param lh
 *            ledger handle
 * @throws {@link BKException}, {@link InterruptedException}
 */
public LedgerInputStream(LedgerHandle lh) throws BKException, InterruptedException {
    this.lh = lh;
    bbytes = new byte[defaultSize];
    this.bytebuff = ByteBuffer.wrap(bbytes);
    this.bytebuff.position(this.bytebuff.limit());
    lastEntry = Math.min(lh.getLastAddConfirmed(), increment);
    ledgerSeq = lh.readEntries(0, lastEntry);
}
 
开发者ID:gerritjvv,项目名称:bigstreams,代码行数:16,代码来源:LedgerInputStream.java

示例6: testBookieRecovery

import org.apache.bookkeeper.client.LedgerHandle; //导入方法依赖的package包/类
@Test
public void testBookieRecovery() throws Exception{
    bkc = new BookKeeper("127.0.0.1");
    
    //Shutdown all but 1 bookie
    bs.get(0).shutdown();
    bs.get(1).shutdown();
    bs.get(2).shutdown();
    
    byte[] passwd = "blah".getBytes();
    LedgerHandle lh = bkc.createLedger(1, 1,digestType, passwd);
    
    int numEntries = 100;
    for (int i=0; i< numEntries; i++){
        byte[] data = (""+i).getBytes();
        lh.addEntry(data);
    }
    
    bs.get(3).shutdown();
    BookieServer server = new BookieServer(initialPort + 3, HOSTPORT, tmpDirs.get(3), new File[] { tmpDirs.get(3)});
    server.start();
    bs.set(3, server);

    assertEquals(numEntries - 1 , lh.getLastAddConfirmed());
    Enumeration<LedgerEntry> entries = lh.readEntries(0, lh.getLastAddConfirmed());
    
    int numScanned = 0;
    while (entries.hasMoreElements()){
        assertEquals((""+numScanned), new String(entries.nextElement().getEntry()));
        numScanned++;
    }
    assertEquals(numEntries, numScanned);
    
    
}
 
开发者ID:gerritjvv,项目名称:bigstreams,代码行数:36,代码来源:BookieFailureTest.java

示例7: repairLogSegment

import org.apache.bookkeeper.client.LedgerHandle; //导入方法依赖的package包/类
protected void repairLogSegment(BookKeeperAdmin bkAdmin,
                                MetadataUpdater metadataUpdater,
                                LogSegmentMetadata segment) throws Exception {
    if (segment.isInProgress()) {
        System.out.println("Skip inprogress log segment " + segment);
        return;
    }
    LedgerHandle lh = bkAdmin.openLedger(segment.getLedgerId(), true);
    long lac = lh.getLastAddConfirmed();
    Enumeration<LedgerEntry> entries = lh.readEntries(lac, lac);
    if (!entries.hasMoreElements()) {
        throw new IOException("Entry " + lac + " isn't found for " + segment);
    }
    LedgerEntry lastEntry = entries.nextElement();
    Entry.Reader reader = Entry.newBuilder()
            .setLogSegmentInfo(segment.getLogSegmentSequenceNumber(), segment.getStartSequenceId())
            .setEntryId(lastEntry.getEntryId())
            .setEnvelopeEntry(LogSegmentMetadata.supportsEnvelopedEntries(segment.getVersion()))
            .setInputStream(lastEntry.getEntryInputStream())
            .buildReader();
    LogRecordWithDLSN record = reader.nextRecord();
    LogRecordWithDLSN lastRecord = null;
    while (null != record) {
        lastRecord = record;
        record = reader.nextRecord();
    }
    if (null == lastRecord) {
        throw new IOException("No record found in entry " + lac + " for " + segment);
    }
    System.out.println("Updating last record for " + segment + " to " + lastRecord);
    if (!IOUtils.confirmPrompt("Do you want to make this change (Y/N): ")) {
        return;
    }
    metadataUpdater.updateLastRecord(segment, lastRecord);
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:36,代码来源:DistributedLogTool.java

示例8: testBadVersionOnTwoAllocators

import org.apache.bookkeeper.client.LedgerHandle; //导入方法依赖的package包/类
@Test(timeout = 60000)
public void testBadVersionOnTwoAllocators() throws Exception {
    String allocationPath = "/allocation-bad-version";
    zkc.get().create(allocationPath, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    Stat stat = new Stat();
    byte[] data = zkc.get().getData(allocationPath, false, stat);
    Versioned<byte[]> allocationData = new Versioned<byte[]>(data, new ZkVersion(stat.getVersion()));

    SimpleLedgerAllocator allocator1 =
            new SimpleLedgerAllocator(allocationPath, allocationData, newQuorumConfigProvider(dlConf), zkc, bkc);
    SimpleLedgerAllocator allocator2 =
            new SimpleLedgerAllocator(allocationPath, allocationData, newQuorumConfigProvider(dlConf), zkc, bkc);
    allocator1.allocate();
    // wait until allocated
    ZKTransaction txn1 = newTxn();
    LedgerHandle lh = FutureUtils.result(allocator1.tryObtain(txn1, NULL_LISTENER));
    allocator2.allocate();
    ZKTransaction txn2 = newTxn();
    try {
        FutureUtils.result(allocator2.tryObtain(txn2, NULL_LISTENER));
        fail("Should fail allocating on second allocator as allocator1 is starting allocating something.");
    } catch (ZKException zke) {
        assertEquals(KeeperException.Code.BADVERSION, zke.getKeeperExceptionCode());
    }
    FutureUtils.result(txn1.execute());
    Utils.close(allocator1);
    Utils.close(allocator2);

    long eid = lh.addEntry("hello world".getBytes());
    lh.close();
    LedgerHandle readLh = bkc.get().openLedger(lh.getId(), BookKeeper.DigestType.CRC32, dlConf.getBKDigestPW().getBytes());
    Enumeration<LedgerEntry> entries = readLh.readEntries(eid, eid);
    int i = 0;
    while (entries.hasMoreElements()) {
        LedgerEntry entry = entries.nextElement();
        assertEquals("hello world", new String(entry.getEntry(), UTF_8));
        ++i;
    }
    assertEquals(1, i);
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:41,代码来源:TestLedgerAllocator.java

示例9: 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

示例10: testSuccessAllocatorShouldDeleteUnusedledger

import org.apache.bookkeeper.client.LedgerHandle; //导入方法依赖的package包/类
@Test(timeout = 60000)
public void testSuccessAllocatorShouldDeleteUnusedledger() throws Exception {
    String allocationPath = "/allocation-delete-unused-ledger";
    zkc.get().create(allocationPath, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    Stat stat = new Stat();
    byte[] data = zkc.get().getData(allocationPath, false, stat);

    Versioned<byte[]> allocationData = new Versioned<byte[]>(data, new ZkVersion(stat.getVersion()));

    SimpleLedgerAllocator allocator1 =
            new SimpleLedgerAllocator(allocationPath, allocationData, newQuorumConfigProvider(dlConf), zkc, bkc);
    allocator1.allocate();
    // wait until allocated
    ZKTransaction txn1 = newTxn();
    LedgerHandle lh1 = FutureUtils.result(allocator1.tryObtain(txn1, NULL_LISTENER));

    // Second allocator kicks in
    stat = new Stat();
    data = zkc.get().getData(allocationPath, false, stat);
    allocationData = new Versioned<byte[]>(data, new ZkVersion(stat.getVersion()));
    SimpleLedgerAllocator allocator2 =
            new SimpleLedgerAllocator(allocationPath, allocationData, newQuorumConfigProvider(dlConf), zkc, bkc);
    allocator2.allocate();
    // wait until allocated
    ZKTransaction txn2 = newTxn();
    LedgerHandle lh2 = FutureUtils.result(allocator2.tryObtain(txn2, NULL_LISTENER));

    // should fail to commit txn1 as version is changed by second allocator
    try {
        FutureUtils.result(txn1.execute());
        fail("Should fail commit obtaining ledger handle from first allocator as allocator is modified by second allocator.");
    } catch (ZKException ke) {
        // as expected
    }
    FutureUtils.result(txn2.execute());
    Utils.close(allocator1);
    Utils.close(allocator2);

    // ledger handle should be deleted
    try {
        lh1.close();
        fail("LedgerHandle allocated by allocator1 should be deleted.");
    } catch (BKException bke) {
        // as expected
    }
    try {
        bkc.get().openLedger(lh1.getId(), BookKeeper.DigestType.CRC32, dlConf.getBKDigestPW().getBytes());
        fail("LedgerHandle allocated by allocator1 should be deleted.");
    } catch (BKException.BKNoSuchLedgerExistsException nslee) {
        // as expected
    }
    long eid = lh2.addEntry("hello world".getBytes());
    lh2.close();
    LedgerHandle readLh = bkc.get().openLedger(lh2.getId(), BookKeeper.DigestType.CRC32, dlConf.getBKDigestPW().getBytes());
    Enumeration<LedgerEntry> entries = readLh.readEntries(eid, eid);
    int i = 0;
    while (entries.hasMoreElements()) {
        LedgerEntry entry = entries.nextElement();
        assertEquals("hello world", new String(entry.getEntry(), UTF_8));
        ++i;
    }
    assertEquals(1, i);
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:64,代码来源:TestLedgerAllocator.java


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