Class TrackerCluster

java.lang.Object
io.fluxcapacitor.common.tracking.TrackerCluster

public class TrackerCluster extends Object
Represents the current set of Trackers that are connected for a specific consumer.

A TrackerCluster tracks which segments of the message log are assigned to which tracker, as well as which trackers are actively processing messages. It is used during tracking strategy evaluation to balance work across multiple clients or threads.

This class is immutable. Methods that alter the state (e.g., withActiveTracker, withoutTracker) return a new updated instance.

  • Field Details

    • emptyRange

      public static final int[] emptyRange
      Shared constant representing an empty segment range.
  • Constructor Details

    • TrackerCluster

      public TrackerCluster(int segments)
      Creates a new, empty cluster with the given number of segments.
      Parameters:
      segments - number of total segments to divide among trackers
  • Method Details

    • withActiveTracker

      public TrackerCluster withActiveTracker(Tracker tracker)
      Marks the given tracker as actively processing messages. If the tracker is not currently in the cluster, it is first added.
      Parameters:
      tracker - tracker to mark as active
      Returns:
      new updated cluster instance
    • withWaitingTracker

      public TrackerCluster withWaitingTracker(Tracker tracker)
      Adds or updates the tracker as waiting (not currently processing).
      Parameters:
      tracker - tracker to register
      Returns:
      new updated cluster instance
    • withoutTracker

      public TrackerCluster withoutTracker(Tracker tracker)
      Removes the tracker from the cluster.
      Parameters:
      tracker - tracker to remove
      Returns:
      new updated cluster instance
    • purgeTrackers

      public TrackerCluster purgeTrackers(Predicate<Tracker> predicate)
      Removes all trackers that match the provided predicate.
      Parameters:
      predicate - filter to determine which trackers to remove
      Returns:
      new updated cluster instance
    • purgeCeasedTrackers

      public TrackerCluster purgeCeasedTrackers(Instant threshold)
      Removes trackers that have not sent activity after the given timestamp.
      Parameters:
      threshold - timestamp threshold for inactivity
      Returns:
      new updated cluster instance
    • getProcessingDuration

      public Optional<Duration> getProcessingDuration(Tracker tracker)
      Returns how long the given tracker has been active.
      Parameters:
      tracker - tracker whose processing duration to retrieve
      Returns:
      duration since the tracker became active, if available
    • getSegment

      public int[] getSegment(Tracker tracker)
      Returns the segment range assigned to the tracker.
      Parameters:
      tracker - tracker to query
      Returns:
      assigned segment range or null if unassigned
    • contains

      public boolean contains(Tracker tracker)
      Checks if the tracker is part of this cluster.
    • isActive

      public boolean isActive(Tracker tracker)
      Checks if the tracker is currently marked as active. I.e., if it is currently processing a batch of messages.
    • getTrackers

      public Set<Tracker> getTrackers()
      Returns an unmodifiable view of the current set of trackers.
    • isEmpty

      public boolean isEmpty()
      Returns true if no trackers are currently registered.