Class ManagedCursorImpl
- java.lang.Object
-
- org.apache.bookkeeper.mledger.impl.ManagedCursorImpl
-
- All Implemented Interfaces:
ManagedCursor
- Direct Known Subclasses:
NonDurableCursorImpl,ReadOnlyCursorImpl
public class ManagedCursorImpl extends java.lang.Object implements ManagedCursor
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceManagedCursorImpl.VoidCallback-
Nested classes/interfaces inherited from interface org.apache.bookkeeper.mledger.ManagedCursor
ManagedCursor.FindPositionConstraint, ManagedCursor.IndividualDeletedEntries
-
-
Field Summary
Fields Modifier and Type Field Description protected org.apache.bookkeeper.client.BookKeeperbookkeeperprotected ManagedLedgerConfigconfigstatic intFALSEprotected static java.util.concurrent.atomic.AtomicReferenceFieldUpdater<ManagedCursorImpl,org.apache.bookkeeper.mledger.impl.ManagedCursorImpl.MarkDeleteEntry>LAST_MARK_DELETE_ENTRY_UPDATERprotected org.apache.bookkeeper.mledger.impl.ManagedCursorImpl.MarkDeleteEntrylastMarkDeleteEntryprotected ManagedLedgerImplledgerprotected PositionImplmarkDeletePositionprotected ManagedCursorMXBeanmbeanprotected longmessagesConsumedCounterprotected java.util.ArrayDeque<org.apache.bookkeeper.mledger.impl.ManagedCursorImpl.MarkDeleteEntry>pendingMarkDeleteOpsprotected PositionImplpersistentMarkDeletePositionprotected static java.util.concurrent.atomic.AtomicReferenceFieldUpdater<ManagedCursorImpl,PositionImpl>READ_POSITION_UPDATERprotected PositionImplreadPositionprotected org.apache.bookkeeper.mledger.impl.ManagedCursorImpl.Statestateprotected PositionImplstatsLastReadPositionstatic intTRUEprotected static java.util.concurrent.atomic.AtomicReferenceFieldUpdater<ManagedCursorImpl,org.apache.bookkeeper.mledger.impl.OpReadEntry>WAITING_READ_OP_UPDATER
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidasyncClearBacklog(AsyncCallbacks.ClearBacklogCallback callback, java.lang.Object ctx)Clear the cursor backlog.voidasyncClose(AsyncCallbacks.CloseCallback callback, java.lang.Object ctx)Close the cursor asynchronously and release the associated resources.voidasyncDelete(java.lang.Iterable<Position> positions, AsyncCallbacks.DeleteCallback callback, java.lang.Object ctx)Delete a group of messages asynchronouslyvoidasyncDelete(Position pos, AsyncCallbacks.DeleteCallback callback, java.lang.Object ctx)Delete a single message asynchronouslyvoidasyncFindNewestMatching(ManagedCursor.FindPositionConstraint constraint, com.google.common.base.Predicate<Entry> condition, AsyncCallbacks.FindEntryCallback callback, java.lang.Object ctx)Find the newest entry that matches the given predicate.voidasyncGetNthEntry(int n, ManagedCursor.IndividualDeletedEntries deletedEntries, AsyncCallbacks.ReadEntryCallback callback, java.lang.Object ctx)Asynchronously get 'N'th entry from the mark delete position in the cursor without updating any cursor positions.voidasyncMarkDelete(Position position, java.util.Map<java.lang.String,java.lang.Long> properties, AsyncCallbacks.MarkDeleteCallback callback, java.lang.Object ctx)Asynchronous mark delete.voidasyncMarkDelete(Position position, AsyncCallbacks.MarkDeleteCallback callback, java.lang.Object ctx)Asynchronous mark delete.voidasyncReadEntries(int numberOfEntriesToRead, long maxSizeBytes, AsyncCallbacks.ReadEntriesCallback callback, java.lang.Object ctx, PositionImpl maxPosition)Asynchronously read entries from the ManagedLedger.voidasyncReadEntries(int numberOfEntriesToRead, AsyncCallbacks.ReadEntriesCallback callback, java.lang.Object ctx, PositionImpl maxPosition)Asynchronously read entries from the ManagedLedger.voidasyncReadEntriesOrWait(int maxEntries, long maxSizeBytes, AsyncCallbacks.ReadEntriesCallback callback, java.lang.Object ctx, PositionImpl maxPosition)Asynchronously read entries from the ManagedLedger, up to the specified number and size.voidasyncReadEntriesOrWait(int numberOfEntriesToRead, AsyncCallbacks.ReadEntriesCallback callback, java.lang.Object ctx, PositionImpl maxPosition)Asynchronously read entries from the ManagedLedger.java.util.Set<? extends Position>asyncReplayEntries(java.util.Set<? extends Position> positions, AsyncCallbacks.ReadEntriesCallback callback, java.lang.Object ctx)Async replays given positions: a.java.util.Set<? extends Position>asyncReplayEntries(java.util.Set<? extends Position> positions, AsyncCallbacks.ReadEntriesCallback callback, java.lang.Object ctx, boolean sortEntries)Read the specified set of positions from ManagedLedger.voidasyncResetCursor(Position newPos, AsyncCallbacks.ResetCursorCallback callback)reset the cursor to specified position to enable replay of messages.voidasyncSkipEntries(int numEntriesToSkip, ManagedCursor.IndividualDeletedEntries deletedEntries, AsyncCallbacks.SkipEntriesCallback callback, java.lang.Object ctx)Skip n entries from the read position of this cursor.booleancancelPendingReadRequest()Cancel a previously scheduled asyncReadEntriesOrWait operation.booleancheckAndUpdateReadPositionChanged()Checks if read position changed since this method was called last time.voidclearBacklog()Clear the cursor backlog.voidclose()Close the cursor and releases the associated resources.voiddelete(java.lang.Iterable<Position> positions)Delete a group of entries.voiddelete(Position position)Delete a single message.PositionfindNewestMatching(com.google.common.base.Predicate<Entry> condition)Find the newest entry that matches the given predicate.PositionfindNewestMatching(ManagedCursor.FindPositionConstraint constraint, com.google.common.base.Predicate<Entry> condition)Find the newest entry that matches the given predicate.long[]getBatchPositionAckSet(Position position)longgetCursorLedger()longgetCursorLedgerLastEntry()long[]getDeletedBatchIndexesAsLongArray(PositionImpl position)Get deleted batch indexes list for a batch message.longgetEstimatedSizeSinceMarkDeletePosition()Returns the estimated size of the unacknowledged backlog for this cursorPositiongetFirstPosition()Get the first position.java.lang.StringgetIndividuallyDeletedMessages()org.apache.pulsar.common.util.collections.LongPairRangeSet<PositionImpl>getIndividuallyDeletedMessagesSet()longgetLastActive()Get the last active time of the cursor.com.google.common.collect.Range<PositionImpl>getLastIndividualDeletedRange()Get last individual deleted rangelonggetLastLedgerSwitchTimestamp()ManagedLedgergetManagedLedger()GetManagedLedgerattached with cursorPositiongetMarkDeletedPosition()Get the newest mark deleted position on this cursor.longgetMessagesConsumedCounter()java.lang.StringgetName()Get the unique cursor name.PositionImplgetNextAvailablePosition(PositionImpl position)Checks given position is part of deleted-range and returns next position of upper-end as all the messages are deleted up to that point.PositiongetNextLedgerPosition(long currentLedgerId)intgetNonContiguousDeletedMessagesRangeSerializedSize()Returns the serialized size of mark-Delete ranges.EntrygetNthEntry(int n, ManagedCursor.IndividualDeletedEntries deletedEntries)Get 'N'th entry from the mark delete position in the cursor without updating any cursor positions.longgetNumberOfEntries()Return the number of messages that this cursor still has to read.protected longgetNumberOfEntries(com.google.common.collect.Range<PositionImpl> range)longgetNumberOfEntriesInBacklog(boolean isPrecise)Return the number of non-deleted messages on this cursor.longgetNumberOfEntriesInStorage()longgetNumberOfEntriesSinceFirstNotAckedMessage()Returns total number of entries from the first not-acked message to current dispatching position.intgetPendingReadOpsCount()PositiongetPersistentMarkDeletedPosition()Get the persistent newest mark deleted position on this cursor.java.util.Map<java.lang.String,java.lang.Long>getProperties()Return any properties that were associated with the last stored position.PositiongetReadPosition()Get the read position.java.lang.StringgetState()ManagedCursorMXBeangetStats()doublegetThrottleMarkDelete()Returns cursor throttle mark-delete rate.intgetTotalNonContiguousDeletedMessagesRange()Returns number of mark-Delete range.booleanhasMoreEntries()Tells whether this cursor has already consumed all the available entries.booleanhasPendingReadRequest()protected voidinternalAsyncMarkDelete(PositionImpl newPosition, java.util.Map<java.lang.String,java.lang.Long> properties, AsyncCallbacks.MarkDeleteCallback callback, java.lang.Object ctx)protected voidinternalResetCursor(PositionImpl position, AsyncCallbacks.ResetCursorCallback resetCursorCallback)booleanisActive()Checks if cursor is active or not.static booleanisBkErrorNotRecoverable(int rc)return BK error codes that are considered not likely to be recoverable.booleanisClosed()booleanisDurable()Tells whether the cursor is durable or just kept in memory.booleanisIndividuallyDeletedEntriesEmpty()booleanisMessageDeleted(Position position)voidmarkDelete(Position position)This signals that the reader is done with all the entries up to "position" (included).voidmarkDelete(Position position, java.util.Map<java.lang.String,java.lang.Long> properties)This signals that the reader is done with all the entries up to "position" (included).java.util.List<Entry>readEntries(int numberOfEntriesToRead)Read entries from the ManagedLedger, up to the specified number.java.util.List<Entry>readEntriesOrWait(int numberOfEntriesToRead)Read entries from the ManagedLedger, up to the specified number.java.util.List<Entry>readEntriesOrWait(int numberOfEntriesToRead, long maxSizeBytes)Read entries from the ManagedLedger, up to the specified number and size.protected voidrecoverFromLedger(MLDataFormats.ManagedCursorInfo info, ManagedCursorImpl.VoidCallback callback)java.util.List<Entry>replayEntries(java.util.Set<? extends Position> positions)Read the specified set of positions from ManagedLedger.voidresetCursor(Position newPos)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.voidseek(Position newReadPositionInt)Move the cursor to a different read position.voidsetActive()Activate cursor: EntryCacheManager caches entries only for activated-cursors.voidsetAlwaysInactive()A cursor that is set as always-inactive will never trigger the caching of entries.voidsetInactive()Deactivate 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.java.lang.StringtoString()voidtrimDeletedEntries(java.util.List<Entry> entries)Trim delete entries for the given entriesvoidupdateLastActive()Update the last active time of the cursor
-
-
-
Field Detail
-
bookkeeper
protected final org.apache.bookkeeper.client.BookKeeper bookkeeper
-
config
protected final ManagedLedgerConfig config
-
ledger
protected final ManagedLedgerImpl ledger
-
markDeletePosition
protected volatile PositionImpl markDeletePosition
-
persistentMarkDeletePosition
protected volatile PositionImpl persistentMarkDeletePosition
-
READ_POSITION_UPDATER
protected static final java.util.concurrent.atomic.AtomicReferenceFieldUpdater<ManagedCursorImpl,PositionImpl> READ_POSITION_UPDATER
-
readPosition
protected volatile PositionImpl readPosition
-
statsLastReadPosition
protected volatile PositionImpl statsLastReadPosition
-
LAST_MARK_DELETE_ENTRY_UPDATER
protected static final java.util.concurrent.atomic.AtomicReferenceFieldUpdater<ManagedCursorImpl,org.apache.bookkeeper.mledger.impl.ManagedCursorImpl.MarkDeleteEntry> LAST_MARK_DELETE_ENTRY_UPDATER
-
lastMarkDeleteEntry
protected volatile org.apache.bookkeeper.mledger.impl.ManagedCursorImpl.MarkDeleteEntry lastMarkDeleteEntry
-
WAITING_READ_OP_UPDATER
protected static final java.util.concurrent.atomic.AtomicReferenceFieldUpdater<ManagedCursorImpl,org.apache.bookkeeper.mledger.impl.OpReadEntry> WAITING_READ_OP_UPDATER
-
FALSE
public static final int FALSE
- See Also:
- Constant Field Values
-
TRUE
public static final int TRUE
- See Also:
- Constant Field Values
-
messagesConsumedCounter
protected volatile long messagesConsumedCounter
-
pendingMarkDeleteOps
protected final java.util.ArrayDeque<org.apache.bookkeeper.mledger.impl.ManagedCursorImpl.MarkDeleteEntry> pendingMarkDeleteOps
-
state
protected volatile org.apache.bookkeeper.mledger.impl.ManagedCursorImpl.State state
-
mbean
protected final ManagedCursorMXBean mbean
-
-
Method Detail
-
getProperties
public java.util.Map<java.lang.String,java.lang.Long> getProperties()
Description copied from interface:ManagedCursorReturn any properties that were associated with the last stored position.- Specified by:
getPropertiesin interfaceManagedCursor
-
recoverFromLedger
protected void recoverFromLedger(MLDataFormats.ManagedCursorInfo info, ManagedCursorImpl.VoidCallback callback)
-
readEntries
public java.util.List<Entry> readEntries(int numberOfEntriesToRead) throws java.lang.InterruptedException, ManagedLedgerException
Description copied from interface:ManagedCursorRead entries from the ManagedLedger, up to the specified number. The returned list can be smaller.- Specified by:
readEntriesin interfaceManagedCursor- Parameters:
numberOfEntriesToRead- maximum number of entries to return- Returns:
- the list of entries
- Throws:
ManagedLedgerExceptionjava.lang.InterruptedException
-
asyncReadEntries
public void asyncReadEntries(int numberOfEntriesToRead, AsyncCallbacks.ReadEntriesCallback callback, java.lang.Object ctx, PositionImpl maxPosition)Description copied from interface:ManagedCursorAsynchronously read entries from the ManagedLedger.- Specified by:
asyncReadEntriesin interfaceManagedCursor- Parameters:
numberOfEntriesToRead- maximum number of entries to returncallback- callback objectctx- opaque contextmaxPosition- max position can read- See Also:
ManagedCursor.readEntries(int)
-
asyncReadEntries
public void asyncReadEntries(int numberOfEntriesToRead, long maxSizeBytes, AsyncCallbacks.ReadEntriesCallback callback, java.lang.Object ctx, PositionImpl maxPosition)Description copied from interface:ManagedCursorAsynchronously read entries from the ManagedLedger.- Specified by:
asyncReadEntriesin interfaceManagedCursor- Parameters:
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
public Entry getNthEntry(int n, ManagedCursor.IndividualDeletedEntries deletedEntries) throws java.lang.InterruptedException, ManagedLedgerException
Description copied from interface:ManagedCursorGet 'N'th entry from the mark delete position in the cursor without updating any cursor positions.- Specified by:
getNthEntryin interfaceManagedCursor- Parameters:
n- entry positiondeletedEntries- skip individual deleted entries- Returns:
- the entry
- Throws:
java.lang.InterruptedExceptionManagedLedgerException
-
asyncGetNthEntry
public void asyncGetNthEntry(int n, ManagedCursor.IndividualDeletedEntries deletedEntries, AsyncCallbacks.ReadEntryCallback callback, java.lang.Object ctx)Description copied from interface:ManagedCursorAsynchronously get 'N'th entry from the mark delete position in the cursor without updating any cursor positions.- Specified by:
asyncGetNthEntryin interfaceManagedCursor- Parameters:
n- entry positiondeletedEntries- skip individual deleted entries
-
readEntriesOrWait
public java.util.List<Entry> readEntriesOrWait(int numberOfEntriesToRead) throws java.lang.InterruptedException, ManagedLedgerException
Description copied from interface:ManagedCursorRead 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.- Specified by:
readEntriesOrWaitin interfaceManagedCursor- Parameters:
numberOfEntriesToRead- maximum number of entries to return- Returns:
- the list of entries
- Throws:
ManagedLedgerExceptionjava.lang.InterruptedException
-
readEntriesOrWait
public java.util.List<Entry> readEntriesOrWait(int numberOfEntriesToRead, long maxSizeBytes) throws java.lang.InterruptedException, ManagedLedgerException
Description copied from interface:ManagedCursorRead 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.- Specified by:
readEntriesOrWaitin interfaceManagedCursor- Parameters:
numberOfEntriesToRead- maximum number of entries to returnmaxSizeBytes- max size in bytes of the entries to return- Returns:
- the list of entries
- Throws:
ManagedLedgerExceptionjava.lang.InterruptedException
-
asyncReadEntriesOrWait
public void asyncReadEntriesOrWait(int numberOfEntriesToRead, AsyncCallbacks.ReadEntriesCallback callback, java.lang.Object ctx, PositionImpl maxPosition)Description copied from interface:ManagedCursorAsynchronously 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- Specified by:
asyncReadEntriesOrWaitin interfaceManagedCursor- Parameters:
numberOfEntriesToRead- maximum number of entries to returncallback- callback objectctx- opaque contextmaxPosition- max position can read- See Also:
ManagedCursor.readEntriesOrWait(int)
-
asyncReadEntriesOrWait
public void asyncReadEntriesOrWait(int maxEntries, long maxSizeBytes, AsyncCallbacks.ReadEntriesCallback callback, java.lang.Object ctx, PositionImpl maxPosition)Description copied from interface:ManagedCursorAsynchronously 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- Specified by:
asyncReadEntriesOrWaitin interfaceManagedCursor- Parameters:
maxEntries- maximum number of entries to returnmaxSizeBytes- max size in bytes of the entries to returncallback- callback objectctx- opaque contextmaxPosition- max position can read- See Also:
ManagedCursor.readEntriesOrWait(int, long)
-
isClosed
public boolean isClosed()
-
cancelPendingReadRequest
public boolean cancelPendingReadRequest()
Description copied from interface:ManagedCursorCancel a previously scheduled asyncReadEntriesOrWait operation.- Specified by:
cancelPendingReadRequestin interfaceManagedCursor- Returns:
- true if the read operation was canceled or false if there was no pending operation
- See Also:
ManagedCursor.asyncReadEntriesOrWait(int, ReadEntriesCallback, Object, PositionImpl)
-
hasPendingReadRequest
public boolean hasPendingReadRequest()
-
hasMoreEntries
public boolean hasMoreEntries()
Description copied from interface:ManagedCursorTells whether this cursor has already consumed all the available entries. This method is not blocking.- Specified by:
hasMoreEntriesin interfaceManagedCursor- Returns:
- true if there are pending entries to read, false otherwise
-
getNumberOfEntries
public long getNumberOfEntries()
Description copied from interface:ManagedCursorReturn 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.- Specified by:
getNumberOfEntriesin interfaceManagedCursor- Returns:
- the number of entries
-
getNumberOfEntriesSinceFirstNotAckedMessage
public long getNumberOfEntriesSinceFirstNotAckedMessage()
Description copied from interface:ManagedCursorReturns total number of entries from the first not-acked message to current dispatching position.- Specified by:
getNumberOfEntriesSinceFirstNotAckedMessagein interfaceManagedCursor- Returns:
-
getTotalNonContiguousDeletedMessagesRange
public int getTotalNonContiguousDeletedMessagesRange()
Description copied from interface:ManagedCursorReturns number of mark-Delete range.- Specified by:
getTotalNonContiguousDeletedMessagesRangein interfaceManagedCursor- Returns:
-
getNonContiguousDeletedMessagesRangeSerializedSize
public int getNonContiguousDeletedMessagesRangeSerializedSize()
Description copied from interface:ManagedCursorReturns the serialized size of mark-Delete ranges.- Specified by:
getNonContiguousDeletedMessagesRangeSerializedSizein interfaceManagedCursor
-
getEstimatedSizeSinceMarkDeletePosition
public long getEstimatedSizeSinceMarkDeletePosition()
Description copied from interface:ManagedCursorReturns the estimated size of the unacknowledged backlog for this cursor- Specified by:
getEstimatedSizeSinceMarkDeletePositionin interfaceManagedCursor- Returns:
- the estimated size from the mark delete position of the cursor
-
getNumberOfEntriesInBacklog
public long getNumberOfEntriesInBacklog(boolean isPrecise)
Description copied from interface:ManagedCursorReturn 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.- Specified by:
getNumberOfEntriesInBacklogin interfaceManagedCursor- Parameters:
isPrecise- set to true to get precise backlog count- Returns:
- the number of entries
-
getNumberOfEntriesInStorage
public long getNumberOfEntriesInStorage()
-
findNewestMatching
public Position findNewestMatching(com.google.common.base.Predicate<Entry> condition) throws java.lang.InterruptedException, ManagedLedgerException
Description copied from interface:ManagedCursorFind the newest entry that matches the given predicate. Will only search among active entries- Specified by:
findNewestMatchingin interfaceManagedCursor- Parameters:
condition- predicate that reads an entry an applies a condition- Returns:
- Position of the newest entry that matches the given predicate
- Throws:
java.lang.InterruptedExceptionManagedLedgerException
-
findNewestMatching
public Position findNewestMatching(ManagedCursor.FindPositionConstraint constraint, com.google.common.base.Predicate<Entry> condition) throws java.lang.InterruptedException, ManagedLedgerException
Description copied from interface:ManagedCursorFind the newest entry that matches the given predicate.- Specified by:
findNewestMatchingin interfaceManagedCursor- Parameters:
constraint- search only active entries or all entriescondition- predicate that reads an entry an applies a condition- Returns:
- Position of the newest entry that matches the given predicate
- Throws:
java.lang.InterruptedExceptionManagedLedgerException
-
asyncFindNewestMatching
public void asyncFindNewestMatching(ManagedCursor.FindPositionConstraint constraint, com.google.common.base.Predicate<Entry> condition, AsyncCallbacks.FindEntryCallback callback, java.lang.Object ctx)
Description copied from interface:ManagedCursorFind the newest entry that matches the given predicate.- Specified by:
asyncFindNewestMatchingin interfaceManagedCursor- Parameters:
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
-
setActive
public void setActive()
Description copied from interface:ManagedCursorActivate cursor: EntryCacheManager caches entries only for activated-cursors.- Specified by:
setActivein interfaceManagedCursor
-
isActive
public boolean isActive()
Description copied from interface:ManagedCursorChecks if cursor is active or not.- Specified by:
isActivein interfaceManagedCursor- Returns:
-
setInactive
public void setInactive()
Description copied from interface:ManagedCursorDeactivate cursor.- Specified by:
setInactivein interfaceManagedCursor
-
setAlwaysInactive
public void setAlwaysInactive()
Description copied from interface:ManagedCursorA cursor that is set as always-inactive will never trigger the caching of entries.- Specified by:
setAlwaysInactivein interfaceManagedCursor
-
getFirstPosition
public Position getFirstPosition()
Description copied from interface:ManagedCursorGet the first position.- Specified by:
getFirstPositionin interfaceManagedCursor- Returns:
- the first position
-
internalResetCursor
protected void internalResetCursor(PositionImpl position, AsyncCallbacks.ResetCursorCallback resetCursorCallback)
-
asyncResetCursor
public void asyncResetCursor(Position newPos, AsyncCallbacks.ResetCursorCallback callback)
Description copied from interface:ManagedCursorreset the cursor to specified position to enable replay of messages.- Specified by:
asyncResetCursorin interfaceManagedCursor- Parameters:
newPos- position to move the cursor tocallback- callback object
-
resetCursor
public void resetCursor(Position newPos) throws ManagedLedgerException, java.lang.InterruptedException
Description copied from interface:ManagedCursorreset the cursor to specified position to enable replay of messages.- Specified by:
resetCursorin interfaceManagedCursor- Parameters:
newPos- position to move the cursor to- Throws:
ManagedLedgerExceptionjava.lang.InterruptedException
-
replayEntries
public java.util.List<Entry> replayEntries(java.util.Set<? extends Position> positions) throws java.lang.InterruptedException, ManagedLedgerException
Description copied from interface:ManagedCursorRead the specified set of positions from ManagedLedger.- Specified by:
replayEntriesin interfaceManagedCursor- Parameters:
positions- set of positions to read- Returns:
- the list of entries
- Throws:
java.lang.InterruptedExceptionManagedLedgerException
-
asyncReplayEntries
public java.util.Set<? extends Position> asyncReplayEntries(java.util.Set<? extends Position> positions, AsyncCallbacks.ReadEntriesCallback callback, java.lang.Object ctx)
Async replays given positions: a. before reading it filters out already-acked messages b. reads remaining entries async and gives it to given ReadEntriesCallback c. returns all already-acked messages which are not replayed so, those messages can be removed by caller(Dispatcher)'s replay-list and it won't try to replay it again- Specified by:
asyncReplayEntriesin interfaceManagedCursor- Parameters:
positions- set of positions to readcallback- callback object returning the list of entriesctx- opaque context- Returns:
- skipped positions set of positions which are already deleted/acknowledged and skipped while replaying them
-
asyncReplayEntries
public java.util.Set<? extends Position> asyncReplayEntries(java.util.Set<? extends Position> positions, AsyncCallbacks.ReadEntriesCallback callback, java.lang.Object ctx, boolean sortEntries)
Description copied from interface:ManagedCursorRead the specified set of positions from ManagedLedger.- Specified by:
asyncReplayEntriesin interfaceManagedCursor- Parameters:
positions- set of positions to readcallback- callback object returning the list of entriesctx- opaque contextsortEntries- callback with sorted entry list.- Returns:
- skipped positions set of positions which are already deleted/acknowledged and skipped while replaying them
-
getNumberOfEntries
protected long getNumberOfEntries(com.google.common.collect.Range<PositionImpl> range)
-
markDelete
public void markDelete(Position position) throws java.lang.InterruptedException, ManagedLedgerException
Description copied from interface:ManagedCursorThis 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.- Specified by:
markDeletein interfaceManagedCursor- Parameters:
position- the last position that have been successfully consumed- Throws:
ManagedLedgerExceptionjava.lang.InterruptedException
-
markDelete
public void markDelete(Position position, java.util.Map<java.lang.String,java.lang.Long> properties) throws java.lang.InterruptedException, ManagedLedgerException
Description copied from interface:ManagedCursorThis 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.- Specified by:
markDeletein interfaceManagedCursor- Parameters:
position- the last position that have been successfully consumedproperties- additional user-defined properties that can be associated with a particular cursor position- Throws:
ManagedLedgerExceptionjava.lang.InterruptedException
-
clearBacklog
public void clearBacklog() throws java.lang.InterruptedException, ManagedLedgerExceptionDescription copied from interface:ManagedCursorClear the cursor backlog. Consume all the entries for this cursor.- Specified by:
clearBacklogin interfaceManagedCursor- Throws:
java.lang.InterruptedExceptionManagedLedgerException
-
asyncClearBacklog
public void asyncClearBacklog(AsyncCallbacks.ClearBacklogCallback callback, java.lang.Object ctx)
Description copied from interface:ManagedCursorClear the cursor backlog. Consume all the entries for this cursor.- Specified by:
asyncClearBacklogin interfaceManagedCursor- Parameters:
callback- callback objectctx- opaque context
-
skipEntries
public void skipEntries(int numEntriesToSkip, ManagedCursor.IndividualDeletedEntries deletedEntries) throws java.lang.InterruptedException, ManagedLedgerExceptionDescription copied from interface:ManagedCursorSkip n entries from the read position of this cursor.- Specified by:
skipEntriesin interfaceManagedCursor- Parameters:
numEntriesToSkip- number of entries to skipdeletedEntries- skip individual deleted entries- Throws:
java.lang.InterruptedExceptionManagedLedgerException
-
asyncSkipEntries
public void asyncSkipEntries(int numEntriesToSkip, ManagedCursor.IndividualDeletedEntries deletedEntries, AsyncCallbacks.SkipEntriesCallback callback, java.lang.Object ctx)Description copied from interface:ManagedCursorSkip n entries from the read position of this cursor.- Specified by:
asyncSkipEntriesin interfaceManagedCursor- Parameters:
numEntriesToSkip- number of entries to skipdeletedEntries- skip individual deleted entriescallback- callback objectctx- opaque context
-
asyncMarkDelete
public void asyncMarkDelete(Position position, AsyncCallbacks.MarkDeleteCallback callback, java.lang.Object ctx)
Description copied from interface:ManagedCursorAsynchronous mark delete.- Specified by:
asyncMarkDeletein interfaceManagedCursor- Parameters:
position- the last position that have been successfully consumedcallback- callback objectctx- opaque context- See Also:
ManagedCursor.markDelete(Position)
-
asyncMarkDelete
public void asyncMarkDelete(Position position, java.util.Map<java.lang.String,java.lang.Long> properties, AsyncCallbacks.MarkDeleteCallback callback, java.lang.Object ctx)
Description copied from interface:ManagedCursorAsynchronous mark delete.- Specified by:
asyncMarkDeletein interfaceManagedCursor- Parameters:
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- See Also:
ManagedCursor.markDelete(Position)
-
internalAsyncMarkDelete
protected void internalAsyncMarkDelete(PositionImpl newPosition, java.util.Map<java.lang.String,java.lang.Long> properties, AsyncCallbacks.MarkDeleteCallback callback, java.lang.Object ctx)
-
delete
public void delete(Position position) throws java.lang.InterruptedException, ManagedLedgerException
Description copied from interface:ManagedCursorDelete 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- Specified by:
deletein interfaceManagedCursor- Parameters:
position- the position of the message to be deleted- Throws:
java.lang.InterruptedExceptionManagedLedgerException
-
asyncDelete
public void asyncDelete(Position pos, AsyncCallbacks.DeleteCallback callback, java.lang.Object ctx)
Description copied from interface:ManagedCursorDelete 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- Specified by:
asyncDeletein interfaceManagedCursor- Parameters:
pos- the position of the message to be deletedcallback- callback objectctx- opaque context
-
delete
public void delete(java.lang.Iterable<Position> positions) throws java.lang.InterruptedException, ManagedLedgerException
Description copied from interface:ManagedCursorDelete 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- Specified by:
deletein interfaceManagedCursor- Parameters:
positions- positions of the messages to be deleted- Throws:
java.lang.InterruptedExceptionManagedLedgerException
-
asyncDelete
public void asyncDelete(java.lang.Iterable<Position> positions, AsyncCallbacks.DeleteCallback callback, java.lang.Object ctx)
Description copied from interface:ManagedCursorDelete 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- Specified by:
asyncDeletein interfaceManagedCursor- Parameters:
positions- the positions of the messages to be deletedcallback- callback objectctx- opaque context
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getName
public java.lang.String getName()
Description copied from interface:ManagedCursorGet the unique cursor name.- Specified by:
getNamein interfaceManagedCursor- Returns:
- the cursor name
-
getLastActive
public long getLastActive()
Description copied from interface:ManagedCursorGet the last active time of the cursor.- Specified by:
getLastActivein interfaceManagedCursor- Returns:
- the last active time of the cursor
-
updateLastActive
public void updateLastActive()
Description copied from interface:ManagedCursorUpdate the last active time of the cursor- Specified by:
updateLastActivein interfaceManagedCursor
-
isDurable
public boolean isDurable()
Description copied from interface:ManagedCursorTells whether the cursor is durable or just kept in memory.- Specified by:
isDurablein interfaceManagedCursor
-
getReadPosition
public Position getReadPosition()
Description copied from interface:ManagedCursorGet the read position. This points to the next message to be read from the cursor.- Specified by:
getReadPositionin interfaceManagedCursor- Returns:
- the read position
-
getMarkDeletedPosition
public Position getMarkDeletedPosition()
Description copied from interface:ManagedCursorGet the newest mark deleted position on this cursor.- Specified by:
getMarkDeletedPositionin interfaceManagedCursor- Returns:
- the mark deleted position
-
getPersistentMarkDeletedPosition
public Position getPersistentMarkDeletedPosition()
Description copied from interface:ManagedCursorGet the persistent newest mark deleted position on this cursor.- Specified by:
getPersistentMarkDeletedPositionin interfaceManagedCursor- Returns:
- the persistent mark deleted position
-
rewind
public void rewind()
Description copied from interface:ManagedCursorRewind 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.- Specified by:
rewindin interfaceManagedCursor
-
seek
public void seek(Position newReadPositionInt)
Description copied from interface:ManagedCursorMove 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.- Specified by:
seekin interfaceManagedCursor- Parameters:
newReadPositionInt- the position where to move the cursor
-
close
public void close() throws java.lang.InterruptedException, ManagedLedgerExceptionDescription copied from interface:ManagedCursorClose the cursor and releases the associated resources.- Specified by:
closein interfaceManagedCursor- Throws:
java.lang.InterruptedExceptionManagedLedgerException
-
asyncClose
public void asyncClose(AsyncCallbacks.CloseCallback callback, java.lang.Object ctx)
Description copied from interface:ManagedCursorClose the cursor asynchronously and release the associated resources.- Specified by:
asyncClosein interfaceManagedCursor- Parameters:
callback- callback objectctx- opaque context
-
isBkErrorNotRecoverable
public static boolean isBkErrorNotRecoverable(int rc)
return BK error codes that are considered not likely to be recoverable.
-
getPendingReadOpsCount
public int getPendingReadOpsCount()
-
getMessagesConsumedCounter
public long getMessagesConsumedCounter()
-
getCursorLedger
public long getCursorLedger()
-
getCursorLedgerLastEntry
public long getCursorLedgerLastEntry()
-
getIndividuallyDeletedMessages
public java.lang.String getIndividuallyDeletedMessages()
-
getIndividuallyDeletedMessagesSet
public org.apache.pulsar.common.util.collections.LongPairRangeSet<PositionImpl> getIndividuallyDeletedMessagesSet()
-
isMessageDeleted
public boolean isMessageDeleted(Position position)
-
getBatchPositionAckSet
public long[] getBatchPositionAckSet(Position position)
-
getNextAvailablePosition
public PositionImpl getNextAvailablePosition(PositionImpl position)
Checks given position is part of deleted-range and returns next position of upper-end as all the messages are deleted up to that point.- Parameters:
position-- Returns:
- next available position
-
getNextLedgerPosition
public Position getNextLedgerPosition(long currentLedgerId)
-
isIndividuallyDeletedEntriesEmpty
public boolean isIndividuallyDeletedEntriesEmpty()
-
getLastLedgerSwitchTimestamp
public long getLastLedgerSwitchTimestamp()
-
getState
public java.lang.String getState()
-
getThrottleMarkDelete
public double getThrottleMarkDelete()
Description copied from interface:ManagedCursorReturns cursor throttle mark-delete rate.- Specified by:
getThrottleMarkDeletein interfaceManagedCursor- Returns:
-
setThrottleMarkDelete
public void setThrottleMarkDelete(double throttleMarkDelete)
Description copied from interface:ManagedCursorUpdate throttle mark delete rate.- Specified by:
setThrottleMarkDeletein interfaceManagedCursor
-
getManagedLedger
public ManagedLedger getManagedLedger()
Description copied from interface:ManagedCursorGetManagedLedgerattached with cursor- Specified by:
getManagedLedgerin interfaceManagedCursor- Returns:
- ManagedLedger
-
getLastIndividualDeletedRange
public com.google.common.collect.Range<PositionImpl> getLastIndividualDeletedRange()
Description copied from interface:ManagedCursorGet last individual deleted range- Specified by:
getLastIndividualDeletedRangein interfaceManagedCursor- Returns:
- range
-
trimDeletedEntries
public void trimDeletedEntries(java.util.List<Entry> entries)
Description copied from interface:ManagedCursorTrim delete entries for the given entries- Specified by:
trimDeletedEntriesin interfaceManagedCursor
-
getDeletedBatchIndexesAsLongArray
public long[] getDeletedBatchIndexesAsLongArray(PositionImpl position)
Description copied from interface:ManagedCursorGet deleted batch indexes list for a batch message.- Specified by:
getDeletedBatchIndexesAsLongArrayin interfaceManagedCursor
-
getStats
public ManagedCursorMXBean getStats()
- Specified by:
getStatsin interfaceManagedCursor- Returns:
- the managed cursor stats MBean
-
checkAndUpdateReadPositionChanged
public boolean checkAndUpdateReadPositionChanged()
Description copied from interface:ManagedCursorChecks if read position changed since this method was called last time.- Specified by:
checkAndUpdateReadPositionChangedin interfaceManagedCursor- Returns:
- if read position changed
-
-