Skip to content

Allow a segment claim to trigger an ad-hoc replay#4620

Draft
abuijze wants to merge 1 commit into
mainfrom
feature/event-handler-safe-points
Draft

Allow a segment claim to trigger an ad-hoc replay#4620
abuijze wants to merge 1 commit into
mainfrom
feature/event-handler-safe-points

Conversation

@abuijze
Copy link
Copy Markdown
Contributor

@abuijze abuijze commented May 29, 2026

Summary

Adds two building blocks to the pooled streaming event processor so that a component can request an ad-hoc replay of a single segment at the moment it is claimed.

Segment claim can return a reset position

SegmentChangeListener#onSegmentClaimed now returns a TrackingToken — the position the segment should be reset to. When that token is strictly behind the segment's stored token, the Coordinator wraps the stored token in a ReplayToken, so the segment streams from the returned position instead of the stored one. Returning null leaves the stored position untouched.

  • On a first-ever claim (stored token is null) the returned position is ignored — a reset is only meaningful relative to a position the processor has already moved past. The listener is still invoked for any side effects.
  • Positions returned by composed (andThen) listeners are merged via TrackingToken#lowerBound, so the chain requests the lowest position any constituent requires.
  • SegmentChangeListener#onClaimWithReset(...) is added for listeners that supply such a position.

Handler-aware processor customization

HandlerAwareProcessorCustomization is a new hook invoked when a PooledStreamingEventProcessor is built, with access to the resolved EventHandlingComponent list. This lets processor configuration (such as registering a SegmentChangeListener) be derived from the handlers assigned to that processor. PooledStreamingEventProcessorModule discovers these customizations from the root configuration, so where they are registered does not matter.

Testing

./mvnw -pl messaging test -Dtest='SegmentChangeListenerTest,HandlerAwareProcessorCustomizationTest,CoordinatorTest' — 40 tests, all green.

Extend SegmentChangeListener#onSegmentClaimed to return a TrackingToken
on segment claim, the segment's reset position. When the returned token
is strictly behind the segment's stored token, the Coordinator wraps the
stored token in a ReplayToken so the segment streams from the reset
position instead of the stored one. Returning null leaves the stored
position untouched. On a first-ever claim (stored token null) the
returned token is ignored, as a reset is only meaningful relative to a
position the processor has already moved past.

Reset positions returned by composed listeners are merged via
TrackingToken#lowerBound, yielding the lowest position required by any
constituent. Add SegmentChangeListener#onClaimWithReset for listeners
that supply such a position.

Introduce HandlerAwareProcessorCustomization: a customization hook
invoked when a PooledStreamingEventProcessor is built, with access to
the resolved EventHandlingComponent list, allowing processor
configuration to be derived from the handlers themselves.
PooledStreamingEventProcessorModule discovers these customizations from
the root configuration so registration location is irrelevant.
@abuijze abuijze requested a review from a team as a code owner May 29, 2026 12:01
@abuijze abuijze requested review from MateuszNaKodach, hjohn and zambrovski and removed request for a team May 29, 2026 12:01
@sonarqubecloud
Copy link
Copy Markdown

@abuijze abuijze marked this pull request as draft June 1, 2026 21:11
@abuijze
Copy link
Copy Markdown
Contributor Author

abuijze commented Jun 1, 2026

Converted back to draft. John had some questions and suggestions that gave me another idea. Working on that one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant