Class LedgerHandleAdv

java.lang.Object
org.apache.bookkeeper.client.LedgerHandle
org.apache.bookkeeper.client.LedgerHandleAdv
All Implemented Interfaces:
AutoCloseable, ForceableHandle, Handle, ReadHandle, WriteAdvHandle, WriteHandle

public class LedgerHandleAdv extends LedgerHandle implements WriteAdvHandle
Ledger Advanced handle extends LedgerHandle to provide API to add entries with user supplied entryIds. Through this interface Ledger Length may not be accurate while the ledger being written.
  • Field Details

    • LOG

      static final org.slf4j.Logger LOG
  • Constructor Details

  • Method Details

    • addEntry

      public long addEntry(long entryId, byte[] data) throws InterruptedException, BKException
      Add entry synchronously to an open ledger.
      Overrides:
      addEntry in class LedgerHandle
      Parameters:
      entryId - entryId of the entry to add
      data - array of bytes to be written to the ledger do not reuse the buffer, bk-client will release it appropriately
      Returns:
      entryId that is just created.
      Throws:
      InterruptedException
      BKException
    • addEntry

      public long addEntry(long entryId, byte[] data, int offset, int length) throws InterruptedException, BKException
      Add entry synchronously to an open ledger.
      Overrides:
      addEntry in class LedgerHandle
      Parameters:
      entryId - entryId of the entry to add
      data - array of bytes to be written to the ledger do not reuse the buffer, bk-client will release it appropriately
      offset - offset from which to take bytes from data
      length - number of bytes to take from data
      Returns:
      The entryId of newly inserted entry.
      Throws:
      InterruptedException
      BKException
    • asyncAddEntry

      public void asyncAddEntry(long entryId, byte[] data, AsyncCallback.AddCallback cb, Object ctx)
      Add entry asynchronously to an open ledger.
      Overrides:
      asyncAddEntry in class LedgerHandle
      Parameters:
      entryId - entryId of the entry to add
      data - array of bytes to be written do not reuse the buffer, bk-client will release it appropriately
      cb - object implementing callbackinterface
      ctx - some control object
    • asyncAddEntry

      public void asyncAddEntry(long entryId, byte[] data, int offset, int length, AsyncCallback.AddCallback cb, Object ctx)
      Add entry asynchronously to an open ledger, using an offset and range.
      Overrides:
      asyncAddEntry in class LedgerHandle
      Parameters:
      entryId - entryId of the entry to add
      data - array of bytes to be written do not reuse the buffer, bk-client will release it appropriately
      offset - offset from which to take bytes from data
      length - number of bytes to take from data
      cb - object implementing callbackinterface
      ctx - some control object
      Throws:
      ArrayIndexOutOfBoundsException - if offset or length is negative or offset and length sum to a value higher than the length of data.
    • asyncAddEntry

      public void asyncAddEntry(long entryId, byte[] data, int offset, int length, AsyncCallback.AddCallbackWithLatency cb, Object ctx)
      Add entry asynchronously to an open ledger, using an offset and range.
      Overrides:
      asyncAddEntry in class LedgerHandle
      Parameters:
      entryId - entryId of the entry to add
      data - array of bytes to be written do not reuse the buffer, bk-client will release it appropriately
      offset - offset from which to take bytes from data
      length - number of bytes to take from data
      cb - object implementing callbackinterface
      ctx - some control object
      Throws:
      ArrayIndexOutOfBoundsException - if offset or length is negative or offset and length sum to a value higher than the length of data.
    • asyncAddEntry

      public void asyncAddEntry(long entryId, io.netty.buffer.ByteBuf data, AsyncCallback.AddCallbackWithLatency cb, Object ctx)
      Add entry asynchronously to an open ledger, using an offset and range. This can be used only with LedgerHandleAdv returned through ledgers created with BookKeeper.createLedgerAdv(int, int, int, BookKeeper.DigestType, byte[]).
      Overrides:
      asyncAddEntry in class LedgerHandle
      Parameters:
      entryId - entryId of the entry to add.
      data - io.netty.buffer.ByteBuf of bytes to be written do not reuse the buffer, bk-client will release it appropriately
      cb - object implementing callbackinterface
      ctx - some control object
    • doAsyncAddEntry

      protected void doAsyncAddEntry(PendingAddOp op)
      Overriding part is mostly around setting entryId. Though there may be some code duplication, Choose to have the override routine so the control flow is unaltered in the base class.
      Overrides:
      doAsyncAddEntry in class LedgerHandle
    • writeAsync

      public CompletableFuture<Long> writeAsync(long entryId, io.netty.buffer.ByteBuf data)
      Description copied from interface: WriteAdvHandle
      Add entry asynchronously to an open ledger.
      Specified by:
      writeAsync in interface WriteAdvHandle
      Parameters:
      entryId - entryId to be added
      data - array of bytes to be written do not reuse the buffer, bk-client will release it appropriately.
      Returns:
      an handle to the result, in case of success it will return the same value of param entryId
    • asyncAddEntry

      public void asyncAddEntry(io.netty.buffer.ByteBuf data, AsyncCallback.AddCallback cb, Object ctx)
      LedgerHandleAdv will not allow addEntry without providing an entryId.
      Overrides:
      asyncAddEntry in class LedgerHandle
    • asyncAddEntry

      public void asyncAddEntry(byte[] data, int offset, int length, AsyncCallback.AddCallback cb, Object ctx)
      LedgerHandleAdv will not allow addEntry without providing an entryId.
      Overrides:
      asyncAddEntry in class LedgerHandle
      Parameters:
      data - array of bytes to be written do not reuse the buffer, bk-client will release it appropriately
      offset - offset from which to take bytes from data
      length - number of bytes to take from data
      cb - object implementing callbackinterface
      ctx - some control object