Interface SegmentProgressStrategy
- All Known Implementing Classes:
CheckpointingProgressStrategy,TokenStoringProgressStrategy
Decides how a single
Segment's progress is persisted as its events are processed. One instance exists per
segment; it is invoked around every batch and on claim/release, while the SegmentProgressContext performs the
actual store.
The default TokenStoringProgressStrategy persists the batch-end token every batch. A strategy may instead
defer persistence and advance the stored token only on its own signal (for example, self-checkpointing), reconciling
several participants to a single safe position before persisting.
Internal API. This interface is marked Internal: it is the extension point through which advanced (and
out-of-module) progress handling is provided, not stable end-user API, and its shape may change in a minor or patch
release.
- Since:
- 5.3.0
- Author:
- Allard Buijze
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidContributes per-batch resources tocontextbefore the batch is handled, for example a handle a handler may use to influence persistence (such as a checkpoint trigger).booleanIndicates whether the strategy has out-of-band work that requires a worker cycle even when no events are queued (for example, an asynchronous checkpoint request recorded between cycles).default voidonAbort()Invoked when processing of the segment aborts, so the strategy can deactivate any out-of-band signal (for example, render a checkpoint trigger inert so a late request becomes a no-op).onBatchCommit(ProcessingContext context) Decides the safeTrackingTokenfor the current cycle and persists it throughSegmentProgressContext.persistProgress(TrackingToken, ProcessingContext), withincontext.default voidInvoked when the segment is claimed, before any events are handled.default CompletableFuture<Void> onSegmentReleased(ProcessingContext context) Performs the final progress persistence as the segment is released: decides the safe token and persists it throughSegmentProgressContext.persistProgress(TrackingToken, ProcessingContext)withincontext, while the token-store claim is still held.
-
Method Details
-
contributeBatchResources
Contributes per-batch resources tocontextbefore the batch is handled, for example a handle a handler may use to influence persistence (such as a checkpoint trigger). Invoked only for non-empty batches, before invocation. Defaults to a no-op.- Parameters:
context- the processing context of the batch about to be handled
-
onBatchCommit
Decides the safeTrackingTokenfor the current cycle and persists it throughSegmentProgressContext.persistProgress(TrackingToken, ProcessingContext), withincontext. Invoked on the commit of a non-empty batch (so the store commits atomically with the batch), and on an idle cycle to store progress that advanced without a handled batch. May store nothing (for example, when nothing advanced or no persistence is due yet).- Parameters:
context- the processing context whose transaction the store participates in- Returns:
- a
CompletableFuturecompleting when the cycle's persistence (if any) has been applied
-
hasPendingWork
boolean hasPendingWork()Indicates whether the strategy has out-of-band work that requires a worker cycle even when no events are queued (for example, an asynchronous checkpoint request recorded between cycles). Drives the post-cycle reschedule and lets an idle segment run a commit cycle. Strategies that act only within their batches never schedule out-of-band and returnfalse; this is deliberately not a throttle for idle catch-up stores, which are driven on the claim-extension beat.- Returns:
trueif a worker cycle is needed for out-of-band work,falseotherwise
-
onSegmentClaimed
default void onSegmentClaimed()Invoked when the segment is claimed, before any events are handled. Defaults to a no-op. -
onSegmentReleased
Performs the final progress persistence as the segment is released: decides the safe token and persists it throughSegmentProgressContext.persistProgress(TrackingToken, ProcessingContext)withincontext, while the token-store claim is still held. Defaults to a no-op (the per-batch persistence already covered progress).- Parameters:
context- the processing context whose transaction the final store participates in- Returns:
- a
CompletableFuturecompleting when the final persistence (if any) has been applied
-
onAbort
default void onAbort()Invoked when processing of the segment aborts, so the strategy can deactivate any out-of-band signal (for example, render a checkpoint trigger inert so a late request becomes a no-op). Defaults to a no-op.
-