本文整理汇总了Java中org.apache.bookkeeper.client.AsyncCallback.ReadCallback类的典型用法代码示例。如果您正苦于以下问题:Java ReadCallback类的具体用法?Java ReadCallback怎么用?Java ReadCallback使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ReadCallback类属于org.apache.bookkeeper.client.AsyncCallback包,在下文中一共展示了ReadCallback类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getLedgerHandle
import org.apache.bookkeeper.client.AsyncCallback.ReadCallback; //导入依赖的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;
}
示例2: PendingReadOp
import org.apache.bookkeeper.client.AsyncCallback.ReadCallback; //导入依赖的package包/类
PendingReadOp(LedgerHandle lh, long startEntryId, long endEntryId, ReadCallback cb, Object ctx) {
seq = new ArrayDeque<LedgerEntry>((int) (endEntryId - startEntryId));
this.cb = cb;
this.ctx = ctx;
this.lh = lh;
this.startEntryId = startEntryId;
this.endEntryId = endEntryId;
numPendingReads = endEntryId - startEntryId + 1;
}
示例3: asyncReadEntries
import org.apache.bookkeeper.client.AsyncCallback.ReadCallback; //导入依赖的package包/类
/**
* Read a sequence of entries asynchronously.
*
* @param firstEntry
* id of first entry of sequence
* @param lastEntry
* id of last entry of sequence
* @param cb
* object implementing read callback interface
* @param ctx
* control object
*/
public void asyncReadEntries(long firstEntry, long lastEntry,
ReadCallback cb, Object ctx) {
// Little sanity check
if (firstEntry < 0 || lastEntry > lastAddConfirmed
|| firstEntry > lastEntry) {
cb.readComplete(BKException.Code.ReadException, this, null, ctx);
return;
}
new PendingReadOp(this, firstEntry, lastEntry, cb, ctx).initiate();
}
示例4: asyncReadEntries
import org.apache.bookkeeper.client.AsyncCallback.ReadCallback; //导入依赖的package包/类
@Override
public void asyncReadEntries(final long firstEntry, final long lastEntry, final ReadCallback cb, final Object ctx) {
if (bk.isStopped()) {
cb.readComplete(-1, MockLedgerHandle.this, null, ctx);
return;
}
bk.executor.execute(new Runnable() {
public void run() {
if (bk.getProgrammedFailStatus()) {
cb.readComplete(bk.failReturnCode, MockLedgerHandle.this, null, ctx);
return;
} else if (bk.isStopped()) {
log.debug("Bookkeeper is closed!");
cb.readComplete(-1, MockLedgerHandle.this, null, ctx);
return;
}
log.debug("readEntries: first={} last={} total={}", firstEntry, lastEntry, entries.size());
final Queue<LedgerEntry> seq = new ArrayDeque<LedgerEntry>();
long entryId = firstEntry;
while (entryId <= lastEntry && entryId < entries.size()) {
seq.add(entries.get((int) entryId++));
}
log.debug("Entries read: {}", seq);
try {
Thread.sleep(1);
} catch (InterruptedException e) {
}
cb.readComplete(0, MockLedgerHandle.this, new Enumeration<LedgerEntry>() {
public boolean hasMoreElements() {
return !seq.isEmpty();
}
public LedgerEntry nextElement() {
return seq.remove();
}
}, ctx);
}
});
}
示例5: asyncReadLastEntry
import org.apache.bookkeeper.client.AsyncCallback.ReadCallback; //导入依赖的package包/类
@Override
public void asyncReadLastEntry(final ReadCallback cb, final Object ctx) {
long lastEntryId = getLastAddConfirmed();
asyncReadEntries(lastEntryId, lastEntryId, cb, ctx);
}