Search in sources :

Example 1 with SyncReadCallback

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);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) Enumeration(java.util.Enumeration) SyncReadCallback(org.apache.bookkeeper.client.SyncCallbackUtils.SyncReadCallback)

Example 2 with SyncReadCallback

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);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) Enumeration(java.util.Enumeration) SyncReadCallback(org.apache.bookkeeper.client.SyncCallbackUtils.SyncReadCallback)

Example 3 with SyncReadCallback

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();
    }
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) Enumeration(java.util.Enumeration) SyncReadCallback(org.apache.bookkeeper.client.SyncCallbackUtils.SyncReadCallback)

Aggregations

Enumeration (java.util.Enumeration)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 SyncReadCallback (org.apache.bookkeeper.client.SyncCallbackUtils.SyncReadCallback)3