Search in sources :

Example 21 with OpenCursorCallback

use of org.apache.bookkeeper.mledger.AsyncCallbacks.OpenCursorCallback in project incubator-pulsar by apache.

the class ManagedLedgerImpl method openCursor.

@Override
public ManagedCursor openCursor(String cursorName, InitialPosition initialPosition) throws InterruptedException, ManagedLedgerException {
    final CountDownLatch counter = new CountDownLatch(1);
    class Result {

        ManagedCursor cursor = null;

        ManagedLedgerException exception = null;
    }
    final Result result = new Result();
    asyncOpenCursor(cursorName, initialPosition, new OpenCursorCallback() {

        @Override
        public void openCursorComplete(ManagedCursor cursor, Object ctx) {
            result.cursor = cursor;
            counter.countDown();
        }

        @Override
        public void openCursorFailed(ManagedLedgerException exception, Object ctx) {
            result.exception = exception;
            counter.countDown();
        }
    }, null);
    if (!counter.await(AsyncOperationTimeoutSeconds, TimeUnit.SECONDS)) {
        throw new ManagedLedgerException("Timeout during open-cursor operation");
    }
    if (result.exception != null) {
        log.error("Error adding entry", result.exception);
        throw result.exception;
    }
    return result.cursor;
}
Also used : ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) OpenCursorCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.OpenCursorCallback) CountDownLatch(java.util.concurrent.CountDownLatch) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor)

Aggregations

OpenCursorCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.OpenCursorCallback)21 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)21 ManagedCursor (org.apache.bookkeeper.mledger.ManagedCursor)19 CountDownLatch (java.util.concurrent.CountDownLatch)12 ManagedLedger (org.apache.bookkeeper.mledger.ManagedLedger)12 AddEntryCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.AddEntryCallback)10 CompletableFuture (java.util.concurrent.CompletableFuture)9 DeleteCursorCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.DeleteCursorCallback)9 ByteBuf (io.netty.buffer.ByteBuf)8 CloseCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.CloseCallback)8 ManagedLedgerConfig (org.apache.bookkeeper.mledger.ManagedLedgerConfig)8 Test (org.testng.annotations.Test)8 List (java.util.List)6 Entry (org.apache.bookkeeper.mledger.Entry)6 ManagedLedgerFencedException (org.apache.bookkeeper.mledger.ManagedLedgerException.ManagedLedgerFencedException)6 Position (org.apache.bookkeeper.mledger.Position)6 OpenLedgerCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.OpenLedgerCallback)5 PositionImpl (org.apache.bookkeeper.mledger.impl.PositionImpl)5 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)4 Maps (com.google.common.collect.Maps)4