接口 ManagedCursor

所有已知实现类:
ManagedCursorImpl, NonDurableCursorImpl, ReadOnlyCursorImpl

@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.

  • 方法详细资料

    • 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

      Map<String,Long> getProperties()
      Return any properties that were associated with the last stored position.
    • getCursorProperties

      Map<String,String> getCursorProperties()
      Return any properties that were associated with the cursor.
    • setCursorProperties

      default CompletableFuture<Void> setCursorProperties(Map<String,String> cursorProperties)
      Updates the properties.
      参数:
      cursorProperties -
      返回:
      a handle to the result of the operation
    • putProperty

      boolean putProperty(String key, Long value)
      Add a property associated with the last stored position.
    • removeProperty

      boolean removeProperty(String key)
      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
      抛出:
      ManagedLedgerException
      InterruptedException
    • asyncReadEntries

      void asyncReadEntries(int numberOfEntriesToRead, AsyncCallbacks.ReadEntriesCallback callback, Object ctx, PositionImpl maxPosition)
      Asynchronously read entries from the ManagedLedger.
      参数:
      numberOfEntriesToRead - maximum number of entries to return
      callback - callback object
      ctx - opaque context
      maxPosition - 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 return
      maxSizeBytes - max size in bytes of the entries to return
      callback - callback object
      ctx - opaque context
      maxPosition - max position can read
    • getNthEntry

      Get 'N'th entry from the mark delete position in the cursor without updating any cursor positions.
      参数:
      n - entry position
      deletedEntries - skip individual deleted entries
      返回:
      the entry
      抛出:
      InterruptedException
      ManagedLedgerException
    • 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 position
      deletedEntries - skip individual deleted entries
      callback -
      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
      抛出:
      ManagedLedgerException
      InterruptedException
    • 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 return
      maxSizeBytes - max size in bytes of the entries to return
      返回:
      the list of entries
      抛出:
      ManagedLedgerException
      InterruptedException
    • 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 return
      callback - callback object
      ctx - opaque context
      maxPosition - 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 return
      maxSizeBytes - max size in bytes of the entries to return
      callback - callback object
      ctx - opaque context
      maxPosition - 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

      void markDelete(Position position) throws InterruptedException, ManagedLedgerException
      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
      抛出:
      ManagedLedgerException
      InterruptedException
    • markDelete

      void markDelete(Position position, Map<String,Long> properties) throws InterruptedException, ManagedLedgerException
      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
      properties - additional user-defined properties that can be associated with a particular cursor position
      抛出:
      ManagedLedgerException
      InterruptedException
    • asyncMarkDelete

      void asyncMarkDelete(Position position, AsyncCallbacks.MarkDeleteCallback callback, Object ctx)
      Asynchronous mark delete.
      参数:
      position - the last position that have been successfully consumed
      callback - callback object
      ctx - 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 consumed
      properties - additional user-defined properties that can be associated with a particular cursor position
      callback - callback object
      ctx - opaque context
      另请参阅:
    • delete

      void delete(Position position) throws InterruptedException, ManagedLedgerException
      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
      抛出:
      InterruptedException
      ManagedLedgerException
    • asyncDelete

      void asyncDelete(Position position, AsyncCallbacks.DeleteCallback callback, Object ctx)
      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 deleted
      callback - callback object
      ctx - 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
      抛出:
      InterruptedException
      ManagedLedgerException
    • asyncDelete

      void asyncDelete(Iterable<Position> position, AsyncCallbacks.DeleteCallback callback, Object ctx)
      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 deleted
      callback - callback object
      ctx - 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

      default void seek(Position newReadPosition)
      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

      void seek(Position newReadPosition, boolean force)
    • clearBacklog

      void clearBacklog() throws InterruptedException, ManagedLedgerException
      Clear the cursor backlog.

      Consume all the entries for this cursor.

      抛出:
      InterruptedException
      ManagedLedgerException
    • asyncClearBacklog

      void asyncClearBacklog(AsyncCallbacks.ClearBacklogCallback callback, Object ctx)
      Clear the cursor backlog.

      Consume all the entries for this cursor.

      参数:
      callback - callback object
      ctx - 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 skip
      deletedEntries - skip individual deleted entries
      抛出:
      InterruptedException
      ManagedLedgerException
    • 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 skip
      deletedEntries - skip individual deleted entries
      callback - callback object
      ctx - 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
      抛出:
      InterruptedException
      ManagedLedgerException
    • 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 entries
      condition - predicate that reads an entry an applies a condition
      返回:
      Position of the newest entry that matches the given predicate
      抛出:
      InterruptedException
      ManagedLedgerException
    • 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 entries
      condition - predicate that reads an entry an applies a condition
      callback - callback object returning the resultant position
      ctx - opaque context
    • resetCursor

      void resetCursor(Position position) throws InterruptedException, ManagedLedgerException
      reset the cursor to specified position to enable replay of messages.
      参数:
      position - position to move the cursor to
      抛出:
      InterruptedException
      ManagedLedgerException
    • 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 to
      forceReset - 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
      抛出:
      InterruptedException
      ManagedLedgerException
    • 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 read
      callback - callback object returning the list of entries
      ctx - 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 read
      callback - callback object returning the list of entries
      ctx - opaque context
      sortEntries - 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.
      抛出:
      InterruptedException
      ManagedLedgerException
    • asyncClose

      void asyncClose(AsyncCallbacks.CloseCallback callback, Object ctx)
      Close the cursor asynchronously and release the associated resources.
      参数:
      callback - callback object
      ctx - 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()
      Get ManagedLedger attached with cursor.
      返回:
      ManagedLedger
    • getLastIndividualDeletedRange

      com.google.common.collect.Range<PositionImpl> getLastIndividualDeletedRange()
      Get last individual deleted range.
      返回:
      range
    • trimDeletedEntries

      void trimDeletedEntries(List<Entry> entries)
      Trim delete entries for the given entries.
    • getDeletedBatchIndexesAsLongArray

      long[] getDeletedBatchIndexesAsLongArray(PositionImpl position)
      Get deleted batch indexes list for a batch message.
    • 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.