allthingssecurity commented on code in PR #28645:
URL: https://github.com/apache/camel/pull/28645#discussion_r4411499087


##########
components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheConsumer.java:
##########
@@ -53,18 +54,32 @@ protected void doStart() throws Exception {
         if (configuration.getValueType() != null) {
             vt = 
getEndpoint().getCamelContext().getClassResolver().resolveClass(configuration.getValueType());
         }
-        this.cache = getEndpoint().getManager().getCache(cacheName, kt, vt);
+        EhcacheManager endpointManager = getEndpoint().getManager();
+        this.cache = endpointManager.getCache(cacheName, kt, vt);
 
         this.cache.getRuntimeConfiguration().registerCacheEventListener(
                 this,
                 configuration.getEventOrdering(),
                 configuration.getEventFiring(),
                 configuration.getEventTypesSet());
+        // the cache manager (and its caches) are kept while the consumer uses 
them
+        endpointManager.incRef();
+        this.manager = endpointManager;

Review Comment:
   Done in c9afb89828ce: the consumer now takes its reference first, as the 
producer does. If `getCache()` or `registerCacheEventListener()` then fails, it 
releases the reference again and keeps no `manager` or `cache`, so `doStop` has 
nothing to release or deregister after a failed start (and still nothing for a 
consumer that never started). New test 
`EhcacheManagerTest.aConsumerThatFailsToStartReleasesItsReference`: a consumer 
already registered as a listener of a configured cache fails to start, and the 
count is back to what it was, also after the stop; without the release it fails 
with `expected: <1> but was: <2>`.
   
   _Claude Code on behalf of allthingssecurity_
   



-- 
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