Interface TrackingStrategy
- All Superinterfaces:
AutoCloseable, Closeable
- All Known Implementing Classes:
DefaultTrackingStrategy
TrackingStrategy defines how a Tracker consumes messages from a message log or distributed segment
space.
This interface enables pluggable strategies for message consumption and parallelism. Depending on the configuration and type of tracker, a strategy may either:
- Fetch and supply message batches directly from the message store (tailing a log), or
- Negotiate segment claims and delegate message retrieval to the tracker itself (client-side tracking).
Tracking strategies are a key part of Fluxzero's support for distributed, fault-tolerant, and parallel message handling.
Responsibilities
ATrackingStrategy is responsible for:
- Providing the next batch of messages for a
Tracker(viagetBatch(Tracker, PositionStore)) - Assigning ownership of message segments (via
claimSegment(Tracker, PositionStore)) - Disconnecting active trackers when needed (via
disconnectTrackers(Predicate, boolean))
Implementations should be thread-safe and able to handle dynamic tracker registration and segment rebalancing.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclaimSegment(Tracker tracker, PositionStore positionStore) Claims one or more message segments for the given tracker.voidclose()Closes the tracking strategy and releases any underlying resources.disconnectTrackers(Predicate<Tracker> predicate, boolean sendFinalBatch) Disconnects trackers that match the provided filter.voidgetBatch(Tracker tracker, PositionStore positionStore) Requests a new batch of messages for the given tracker.
-
Method Details
-
getBatch
Requests a new batch of messages for the given tracker.This method is typically invoked by the
Trackerwhen it is ready to handle more messages. Depending on the strategy, this method may:- Fetch messages directly from a
MessageStoreand deliver them to the tracker (e.g. for log tailing), or - Suspend the tracker until messages become available
- Parameters:
tracker- the tracker requesting a batchpositionStore- to fetch or update tracking positions
- Fetch messages directly from a
-
claimSegment
Claims one or more message segments for the given tracker.This method is invoked when segment-based partitioning is enabled. It ensures that each segment is only claimed by a single tracker at a time and may release conflicting claims if necessary.
- Parameters:
tracker- the tracker attempting to claim a segmentpositionStore- to fetch tracking positions
-
disconnectTrackers
Disconnects trackers that match the provided filter.This is typically used during client shutdown, reconfiguration, or error handling to forcibly remove trackers from the strategy's internal registry.
- Parameters:
predicate- filter for matching trackers to disconnectsendFinalBatch- iftrue, a final empty batch should be sent to each disconnected tracker to allow graceful termination- Returns:
- the trackers that were disconnected (empty if no trackers matched the filter)
-
close
void close()Closes the tracking strategy and releases any underlying resources.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-