Class Position

java.lang.Object
io.fluxzero.common.api.tracking.Position

public class Position extends Object
Represents the tracking state of a consumer, i.e. the last known indexes of consumed messages per segment.

Fluxzero segments the message log to support parallel consumption. A Position stores the most recent message index processed for each segment. This allows precise resumption of message consumption on restarts or rebalances.

A Position is an immutable structure and may be merged or queried to support multi-segment tracking.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Position(int[] segment, long lastIndex)
    Creates a position for a single segment range.
    Position(long index)
    Creates a position that applies the same index to all segments.
    Position(SegmentRange segmentRange)
    Creates a position for a single segment range.
    Position(List<SegmentRange> segmentRanges)
    Creates a position from a list of segment ranges.
  • Method Summary

    Modifier and Type
    Method
    Description
    getIndex(int segment)
    Returns the last known index for a specific segment.
    boolean
    isNew(int[] segment)
    Indicates whether no index has been tracked yet for any segment in the given range.
    boolean
    isNewIndex(int segment, Long messageIndex)
    Indicates whether the provided message index is newer than what is currently tracked for a segment.
    boolean
    Indicates whether the message index is newer than what is currently tracked for its segment.
    lowestIndexForSegment(int[] segment)
    Returns the lowest tracked index within the given segment range.
    merge(Position other)
    Merges two Position objects by taking the highest known index per segment.
    static Position
    Creates an empty position.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Position

      public Position(List<SegmentRange> segmentRanges)
      Creates a position from a list of segment ranges.
      Parameters:
      segmentRanges - a list of segment ranges, this list is expected to be sorted by segment start, segments are expected to not overlap.
    • Position

      public Position(long index)
      Creates a position that applies the same index to all segments.
    • Position

      public Position(int[] segment, long lastIndex)
      Creates a position for a single segment range.
    • Position

      public Position(SegmentRange segmentRange)
      Creates a position for a single segment range.
  • Method Details

    • newPosition

      public static Position newPosition()
      Creates an empty position.
    • getIndex

      public Optional<Long> getIndex(int segment)
      Returns the last known index for a specific segment.
    • isNew

      public boolean isNew(int[] segment)
      Indicates whether no index has been tracked yet for any segment in the given range.
    • lowestIndexForSegment

      public Optional<Long> lowestIndexForSegment(int[] segment)
      Returns the lowest tracked index within the given segment range.
    • isNewMessage

      public boolean isNewMessage(SerializedMessage message)
      Indicates whether the message index is newer than what is currently tracked for its segment.
    • isNewIndex

      public boolean isNewIndex(int segment, Long messageIndex)
      Indicates whether the provided message index is newer than what is currently tracked for a segment.
    • merge

      public Position merge(Position other)
      Merges two Position objects by taking the highest known index per segment.