Package io.fluxcapacitor.common.tracking
Class DefaultTrackingStrategy
java.lang.Object
io.fluxcapacitor.common.tracking.DefaultTrackingStrategy
- All Implemented Interfaces:
TrackingStrategy,Closeable,AutoCloseable
Streaming strategy that allows multiple clients to concurrently consume a message stream. Messages are routed to
clients based on the value of their segment. Each connected client handles a distinct range of segments.
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) protectedDefaultTrackingStrategy(MessageStore source, TaskScheduler scheduler, int segments) -
Method Summary
Modifier and TypeMethodDescriptionprotected intadjustMaxSize(Tracker tracker, int maxSize) protected int[]claimSegment(Tracker tracker) voidclaimSegment(Tracker tracker, PositionStore positionStore) voidclose()voiddisconnectTrackers(Predicate<Tracker> predicate, boolean sendFinalEmptyBatch) protected SerializedMessageensureMessageSegment(SerializedMessage message) protected List<SerializedMessage> filter(List<SerializedMessage> messages, int[] segmentRange, Position position, Tracker tracker) protected List<SerializedMessage> voidgetBatch(Tracker tracker, PositionStore positionStore) protected voidonClusterUpdate(TrackerCluster cluster) protected voidonUpdate(List<SerializedMessage> messages) protected Positionposition(Tracker tracker, PositionStore positionStore, int[] segment) protected voidpurgeCeasedTrackers(Duration delay) protected voidwaitForMessages(Tracker tracker, MessageBatch emptyBatch, PositionStore positionStore) protected voidwaitForUpdate(Tracker tracker, MessageBatch emptyBatch, Runnable followUp)
-
Constructor Details
-
DefaultTrackingStrategy
-
DefaultTrackingStrategy
-
DefaultTrackingStrategy
-
-
Method Details
-
getBatch
- Specified by:
getBatchin interfaceTrackingStrategy
-
claimSegment
- Specified by:
claimSegmentin interfaceTrackingStrategy
-
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
- Specified by:
disconnectTrackersin interfaceTrackingStrategy
-
purgeCeasedTrackers
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceTrackingStrategy
-