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 Flux'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(io.fluxcapacitor.common.tracking.Tracker, io.fluxcapacitor.common.tracking.PositionStore)
) - Assigning ownership of message segments (via
claimSegment(io.fluxcapacitor.common.tracking.Tracker, io.fluxcapacitor.common.tracking.PositionStore)
) - Disconnecting active trackers when needed (via
disconnectTrackers(java.util.function.Predicate<io.fluxcapacitor.common.tracking.Tracker>, boolean)
)
Implementations should be thread-safe and able to handle dynamic tracker registration and segment rebalancing.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
claimSegment
(Tracker tracker, PositionStore positionStore) Claims one or more message segments for the given tracker.void
close()
Closes the tracking strategy and releases any underlying resources.void
disconnectTrackers
(Predicate<Tracker> predicate, boolean sendFinalBatch) Disconnects trackers that match the provided filter.void
getBatch
(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
Tracker
when it is ready to handle more messages. Depending on the strategy, this method may:- Fetch messages directly from a
MessageStore
and 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
-
close
void close()Closes the tracking strategy and releases any underlying resources.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-