Package io.fluxcapacitor.common.tracking
Class TrackerCluster
java.lang.Object
io.fluxcapacitor.common.tracking.TrackerCluster
Represents the current set of
Tracker
s 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 Summary
FieldsModifier and TypeFieldDescriptionstatic final int[]
Shared constant representing an empty segment range. -
Constructor Summary
ConstructorsConstructorDescriptionTrackerCluster
(int segments) Creates a new, empty cluster with the given number of segments. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Checks if the tracker is part of this cluster.getProcessingDuration
(Tracker tracker) Returns how long the given tracker has been active.int[]
getSegment
(Tracker tracker) Returns the segment range assigned to the tracker.Returns an unmodifiable view of the current set of trackers.boolean
Checks if the tracker is currently marked as active.boolean
isEmpty()
Returns true if no trackers are currently registered.purgeCeasedTrackers
(Instant threshold) Removes trackers that have not sent activity after the given timestamp.purgeTrackers
(Predicate<Tracker> predicate) Removes all trackers that match the provided predicate.withActiveTracker
(Tracker tracker) Marks the given tracker as actively processing messages.withoutTracker
(Tracker tracker) Removes the tracker from the cluster.withWaitingTracker
(Tracker tracker) Adds or updates the tracker as waiting (not currently processing).
-
Field Details
-
emptyRange
public static final int[] emptyRangeShared 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
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
Adds or updates the tracker as waiting (not currently processing).- Parameters:
tracker
- tracker to register- Returns:
- new updated cluster instance
-
withoutTracker
Removes the tracker from the cluster.- Parameters:
tracker
- tracker to remove- Returns:
- new updated cluster instance
-
purgeTrackers
Removes all trackers that match the provided predicate.- Parameters:
predicate
- filter to determine which trackers to remove- Returns:
- new updated cluster instance
-
purgeCeasedTrackers
Removes trackers that have not sent activity after the given timestamp.- Parameters:
threshold
- timestamp threshold for inactivity- Returns:
- new updated cluster instance
-
getProcessingDuration
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
Returns the segment range assigned to the tracker.- Parameters:
tracker
- tracker to query- Returns:
- assigned segment range or null if unassigned
-
contains
Checks if the tracker is part of this cluster. -
isActive
Checks if the tracker is currently marked as active. I.e., if it is currently processing a batch of messages. -
getTrackers
Returns an unmodifiable view of the current set of trackers. -
isEmpty
public boolean isEmpty()Returns true if no trackers are currently registered.
-