camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/3] git commit: CAMEL-7004: Added jmx attributes for total/started routes on CamelContextMBean
Date Sun, 24 Nov 2013 10:27:26 GMT
CAMEL-7004: Added jmx attributes for total/started routes on CamelContextMBean


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

Branch: refs/heads/camel-2.12.x
Commit: 14a77ae9c87cb2dfa99df12b882e2e08f44740e8
Parents: 3b8d80d
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sun Nov 24 11:27:20 2013 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sun Nov 24 11:27:35 2013 +0100

----------------------------------------------------------------------
 .../management/mbean/ManagedCamelContextMBean.java   |  6 ++++++
 .../org/apache/camel/impl/DefaultCamelContext.java   |  7 ++++++-
 .../camel/management/mbean/ManagedCamelContext.java  | 15 +++++++++++++++
 .../camel/management/ManagedCamelContextTest.java    |  6 ++++++
 4 files changed, 33 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/14a77ae9/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
index 566f6e0..5ec2a4c 100644
--- a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
+++ b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
@@ -86,6 +86,12 @@ public interface ManagedCamelContextMBean extends ManagedPerformanceCounterMBean
     @ManagedAttribute(description = "Current number of inflight Exchanges")
     Integer getInflightExchanges();
 
+    @ManagedAttribute(description = "Total number of routes")
+    Integer getTotalRoutes();
+
+    @ManagedAttribute(description = "Current number of started routes")
+    Integer getStartedRoutes();
+
     @ManagedAttribute(description = "Shutdown timeout")
     void setTimeout(long timeout);
 

http://git-wip-us.apache.org/repos/asf/camel/blob/14a77ae9/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index 9fe8bb1..bf90c7b 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -636,9 +636,14 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
         return routeStartupOrder;
     }
 
+    @SuppressWarnings("unchecked")
     public List<Route> getRoutes() {
         // lets return a copy of the collection as objects are removed later when services
are stopped
-        return new ArrayList<Route>(routes);
+        if (routes.isEmpty()) {
+            return Collections.EMPTY_LIST;
+        } else {
+            return new ArrayList<Route>(routes);
+        }
     }
 
     public Route getRoute(String id) {

http://git-wip-us.apache.org/repos/asf/camel/blob/14a77ae9/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 b41ff35..29d4521 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
@@ -36,6 +36,7 @@ import org.apache.camel.ComponentConfiguration;
 import org.apache.camel.Endpoint;
 import org.apache.camel.ManagementStatisticsLevel;
 import org.apache.camel.ProducerTemplate;
+import org.apache.camel.Route;
 import org.apache.camel.TimerListener;
 import org.apache.camel.api.management.ManagedResource;
 import org.apache.camel.api.management.mbean.ManagedCamelContextMBean;
@@ -131,6 +132,20 @@ public class ManagedCamelContext extends ManagedPerformanceCounter implements
Ti
         return context.getInflightRepository().size();
     }
 
+    public Integer getTotalRoutes() {
+        return context.getRoutes().size();
+    }
+
+    public Integer getStartedRoutes() {
+        int started = 0;
+        for (Route route : context.getRoutes()) {
+            if (context.getRouteStatus(route.getId()).isStarted()) {
+                started++;
+            }
+        }
+        return started;
+    }
+
     public void setTimeout(long timeout) {
         context.getShutdownStrategy().setTimeout(timeout);
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/14a77ae9/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTest.java
b/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTest.java
index 309a378..5b8ec5e 100644
--- a/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTest.java
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTest.java
@@ -65,6 +65,12 @@ public class ManagedCamelContextTest extends ManagementTestSupport {
         Boolean messageHistory = (Boolean) mbeanServer.getAttribute(on, "MessageHistory");
         assertEquals(Boolean.TRUE, messageHistory);
 
+        Integer total = (Integer) mbeanServer.getAttribute(on, "TotalRoutes");
+        assertEquals(2, total.intValue());
+
+        Integer started = (Integer) mbeanServer.getAttribute(on, "StartedRoutes");
+        assertEquals(2, started.intValue());
+
         // invoke operations
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedBodiesReceived("Hello World");


Mime
View raw message