gnodet-bot commented on code in PR #29531:
URL: https://github.com/apache/camel/pull/29531#discussion_r4519642497


##########
core/camel-cluster/src/main/java/org/apache/camel/impl/cluster/ClusteredRouteController.java:
##########
@@ -193,11 +200,26 @@ public void doStart() throws Exception {
             clusterService.start();
         }
 
+        if 
(!context.getManagementStrategy().getEventNotifiers().contains(routesStoppedListener))
 {
+            
context.getManagementStrategy().addEventNotifier(routesStoppedListener);
+        }
+
         super.doStart();
     }
 
     @Override
     public void doStop() throws Exception {
+        if (getCamelContext() != null && getCamelContext().isStopping()) {
+            // The CamelContext stops the route controller before the routes. 
The routes must keep the leadership until
+            // their consumers have stopped and their in-flight exchanges are 
done, or another node would start them in
+            // the meantime, so the cluster service is stopped once the routes 
have stopped.
+            return;

Review Comment:
   💡 **Nit:** A `LOGGER.debug()` trace here would help operators understand why 
the cluster service isn't stopped immediately during context shutdown:
   
   ```suggestion
               LOGGER.debug("CamelContext is stopping — deferring cluster 
service stop until routes have stopped");
               return;
   ```



##########
core/camel-cluster/src/main/java/org/apache/camel/impl/cluster/ClusteredRouteController.java:
##########
@@ -213,6 +235,29 @@ public void setCamelContext(CamelContext camelContext) {
         super.setCamelContext(camelContext);
     }
 
+    /**
+     * Stops the cluster service once the routes have stopped, when the 
CamelContext stops.
+     */
+    private final class RoutesStoppedListener extends 
SimpleEventNotifierSupport implements NonManagedService {
+        RoutesStoppedListener() {
+            // only the CamelContext events are needed
+            setIgnoreExchangeEvents(true);
+            setIgnoreRouteEvents(true);
+            setIgnoreServiceEvents(true);
+            setIgnoreStepEvents(true);

Review Comment:
   💡 **Nit:** `setIgnoreExchangeEvents(true)` (line 244) and 
`setIgnoreStepEvents(true)` (line 247) are redundant — 
`SimpleEventNotifierSupport`'s constructor already calls `setupIgnore(true)` 
which sets both to `true`. Only `setIgnoreRouteEvents(true)` and 
`setIgnoreServiceEvents(true)` add new filtering here.



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