接口 ManagedCursor
@LimitedPrivate
@Stable
public interface ManagedCursor
A ManagedCursor is a persisted cursor inside a ManagedLedger.
The ManagedCursor is used to read from the ManagedLedger and to signal when the consumer is done with the
messages that it has read before.
-
嵌套类概要
嵌套类修饰符和类型接口说明static enumstatic enum -
方法概要
修饰符和类型方法说明voidasyncClearBacklog(AsyncCallbacks.ClearBacklogCallback callback, Object ctx) Clear the cursor backlog.voidasyncClose(AsyncCallbacks.CloseCallback callback, Object ctx) Close the cursor asynchronously and release the associated resources.voidasyncDelete(Iterable<Position> position, AsyncCallbacks.DeleteCallback callback, Object ctx) Delete a group of messages asynchronouslyvoidasyncDelete(Position position, AsyncCallbacks.DeleteCallback callback, Object ctx) Delete a single message asynchronouslyvoidasyncFindNewestMatching(ManagedCursor.FindPositionConstraint constraint, com.google.common.base.Predicate<Entry> condition, AsyncCallbacks.FindEntryCallback callback, Object ctx) Find the newest entry that matches the given predicate.voidasyncGetNthEntry(int n, ManagedCursor.IndividualDeletedEntries deletedEntries, AsyncCallbacks.ReadEntryCallback callback, Object ctx) Asynchronously get 'N'th entry from the mark delete position in the cursor without updating any cursor positions.voidasyncMarkDelete(Position position, Map<String, Long> properties, AsyncCallbacks.MarkDeleteCallback callback, Object ctx) Asynchronous mark delete.voidasyncMarkDelete(Position position, AsyncCallbacks.MarkDeleteCallback callback, Object ctx) Asynchronous mark delete.voidasyncReadEntries(int numberOfEntriesToRead, long maxSizeBytes, AsyncCallbacks.ReadEntriesCallback callback, Object ctx, PositionImpl maxPosition) Asynchronously read entries from the ManagedLedger.voidasyncReadEntries(int numberOfEntriesToRead, AsyncCallbacks.ReadEntriesCallback callback, Object ctx, PositionImpl maxPosition) Asynchronously read entries from the ManagedLedger.voidasyncReadEntriesOrWait(int maxEntries, long maxSizeBytes, AsyncCallbacks.ReadEntriesCallback callback, Object ctx, PositionImpl maxPosition) Asynchronously read entries from the ManagedLedger, up to the specified number and size.voidasyncReadEntriesOrWait(int numberOfEntriesToRead, AsyncCallbacks.ReadEntriesCallback callback, Object ctx, PositionImpl maxPosition) Asynchronously read entries from the ManagedLedger.asyncReplayEntries(Set<? extends Position> positions, AsyncCallbacks.ReadEntriesCallback callback, Object ctx) Read the specified set of positions from ManagedLedger without ordering.asyncReplayEntries(Set<? extends Position> positions, AsyncCallbacks.ReadEntriesCallback callback, Object ctx, boolean sortEntries) Read the specified set of positions from ManagedLedger.voidasyncResetCursor(Position position, boolean forceReset, AsyncCallbacks.ResetCursorCallback callback) reset the cursor to specified position to enable replay of messages.voidasyncSkipEntries(int numEntriesToSkip, ManagedCursor.IndividualDeletedEntries deletedEntries, AsyncCallbacks.SkipEntriesCallback callback, Object ctx) Skip n entries from the read position of this cursor.booleanCancel a previously scheduled asyncReadEntriesOrWait operation.booleanChecks if read position changed since this method was called last time.voidClear the cursor backlog.voidclose()Close the cursor and releases the associated resources.voidDelete a group of entries.voidDelete a single message.findNewestMatching(com.google.common.base.Predicate<Entry> condition) Find the newest entry that matches the given predicate.findNewestMatching(ManagedCursor.FindPositionConstraint constraint, com.google.common.base.Predicate<Entry> condition) Find the newest entry that matches the given predicate.Return any properties that were associated with the cursor.long[]Get deleted batch indexes list for a batch message.longReturns the estimated size of the unacknowledged backlog for this cursor.Get the first position.longGet the last active time of the cursor.com.google.common.collect.Range<PositionImpl>Get last individual deleted range.GetManagedLedgerattached with cursor.Get the newest mark deleted position on this cursor.getName()Get the unique cursor name.intReturns the serialized size of mark-Delete ranges.getNthEntry(int n, ManagedCursor.IndividualDeletedEntries deletedEntries) Get 'N'th entry from the mark delete position in the cursor without updating any cursor positions.longReturn the number of messages that this cursor still has to read.longgetNumberOfEntriesInBacklog(boolean isPrecise) Return the number of non-deleted messages on this cursor.longReturns total number of entries from the first not-acked message to current dispatching position.Get the persistent newest mark deleted position on this cursor.Return any properties that were associated with the last stored position.Get the read position.getStats()doubleReturns cursor throttle mark-delete rate.intReturns number of mark-Delete range.booleanTells whether this cursor has already consumed all the available entries.booleanisActive()Checks if cursor is active or not.booleanisClosed()Checks if the cursor is closed.booleanTells whether the cursor is durable or just kept in memory.voidmarkDelete(Position position) This signals that the reader is done with all the entries up to "position" (included).voidmarkDelete(Position position, Map<String, Long> properties) This signals that the reader is done with all the entries up to "position" (included).booleanputProperty(String key, Long value) Add a property associated with the last stored position.readEntries(int numberOfEntriesToRead) Read entries from the ManagedLedger, up to the specified number.readEntriesOrWait(int numberOfEntriesToRead) Read entries from the ManagedLedger, up to the specified number.readEntriesOrWait(int maxEntries, long maxSizeBytes) Read entries from the ManagedLedger, up to the specified number and size.booleanremoveProperty(String key) Remove a property associated with the last stored position.replayEntries(Set<? extends Position> positions) Read the specified set of positions from ManagedLedger.voidresetCursor(Position position) reset the cursor to specified position to enable replay of messages.voidrewind()Rewind the cursor to the mark deleted position to replay all the already read but not yet mark deleted messages.default voidMove the cursor to a different read position.voidvoidActivate cursor: EntryCacheManager caches entries only for activated-cursors.voidA cursor that is set as always-inactive will never trigger the caching of entries.default CompletableFuture<Void>setCursorProperties(Map<String, String> cursorProperties) Updates the properties.voidDeactivate cursor.voidsetThrottleMarkDelete(double throttleMarkDelete) Update throttle mark delete rate.voidskipEntries(int numEntriesToSkip, ManagedCursor.IndividualDeletedEntries deletedEntries) Skip n entries from the read position of this cursor.voidtrimDeletedEntries(List<Entry> entries) Trim delete entries for the given entries.voidUpdate the last active time of the cursor.
-
方法详细资料
-
getName
String getName()Get the unique cursor name.- 返回:
- the cursor name
-
getLastActive
long getLastActive()Get the last active time of the cursor.- 返回:
- the last active time of the cursor
-
updateLastActive
void updateLastActive()Update the last active time of the cursor. -
getProperties
Return any properties that were associated with the last stored position. -
getCursorProperties
Return any properties that were associated with the cursor. -
setCursorProperties
Updates the properties.- 参数:
cursorProperties-- 返回:
- a handle to the result of the operation
-
putProperty
Add a property associated with the last stored position. -
removeProperty
Remove a property associated with the last stored position. -
readEntries
List<Entry> readEntries(int numberOfEntriesToRead) throws InterruptedException, ManagedLedgerException Read entries from the ManagedLedger, up to the specified number. The returned list can be smaller.- 参数:
numberOfEntriesToRead- maximum number of entries to return- 返回:
- the list of entries
- 抛出:
ManagedLedgerExceptionInterruptedException
-
asyncReadEntries
void asyncReadEntries(int numberOfEntriesToRead, AsyncCallbacks.ReadEntriesCallback callback, Object ctx, PositionImpl maxPosition) Asynchronously read entries from the ManagedLedger.- 参数:
numberOfEntriesToRead- maximum number of entries to returncallback- callback objectctx- opaque contextmaxPosition- max position can read- 另请参阅:
-
asyncReadEntries
void asyncReadEntries(int numberOfEntriesToRead, long maxSizeBytes, AsyncCallbacks.ReadEntriesCallback callback, Object ctx, PositionImpl maxPosition) Asynchronously read entries from the ManagedLedger.- 参数:
numberOfEntriesToRead- maximum number of entries to returnmaxSizeBytes- max size in bytes of the entries to returncallback- callback objectctx- opaque contextmaxPosition- max position can read
-
getNthEntry
Entry getNthEntry(int n, ManagedCursor.IndividualDeletedEntries deletedEntries) throws InterruptedException, ManagedLedgerException Get 'N'th entry from the mark delete position in the cursor without updating any cursor positions.- 参数:
n- entry positiondeletedEntries- skip individual deleted entries- 返回:
- the entry
- 抛出:
InterruptedExceptionManagedLedgerException
-
asyncGetNthEntry
void asyncGetNthEntry(int n, ManagedCursor.IndividualDeletedEntries deletedEntries, AsyncCallbacks.ReadEntryCallback callback, Object ctx) Asynchronously get 'N'th entry from the mark delete position in the cursor without updating any cursor positions.- 参数:
n- entry positiondeletedEntries- skip individual deleted entriescallback-ctx-
-
readEntriesOrWait
List<Entry> readEntriesOrWait(int numberOfEntriesToRead) throws InterruptedException, ManagedLedgerException Read entries from the ManagedLedger, up to the specified number. The returned list can be smaller. If no entries are available, the method will block until at least a new message will be persisted.- 参数:
numberOfEntriesToRead- maximum number of entries to return- 返回:
- the list of entries
- 抛出:
ManagedLedgerExceptionInterruptedException
-
readEntriesOrWait
List<Entry> readEntriesOrWait(int maxEntries, long maxSizeBytes) throws InterruptedException, ManagedLedgerException Read entries from the ManagedLedger, up to the specified number and size. If no entries are available, the method will block until at least a new message will be persisted.- 参数:
maxEntries- maximum number of entries to returnmaxSizeBytes- max size in bytes of the entries to return- 返回:
- the list of entries
- 抛出:
ManagedLedgerExceptionInterruptedException
-
asyncReadEntriesOrWait
void asyncReadEntriesOrWait(int numberOfEntriesToRead, AsyncCallbacks.ReadEntriesCallback callback, Object ctx, PositionImpl maxPosition) Asynchronously read entries from the ManagedLedger. If no entries are available, the callback will not be triggered. Instead it will be registered to wait until a new message will be persisted into the managed ledger- 参数:
numberOfEntriesToRead- maximum number of entries to returncallback- callback objectctx- opaque contextmaxPosition- max position can read- 另请参阅:
-
asyncReadEntriesOrWait
void asyncReadEntriesOrWait(int maxEntries, long maxSizeBytes, AsyncCallbacks.ReadEntriesCallback callback, Object ctx, PositionImpl maxPosition) Asynchronously read entries from the ManagedLedger, up to the specified number and size. If no entries are available, the callback will not be triggered. Instead it will be registered to wait until a new message will be persisted into the managed ledger- 参数:
maxEntries- maximum number of entries to returnmaxSizeBytes- max size in bytes of the entries to returncallback- callback objectctx- opaque contextmaxPosition- max position can read- 另请参阅:
-
cancelPendingReadRequest
boolean cancelPendingReadRequest()Cancel a previously scheduled asyncReadEntriesOrWait operation.- 返回:
- true if the read operation was canceled or false if there was no pending operation
- 另请参阅:
-
hasMoreEntries
boolean hasMoreEntries()Tells whether this cursor has already consumed all the available entries. This method is not blocking.- 返回:
- true if there are pending entries to read, false otherwise
-
getNumberOfEntries
long getNumberOfEntries()Return the number of messages that this cursor still has to read. This method has linear time complexity on the number of ledgers included in the managed ledger.- 返回:
- the number of entries
-
getNumberOfEntriesInBacklog
long getNumberOfEntriesInBacklog(boolean isPrecise) Return the number of non-deleted messages on this cursor. This will also include messages that have already been read from the cursor but not deleted or mark-deleted yet. This method has linear time complexity on the number of ledgers included in the managed ledger.- 参数:
isPrecise- set to true to get precise backlog count- 返回:
- the number of entries
-
markDelete
This signals that the reader is done with all the entries up to "position" (included). This can potentially trigger a ledger deletion, if all the other cursors are done too with the underlying ledger.- 参数:
position- the last position that have been successfully consumed- 抛出:
ManagedLedgerExceptionInterruptedException
-
markDelete
void markDelete(Position position, Map<String, Long> properties) throws InterruptedException, ManagedLedgerExceptionThis signals that the reader is done with all the entries up to "position" (included). This can potentially trigger a ledger deletion, if all the other cursors are done too with the underlying ledger.- 参数:
position- the last position that have been successfully consumedproperties- additional user-defined properties that can be associated with a particular cursor position- 抛出:
ManagedLedgerExceptionInterruptedException
-
asyncMarkDelete
Asynchronous mark delete.- 参数:
position- the last position that have been successfully consumedcallback- callback objectctx- opaque context- 另请参阅:
-
asyncMarkDelete
void asyncMarkDelete(Position position, Map<String, Long> properties, AsyncCallbacks.MarkDeleteCallback callback, Object ctx) Asynchronous mark delete.- 参数:
position- the last position that have been successfully consumedproperties- additional user-defined properties that can be associated with a particular cursor positioncallback- callback objectctx- opaque context- 另请参阅:
-
delete
Delete a single message. Mark a single message for deletion. When all the previous messages are all deleted, then markDelete() will be called internally to advance the persistent acknowledged position. The deletion of the message is not persisted into the durable storage and cannot be recovered upon the reopening of the ManagedLedger- 参数:
position- the position of the message to be deleted- 抛出:
InterruptedExceptionManagedLedgerException
-
asyncDelete
Delete a single message asynchronously Mark a single message for deletion. When all the previous messages are all deleted, then markDelete() will be called internally to advance the persistent acknowledged position. The deletion of the message is not persisted into the durable storage and cannot be recovered upon the reopening of the ManagedLedger- 参数:
position- the position of the message to be deletedcallback- callback objectctx- opaque context
-
delete
Delete a group of entries. Mark multiple single messages for deletion. When all the previous messages are all deleted, then markDelete() will be called internally to advance the persistent acknowledged position. The deletion of the message is not persisted into the durable storage and cannot be recovered upon the reopening of the ManagedLedger- 参数:
positions- positions of the messages to be deleted- 抛出:
InterruptedExceptionManagedLedgerException
-
asyncDelete
Delete a group of messages asynchronously Mark a group of messages for deletion. When all the previous messages are all deleted, then markDelete() will be called internally to advance the persistent acknowledged position. The deletion of the messages is not persisted into the durable storage and cannot be recovered upon the reopening of the ManagedLedger- 参数:
position- the positions of the messages to be deletedcallback- callback objectctx- opaque context
-
getReadPosition
Position getReadPosition()Get the read position. This points to the next message to be read from the cursor.- 返回:
- the read position
-
getMarkDeletedPosition
Position getMarkDeletedPosition()Get the newest mark deleted position on this cursor.- 返回:
- the mark deleted position
-
getPersistentMarkDeletedPosition
Position getPersistentMarkDeletedPosition()Get the persistent newest mark deleted position on this cursor.- 返回:
- the persistent mark deleted position
-
rewind
void rewind()Rewind the cursor to the mark deleted position to replay all the already read but not yet mark deleted messages. The next message to be read is the one after the current mark deleted message. -
seek
Move the cursor to a different read position. If the new position happens to be before the already mark deleted position, it will be set to the mark deleted position instead.- 参数:
newReadPosition- the position where to move the cursor
-
seek
-
clearBacklog
Clear the cursor backlog. Consume all the entries for this cursor. -
asyncClearBacklog
Clear the cursor backlog. Consume all the entries for this cursor.- 参数:
callback- callback objectctx- opaque context
-
skipEntries
void skipEntries(int numEntriesToSkip, ManagedCursor.IndividualDeletedEntries deletedEntries) throws InterruptedException, ManagedLedgerException Skip n entries from the read position of this cursor.- 参数:
numEntriesToSkip- number of entries to skipdeletedEntries- skip individual deleted entries- 抛出:
InterruptedExceptionManagedLedgerException
-
asyncSkipEntries
void asyncSkipEntries(int numEntriesToSkip, ManagedCursor.IndividualDeletedEntries deletedEntries, AsyncCallbacks.SkipEntriesCallback callback, Object ctx) Skip n entries from the read position of this cursor.- 参数:
numEntriesToSkip- number of entries to skipdeletedEntries- skip individual deleted entriescallback- callback objectctx- opaque context
-
findNewestMatching
Position findNewestMatching(com.google.common.base.Predicate<Entry> condition) throws InterruptedException, ManagedLedgerException Find the newest entry that matches the given predicate. Will only search among active entries- 参数:
condition- predicate that reads an entry an applies a condition- 返回:
- Position of the newest entry that matches the given predicate
- 抛出:
InterruptedExceptionManagedLedgerException
-
findNewestMatching
Position findNewestMatching(ManagedCursor.FindPositionConstraint constraint, com.google.common.base.Predicate<Entry> condition) throws InterruptedException, ManagedLedgerException Find the newest entry that matches the given predicate.- 参数:
constraint- search only active entries or all entriescondition- predicate that reads an entry an applies a condition- 返回:
- Position of the newest entry that matches the given predicate
- 抛出:
InterruptedExceptionManagedLedgerException
-
asyncFindNewestMatching
void asyncFindNewestMatching(ManagedCursor.FindPositionConstraint constraint, com.google.common.base.Predicate<Entry> condition, AsyncCallbacks.FindEntryCallback callback, Object ctx) Find the newest entry that matches the given predicate.- 参数:
constraint- search only active entries or all entriescondition- predicate that reads an entry an applies a conditioncallback- callback object returning the resultant positionctx- opaque context
-
resetCursor
reset the cursor to specified position to enable replay of messages.- 参数:
position- position to move the cursor to- 抛出:
InterruptedExceptionManagedLedgerException
-
asyncResetCursor
void asyncResetCursor(Position position, boolean forceReset, AsyncCallbacks.ResetCursorCallback callback) reset the cursor to specified position to enable replay of messages.- 参数:
position- position to move the cursor toforceReset- whether to force reset the position even if the position is no longer in the managed ledger, this is used by compacted topic which has data in the compacted ledger, to ensure the cursor can read data from the compacted ledger.callback- callback object
-
replayEntries
List<Entry> replayEntries(Set<? extends Position> positions) throws InterruptedException, ManagedLedgerException Read the specified set of positions from ManagedLedger.- 参数:
positions- set of positions to read- 返回:
- the list of entries
- 抛出:
InterruptedExceptionManagedLedgerException
-
asyncReplayEntries
Set<? extends Position> asyncReplayEntries(Set<? extends Position> positions, AsyncCallbacks.ReadEntriesCallback callback, Object ctx) Read the specified set of positions from ManagedLedger without ordering.- 参数:
positions- set of positions to readcallback- callback object returning the list of entriesctx- opaque context- 返回:
- skipped positions set of positions which are already deleted/acknowledged and skipped while replaying them
-
asyncReplayEntries
Set<? extends Position> asyncReplayEntries(Set<? extends Position> positions, AsyncCallbacks.ReadEntriesCallback callback, Object ctx, boolean sortEntries) Read the specified set of positions from ManagedLedger.- 参数:
positions- set of positions to readcallback- callback object returning the list of entriesctx- opaque contextsortEntries- callback with sorted entry list.- 返回:
- skipped positions set of positions which are already deleted/acknowledged and skipped while replaying them
-
close
Close the cursor and releases the associated resources. -
asyncClose
Close the cursor asynchronously and release the associated resources.- 参数:
callback- callback objectctx- opaque context
-
getFirstPosition
Position getFirstPosition()Get the first position.- 返回:
- the first position
-
setActive
void setActive()Activate cursor: EntryCacheManager caches entries only for activated-cursors. -
setInactive
void setInactive()Deactivate cursor. -
setAlwaysInactive
void setAlwaysInactive()A cursor that is set as always-inactive will never trigger the caching of entries. -
isActive
boolean isActive()Checks if cursor is active or not.- 返回:
-
isDurable
boolean isDurable()Tells whether the cursor is durable or just kept in memory. -
getNumberOfEntriesSinceFirstNotAckedMessage
long getNumberOfEntriesSinceFirstNotAckedMessage()Returns total number of entries from the first not-acked message to current dispatching position.- 返回:
-
getTotalNonContiguousDeletedMessagesRange
int getTotalNonContiguousDeletedMessagesRange()Returns number of mark-Delete range.- 返回:
-
getNonContiguousDeletedMessagesRangeSerializedSize
int getNonContiguousDeletedMessagesRangeSerializedSize()Returns the serialized size of mark-Delete ranges. -
getEstimatedSizeSinceMarkDeletePosition
long getEstimatedSizeSinceMarkDeletePosition()Returns the estimated size of the unacknowledged backlog for this cursor.- 返回:
- the estimated size from the mark delete position of the cursor
-
getThrottleMarkDelete
double getThrottleMarkDelete()Returns cursor throttle mark-delete rate.- 返回:
-
setThrottleMarkDelete
void setThrottleMarkDelete(double throttleMarkDelete) Update throttle mark delete rate. -
getManagedLedger
ManagedLedger getManagedLedger()GetManagedLedgerattached with cursor.- 返回:
- ManagedLedger
-
getLastIndividualDeletedRange
com.google.common.collect.Range<PositionImpl> getLastIndividualDeletedRange()Get last individual deleted range.- 返回:
- range
-
trimDeletedEntries
Trim delete entries for the given entries. -
getDeletedBatchIndexesAsLongArray
Get deleted batch indexes list for a batch message. -
getStats
ManagedCursorMXBean getStats()- 返回:
- the managed cursor stats MBean
-
checkAndUpdateReadPositionChanged
boolean checkAndUpdateReadPositionChanged()Checks if read position changed since this method was called last time.- 返回:
- if read position changed
-
isClosed
boolean isClosed()Checks if the cursor is closed.- 返回:
- whether this cursor is closed.
-