Class ManagedCursorContainer

java.lang.Object
org.apache.bookkeeper.mledger.impl.ManagedCursorContainer
All Implemented Interfaces:
Iterable<ManagedCursor>

public class ManagedCursorContainer extends Object implements 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 Details

    • ManagedCursorContainer

      public ManagedCursorContainer()
  • Method Details

    • add

      public void add(ManagedCursor cursor, Position position)
      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 with cursorUpdated(ManagedCursor, Position) method when the position changes.
      Parameters:
      cursor - cursor to add
      position - position of the cursor to use for ordering, pass null if the cursor's position shouldn't be tracked for the slowest reader.
    • get

      public ManagedCursor get(String name)
    • removeCursor

      public boolean removeCursor(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 heap tracking the slowest reader. Only those cursors are tracked and can be updated which were added to the container with the add(ManagedCursor, Position) method that specified the initial position in the position parameter.
      Parameters:
      cursor - the cursor to update the position for
      newPosition - 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

      public PositionImpl getSlowestReaderPosition()
      Get the slowest reader position for the cursors that are ordered.
      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 String toString()
      Overrides:
      toString in class Object
    • iterator

      public Iterator<ManagedCursor> iterator()
      Specified by:
      iterator in interface Iterable<ManagedCursor>