Author: davsclaus
Date: Fri Aug 28 06:53:40 2009
New Revision: 808777
URL: http://svn.apache.org/viewvc?rev=808777&view=rev
Log:
CAMEL-1933: Overhaul of JMX. Added managed send to.Prepared for camel/route
context runtime configuration to be managed.
Added:
camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedSendProcessor.java
(with props)
camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedSendProcessorTest.java
(with props)
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/Route.java
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRoute.java
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/EventDrivenConsumerRoute.java
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/RouteService.java
camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagedLifecycleStrategy.java
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/SendProcessor.java
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/Route.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/Route.java?rev=808777&r1=808776&r2=808777&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/Route.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/Route.java Fri Aug 28
06:53:40 2009
@@ -19,6 +19,8 @@
import java.util.List;
import java.util.Map;
+import org.apache.camel.spi.RouteContext;
+
public interface Route {
String ID_PROPERTY = "id";
@@ -45,6 +47,13 @@
Map<String, Object> getProperties();
/**
+ * Gets the route context
+ *
+ * @return the route context
+ */
+ RouteContext getRouteContext();
+
+ /**
* This property map is used to associate information about
* the route. Gets all the services for this routes
* </p>
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?rev=808777&r1=808776&r2=808777&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
Fri Aug 28 06:53:40 2009
@@ -591,7 +591,7 @@
}
public void startRoute(RouteDefinition route) throws Exception {
- Collection<Route> routes = new ArrayList<Route>();
+ List<Route> routes = new ArrayList<Route>();
List<RouteContext> routeContexts = route.addRoutes(this, routes);
RouteService routeService = new RouteService(this, route,
routeContexts, routes);
startRouteService(routeService);
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRoute.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRoute.java?rev=808777&r1=808776&r2=808777&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRoute.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRoute.java
Fri Aug 28 06:53:40 2009
@@ -24,6 +24,7 @@
import org.apache.camel.Endpoint;
import org.apache.camel.Route;
import org.apache.camel.Service;
+import org.apache.camel.spi.RouteContext;
/**
* A <a href="http://camel.apache.org/routes.html">Route</a>
@@ -37,13 +38,15 @@
private final Endpoint endpoint;
private final Map<String, Object> properties = new HashMap<String,
Object>();
private final List<Service> services = new ArrayList<Service>();
+ private final RouteContext routeContext;
- public DefaultRoute(Endpoint endpoint) {
+ public DefaultRoute(RouteContext routeContext, Endpoint endpoint) {
+ this.routeContext = routeContext;
this.endpoint = endpoint;
}
- public DefaultRoute(Endpoint endpoint, Service... services) {
- this(endpoint);
+ public DefaultRoute(RouteContext routeContext, Endpoint endpoint,
Service... services) {
+ this(routeContext, endpoint);
for (Service service : services) {
addService(service);
}
@@ -62,6 +65,10 @@
return endpoint;
}
+ public RouteContext getRouteContext() {
+ return routeContext;
+ }
+
public Map<String, Object> getProperties() {
return properties;
}
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java?rev=808777&r1=808776&r2=808777&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java
Fri Aug 28 06:53:40 2009
@@ -145,7 +145,7 @@
wrapper.setProcessor(unitOfWorkProcessor);
// and create the route that wraps the UoW
- Route edcr = new EventDrivenConsumerRoute(getEndpoint(), wrapper);
+ Route edcr = new EventDrivenConsumerRoute(this, getEndpoint(),
wrapper);
edcr.getProperties().put(Route.ID_PROPERTY,
route.idOrCreate(getCamelContext().getNodeIdFactory()));
edcr.getProperties().put(Route.PARENT_PROPERTY,
Integer.toHexString(route.hashCode()));
if (route.getGroup() != null) {
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/EventDrivenConsumerRoute.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/EventDrivenConsumerRoute.java?rev=808777&r1=808776&r2=808777&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/EventDrivenConsumerRoute.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/EventDrivenConsumerRoute.java
Fri Aug 28 06:53:40 2009
@@ -23,6 +23,7 @@
import org.apache.camel.Navigate;
import org.apache.camel.Processor;
import org.apache.camel.Service;
+import org.apache.camel.spi.RouteContext;
import org.apache.camel.management.InstrumentationProcessor;
/**
@@ -34,8 +35,8 @@
public class EventDrivenConsumerRoute extends DefaultRoute {
private final Processor processor;
- public EventDrivenConsumerRoute(Endpoint endpoint, Processor processor) {
- super(endpoint);
+ public EventDrivenConsumerRoute(RouteContext routeContext, Endpoint
endpoint, Processor processor) {
+ super(routeContext, endpoint);
this.processor = processor;
}
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/RouteService.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/RouteService.java?rev=808777&r1=808776&r2=808777&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/RouteService.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/RouteService.java
Fri Aug 28 06:53:40 2009
@@ -45,10 +45,10 @@
private final DefaultCamelContext camelContext;
private final RouteDefinition routeDefinition;
private final List<RouteContext> routeContexts;
- private final Collection<Route> routes;
+ private final List<Route> routes;
private final String id;
- public RouteService(DefaultCamelContext camelContext, RouteDefinition
routeDefinition, List<RouteContext> routeContexts, Collection<Route> routes) {
+ public RouteService(DefaultCamelContext camelContext, RouteDefinition
routeDefinition, List<RouteContext> routeContexts, List<Route> routes) {
this.camelContext = camelContext;
this.routeDefinition = routeDefinition;
this.routeContexts = routeContexts;
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagedLifecycleStrategy.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagedLifecycleStrategy.java?rev=808777&r1=808776&r2=808777&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagedLifecycleStrategy.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagedLifecycleStrategy.java
Fri Aug 28 06:53:40 2009
@@ -43,6 +43,7 @@
import org.apache.camel.management.mbean.ManagedProcessor;
import org.apache.camel.management.mbean.ManagedProducer;
import org.apache.camel.management.mbean.ManagedRoute;
+import org.apache.camel.management.mbean.ManagedSendProcessor;
import org.apache.camel.management.mbean.ManagedThrottler;
import org.apache.camel.model.AOPDefinition;
import org.apache.camel.model.InterceptDefinition;
@@ -51,6 +52,7 @@
import org.apache.camel.model.ProcessorDefinition;
import org.apache.camel.model.RouteDefinition;
import org.apache.camel.processor.Delayer;
+import org.apache.camel.processor.SendProcessor;
import org.apache.camel.processor.Throttler;
import org.apache.camel.spi.BrowsableEndpoint;
import org.apache.camel.spi.ClassResolver;
@@ -316,10 +318,10 @@
return new ManagedDelayer(context, (Delayer) processor,
definition);
} else if (processor instanceof Throttler) {
return new ManagedThrottler(context, (Throttler) processor,
definition);
+ } else if (processor instanceof SendProcessor) {
+ return new ManagedSendProcessor(context, (SendProcessor)
processor, definition);
}
- // TODO Add more specialized support for processors such as SendTo,
WireTap etc.
-
// fallback to a generic processor
return new ManagedProcessor(context, processor, definition);
}
Added:
camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedSendProcessor.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedSendProcessor.java?rev=808777&view=auto
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedSendProcessor.java
(added)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedSendProcessor.java
Fri Aug 28 06:53:40 2009
@@ -0,0 +1,64 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.management.mbean;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.processor.SendProcessor;
+import org.springframework.jmx.export.annotation.ManagedAttribute;
+import org.springframework.jmx.export.annotation.ManagedOperation;
+import org.springframework.jmx.export.annotation.ManagedResource;
+
+/**
+ * @version $Revision$
+ */
+...@managedresource(description = "Managed SendProcessor")
+public class ManagedSendProcessor extends ManagedProcessor {
+
+ private SendProcessor processor;
+
+ public ManagedSendProcessor(CamelContext context, SendProcessor processor,
ProcessorDefinition definition) {
+ super(context, processor, definition);
+ this.processor = processor;
+ }
+
+ public SendProcessor getProcessor() {
+ return processor;
+ }
+
+ @ManagedAttribute(description = "Destination as Endpoint Uri")
+ public String getDestination() {
+ return processor.getDestination().getEndpointUri();
+ }
+
+ @ManagedAttribute(description = "Message Exchange Pattern")
+ public String getMessageExchangePattern() {
+ if (processor.getPattern() != null) {
+ return processor.getPattern().name();
+ } else {
+ return null;
+ }
+ }
+
+ @ManagedOperation(description = "Change Destination Endpoint Uri")
+ public void changeDestination(String uri) throws Exception {
+ Endpoint endpoint = getContext().getEndpoint(uri);
+ processor.setDestination(endpoint);
+ }
+
+}
Propchange:
camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedSendProcessor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedSendProcessor.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/SendProcessor.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/SendProcessor.java?rev=808777&r1=808776&r2=808777&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/SendProcessor.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/SendProcessor.java
Fri Aug 28 06:53:40 2009
@@ -56,6 +56,11 @@
return "sendTo(" + destination + (pattern != null ? " " + pattern :
"") + ")";
}
+ public synchronized void setDestination(Endpoint destination) {
+ this.destination = destination;
+ this.init = false;
+ }
+
public String getTraceLabel() {
return destination.getEndpointUri();
}
@@ -97,6 +102,10 @@
return destination;
}
+ public ExchangePattern getPattern() {
+ return pattern;
+ }
+
protected Exchange configureExchange(Exchange exchange, ExchangePattern
pattern) {
if (pattern != null) {
exchange.setPattern(pattern);
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedSendProcessorTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedSendProcessorTest.java?rev=808777&view=auto
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedSendProcessorTest.java
(added)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedSendProcessorTest.java
Fri Aug 28 06:53:40 2009
@@ -0,0 +1,86 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.management;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * @version $Revision$
+ */
+public class ManagedSendProcessorTest extends ContextTestSupport {
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext context = super.createCamelContext();
+ DefaultManagementNamingStrategy naming =
(DefaultManagementNamingStrategy)
context.getManagementStrategy().getManagementNamingStrategy();
+ naming.setHostName("localhost");
+ naming.setDomainName("org.apache.camel");
+ return context;
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testManageSendProcessor() throws Exception {
+ MockEndpoint result = getMockEndpoint("mock:result");
+ result.expectedMessageCount(1);
+ MockEndpoint foo = getMockEndpoint("mock:foo");
+ foo.expectedMessageCount(0);
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+
+ // get the stats for the route
+ MBeanServer mbeanServer =
context.getManagementStrategy().getManagementAgent().getMBeanServer();
+
+ // get the object name for the delayer
+ ObjectName on =
ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=processors,name=\"mysend\"");
+
+ // send it somewhere else
+ mbeanServer.invoke(on, "changeDestination", new
Object[]{"direct:foo"}, new String[]{"java.lang.String"});
+
+ // prepare mocks
+ result.reset();
+ result.expectedMessageCount(0);
+ foo.reset();
+ foo.expectedMessageCount(1);
+
+ // send in another message that should be sent to mock:foo
+ template.sendBody("direct:start", "Bye World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .to("mock:result").id("mysend");
+
+ from("direct:foo").to("mock:foo");
+ }
+ };
+ }
+
+}
Propchange:
camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedSendProcessorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedSendProcessorTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date