Repository: camel
Updated Branches:
  refs/heads/master 47bae5e77 -> 3cad8db9b


CAMEL-8252: Camel route status - Include inflight counter per processor node


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/3cad8db9
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/3cad8db9
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/3cad8db9

Branch: refs/heads/master
Commit: 3cad8db9b91d3e40474d4cd4c2b753ee77717935
Parents: 47bae5e
Author: Claus Ibsen <davscl...@apache.org>
Authored: Fri Jan 16 16:39:42 2015 +0100
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Fri Jan 16 16:39:42 2015 +0100

----------------------------------------------------------------------
 .../management/mbean/ManagedCamelContext.java   | 36 +++++++++++++++++---
 1 file changed, 32 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/3cad8db9/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
 
b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
index 16f34cf..be1a69f 100644
--- 
a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
+++ 
b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
@@ -57,16 +57,17 @@ import org.apache.camel.model.RouteDefinition;
 import org.apache.camel.model.RoutesDefinition;
 import org.apache.camel.model.rest.RestDefinition;
 import org.apache.camel.model.rest.RestsDefinition;
+import org.apache.camel.spi.InflightRepository;
 import org.apache.camel.util.CamelContextHelper;
 import org.apache.camel.util.JsonSchemaHelper;
 import org.apache.camel.util.ObjectHelper;
 
 /**
- * @version 
+ * @version
  */
 @ManagedResource(description = "Managed CamelContext")
 public class ManagedCamelContext extends ManagedPerformanceCounter implements 
TimerListener, ManagedCamelContextMBean {
-    private final ModelCamelContext context;   
+    private final ModelCamelContext context;
     private final LoadTriplet load = new LoadTriplet();
 
     public ManagedCamelContext(ModelCamelContext context) {
@@ -121,7 +122,7 @@ public class ManagedCamelContext extends 
ManagedPerformanceCounter implements Ti
         }
         return context.getProperties();
     }
-    
+
     public String getProperty(String name) throws Exception {
         return context.getProperty(name);
     }
@@ -397,6 +398,11 @@ public class ManagedCamelContext extends 
ManagedPerformanceCounter implements Ti
             }
             Collections.sort(processors, new OrderProcessorMBeans());
 
+            Collection<InflightRepository.InflightExchange> inflights = null;
+            if (fullStats) {
+                inflights = context.getInflightRepository().browse();
+            }
+
             // loop the routes, and append the processor stats if needed
             sb.append("  <routeStats>\n");
             for (ObjectName on : routes) {
@@ -415,7 +421,12 @@ public class ManagedCamelContext extends 
ManagedPerformanceCounter implements Ti
                         if (route.getRouteId().equals(processor.getRouteId())) 
{
                             sb.append("        
<processorStat").append(String.format(" id=\"%s\" index=\"%s\" state=\"%s\"", 
processor.getProcessorId(), processor.getIndex(), processor.getState()));
                             // use substring as we only want the attributes
-                            sb.append(" 
").append(processor.dumpStatsAsXml(fullStats).substring(7)).append("\n");
+                            stat = processor.dumpStatsAsXml(fullStats);
+                            if (fullStats) {
+                                // only include this in full stats as it may 
be more expensive to compute
+                                sb.append(" 
exchangesInflight=\"").append(inflightSizeAtProcessor(inflights, 
processor.getProcessorId())).append("\"");
+                            }
+                            sb.append(" 
").append(stat.substring(7)).append("\n");
                         }
                     }
                     sb.append("      </processorStats>\n");
@@ -429,6 +440,23 @@ public class ManagedCamelContext extends 
ManagedPerformanceCounter implements Ti
         return sb.toString();
     }
 
+    /**
+     * Number of inflight exchanges at the given processor
+     *
+     * @param inflights   all inflight exchanges
+     * @param processorId the processor id
+     * @return the number
+     */
+    private String 
inflightSizeAtProcessor(Collection<InflightRepository.InflightExchange> 
inflights, String processorId) {
+        int count = 0;
+        for (InflightRepository.InflightExchange inflight : inflights) {
+            if (processorId.equals(inflight.getNodeId())) {
+                count++;
+            }
+        }
+        return String.valueOf(count);
+    }
+
     public boolean createEndpoint(String uri) throws Exception {
         if (context.hasEndpoint(uri) != null) {
             // endpoint already exists

Reply via email to