All Known Implementing Classes:
CheckpointingProgressStrategy, TokenStoringProgressStrategy

@Internal public interface SegmentProgressStrategy
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 Details

    • contributeBatchResources

      default void contributeBatchResources(ProcessingContext context)
      Contributes per-batch resources to context before 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

      CompletableFuture<Void> onBatchCommit(ProcessingContext context)
      Decides the safe TrackingToken for the current cycle and persists it through SegmentProgressContext.persistProgress(TrackingToken, ProcessingContext), within context. 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 CompletableFuture completing 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 return false; this is deliberately not a throttle for idle catch-up stores, which are driven on the claim-extension beat.
      Returns:
      true if a worker cycle is needed for out-of-band work, false otherwise
    • onSegmentClaimed

      default void onSegmentClaimed()
      Invoked when the segment is claimed, before any events are handled. Defaults to a no-op.
    • onSegmentReleased

      default CompletableFuture<Void> onSegmentReleased(ProcessingContext context)
      Performs the final progress persistence as the segment is released: decides the safe token and persists it through SegmentProgressContext.persistProgress(TrackingToken, ProcessingContext) within context, 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 CompletableFuture completing 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.