Package org.apache.bookkeeper.client
Class LedgerHandleAdv
- java.lang.Object
-
- org.apache.bookkeeper.client.LedgerHandle
-
- org.apache.bookkeeper.client.LedgerHandleAdv
-
- All Implemented Interfaces:
java.lang.AutoCloseable
,ForceableHandle
,Handle
,ReadHandle
,WriteAdvHandle
,WriteHandle
public class LedgerHandleAdv extends LedgerHandle implements WriteAdvHandle
Ledger Advanced handle extendsLedgerHandle
to provide API to add entries with user supplied entryIds. Through this interface Ledger Length may not be accurate while the ledger being written.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
LedgerHandleAdv.PendingOpsComparator
-
Nested classes/interfaces inherited from class org.apache.bookkeeper.client.LedgerHandle
LedgerHandle.LastConfirmedCtx, LedgerHandle.NoopCloseCallback
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static org.slf4j.Logger
LOG
-
Fields inherited from class org.apache.bookkeeper.client.LedgerHandle
bookieFailureHistory, bookiesHealthInfo, changingEnsemble, clientCtx, delayedWriteFailedBookies, distributionSchedule, ensembleChangeCounter, executor, explicitLacFlushPolicy, INVALID_ENTRY_ID, INVALID_LEDGER_ID, lacUpdateHitsCounter, lacUpdateMissesCounter, lastAddConfirmed, lastAddPushed, ledgerId, ledgerKey, length, macManager, metadataLock, notSupportBatch, numEnsembleChanges, pendingAddOps, pendingAddsSequenceHead, throttler, timeoutFuture, writeFlags
-
-
Constructor Summary
Constructors Constructor Description LedgerHandleAdv(ClientContext clientCtx, long ledgerId, Versioned<LedgerMetadata> metadata, BookKeeper.DigestType digestType, byte[] password, java.util.EnumSet<WriteFlag> writeFlags)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
addEntry(long entryId, byte[] data)
Add entry synchronously to an open ledger.long
addEntry(long entryId, byte[] data, int offset, int length)
Add entry synchronously to an open ledger.void
asyncAddEntry(byte[] data, int offset, int length, AsyncCallback.AddCallback cb, java.lang.Object ctx)
LedgerHandleAdv will not allow addEntry without providing an entryId.void
asyncAddEntry(long entryId, byte[] data, int offset, int length, AsyncCallback.AddCallback cb, java.lang.Object ctx)
Add entry asynchronously to an open ledger, using an offset and range.void
asyncAddEntry(long entryId, byte[] data, int offset, int length, AsyncCallback.AddCallbackWithLatency cb, java.lang.Object ctx)
Add entry asynchronously to an open ledger, using an offset and range.void
asyncAddEntry(long entryId, byte[] data, AsyncCallback.AddCallback cb, java.lang.Object ctx)
Add entry asynchronously to an open ledger.void
asyncAddEntry(long entryId, io.netty.buffer.ByteBuf data, AsyncCallback.AddCallbackWithLatency cb, java.lang.Object ctx)
Add entry asynchronously to an open ledger, using an offset and range.void
asyncAddEntry(io.netty.buffer.ByteBuf data, AsyncCallback.AddCallback cb, java.lang.Object ctx)
LedgerHandleAdv will not allow addEntry without providing an entryId.protected void
doAsyncAddEntry(PendingAddOp op)
Overriding part is mostly around setting entryId.java.util.concurrent.CompletableFuture<java.lang.Long>
writeAsync(long entryId, io.netty.buffer.ByteBuf data)
Add entry asynchronously to an open ledger.-
Methods inherited from class org.apache.bookkeeper.client.LedgerHandle
addEntry, addEntry, addToLength, appendAsync, asyncAddEntry, asyncBatchReadEntries, asyncBatchReadEntriesInternal, asyncBatchReadUnconfirmedEntries, asyncClose, asyncCloseInternal, asyncReadEntries, asyncReadEntriesInternal, asyncReadExplicitLastConfirmed, asyncReadLastConfirmed, asyncReadLastConfirmedAndEntry, asyncReadLastEntry, asyncReadUnconfirmedEntries, asyncRecoveryAddEntry, asyncTryReadLastConfirmed, batchReadAsync, batchReadEntries, batchReadUnconfirmedEntries, close, closeAsync, doAsyncCloseInternal, drainPendingAddsAndAdjustLength, ensembleChangeLoop, errorOutPendingAdds, errorOutPendingAdds, executeOrdered, force, getBookiesHealthInfo, getCtime, getCurrentEnsemble, getCustomMetadata, getDigestManager, getDistributionSchedule, getId, getLastAddConfirmed, getLastAddPushed, getLedgerKey, getLedgerMetadata, getLength, getNumBookies, getNumFragments, getPendingAddOps, getVersionedLedgerMetadata, getWriteFlags, getWriteSetForReadOperation, handleBookieFailure, handleUnrecoverableErrorDuringAdd, hasDelayedWriteFailedBookies, initializeWriteHandleState, isClosed, isHandleWritable, maybeHandleDelayedWriteBookieFailure, notifyWriteFailed, readAsync, readEntries, readEntriesInternalAsync, readExplicitLastConfirmed, readLastAddConfirmedAndEntryAsync, readLastAddConfirmedAsync, readLastConfirmed, readLastEntry, readUnconfirmedAsync, readUnconfirmedEntries, recordReadErrorOnBookie, registerOperationFailureOnBookie, sendAddSuccessCallbacks, setLastAddConfirmed, setLedgerMetadata, tryReadLastAddConfirmedAsync, tryReadLastConfirmed, unsetSuccessAndSendWriteRequest, updateLastConfirmed, waitForWritable
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.bookkeeper.client.api.ForceableHandle
force
-
Methods inherited from interface org.apache.bookkeeper.client.api.Handle
getId, getLedgerMetadata
-
Methods inherited from interface org.apache.bookkeeper.client.api.ReadHandle
batchRead, batchReadAsync, getLastAddConfirmed, getLength, isClosed, read, readAsync, readLastAddConfirmed, readLastAddConfirmedAndEntry, readLastAddConfirmedAndEntryAsync, readLastAddConfirmedAsync, readUnconfirmed, readUnconfirmedAsync, tryReadLastAddConfirmed, tryReadLastAddConfirmedAsync
-
Methods inherited from interface org.apache.bookkeeper.client.api.WriteAdvHandle
write, write, write, write, writeAsync, writeAsync, writeAsync
-
Methods inherited from interface org.apache.bookkeeper.client.api.WriteHandle
append, append, append, append, appendAsync, appendAsync, appendAsync
-
-
-
-
Constructor Detail
-
LedgerHandleAdv
LedgerHandleAdv(ClientContext clientCtx, long ledgerId, Versioned<LedgerMetadata> metadata, BookKeeper.DigestType digestType, byte[] password, java.util.EnumSet<WriteFlag> writeFlags) throws java.security.GeneralSecurityException, java.lang.NumberFormatException
- Throws:
java.security.GeneralSecurityException
java.lang.NumberFormatException
-
-
Method Detail
-
addEntry
public long addEntry(long entryId, byte[] data) throws java.lang.InterruptedException, BKException
Add entry synchronously to an open ledger.- Overrides:
addEntry
in classLedgerHandle
- Parameters:
entryId
- entryId of the entry to adddata
- 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:
java.lang.InterruptedException
BKException
-
addEntry
public long addEntry(long entryId, byte[] data, int offset, int length) throws java.lang.InterruptedException, BKException
Add entry synchronously to an open ledger.- Overrides:
addEntry
in classLedgerHandle
- Parameters:
entryId
- entryId of the entry to adddata
- array of bytes to be written to the ledger do not reuse the buffer, bk-client will release it appropriatelyoffset
- offset from which to take bytes from datalength
- number of bytes to take from data- Returns:
- The entryId of newly inserted entry.
- Throws:
java.lang.InterruptedException
BKException
-
asyncAddEntry
public void asyncAddEntry(long entryId, byte[] data, AsyncCallback.AddCallback cb, java.lang.Object ctx)
Add entry asynchronously to an open ledger.- Overrides:
asyncAddEntry
in classLedgerHandle
- Parameters:
entryId
- entryId of the entry to adddata
- array of bytes to be written do not reuse the buffer, bk-client will release it appropriatelycb
- object implementing callbackinterfacectx
- some control object
-
asyncAddEntry
public void asyncAddEntry(long entryId, byte[] data, int offset, int length, AsyncCallback.AddCallback cb, java.lang.Object ctx)
Add entry asynchronously to an open ledger, using an offset and range.- Overrides:
asyncAddEntry
in classLedgerHandle
- Parameters:
entryId
- entryId of the entry to adddata
- array of bytes to be written do not reuse the buffer, bk-client will release it appropriatelyoffset
- offset from which to take bytes from datalength
- number of bytes to take from datacb
- object implementing callbackinterfacectx
- some control object- Throws:
java.lang.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, java.lang.Object ctx)
Add entry asynchronously to an open ledger, using an offset and range.- Overrides:
asyncAddEntry
in classLedgerHandle
- Parameters:
entryId
- entryId of the entry to adddata
- array of bytes to be written do not reuse the buffer, bk-client will release it appropriatelyoffset
- offset from which to take bytes from datalength
- number of bytes to take from datacb
- object implementing callbackinterfacectx
- some control object- Throws:
java.lang.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, java.lang.Object ctx)
Add entry asynchronously to an open ledger, using an offset and range. This can be used only withLedgerHandleAdv
returned through ledgers created withBookKeeper.createLedgerAdv(int, int, int, BookKeeper.DigestType, byte[])
.- Overrides:
asyncAddEntry
in classLedgerHandle
- 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 appropriatelycb
- object implementing callbackinterfacectx
- 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 classLedgerHandle
-
writeAsync
public java.util.concurrent.CompletableFuture<java.lang.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 interfaceWriteAdvHandle
- Parameters:
entryId
- entryId to be addeddata
- 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, java.lang.Object ctx)
LedgerHandleAdv will not allow addEntry without providing an entryId.- Overrides:
asyncAddEntry
in classLedgerHandle
-
asyncAddEntry
public void asyncAddEntry(byte[] data, int offset, int length, AsyncCallback.AddCallback cb, java.lang.Object ctx)
LedgerHandleAdv will not allow addEntry without providing an entryId.- Overrides:
asyncAddEntry
in classLedgerHandle
- Parameters:
data
- array of bytes to be written do not reuse the buffer, bk-client will release it appropriatelyoffset
- offset from which to take bytes from datalength
- number of bytes to take from datacb
- object implementing callbackinterfacectx
- some control object
-
-