Class DefaultTrackingStrategy
- All Implemented Interfaces:
TrackingStrategy
,Closeable
,AutoCloseable
Message segments are determined by the clients that publish the messages (usually based on the consistent hash of some routing key, like the value of a user id).
If a client joins or leaves the cluster the segment range mapped to each client is recalculated so messages may get routed differently than before.
Clients can safely join or leave the cluster at any time. The strategy guarantees that a message is not consumed by more than one client.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsModifierConstructorDescriptionDefaultTrackingStrategy
(MessageStore source) DefaultTrackingStrategy
(MessageStore source, TaskScheduler scheduler) protected
DefaultTrackingStrategy
(MessageStore source, TaskScheduler scheduler, int segments) -
Method Summary
Modifier and TypeMethodDescriptionprotected int
adjustMaxSize
(Tracker tracker, int maxSize) protected int[]
claimSegment
(Tracker tracker) void
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 sendFinalEmptyBatch) Disconnects trackers that match the provided filter.protected SerializedMessage
ensureMessageSegment
(SerializedMessage message) protected List
<SerializedMessage> filter
(List<SerializedMessage> messages, int[] segmentRange, Position position, Tracker tracker) protected List
<SerializedMessage> void
getBatch
(Tracker tracker, PositionStore positionStore) Requests a new batch of messages for the given tracker.protected void
onClusterUpdate
(TrackerCluster cluster) protected void
onUpdate
(List<SerializedMessage> messages) protected Position
position
(Tracker tracker, PositionStore positionStore, int[] segment) protected void
purgeCeasedTrackers
(Duration delay) protected void
waitForMessages
(Tracker tracker, MessageBatch emptyBatch, PositionStore positionStore) protected void
waitForUpdate
(Tracker tracker, MessageBatch emptyBatch, Runnable followUp)
-
Constructor Details
-
DefaultTrackingStrategy
-
DefaultTrackingStrategy
-
DefaultTrackingStrategy
-
-
Method Details
-
getBatch
Description copied from interface:TrackingStrategy
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
- Specified by:
getBatch
in interfaceTrackingStrategy
- Parameters:
tracker
- the tracker requesting a batchpositionStore
- to fetch or update tracking positions
- Fetch messages directly from a
-
claimSegment
Description copied from interface:TrackingStrategy
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.
- Specified by:
claimSegment
in interfaceTrackingStrategy
- Parameters:
tracker
- the tracker attempting to claim a segmentpositionStore
- to fetch tracking positions
-
getBatch
-
waitForMessages
protected void waitForMessages(Tracker tracker, MessageBatch emptyBatch, PositionStore positionStore) -
waitForUpdate
-
position
-
filter
protected List<SerializedMessage> filter(List<SerializedMessage> messages, int[] segmentRange, Position position, Tracker tracker) -
ensureMessageSegment
-
adjustMaxSize
-
claimSegment
-
onUpdate
-
onClusterUpdate
-
disconnectTrackers
Description copied from interface:TrackingStrategy
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.
- Specified by:
disconnectTrackers
in interfaceTrackingStrategy
- Parameters:
predicate
- filter for matching trackers to disconnectsendFinalEmptyBatch
- iftrue
, a final empty batch should be sent to each disconnected tracker to allow graceful termination
-
purgeCeasedTrackers
-
close
public void close()Description copied from interface:TrackingStrategy
Closes the tracking strategy and releases any underlying resources.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceTrackingStrategy
-