org.apache.bookkeeper.client.AsyncCallback.AddCallback Java Examples

The following examples show how to use org.apache.bookkeeper.client.AsyncCallback.AddCallback. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PulsarMockLedgerHandle.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@Override
public void asyncAddEntry(final ByteBuf data, final AddCallback cb, final Object ctx) {
    bk.getProgrammedFailure().thenComposeAsync((res) -> {
            try {
                Thread.sleep(1);
            } catch (InterruptedException e) {
            }

            if (fenced) {
                return FutureUtils.exception(new BKException.BKLedgerFencedException());
            } else {
                lastEntry = entries.size();
                byte[] storedData = new byte[data.readableBytes()];
                data.readBytes(storedData);
                entries.add(LedgerEntryImpl.create(ledgerId, lastEntry,
                                                   storedData.length, Unpooled.wrappedBuffer(storedData)));
                return FutureUtils.value(lastEntry);
            }

        }, bk.executor).whenCompleteAsync((entryId, exception) -> {
                data.release();
                if (exception != null) {
                    fenced = true;
                    cb.addComplete(PulsarMockBookKeeper.getExceptionCode(exception),
                                   PulsarMockLedgerHandle.this, LedgerHandle.INVALID_ENTRY_ID, ctx);
                } else {
                    cb.addComplete(BKException.Code.OK, PulsarMockLedgerHandle.this, entryId, ctx);
                }
            }, bk.executor);
}
 
Example #2
Source File: PulsarMockLedgerHandle.java    From pulsar with Apache License 2.0 4 votes vote down vote up
@Override
public void asyncAddEntry(final byte[] data, final AddCallback cb, final Object ctx) {
    asyncAddEntry(data, 0, data.length, cb, ctx);
}
 
Example #3
Source File: PulsarMockLedgerHandle.java    From pulsar with Apache License 2.0 4 votes vote down vote up
@Override
public void asyncAddEntry(final byte[] data, final int offset, final int length, final AddCallback cb,
        final Object ctx) {
    asyncAddEntry(Unpooled.wrappedBuffer(data, offset, length), cb, ctx);
}