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


Java LedgerHandle.close方法代码示例

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


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

示例1: close

import org.apache.bookkeeper.client.LedgerHandle; //导入方法依赖的package包/类
@Override
public void close() throws LogNotAvailableException {
    LedgerHandle _out = out;
    if (_out == null) {
        return;
    }
    try {
        LOGGER.log(Level.SEVERE, "Closing ledger " + _out.getId()
            + ", with LastAddConfirmed=" + _out.getLastAddConfirmed()
            + ", LastAddPushed=" + _out.getLastAddPushed()
            + " length=" + _out.getLength()
            + ", errorOccurred:" + errorOccurredDuringWrite);

        _out.close();
    } catch (InterruptedException | BKException err) {
        throw new LogNotAvailableException(err);
    } finally {
        out = null;
    }
}
 
开发者ID:diennea,项目名称:herddb,代码行数:21,代码来源:BookkeeperCommitLog.java

示例2: runCmd

import org.apache.bookkeeper.client.LedgerHandle; //导入方法依赖的package包/类
@Override
protected int runCmd() throws Exception {
    LedgerHandle lh = getBookKeeperClient().get().openLedgerNoRecovery(
            getLedgerID(), BookKeeper.DigestType.CRC32, dlConf.getBKDigestPW().getBytes(UTF_8));
    final CountDownLatch doneLatch = new CountDownLatch(1);
    final AtomicInteger resultHolder = new AtomicInteger(-1234);
    BookkeeperInternalCallbacks.GenericCallback<Void> recoverCb =
            new BookkeeperInternalCallbacks.GenericCallback<Void>() {
        @Override
        public void operationComplete(int rc, Void result) {
            resultHolder.set(rc);
            doneLatch.countDown();
        }
    };
    try {
        BookKeeperAccessor.forceRecoverLedger(lh, recoverCb);
        doneLatch.await();
        if (BKException.Code.OK != resultHolder.get()) {
            throw BKException.create(resultHolder.get());
        }
    } finally {
        lh.close();
    }
    return 0;
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:26,代码来源:DistributedLogTool.java

示例3: testOpenLedgerWhenZkClosed

import org.apache.bookkeeper.client.LedgerHandle; //导入方法依赖的package包/类
@Test(timeout = 60000, expected = BKException.ZKException.class)
public void testOpenLedgerWhenZkClosed() throws Exception {
    ZooKeeperClient newZkc = TestZooKeeperClientBuilder.newBuilder()
            .name("zkc-openledger-when-zk-closed")
            .zkServers(zkServers)
            .build();
    BookKeeperClient newBkc = BookKeeperClientBuilder.newBuilder()
            .name("bkc-openledger-when-zk-closed")
            .zkc(newZkc)
            .ledgersPath(ledgersPath)
            .dlConfig(conf)
            .build();
    try {
        LedgerHandle lh = newBkc.get().createLedger(BookKeeper.DigestType.CRC32, "zkcClosed".getBytes(UTF_8));
        lh.close();
        newZkc.close();
        LedgerHandleCache cache =
                LedgerHandleCache.newBuilder().bkc(newBkc).conf(conf).build();
        // open ledger after zkc closed
        cache.openLedger(new LogSegmentMetadata.LogSegmentMetadataBuilder("",
                2, lh.getId(), 1).setLogSegmentSequenceNo(lh.getId()).build(), false);
    } finally {
        newBkc.close();
    }
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:26,代码来源:TestLedgerHandleCache.java

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

示例5: fenceStream

import org.apache.bookkeeper.client.LedgerHandle; //导入方法依赖的package包/类
public static void fenceStream(DistributedLogConfiguration conf, URI uri, String name) throws Exception {
    BKDistributedLogManager dlm = (BKDistributedLogManager) createNewDLM(name, conf, uri);
    try {
        BKLogReadHandler readHandler = dlm.createReadHandler();
        List<LogSegmentMetadata> ledgerList = readHandler.getFullLedgerList(true, true);
        LogSegmentMetadata lastSegment = ledgerList.get(ledgerList.size() - 1);
        BookKeeperClient bkc = dlm.getWriterBKC();
        LedgerHandle lh = bkc.get().openLedger(lastSegment.getLedgerId(),
                BookKeeper.DigestType.CRC32, conf.getBKDigestPW().getBytes(UTF_8));
        lh.close();
    } finally {
        dlm.close();
    }
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:15,代码来源:DLMTestUtil.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: 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

示例8: testCreateLogStreamWithDifferentReplicationFactor

import org.apache.bookkeeper.client.LedgerHandle; //导入方法依赖的package包/类
@Test(timeout = 60000)
public void testCreateLogStreamWithDifferentReplicationFactor() throws Exception {
    String name = runtime.getMethodName();
    DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
    confLocal.addConfiguration(testConf);
    confLocal.setOutputBufferSize(0);
    confLocal.setImmediateFlushEnabled(false);
    confLocal.setPeriodicFlushFrequencyMilliSeconds(0);

    ConcurrentBaseConfiguration baseConf = new ConcurrentConstConfiguration(confLocal);
    DynamicDistributedLogConfiguration dynConf = new DynamicDistributedLogConfiguration(baseConf);
    dynConf.setProperty(DistributedLogConfiguration.BKDL_BOOKKEEPER_ENSEMBLE_SIZE,
            DistributedLogConfiguration.BKDL_BOOKKEEPER_ENSEMBLE_SIZE_DEFAULT - 1);

    URI uri = createDLMURI("/" + name);
    ensureURICreated(uri);
    DistributedLogNamespace namespace = DistributedLogNamespaceBuilder.newBuilder()
            .conf(confLocal).uri(uri).build();

    // use the pool
    DistributedLogManager dlm = namespace.openLog(name + "-pool");
    AsyncLogWriter writer = dlm.startAsyncLogSegmentNonPartitioned();
    FutureUtils.result(writer.write(DLMTestUtil.getLogRecordInstance(1L)));
    List<LogSegmentMetadata> segments = dlm.getLogSegments();
    assertEquals(1, segments.size());
    long ledgerId = segments.get(0).getLedgerId();
    LedgerHandle lh = ((BKDistributedLogNamespace) namespace).getReaderBKC()
            .get().openLedgerNoRecovery(ledgerId, BookKeeper.DigestType.CRC32, confLocal.getBKDigestPW().getBytes(UTF_8));
    LedgerMetadata metadata = BookKeeperAccessor.getLedgerMetadata(lh);
    assertEquals(DistributedLogConfiguration.BKDL_BOOKKEEPER_ENSEMBLE_SIZE_DEFAULT, metadata.getEnsembleSize());
    lh.close();
    Utils.close(writer);
    dlm.close();

    // use customized configuration
    dlm = namespace.openLog(
            name + "-custom",
            Optional.<DistributedLogConfiguration>absent(),
            Optional.of(dynConf));
    writer = dlm.startAsyncLogSegmentNonPartitioned();
    FutureUtils.result(writer.write(DLMTestUtil.getLogRecordInstance(1L)));
    segments = dlm.getLogSegments();
    assertEquals(1, segments.size());
    ledgerId = segments.get(0).getLedgerId();
    lh = ((BKDistributedLogNamespace) namespace).getReaderBKC()
            .get().openLedgerNoRecovery(ledgerId, BookKeeper.DigestType.CRC32, confLocal.getBKDigestPW().getBytes(UTF_8));
    metadata = BookKeeperAccessor.getLedgerMetadata(lh);
    assertEquals(DistributedLogConfiguration.BKDL_BOOKKEEPER_ENSEMBLE_SIZE_DEFAULT - 1, metadata.getEnsembleSize());
    lh.close();
    Utils.close(writer);
    dlm.close();
    namespace.close();
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:54,代码来源:TestAsyncReaderWriter.java


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