Interface WriteHandle
- All Superinterfaces:
AutoCloseable,ForceableHandle,Handle,ReadHandle
- All Known Implementing Classes:
LedgerHandle,LedgerHandleAdv,ReadOnlyLedgerHandle
- Since:
- 4.6
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault longappend(byte[] data) Add an entry synchronously to an open ledger.default longappend(byte[] data, int offset, int length) Add an entry synchronously to an open ledger.default longappend(io.netty.buffer.ByteBuf data) Add entry synchronously to an open ledger.default longappend(ByteBuffer data) Add entry synchronously to an open ledger.default CompletableFuture<Long>appendAsync(byte[] data) Add an entry asynchronously to an open ledger.default CompletableFuture<Long>appendAsync(byte[] data, int offset, int length) Add an entry asynchronously to an open ledger.appendAsync(io.netty.buffer.ByteBuf data) Add entry asynchronously to an open ledger.default CompletableFuture<Long>appendAsync(ByteBuffer data) Add entry asynchronously to an open ledger.default voidclose()Synchronous close the write handle, any adds in flight will return errors.Asynchronous close the write handle, any adds in flight will return errors.longGet the entry id of the last entry that has been enqueued for addition (but may not have possibly been persisted to the ledger).Methods inherited from interface org.apache.bookkeeper.client.api.ForceableHandle
forceMethods inherited from interface org.apache.bookkeeper.client.api.Handle
getId, getLedgerMetadataMethods inherited from interface org.apache.bookkeeper.client.api.ReadHandle
batchRead, batchReadAsync, getLastAddConfirmed, getLength, isClosed, read, readAsync, readLastAddConfirmed, readLastAddConfirmedAndEntry, readLastAddConfirmedAndEntryAsync, readLastAddConfirmedAsync, readUnconfirmed, readUnconfirmedAsync, tryReadLastAddConfirmed, tryReadLastAddConfirmedAsync
-
Method Details
-
appendAsync
Add entry asynchronously to an open ledger.- Parameters:
data- a bytebuf to be written. The bytebuf's reference count will be decremented by 1 after the completable future is returned 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 id of the newly appended entry
-
append
Add entry synchronously to an open ledger.- Parameters:
data- a bytebuf to be written. The bytebuf's reference count will be decremented by 1 after the call completes. do not reuse the buffer, bk-client will release it appropriately.- Returns:
- the id of the newly appended entry
- Throws:
BKExceptionInterruptedException
-
appendAsync
Add entry asynchronously to an open ledger.- Parameters:
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 id of the newly appended entry
-
append
Add entry synchronously to an open ledger.- Parameters:
data- array of bytes to be written do not reuse the buffer, bk-client will release it appropriately.- Returns:
- the id of the newly appended entry
- Throws:
BKExceptionInterruptedException
-
appendAsync
Add an entry asynchronously to an open ledger.- Parameters:
data- array of bytes to be written do not reuse the buffer, bk-client will release it appropriately.- Returns:
- a completable future represents the add result, in case of success the future returns the entry id of this newly appended entry
-
append
Add an entry synchronously to an open ledger.- Parameters:
data- array of bytes to be written do not reuse the buffer, bk-client will release it appropriately.- Returns:
- the entry id of this newly appended entry
- Throws:
BKExceptionInterruptedException
-
appendAsync
Add an entry asynchronously to an open ledger.- Parameters:
data- array of bytes to be written do not reuse the buffer, bk-client will release it appropriately.offset- the offset in the bytes arraylength- the length of the bytes to be appended- Returns:
- a completable future represents the add result, in case of success the future returns the entry id of this newly appended entry
-
append
Add an entry synchronously to an open ledger.- Parameters:
data- array of bytes to be written do not reuse the buffer, bk-client will release it appropriately.offset- the offset in the bytes arraylength- the length of the bytes to be appended- Returns:
- the entry id of this newly appended entry
- Throws:
BKExceptionInterruptedException
-
getLastAddPushed
long getLastAddPushed()Get the entry id of the last entry that has been enqueued for addition (but may not have possibly been persisted to the ledger).- Returns:
- the entry id of the last entry pushed or -1 if no entry has been pushed
-
closeAsync
CompletableFuture<Void> closeAsync()Asynchronous close the write handle, any adds in flight will return errors.Closing a ledger will ensure that all clients agree on what the last entry of the ledger is. Once the ledger has been closed, all reads from the ledger will return the same set of entries.
The close operation can error if it finds conflicting metadata when it tries to write to the metadata store. On close, the metadata state is set to closed and lastEntry and length of the ledger are fixed in the metadata. A conflict occurs if the metadata in the metadata store has a different value for the lastEntry or length. If another process has updated the metadata, setting it to closed, but have fixed the lastEntry and length to the same values as this process is trying to write, the operation completes successfully.
- Specified by:
closeAsyncin interfaceHandle- Returns:
- an handle to access the result of the operation
-
close
Synchronous close the write handle, any adds in flight will return errors.Closing a ledger will ensure that all clients agree on what the last entry of the ledger is. Once the ledger has been closed, all reads from the ledger will return the same set of entries.
The close operation can error if it finds conflicting metadata when it tries to write to the metadata store. On close, the metadata state is set to closed and lastEntry and length of the ledger are fixed in the metadata. A conflict occurs if the metadata in the metadata store has a different value for the lastEntry or length. If another process has updated the metadata, setting it to closed, but have fixed the lastEntry and length to the same values as this process is trying to write, the operation completes successfully.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceHandle- Throws:
BKExceptionInterruptedException- See Also:
-