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:24 UTC
[4/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/601c97c5
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/601c97c5
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/601c97c5
Branch: refs/heads/master
Commit: 601c97c54de2687d9a32f4662ab24db31295807b
Parents: 4b4611d
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Mar 24 08:30:30 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Mar 24 08:41:23 2015 +0100
----------------------------------------------------------------------
.../main/java/org/apache/camel/CamelContext.java | 13 ++++++++++++-
.../org/apache/camel/impl/DefaultCamelContext.java | 17 ++++++++++++++++-
.../ManagedRouteSuspendAndResumeTest.java | 8 +++++++-
3 files changed, 35 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/601c97c5/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 adeb7c2..51888c8 100644
--- a/camel-core/src/main/java/org/apache/camel/CamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/CamelContext.java
@@ -26,6 +26,7 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import org.apache.camel.api.management.mbean.ManagedProcessorMBean;
+import org.apache.camel.api.management.mbean.ManagedRouteMBean;
import org.apache.camel.builder.ErrorHandlerBuilder;
import org.apache.camel.model.DataFormatDefinition;
import org.apache.camel.model.ProcessorDefinition;
@@ -538,11 +539,21 @@ public interface CamelContext extends SuspendableService, RuntimeConfiguration {
* @param id id of the processor
* @param type the managed processor type from the {@link org.apache.camel.api.management.mbean} package.
* @return the processor or <tt>null</tt> if not found
- * @throws java.lang.ClassCastException is thrown if the type is not correct type
+ * @throws IllegalArgumentException if the type is not compliant
*/
<T extends ManagedProcessorMBean> T getManagedProcessor(String id, Class<T> type);
/**
+ * Gets the managed route 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.
+ * @return the route or <tt>null</tt> if not found
+ * @throws IllegalArgumentException if the type is not compliant
+ */
+ <T extends ManagedRouteMBean> T getManagedRoute(String routeId, Class<T> type);
+
+ /**
* 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/601c97c5/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 4053a1e..25956e0 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
@@ -75,6 +75,7 @@ import org.apache.camel.SuspendableService;
import org.apache.camel.TypeConverter;
import org.apache.camel.VetoCamelContextStartException;
import org.apache.camel.api.management.mbean.ManagedProcessorMBean;
+import org.apache.camel.api.management.mbean.ManagedRouteMBean;
import org.apache.camel.builder.ErrorHandlerBuilder;
import org.apache.camel.builder.ErrorHandlerBuilderSupport;
import org.apache.camel.component.properties.PropertiesComponent;
@@ -735,7 +736,6 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
ProcessorDefinition def = getProcessorDefinition(id);
if (processor != null && def != null) {
- // lookup the processor in mbean
try {
ObjectName on = getManagementStrategy().getManagementNamingStrategy().getObjectNameForProcessor(this, processor, def);
return getManagementStrategy().getManagementAgent().newProxyClient(on, type);
@@ -747,6 +747,21 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
return null;
}
+ public <T extends ManagedRouteMBean> T getManagedRoute(String routeId, Class<T> type) {
+ Route route = getRoute(routeId);
+
+ if (route != null) {
+ try {
+ ObjectName on = getManagementStrategy().getManagementNamingStrategy().getObjectNameForRoute(route);
+ return getManagementStrategy().getManagementAgent().newProxyClient(on, type);
+ } catch (MalformedObjectNameException e) {
+ throw ObjectHelper.wrapRuntimeCamelException(e);
+ }
+ }
+
+ return null;
+ }
+
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/601c97c5/camel-core/src/test/java/org/apache/camel/management/ManagedRouteSuspendAndResumeTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedRouteSuspendAndResumeTest.java b/camel-core/src/test/java/org/apache/camel/management/ManagedRouteSuspendAndResumeTest.java
index e68bcc4..d6d673c 100644
--- a/camel-core/src/test/java/org/apache/camel/management/ManagedRouteSuspendAndResumeTest.java
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedRouteSuspendAndResumeTest.java
@@ -22,6 +22,7 @@ import javax.management.ObjectName;
import org.apache.camel.Exchange;
import org.apache.camel.ServiceStatus;
+import org.apache.camel.api.management.mbean.ManagedSuspendableRouteMBean;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
@@ -84,6 +85,11 @@ public class ManagedRouteSuspendAndResumeTest extends ManagementTestSupport {
// this time the file is consumed
mock.assertIsSatisfied();
+
+ ManagedSuspendableRouteMBean route = context.getManagedRoute("foo", ManagedSuspendableRouteMBean.class);
+ assertNotNull(route);
+
+ assertEquals(2, route.getExchangesCompleted());
}
static ObjectName getRouteObjectName(MBeanServer mbeanServer) throws Exception {
@@ -98,7 +104,7 @@ public class ManagedRouteSuspendAndResumeTest extends ManagementTestSupport {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
- from("file://target/managed").to("mock:result");
+ from("file://target/managed").routeId("foo").to("mock:result");
}
};
}