shashank created CAMEL-26742:
--------------------------------
Summary: camel-core - on completion listener SPI for the exchange
sanitizer
Key: CAMEL-26742
URL: https://issues.apache.org/jira/browse/CAMEL-26742
Project: Camel
Issue Type: Improvement
Components: camel-core
Reporter: shashank
Assignee: shashank
Step 3 of the order of work in the exchange sanitizer design
({{design/exchange-sanitizer.adoc}}, CAMEL-26630), first part: the SPI that
rule R2 (each consumer commit runs exactly once, for the unit of work that owns
it) needs. R2 itself comes in the next step.
As in the design ("The listener SPIs", "Where they are called"):
* A new SPI {{org.apache.camel.spi.OnCompletionListener}} in camel-api, with
empty default methods: {{onUnitOfWork}} (an exchange gets a unit of work, with
the on completions that move into it), {{onCompletionAdded}},
{{onCompletionHandover}}, {{onCompletionTaken}} and {{onCompletionRun}}, plus
{{onCompletionRemoved}} (a commit removed with
{{UnitOfWork.removeSynchronization}} does not run, so R2 must see the removal).
A listener only observes; what it throws is caught and logged at WARN once per
listener.
* {{ExtendedCamelContext}}: {{addOnCompletionListener}},
{{removeOnCompletionListener}}, {{getOnCompletionListeners}} (default methods),
next to the step listener methods of CAMEL-26688.
* {{UnitOfWork}}: a new default method {{handoverSynchronization(Exchange from,
Exchange target, Predicate<Synchronization> filter)}} that hands over and
returns what moved, as only {{DefaultUnitOfWork}} knows which on completions a
{{SynchronizationVetoable}} kept. The default hands over as today and returns
{{null}} (not known), so a custom unit of work keeps working.
* The calls, where Camel changes or runs on completions today:
{{setUnitOfWork}} and {{handoverCompletions}} of the exchange,
{{DefaultUnitOfWork.addSynchronization}} and {{removeSynchronization}}, and
{{UnitOfWorkHelper.doneSynchronizations}}.
With no listener installed each place only checks that the list of listeners is
empty and goes on as today. The design asks for a JMH run that shows no cost
without a listener.
_Filed with Claude Code on behalf of allthingssecurity._
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)