use of org.apache.bookkeeper.client.SyncCallbackUtils.SyncReadCallback in project bookkeeper by apache.
the class LedgerHandle method readEntries.
/**
* Read a sequence of entries synchronously.
*
* @param firstEntry
* id of first entry of sequence (included)
* @param lastEntry
* id of last entry of sequence (included)
*
* @see #asyncReadEntries(long, long, ReadCallback, Object)
*/
public Enumeration<LedgerEntry> readEntries(long firstEntry, long lastEntry) throws InterruptedException, BKException {
CompletableFuture<Enumeration<LedgerEntry>> result = new CompletableFuture<>();
asyncReadEntries(firstEntry, lastEntry, new SyncReadCallback(result), null);
return SyncCallbackUtils.waitForResult(result);
}
use of org.apache.bookkeeper.client.SyncCallbackUtils.SyncReadCallback in project bookkeeper by apache.
the class LedgerHandle method readUnconfirmedEntries.
/**
* Read a sequence of entries synchronously, allowing to read after the LastAddConfirmed range.<br>
* This is the same of
* {@link #asyncReadUnconfirmedEntries(long, long, ReadCallback, Object) }
*
* @param firstEntry
* id of first entry of sequence (included)
* @param lastEntry
* id of last entry of sequence (included)
*
* @see #readEntries(long, long)
* @see #asyncReadUnconfirmedEntries(long, long, ReadCallback, java.lang.Object)
* @see #asyncReadLastConfirmed(ReadLastConfirmedCallback, java.lang.Object)
*/
public Enumeration<LedgerEntry> readUnconfirmedEntries(long firstEntry, long lastEntry) throws InterruptedException, BKException {
CompletableFuture<Enumeration<LedgerEntry>> result = new CompletableFuture<>();
asyncReadUnconfirmedEntries(firstEntry, lastEntry, new SyncReadCallback(result), null);
return SyncCallbackUtils.waitForResult(result);
}
use of org.apache.bookkeeper.client.SyncCallbackUtils.SyncReadCallback in project bookkeeper by apache.
the class LedgerHandle method readLastEntry.
public LedgerEntry readLastEntry() throws InterruptedException, BKException {
long lastEntryId = getLastAddConfirmed();
if (lastEntryId < 0) {
// Ledger was empty, so there is no last entry to read
throw new BKException.BKNoSuchEntryException();
} else {
CompletableFuture<Enumeration<LedgerEntry>> result = new CompletableFuture<>();
asyncReadEntries(lastEntryId, lastEntryId, new SyncReadCallback(result), null);
return SyncCallbackUtils.waitForResult(result).nextElement();
}
}
Aggregations