You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2015/03/24 08:39:25 UTC

[5/6] camel git commit: CAMEL-8531: Make it easy to get the management mbean for a given process by its id

CAMEL-8531: Make it easy to get the management mbean for a given process by its id


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

Branch: refs/heads/master
Commit: a24a781b13a46577843fee06f0f0b7b1b67b6bb7
Parents: 2fcd594
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Mar 24 08:40:36 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Mar 24 08:41:24 2015 +0100

----------------------------------------------------------------------
 .../java/org/apache/camel/CamelContext.java     | 10 ++++++++--
 .../apache/camel/impl/DefaultCamelContext.java  | 10 ++++++++++
 .../management/ManagedCamelContextTest.java     | 20 +++++++++++++++++++-
 3 files changed, 37 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/a24a781b/camel-core/src/main/java/org/apache/camel/CamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/CamelContext.java b/camel-core/src/main/java/org/apache/camel/CamelContext.java
index 51888c8..4b2b246 100644
--- a/camel-core/src/main/java/org/apache/camel/CamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/CamelContext.java
@@ -25,6 +25,7 @@ import java.util.Properties;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
 
+import org.apache.camel.api.management.mbean.ManagedCamelContextMBean;
 import org.apache.camel.api.management.mbean.ManagedProcessorMBean;
 import org.apache.camel.api.management.mbean.ManagedRouteMBean;
 import org.apache.camel.builder.ErrorHandlerBuilder;
@@ -534,7 +535,7 @@ public interface CamelContext extends SuspendableService, RuntimeConfiguration {
     <T extends Processor> T getProcessor(String id, Class<T> type);
 
     /**
-     * Gets the managed processor from any of the routes which with the given id
+     * Gets the managed processor client api from any of the routes which with the given id
      *
      * @param id id of the processor
      * @param type the managed processor type from the {@link org.apache.camel.api.management.mbean} package.
@@ -544,7 +545,7 @@ public interface CamelContext extends SuspendableService, RuntimeConfiguration {
     <T extends ManagedProcessorMBean> T getManagedProcessor(String id, Class<T> type);
 
     /**
-     * Gets the managed route with the given route id
+     * Gets the managed route client api with the given route id
      *
      * @param routeId id of the route
      * @param type the managed route type from the {@link org.apache.camel.api.management.mbean} package.
@@ -554,6 +555,11 @@ public interface CamelContext extends SuspendableService, RuntimeConfiguration {
     <T extends ManagedRouteMBean> T getManagedRoute(String routeId, Class<T> type);
 
     /**
+     * Gets the managed Camel context client api
+     */
+    ManagedCamelContextMBean getManagedCamelContext();
+
+    /**
      * Gets the processor definition from any of the routes which with the given id
      *
      * @param id id of the processor definition

http://git-wip-us.apache.org/repos/asf/camel/blob/a24a781b/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 25956e0..1152600 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
@@ -74,6 +74,7 @@ import org.apache.camel.StatefulService;
 import org.apache.camel.SuspendableService;
 import org.apache.camel.TypeConverter;
 import org.apache.camel.VetoCamelContextStartException;
+import org.apache.camel.api.management.mbean.ManagedCamelContextMBean;
 import org.apache.camel.api.management.mbean.ManagedProcessorMBean;
 import org.apache.camel.api.management.mbean.ManagedRouteMBean;
 import org.apache.camel.builder.ErrorHandlerBuilder;
@@ -762,6 +763,15 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
         return null;
     }
 
+    public ManagedCamelContextMBean getManagedCamelContext() {
+        try {
+            ObjectName on = getManagementStrategy().getManagementNamingStrategy().getObjectNameForCamelContext(this);
+            return getManagementStrategy().getManagementAgent().newProxyClient(on, ManagedCamelContextMBean.class);
+        } catch (MalformedObjectNameException e) {
+            throw ObjectHelper.wrapRuntimeCamelException(e);
+        }
+    }
+
     public ProcessorDefinition getProcessorDefinition(String id) {
         for (RouteDefinition route : getRouteDefinitions()) {
             Iterator<ProcessorDefinition> it = ProcessorDefinitionHelper.filterTypeInOutputs(route.getOutputs(), ProcessorDefinition.class);

http://git-wip-us.apache.org/repos/asf/camel/blob/a24a781b/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 c92eead..3807dc0 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
@@ -17,13 +17,14 @@
 package org.apache.camel.management;
 
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.Properties;
-
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
 
 import org.apache.camel.CamelContext;
+import org.apache.camel.api.management.mbean.ManagedCamelContextMBean;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.util.StringHelper;
@@ -41,6 +42,23 @@ public class ManagedCamelContextTest extends ManagementTestSupport {
         return context;
     }
 
+    public void testManagedCamelContextClient() throws Exception {
+        // JMX tests dont work well on AIX CI servers (hangs them)
+        if (isPlatform("aix")) {
+            return;
+        }
+
+        ManagedCamelContextMBean client = context.getManagedCamelContext();
+        assertNotNull(client);
+
+        assertEquals("camel-1", client.getCamelId());
+        assertEquals("Started", client.getState());
+
+        List<String> names = client.findComponentNames();
+        assertNotNull(names);
+        assertTrue(names.contains("mock"));
+    }
+
     public void testManagedCamelContext() throws Exception {
         // JMX tests dont work well on AIX CI servers (hangs them)
         if (isPlatform("aix")) {