lobtx opened a new pull request, #30303:
URL: https://github.com/apache/camel/pull/30303

   # Description
   
   Fixes [CAMEL-27103](https://issues.apache.org/jira/browse/CAMEL-27103), 
found during the review of #30261.
   
   ## Problem
   
   `camel.main.typeConverterStatisticsEnabled=true` has no effect: 
`CamelContext.isTypeConverterStatisticsEnabled()` returns true, but the type 
converter registry keeps the noop statistics and the counters stay at 0.
   
   The registry picks its statistics (counting or noop) once, in the 
`CoreTypeConverterRegistry` constructor, and the context creates it when it is 
built (`eagerCreateTypeConverter()`). Camel Main calls `camelContext.build()` 
in `BaseMainSupport.postProcessCamelContext` and only later applies the option 
in `DefaultConfigurationConfigurer`, so it comes too late.
   
   ## Reproduction
   
   `MainTypeConverterStatisticsEnabledTest` fails on main with `expected: <1> 
but was: <0>`:
   
       Main main = new Main();
       main.addInitialProperty("camel.main.typeConverterStatisticsEnabled", 
"true");
       main.start();
       CamelContext context = main.getCamelContext();
       assertTrue(context.isTypeConverterStatisticsEnabled());
       assertEquals(123, context.getTypeConverter().convertTo(int.class, 
"123"));
       assertEquals(1, 
context.getTypeConverterRegistry().getStatistics().getAttemptCounter());
   
   The same happens with plain Java on a built context (`new 
DefaultCamelContext()` then `setTypeConverterStatisticsEnabled(true)`), and 
disabling it afterwards does not work either: 
`TypeConverterRegistryStatisticsEnabledAfterBuildTest`.
   
   ## Why it needs a fix
   
   The option is documented for Camel Main 
(`camel.main.typeConverterStatisticsEnabled`) and in the type converter page of 
the user manual, but in Camel Main it silently does nothing. Any runtime that 
configures the context after building it has the same problem.
   
   ## Fix
   
   - `CoreTypeConverterRegistry`: the statistics can be switched after the 
registry is created (`setStatisticsEnabled`); the counters start again from 
zero when the option changes. The field is now `volatile`, as it can be changed 
after the registry is in use.
   - `SimpleCamelContext#setTypeConverterStatisticsEnabled`: passes the option 
on to the existing registry.
   - `CamelContext#setTypeConverterStatisticsEnabled`: the Javadoc (reworded in 
#30261) now says the option can be changed after the context is built.
   
   The fix is in the registry rather than in Camel Main, so it should also 
cover other runtimes that configure the context after building it (not tested 
here: Spring Boot and Quarkus), and any code that sets the option on a context 
that is already built.
   
   Tested with the two new tests, the type converter tests of camel-core, the 
camel-main tests, `ManagedTypeConverterRegistryTest` and the Spring XML 
statistics tests. Also checked with a standalone Camel Main application 
(`application.properties` with `camel.main.typeConverterStatisticsEnabled = 
true`, a timer route converting 10 bodies, counters read through JMX on the 
`DefaultTypeConverter` MBean): `AttemptCounter=0` before the fix, 
`AttemptCounter=11` with it.
   
   AI tool used: Claude Code (Claude Opus 5.5), reviewed and checked by me.
   
   _Claude Code on behalf of lobtx_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to