本文整理汇总了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;
}
}
示例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;
}
示例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();
}
}
示例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);
}
示例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();
}
}
示例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();
}
示例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);
}
示例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();
}