davsclaus commented on code in PR #27280:
URL: https://github.com/apache/camel/pull/27280#discussion_r4166148950


##########
core/camel-management/src/main/java/org/apache/camel/management/DefaultManagementAgent.java:
##########
@@ -506,4 +587,7 @@ protected MBeanServer findOrCreateMBeanServer() {
         return MBeanServerFactory.createMBeanServer(mBeanServerDefaultDomain);
     }
 
+    private record ProcessorMBean(

Review Comment:
   Nit: in JMX an `*MBean` suffix means an MBean interface, so `ProcessorMBean` 
reads like a sibling of `ManagedProcessorMBean`. A name such as 
`IndexedProcessor` would avoid that (and its uses in `processorMBeans`, 
`addProcessorMBean` and `removeProcessorMBean`). Non-blocking.



##########
core/camel-management/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java:
##########
@@ -1007,22 +945,58 @@ public Collection<String> processorIds() throws 
Exception {
 
         MBeanServer server = 
getContext().getManagementStrategy().getManagementAgent().getMBeanServer();
         if (server != null) {
-            String prefix = 
getContext().getManagementStrategy().getManagementAgent().getIncludeHostName() 
? "*/" : "";
-            // gather all the processors for this CamelContext, which requires 
JMX
+            // gather all the processors for this route, which requires JMX
+            for (ManagedProcessorMBean processor : routeProcessorMBeans(false, 
ManagedProcessorMBean.class)) {
+                ids.add(processor.getProcessorId());
+            }
+        }
+
+        return ids;
+    }
+
+    /**
+     * Gets the processor (or step) mbeans of this route.
+     */
+    private <T extends ManagedProcessorMBean> List<T> 
routeProcessorMBeans(boolean steps, Class<T> type) throws Exception {
+        ManagementAgent agent = 
getContext().getManagementStrategy().getManagementAgent();
+        List<T> answer = new ArrayList<>();
+        for (ObjectName on : routeProcessorMBeanNames(steps)) {
+            T mp = agent.newProxyClient(on, type);
+            if (mp != null) {
+                answer.add(mp);
+            }
+        }
+        return answer;
+    }
+
+    /**
+     * Gets the names of the processor (or step) mbeans of this route.
+     * <p/>
+     * The default management agent knows the mbeans of each route, otherwise 
all the processor mbeans of the
+     * CamelContext are queried, which is slow with many routes as the route 
id of each mbean must be read.
+     */
+    private List<ObjectName> routeProcessorMBeanNames(boolean steps) throws 
Exception {
+        ManagementAgent agent = 
getContext().getManagementStrategy().getManagementAgent();
+        if (agent instanceof DefaultManagementAgent dma) {
+            return dma.getRouteProcessorMBeanNames(getRouteId(), steps);

Review Comment:
   Question, non-blocking: for any `DefaultManagementAgent`, including a 
subclass, the index is trusted completely. A third-party subclass that 
overrides `register()` without calling `super` would make `processorIds()` and 
the dumps return nothing instead of the right answer. Nothing in the Apache 
repos does this, so this is only hardening. Falling back to the scan below when 
the index has nothing for this route would cover it, and it stays cheap: with 
processor MBeans switched off, the query matches nothing.



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