Class ManagedCursorContainer
- java.lang.Object
-
- org.apache.bookkeeper.mledger.impl.ManagedCursorContainer
-
- All Implemented Interfaces:
java.lang.Iterable<ManagedCursor>
public class ManagedCursorContainer extends java.lang.Object implements java.lang.Iterable<ManagedCursor>
Contains all the cursors for a ManagedLedger. The goal is to always know the slowest consumer and hence decide which is the oldest ledger we need to keep. This data structure maintains a list and a map of cursors. The map is used to relate a cursor name with an entry in the linked-list. The list is a sorted double linked-list of cursors. When a cursor is markDeleted, this list is updated and the cursor is moved in its new position. To minimize the moving around, the order is maintained using the ledgerId, but not the entryId, since we only care about ledgers to be deleted.
-
-
Constructor Summary
Constructors Constructor Description ManagedCursorContainer()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(ManagedCursor cursor)org.apache.commons.lang3.tuple.Pair<PositionImpl,PositionImpl>cursorUpdated(ManagedCursor cursor, Position newPosition)Signal that a cursor position has been updated and that the container must re-order the cursor list.ManagedCursorget(java.lang.String name)ManagedCursorgetSlowestReader()PositionImplgetSlowestReaderPosition()Get the slowest reader position, meaning older acknowledged position between all the cursors.booleanhasDurableCursors()Check whether that are any durable cursorsbooleanisEmpty()Check whether there are any cursorsjava.util.Iterator<ManagedCursor>iterator()voidremoveCursor(java.lang.String name)java.lang.StringtoString()
-
-
-
Method Detail
-
add
public void add(ManagedCursor cursor)
-
get
public ManagedCursor get(java.lang.String name)
-
removeCursor
public void removeCursor(java.lang.String name)
-
cursorUpdated
public org.apache.commons.lang3.tuple.Pair<PositionImpl,PositionImpl> cursorUpdated(ManagedCursor cursor, Position newPosition)
Signal that a cursor position has been updated and that the container must re-order the cursor list.- Parameters:
cursor-- Returns:
- a pair of positions, representing the previous slowest consumer and the new slowest consumer (after the update).
-
getSlowestReaderPosition
public PositionImpl getSlowestReaderPosition()
Get the slowest reader position, meaning older acknowledged position between all the cursors.- Returns:
- the slowest reader position
-
getSlowestReader
public ManagedCursor getSlowestReader()
-
isEmpty
public boolean isEmpty()
Check whether there are any cursors- Returns:
- true is there are no cursors and false if there are
-
hasDurableCursors
public boolean hasDurableCursors()
Check whether that are any durable cursors- Returns:
- true if there are durable cursors and false if there are not
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
iterator
public java.util.Iterator<ManagedCursor> iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<ManagedCursor>
-
-