Skip to content

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

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

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

@abuijze abuijze commented May 29, 2026

Copy link
Copy Markdown
Contributor

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

abuijze commented Jun 1, 2026

Copy link
Copy Markdown
Contributor Author

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

@smcvb smcvb added Type: Feature Use to signal an issue is completely new to the project. Priority 2: Should High priority. Ideally, these issues are part of the release they’re assigned to. labels Jun 17, 2026
@smcvb smcvb added this to the Release 5.2.0 milestone Jun 17, 2026
@abuijze abuijze closed this Jun 19, 2026
@abuijze abuijze deleted the feature/event-handler-safe-points branch June 19, 2026 11:55
@smcvb smcvb added the Status: Obsolete Use to signal this issue is no longer necessary. label Jun 19, 2026
@smcvb smcvb removed this from the Release 5.2.0 milestone Jun 19, 2026
@smcvb

smcvb commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Marked as obsolete due to #4636.

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

Labels

Priority 2: Should High priority. Ideally, these issues are part of the release they’re assigned to. Status: Obsolete Use to signal this issue is no longer necessary. Type: Feature Use to signal an issue is completely new to the project.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants