本文整理汇总了Java中org.apache.bookkeeper.client.LedgerEntry类的典型用法代码示例。如果您正苦于以下问题:Java LedgerEntry类的具体用法?Java LedgerEntry怎么用?Java LedgerEntry使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LedgerEntry类属于org.apache.bookkeeper.client包,在下文中一共展示了LedgerEntry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createLedgers
import org.apache.bookkeeper.client.LedgerEntry; //导入依赖的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();
}
}
示例2: verifyRecoveredLedgers
import org.apache.bookkeeper.client.LedgerEntry; //导入依赖的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()));
}
}
}
示例3: getLedgerHandle
import org.apache.bookkeeper.client.LedgerEntry; //导入依赖的package包/类
private static LedgerHandle getLedgerHandle() {
final LedgerHandle lh = mock(LedgerHandle.class);
final LedgerEntry ledgerEntry = mock(LedgerEntry.class, Mockito.CALLS_REAL_METHODS);
doReturn(new byte[10]).when(ledgerEntry).getEntry();
doReturn(Unpooled.wrappedBuffer(new byte[10])).when(ledgerEntry).getEntryBuffer();
doReturn((long) 10).when(ledgerEntry).getLength();
doAnswer(new Answer<Object>() {
public Object answer(InvocationOnMock invocation) {
Object[] args = invocation.getArguments();
long firstEntry = (Long) args[0];
long lastEntry = (Long) args[1];
ReadCallback callback = (ReadCallback) args[2];
Object ctx = args[3];
Vector<LedgerEntry> entries = new Vector<LedgerEntry>();
for (int i = 0; i <= (lastEntry - firstEntry); i++) {
entries.add(ledgerEntry);
}
callback.readComplete(0, lh, entries.elements(), ctx);
return null;
}
}).when(lh).asyncReadEntries(anyLong(), anyLong(), any(ReadCallback.class), any());
return lh;
}
示例4: asyncReadLastConfirmedAndEntry
import org.apache.bookkeeper.client.LedgerEntry; //导入依赖的package包/类
/**
* Async read last confirmed and entry
*
* @param ledgerDesc
* ledger descriptor
* @param entryId
* entry id to read
* @param timeOutInMillis
* time out if no newer entry available
* @param parallel
* whether to read from replicas in parallel
*/
public Future<Pair<Long, LedgerEntry>> asyncReadLastConfirmedAndEntry(
LedgerDescriptor ledgerDesc,
long entryId,
long timeOutInMillis,
boolean parallel) {
RefCountedLedgerHandle refHandle = handlesMap.get(ledgerDesc);
if (null == refHandle) {
LOG.error("Accessing ledger {} without opening.", ledgerDesc);
return Future.exception(BKException.create(BKException.Code.UnexpectedConditionException));
}
final Promise<Pair<Long, LedgerEntry>> promise = new Promise<Pair<Long, LedgerEntry>>();
refHandle.handle.asyncReadLastConfirmedAndEntry(entryId, timeOutInMillis, parallel,
new AsyncCallback.ReadLastConfirmedAndEntryCallback() {
@Override
public void readLastConfirmedAndEntryComplete(int rc, long lac, LedgerEntry ledgerEntry, Object ctx) {
if (BKException.Code.OK == rc) {
promise.setValue(Pair.of(lac, ledgerEntry));
} else {
promise.setException(BKException.create(rc));
}
}
}, null);
return promise;
}
示例5: asyncReadEntries
import org.apache.bookkeeper.client.LedgerEntry; //导入依赖的package包/类
/**
* Async Read Entries
*
* @param ledgerDesc
* ledger descriptor
* @param first
* first entry
* @param last
* second entry
*/
public Future<Enumeration<LedgerEntry>> asyncReadEntries(
LedgerDescriptor ledgerDesc, long first, long last) {
RefCountedLedgerHandle refHandle = handlesMap.get(ledgerDesc);
if (null == refHandle) {
LOG.error("Accessing ledger {} without opening.", ledgerDesc);
return Future.exception(BKException.create(BKException.Code.UnexpectedConditionException));
}
final Promise<Enumeration<LedgerEntry>> promise = new Promise<Enumeration<LedgerEntry>>();
refHandle.handle.asyncReadEntries(first, last, new AsyncCallback.ReadCallback() {
@Override
public void readComplete(int rc, LedgerHandle lh, Enumeration<LedgerEntry> entries, Object ctx) {
if (BKException.Code.OK == rc) {
promise.setValue(entries);
} else {
promise.setException(BKException.create(rc));
}
}
}, null);
return promise;
}
示例6: simpleReadEntries
import org.apache.bookkeeper.client.LedgerEntry; //导入依赖的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;
}
}
示例7: readComplete
import org.apache.bookkeeper.client.LedgerEntry; //导入依赖的package包/类
@Override
public void readComplete(int rc, LedgerHandle lh, Enumeration<LedgerEntry> enumeration, Object ctx) {
this.rc = rc;
if (BKException.Code.OK == rc && enumeration.hasMoreElements()) {
entry = enumeration.nextElement();
} else {
entry = null;
}
isDone = true;
// construct a new read request
long nextEntry = nextReadEntry.getAndIncrement();
if (nextEntry <= lac) {
PendingReadRequest nextRead =
new PendingReadRequest(nextEntry);
pendingReads.add(nextRead);
nextRead.read();
}
triggerCallbacks();
}
示例8: readEntry
import org.apache.bookkeeper.client.LedgerEntry; //导入依赖的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());
}
}
示例9: readComplete
import org.apache.bookkeeper.client.LedgerEntry; //导入依赖的package包/类
public void readComplete(int rc, long ledgerId, LedgerSequence seq, Object ctx){
System.out.println("Read callback: " + rc);
while(seq.hasMoreElements()){
LedgerEntry le = seq.nextElement();
LOG.debug(new String(le.getEntry()));
}
synchronized(ctx){
ctx.notify();
}
}
示例10: readComplete
import org.apache.bookkeeper.client.LedgerEntry; //导入依赖的package包/类
public void readComplete(int rc, LedgerHandle lh, Enumeration<LedgerEntry> seq, Object ctx) {
ls = seq;
synchronized (sync) {
sync.value = true;
sync.notify();
}
}
示例11: testBookieRecovery
import org.apache.bookkeeper.client.LedgerEntry; //导入依赖的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);
}
示例12: readComplete
import org.apache.bookkeeper.client.LedgerEntry; //导入依赖的package包/类
public void readComplete(int rc, LedgerHandle lh, Enumeration<LedgerEntry> seq, Object ctx) {
if (rc != 0)
fail("Failed to write entry");
ls = seq;
synchronized (sync) {
sync.value = true;
sync.notify();
}
}
示例13: asyncReadEntry
import org.apache.bookkeeper.client.LedgerEntry; //导入依赖的package包/类
@Override
public void asyncReadEntry(LedgerHandle lh, PositionImpl position, final ReadEntryCallback callback,
final Object ctx) {
if (log.isDebugEnabled()) {
log.debug("[{}] Reading entry ledger {}: {}", ml.getName(), lh.getId(), position.getEntryId());
}
EntryImpl entry = entries.get(position);
if (entry != null) {
EntryImpl cachedEntry = EntryImpl.create(entry);
entry.release();
manager.mlFactoryMBean.recordCacheHit(cachedEntry.getLength());
callback.readEntryComplete(cachedEntry, ctx);
} else {
lh.asyncReadEntries(position.getEntryId(), position.getEntryId(), (rc, ledgerHandle, sequence, obj) -> {
if (rc != BKException.Code.OK) {
ml.invalidateLedgerHandle(ledgerHandle, rc);
callback.readEntryFailed(new ManagedLedgerException(BKException.create(rc)), obj);
return;
}
if (sequence.hasMoreElements()) {
LedgerEntry ledgerEntry = sequence.nextElement();
EntryImpl returnEntry = EntryImpl.create(ledgerEntry);
// The EntryImpl is now the owner of the buffer, so we can release the original one
ledgerEntry.getEntryBuffer().release();
manager.mlFactoryMBean.recordCacheMiss(1, returnEntry.getLength());
ml.mbean.addReadEntriesSample(1, returnEntry.getLength());
ml.getExecutor().submitOrdered(ml.getName(), safeRun(() -> {
callback.readEntryComplete(returnEntry, obj);
}));
} else {
// got an empty sequence
callback.readEntryFailed(new ManagedLedgerException("Could not read given position"), obj);
}
}, ctx);
}
}
示例14: create
import org.apache.bookkeeper.client.LedgerEntry; //导入依赖的package包/类
public static EntryImpl create(LedgerEntry ledgerEntry) {
EntryImpl entry = RECYCLER.get();
entry.ledgerId = ledgerEntry.getLedgerId();
entry.entryId = ledgerEntry.getEntryId();
entry.data = ledgerEntry.getEntryBuffer();
entry.data.retain();
entry.setRefCnt(1);
return entry;
}
示例15: issueReadLastConfirmedAndEntry
import org.apache.bookkeeper.client.LedgerEntry; //导入依赖的package包/类
private void issueReadLastConfirmedAndEntry(final boolean parallel,
final long lastAddConfirmed) {
final String ctx = String.format("ReadLastConfirmedAndEntry(%s, %d)", parallel? "Parallel":"Sequential", lastAddConfirmed);
final ReadLastConfirmedAndEntryCallbackWithNotification callback =
new ReadLastConfirmedAndEntryCallbackWithNotification(lastAddConfirmed, this, ctx);
boolean callbackImmediately = setMetadataNotification(callback);
handleCache.asyncReadLastConfirmedAndEntry(
currentLH,
nextReadAheadPosition.getEntryId(),
conf.getReadLACLongPollTimeout(),
parallel
).addEventListener(new FutureEventListener<Pair<Long, LedgerEntry>>() {
@Override
public void onSuccess(Pair<Long, LedgerEntry> lacAndEntry) {
callback.readLastConfirmedAndEntryComplete(
BKException.Code.OK,
lacAndEntry.getLeft(),
lacAndEntry.getRight(),
ctx);
}
@Override
public void onFailure(Throwable cause) {
callback.readLastConfirmedAndEntryComplete(
FutureUtils.bkResultCode(cause),
lastAddConfirmed,
null,
ctx);
}
});
callback.callbackImmediately(callbackImmediately);
readAheadReadLACAndEntryCounter.inc();
}