Search in sources :

Example 1 with FindEntryCallback

use of org.apache.bookkeeper.mledger.AsyncCallbacks.FindEntryCallback in project pulsar by yahoo.

the class ManagedCursorImpl method findNewestMatching.

@Override
public Position findNewestMatching(Predicate<Entry> condition) throws InterruptedException, ManagedLedgerException {
    final CountDownLatch counter = new CountDownLatch(1);
    class Result {

        ManagedLedgerException exception = null;

        Position position = null;
    }
    final Result result = new Result();
    asyncFindNewestMatching(FindPositionConstraint.SearchActiveEntries, condition, new FindEntryCallback() {

        @Override
        public void findEntryComplete(Position position, Object ctx) {
            result.position = position;
            counter.countDown();
        }

        @Override
        public void findEntryFailed(ManagedLedgerException exception, Object ctx) {
            result.exception = exception;
            counter.countDown();
        }
    }, null);
    counter.await();
    if (result.exception != null)
        throw result.exception;
    return result.position;
}
Also used : ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) Position(org.apache.bookkeeper.mledger.Position) FindEntryCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.FindEntryCallback) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)1 FindEntryCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.FindEntryCallback)1 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)1 Position (org.apache.bookkeeper.mledger.Position)1