Class ManagedCursorContainer
java.lang.Object
org.apache.bookkeeper.mledger.impl.ManagedCursorContainer
- All Implemented Interfaces:
Iterable<ManagedCursor>
Contains 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 heap and a map of cursors. The map is used to relate a cursor name with
an entry index in the heap. The heap data structure sorts cursors in a binary tree which is represented
in a single array. More details about heap implementations:
https://en.wikipedia.org/wiki/Heap_(data_structure)#Implementation
The heap is updated and kept sorted when a cursor is updated.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(ManagedCursor cursor, Position position) Add a cursor to the container.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 heap tracking the slowest reader.Get the slowest reader position for the cursors that are ordered.booleanCheck whether that are any durable cursors.booleanisEmpty()Check whether there are any cursors.iterator()booleanremoveCursor(String name) toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
ManagedCursorContainer
public ManagedCursorContainer()
-
-
Method Details
-
add
Add a cursor to the container. The cursor will be optionally tracked for the slowest reader when a position is passed as the second argument. It is expected that the position is updated withcursorUpdated(ManagedCursor, Position)method when the position changes.- Parameters:
cursor- cursor to addposition- position of the cursor to use for ordering, pass null if the cursor's position shouldn't be tracked for the slowest reader.
-
get
-
removeCursor
-
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 heap tracking the slowest reader. Only those cursors are tracked and can be updated which were added to the container with theadd(ManagedCursor, Position)method that specified the initial position in the position parameter.- Parameters:
cursor- the cursor to update the position fornewPosition- the updated position for the cursor- Returns:
- a pair of positions, representing the previous slowest reader and the new slowest reader (after the update).
-
getSlowestReaderPosition
Get the slowest reader position for the cursors that are ordered.- Returns:
- the slowest reader position
-
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
-
iterator
- Specified by:
iteratorin interfaceIterable<ManagedCursor>
-