svn commit: r565270 - in /activemq/camel/trunk: camel-core/ camel-core/src/main/java/org/apache/camel/ camel-core/src/main/java/org/apache/camel/impl/ camel-core/src/main/java/org/apache/camel/management/ components/camel-spring/src/main/java/org/apach...

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r565270 - in /activemq/camel/trunk: camel-core/ camel-core/src/main/java/org/apache/camel/ camel-core/src/main/java/org/apache/camel/impl/ camel-core/src/main/java/org/apache/camel/management/ components/camel-spring/src/main/java/org/apach...

jstrachan-2
Author: jstrachan
Date: Mon Aug 13 01:46:57 2007
New Revision: 565270

URL: http://svn.apache.org/viewvc?view=rev&rev=565270
Log:
patch applied from Hadrian Zbarcea for CAMEL-4 with thanks!

Added:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/InstrumentationAgent.java   (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/LifecycleStrategy.java   (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultLifecycleStrategy.java   (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/CamelNamingStrategy.java   (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationAgentImpl.java   (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationLifecycleStrategy.java   (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/ManagedEndpoint.java   (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/ManagedRoute.java   (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/ManagedService.java   (with props)
    activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringInstrumentationAgent.java   (with props)
    activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/managment/
    activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/managment/JmxInstrumentationWithConnectorTest.java   (with props)
    activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/management/
    activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/management/jmxInstrumentationWithConnector.xml   (with props)
Modified:
    activemq/camel/trunk/camel-core/pom.xml
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ServiceSupport.java
    activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java

Modified: activemq/camel/trunk/camel-core/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/pom.xml?view=diff&rev=565270&r1=565269&r2=565270
==============================================================================
--- activemq/camel/trunk/camel-core/pom.xml (original)
+++ activemq/camel/trunk/camel-core/pom.xml Mon Aug 13 01:46:57 2007
@@ -42,6 +42,14 @@
       <artifactId>jaxb-api</artifactId>
     </dependency>
 
+    <!-- to allow Spring annotations to be used; could replace with the micro-jar later -->
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring</artifactId>
+      <optional>true</optional>
+      <scope>compile</scope>
+    </dependency>
+
     <!-- testing -->
     <dependency>
       <groupId>com.sun.xml.bind</groupId>

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java?view=diff&rev=565270&r1=565269&r2=565270
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java Mon Aug 13 01:46:57 2007
@@ -173,6 +173,11 @@
     Injector getInjector();
 
     /**
+     * Returns the lifecycle strategy used to handle lifecycle notification
+     */
+    LifecycleStrategy getLifecycleStrategy();
+
+    /**
      * Resolves a language for creating expressions
      */
     Language resolveLanguage(String language);

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/InstrumentationAgent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/InstrumentationAgent.java?view=auto&rev=565270
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/InstrumentationAgent.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/InstrumentationAgent.java Mon Aug 13 01:46:57 2007
@@ -0,0 +1,59 @@
+/**
+ * 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;
+
+import javax.management.JMException;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+public interface InstrumentationAgent {
+
+    /**
+     * Registers object with management infrastructure with a specific name. Object must be annotated or
+     * implement standard MBean interface.
+     * @param obj
+     * @param name
+     * @throws JMException
+     */
+    void register(Object obj, ObjectName name) throws JMException;
+    
+    /**
+     * Registers object with management infrastructure with a specific name. Object must be annotated or
+     * implement standard MBean interface.
+     * @param obj
+     * @param name
+     * @param forceRegistration if set to true, then component will be registered despite existing component.
+     * @throws JMException
+     */
+    void register(Object obj, ObjectName name, boolean forceRegistration) throws JMException;
+    
+    /**
+     * Unregisters component based upon registered name
+     * @param name
+     * @throws JMException
+     */
+    void unregister(ObjectName name) throws JMException;
+
+    /**
+     * Get the MBeanServer which hosts managed components
+     * NOTE: if the configuration is not set the JMXEnabled to be true, this method
+     * will return null
+     * @return the MBeanServer
+     */
+    MBeanServer getMBeanServer();
+
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/InstrumentationAgent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/LifecycleStrategy.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/LifecycleStrategy.java?view=auto&rev=565270
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/LifecycleStrategy.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/LifecycleStrategy.java Mon Aug 13 01:46:57 2007
@@ -0,0 +1,42 @@
+/**
+ * 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;
+
+import java.util.Collection;
+
+public interface LifecycleStrategy {
+
+ /**
+     * Notification on adding a {@see CamelContext}.
+     */
+ void onContextCreate(CamelContext context);
+
+ /**
+     * Notification on adding an {@see Endpoint}.
+     */
+ void onEndpointAdd(Endpoint endpoint);
+
+ /**
+     * Notification on adding a {@see Route}.
+     */
+ void onServiceAdd(CamelContext context, Service service);
+
+ /**
+     * Notification on adding {@see Route}(s).
+     */
+ void onRoutesAdd(Collection<Route> routes);
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/LifecycleStrategy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?view=diff&rev=565270&r1=565269&r2=565270
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java Mon Aug 13 01:46:57 2007
@@ -30,6 +30,7 @@
 import org.apache.camel.Component;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
+import org.apache.camel.LifecycleStrategy;
 import org.apache.camel.Processor;
 import org.apache.camel.ResolveEndpointFailedException;
 import org.apache.camel.Route;
@@ -69,6 +70,7 @@
     private boolean autoCreateComponents = true;
     private LanguageResolver languageResolver = new DefaultLanguageResolver();
     private Registry registry;
+ private LifecycleStrategy lifecycleStrategy = new DefaultLifecycleStrategy();
 
     public DefaultCamelContext() {
     }
@@ -241,10 +243,9 @@
 
                     // If it's a singleton then auto register it.
                     if (answer != null && answer.isSingleton()) {
-                        if (answer != null) {
-                            startServices(answer);
-                            endpoints.put(uri, answer);
-                        }
+                        startServices(answer);
+                        endpoints.put(uri, answer);
+                     lifecycleStrategy.onEndpointAdd(answer);
                     }
                 } catch (Exception e) {
                     throw new ResolveEndpointFailedException(uri, e);
@@ -280,6 +281,7 @@
         } else {
             this.routes.addAll(routes);
         }
+        lifecycleStrategy.onRoutesAdd(routes);
         if (isStarted()) {
             startRoutes(routes);
         }
@@ -372,6 +374,14 @@
 
     public void setRegistry(Registry registry) {
         this.registry = registry;
+    }
+
+    public LifecycleStrategy getLifecycleStrategy() {
+        return lifecycleStrategy;
+    }
+
+    public void setLifecycleStrategy(LifecycleStrategy lifecycleStrategy) {
+        this.lifecycleStrategy = lifecycleStrategy;
     }
 
     // Implementation methods

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultLifecycleStrategy.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultLifecycleStrategy.java?view=auto&rev=565270
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultLifecycleStrategy.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultLifecycleStrategy.java Mon Aug 13 01:46:57 2007
@@ -0,0 +1,44 @@
+/**
+ * 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.impl;
+
+import java.util.Collection;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.LifecycleStrategy;
+import org.apache.camel.Route;
+import org.apache.camel.Service;
+
+public class DefaultLifecycleStrategy implements LifecycleStrategy {
+
+ public void onContextCreate(CamelContext context) {
+ // do nothing
+ }
+
+ public void onEndpointAdd(Endpoint endpoint) {
+ // do nothing
+ }
+
+ public void onServiceAdd(CamelContext context, Service service) {
+ // do nothing
+ }
+
+ public void onRoutesAdd(Collection<Route> routes) {
+ // do nothing
+ }
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultLifecycleStrategy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ServiceSupport.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ServiceSupport.java?view=diff&rev=565270&r1=565269&r2=565270
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ServiceSupport.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ServiceSupport.java Mon Aug 13 01:46:57 2007
@@ -23,6 +23,10 @@
 import java.util.Collection;
 import java.util.concurrent.atomic.AtomicBoolean;
 
+import org.springframework.jmx.export.annotation.ManagedAttribute;
+import org.springframework.jmx.export.annotation.ManagedOperation;
+import org.springframework.jmx.export.annotation.ManagedResource;
+
 /**
  * A useful base class which ensures that a service is only initialized once and
  * provides some helper methods for enquiring of its status

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/CamelNamingStrategy.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/CamelNamingStrategy.java?view=auto&rev=565270
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/CamelNamingStrategy.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/CamelNamingStrategy.java Mon Aug 13 01:46:57 2007
@@ -0,0 +1,142 @@
+/**
+ *
+ * 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 java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.Hashtable;
+
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+
+public class CamelNamingStrategy {
+
+ public static final String VALUE_UNKNOWN = "unknown";
+ public static final String KEY_CONTEXT = "context";
+ public static final String KEY_ENDPOINT = "endpoint";
+ public static final String KEY_ROUTE = "route";
+ public static final String KEY_TYPE = "type";
+ public static final String KEY_NAME = "name";
+ public static final String TYPE_ENDPOINTS = "Endpoints";
+ public static final String TYPE_SERVICES = "Services";
+ public static final String TYPE_ROUTES = "Routes";
+
+ protected String domainName = "org.apache.camel";
+ protected String hostName = "locahost";
+
+ public CamelNamingStrategy(String domainName) {
+ if (domainName != null) {
+    this.domainName = domainName;
+ }
+ try {
+ hostName = InetAddress.getLocalHost().getHostName();
+ }
+ catch (UnknownHostException ex) {
+ // ignore
+ }
+ }
+
+ /**
+ * Implements the naming strategy for a {@see CamelContext}.
+ * The convention used for a {@see CamelContext} ObjectName is
+ * "<domain>:context=<context>,name=camel".
+ *
+ * @param mbean
+ * @return generated ObjectName
+ * @throws MalformedObjectNameException
+ */
+ public ObjectName getObjectName(CamelContext context) throws MalformedObjectNameException {
+ Hashtable<String, String> keys = new Hashtable<String, String>();
+ keys.put(KEY_CONTEXT, getContextId(context));
+ keys.put(KEY_NAME, "camel");
+ return new ObjectName(domainName, keys);
+ }
+
+ /**
+ * Implements the naming strategy for a {@see ManagedEndpoint}.
+ * The convention used for a {@see ManagedEndpoint} ObjectName is
+ * "<domain>:context=<context>,type=Endpoints,endpoint=[urlPrefix]localPart".
+ *
+ * @param mbean
+ * @return generated ObjectName
+ * @throws MalformedObjectNameException
+ */
+ public ObjectName getObjectName(ManagedEndpoint mbean) throws MalformedObjectNameException {
+ Endpoint ep = mbean.getEndpoint();
+ Hashtable<String, String> keys = new Hashtable<String, String>();
+ keys.put(KEY_CONTEXT, getContextId(ep.getContext()));
+ keys.put(KEY_TYPE, TYPE_ENDPOINTS);
+ keys.put(KEY_ENDPOINT, getEndpointId(ep));
+ return new ObjectName(domainName, keys);
+ }
+
+ /**
+ * Implements the naming strategy for a {@see ServiceSpport Service}.
+ * The convention used for a {@see Service} ObjectName is
+ * "<domain>:context=<context>,type=Services,endpoint=[urlPrefix]localPart".
+ *
+ * @param mbean
+ * @return generated ObjectName
+ * @throws MalformedObjectNameException
+ */
+ public ObjectName getObjectName(CamelContext context, ManagedService mbean) throws MalformedObjectNameException {
+ Hashtable<String, String> keys = new Hashtable<String, String>();
+ keys.put(KEY_CONTEXT, getContextId(context));
+ keys.put(KEY_TYPE, TYPE_SERVICES);
+ keys.put(KEY_ENDPOINT, Integer.toHexString(mbean.getService().hashCode()));
+ return new ObjectName(domainName, keys);
+ }
+
+ /**
+ * Implements the naming strategy for a {@see ManagedRoute}.
+ * The convention used for a {@see ManagedEndpoint} ObjectName is
+ * "<domain>:context=<context>,type=Routes,endpoint=[urlPrefix]localPart".
+ *
+ * @param mbean
+ * @return generated ObjectName
+ * @throws MalformedObjectNameException
+ */
+ public ObjectName getObjectName(ManagedRoute mbean) throws MalformedObjectNameException {
+ Hashtable<String, String> keys = new Hashtable<String, String>();
+ Endpoint ep = mbean.getRoute().getEndpoint();
+ String ctxid = ep != null ? getContextId(ep.getContext()) : VALUE_UNKNOWN;
+ keys.put(KEY_CONTEXT, ctxid);
+ keys.put(KEY_TYPE, TYPE_ROUTES);
+ keys.put(KEY_ENDPOINT, getEndpointId(ep));
+ return new ObjectName(domainName, keys);
+ }
+
+ protected String getContextId(CamelContext context) {
+ String id = context != null ? Integer.toString(context.hashCode()) : VALUE_UNKNOWN;
+ return hostName + "/" + id;
+ }
+
+ protected String getEndpointId(Endpoint ep) {
+ String uri = ep.getEndpointUri();
+ int pos = uri.indexOf(':');
+ String id = (pos == -1) ? uri :
+ "[" + uri.substring(0, pos) + "]" + uri.substring(pos + 1);
+ if (!ep.isSingleton()) {
+ id += "." + Integer.toString(ep.hashCode());
+ }
+ return id;
+ }
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/CamelNamingStrategy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationAgentImpl.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationAgentImpl.java?view=auto&rev=565270
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationAgentImpl.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationAgentImpl.java Mon Aug 13 01:46:57 2007
@@ -0,0 +1,138 @@
+/**
+ *
+ * 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 java.util.HashSet;
+import java.util.Set;
+
+import javax.management.InstanceAlreadyExistsException;
+import javax.management.JMException;
+import javax.management.MBeanServer;
+import javax.management.NotCompliantMBeanException;
+import javax.management.ObjectInstance;
+import javax.management.ObjectName;
+import javax.management.modelmbean.InvalidTargetObjectTypeException;
+import javax.management.modelmbean.ModelMBeanInfo;
+import javax.management.modelmbean.RequiredModelMBean;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.InstrumentationAgent;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource;
+import org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler;
+
+public class InstrumentationAgentImpl implements InstrumentationAgent, CamelContextAware {
+
+ private MBeanServer server;
+ private CamelContext context;
+    private Set<ObjectName> mbeans = new HashSet<ObjectName>();
+    MetadataMBeanInfoAssembler assembler;
+
+    public InstrumentationAgentImpl() {
+     assembler = new MetadataMBeanInfoAssembler();
+     assembler.setAttributeSource(new AnnotationJmxAttributeSource());
+    }
+ public CamelContext getCamelContext() {
+ return context;
+ }
+
+ public void setCamelContext(CamelContext camelContext) {
+ context = camelContext;
+ }
+
+ public void setMBeanServer(MBeanServer server) {
+ this.server = server;
+ }
+
+ public MBeanServer getMBeanServer() {
+ return server;
+ }
+
+ public void register(Object obj, ObjectName name) throws JMException {
+ register(obj, name, false);
+ }
+
+ public void register(Object obj, ObjectName name, boolean forceRegistration) throws JMException {
+        try {
+            registerMBeanWithServer(obj, name, forceRegistration);          
+        } catch (NotCompliantMBeanException e) {        
+            //If this is not a "normal" MBean, then try to deploy it using JMX annotations
+         ModelMBeanInfo mbi = null;
+         mbi = assembler.getMBeanInfo(obj, name.toString());
+            RequiredModelMBean mbean = (RequiredModelMBean)server.instantiate(RequiredModelMBean.class.getName());
+            mbean.setModelMBeanInfo(mbi);
+            try {
+             mbean.setManagedResource(obj, "ObjectReference");
+            } catch (InvalidTargetObjectTypeException itotex) {
+                throw new JMException(itotex.getMessage());
+            }
+            registerMBeanWithServer(mbean, name, forceRegistration);
+        }                
+ }
+
+ public void unregister(ObjectName name) throws JMException {
+ }
+
+ public void start() {
+ if (context == null) {
+ // LOG warning
+ return;
+ }
+
+ if (context instanceof DefaultCamelContext) {
+ DefaultCamelContext dc = (DefaultCamelContext)context;
+ InstrumentationLifecycleStrategy ls = new InstrumentationLifecycleStrategy(this);
+ dc.setLifecycleStrategy(ls);
+ ls.onContextCreate(context);
+ }
+ }
+
+    public void stop() {
+        //Using the array to hold the busMBeans to avoid the CurrentModificationException
+        Object[] mBeans = mbeans.toArray();
+        for (Object name : mBeans) {
+         mbeans.remove((ObjectName)name);
+            try {
+                unregister((ObjectName)name);
+            } catch (JMException jmex) {
+                // log
+            }
+        }
+    }
+    
+    private void registerMBeanWithServer(Object obj, ObjectName name, boolean forceRegistration)
+     throws JMException {
+    
+    ObjectInstance instance = null;
+    try {
+        instance = server.registerMBean(obj, name);          
+    } catch (InstanceAlreadyExistsException e) {            
+        if (forceRegistration) {
+         server.unregisterMBean(name);              
+            instance = server.registerMBean(obj, name);
+        } else {
+            throw e;
+        }
+    }
+    
+    if (instance != null) {
+     mbeans.add(name);
+    }
+    }
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationAgentImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationLifecycleStrategy.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationLifecycleStrategy.java?view=auto&rev=565270
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationLifecycleStrategy.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationLifecycleStrategy.java Mon Aug 13 01:46:57 2007
@@ -0,0 +1,88 @@
+/**
+ *
+ * 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 java.util.Collection;
+
+import javax.management.JMException;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.InstrumentationAgent;
+import org.apache.camel.LifecycleStrategy;
+import org.apache.camel.Route;
+import org.apache.camel.Service;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.impl.ServiceSupport;
+
+public class InstrumentationLifecycleStrategy implements LifecycleStrategy {
+ InstrumentationAgent agent;
+ CamelNamingStrategy naming;
+
+ public InstrumentationLifecycleStrategy(InstrumentationAgent agent) {
+ this.agent = agent;
+ naming = new CamelNamingStrategy(agent.getMBeanServer().getDefaultDomain());
+ }
+
+ public void onContextCreate(CamelContext context) {
+ if (context instanceof DefaultCamelContext) {
+ try {
+ DefaultCamelContext dc = (DefaultCamelContext)context;
+ ManagedService ms = new ManagedService(dc);
+ agent.register(ms, naming.getObjectName(dc));
+ }
+ catch(JMException e) {
+ // log a WARN
+ }
+ }
+ }
+
+ public void onEndpointAdd(Endpoint endpoint) {
+ try {
+ ManagedEndpoint me = new ManagedEndpoint(endpoint);
+ agent.register(me, naming.getObjectName(me));
+ }
+ catch(JMException e) {
+ // log a WARN
+ }
+ }
+
+ public void onRoutesAdd(Collection<Route> routes) {
+ for (Route route: routes) {
+ try {
+ ManagedRoute mr = new ManagedRoute(route);
+ agent.register(mr, naming.getObjectName(mr));
+ }
+ catch(JMException e) {
+ // log a WARN
+ }
+ }
+ }
+
+ public void onServiceAdd(CamelContext context, Service service) {
+ if (service instanceof ServiceSupport) {
+ try {
+ ManagedService ms = new ManagedService((ServiceSupport)service);
+ agent.register(ms, naming.getObjectName(context, ms));
+ }
+ catch(JMException e) {
+ // log a WARN
+ }
+ }
+ }
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationLifecycleStrategy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/ManagedEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/ManagedEndpoint.java?view=auto&rev=565270
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/ManagedEndpoint.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/ManagedEndpoint.java Mon Aug 13 01:46:57 2007
@@ -0,0 +1,43 @@
+/**
+ *
+ * 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 org.apache.camel.Endpoint;
+import org.springframework.jmx.export.annotation.ManagedAttribute;
+import org.springframework.jmx.export.annotation.ManagedResource;
+
+@ManagedResource(
+        description="Managed Endpoint",
+        currencyTimeLimit=15)
+public class ManagedEndpoint {
+
+ private Endpoint endpoint;
+
+ public ManagedEndpoint(Endpoint endpoint) {
+ this.endpoint = endpoint;
+ }
+
+ public Endpoint getEndpoint() {
+ return endpoint;
+ }
+
+ @ManagedAttribute(description = "Endpoint Uri")
+ public String getUri() throws Exception {
+ return endpoint.getEndpointUri();
+ }
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/ManagedEndpoint.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/ManagedRoute.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/ManagedRoute.java?view=auto&rev=565270
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/ManagedRoute.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/ManagedRoute.java Mon Aug 13 01:46:57 2007
@@ -0,0 +1,59 @@
+/**
+ *
+ * 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 java.io.IOException;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.Route;
+import org.springframework.jmx.export.annotation.ManagedAttribute;
+import org.springframework.jmx.export.annotation.ManagedOperation;
+import org.springframework.jmx.export.annotation.ManagedResource;
+
+@ManagedResource(
+        description="Managed Route",
+        currencyTimeLimit=15)
+public class ManagedRoute{
+
+ public static final String VALUE_UNKNOWN = "Unknown";
+ private Route route;
+
+ ManagedRoute(Route route) {
+ this.route = route;
+ }
+
+ public Route getRoute() {
+ return route;
+ }
+
+ @ManagedAttribute(description = "Route Endpoint Uri")
+ public String getEndpointUri() {
+ Endpoint ep = route.getEndpoint();
+ return ep != null ? ep.getEndpointUri() : VALUE_UNKNOWN;
+ }
+
+ @ManagedOperation(description = "Start Route")
+    public void start() throws IOException {
+ throw new IOException("Not supported");
+    }
+
+ @ManagedOperation(description = "Stop Route")
+    public void stop() throws IOException {
+ throw new IOException("Not supported");
+    }
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/ManagedRoute.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/ManagedService.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/ManagedService.java?view=auto&rev=565270
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/ManagedService.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/ManagedService.java Mon Aug 13 01:46:57 2007
@@ -0,0 +1,67 @@
+/**
+ *
+ * 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 java.io.IOException;
+
+import org.apache.camel.Service;
+import org.apache.camel.impl.ServiceSupport;
+import org.springframework.jmx.export.annotation.ManagedAttribute;
+import org.springframework.jmx.export.annotation.ManagedOperation;
+import org.springframework.jmx.export.annotation.ManagedResource;
+
+@ManagedResource(
+        description="Managed Service",
+        currencyTimeLimit=15)
+public class ManagedService {
+
+ private ServiceSupport service;
+    
+ public ManagedService(ServiceSupport service) {
+ this.service = service;
+ }
+
+ public Service getService() {
+ return service;
+ }
+
+ @ManagedAttribute(description = "Service running state")
+    private boolean isStarted() throws IOException {
+     return service.isStarted();
+    }
+
+ @ManagedOperation(description = "Start Service")
+    public void start() throws IOException {
+     try {
+     service.start();
+     }
+     catch (Exception e) {
+     throw new IOException(e.getMessage());
+     }
+ }
+
+ @ManagedOperation(description = "Stop Service")
+ public void stop() throws IOException {
+     try {
+     service.stop();
+     }
+     catch (Exception e) {
+     throw new IOException(e.getMessage());
+     }
+ }
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/ManagedService.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java?view=diff&rev=565270&r1=565269&r2=565270
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java (original)
+++ activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java Mon Aug 13 01:46:57 2007
@@ -91,7 +91,11 @@
         getContext();
 
         LOG.debug("Found JAXB created routes: " + getRoutes());
-
+        String[] names = applicationContext.getBeanNamesForType(SpringInstrumentationAgent.class);
+        if (names.length == 1) {
+            applicationContext.getBean(names[0], SpringInstrumentationAgent.class);
+        }
+        
         findRouteBuiders();
         installRoutes();
     }

Added: activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringInstrumentationAgent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringInstrumentationAgent.java?view=auto&rev=565270
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringInstrumentationAgent.java (added)
+++ activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringInstrumentationAgent.java Mon Aug 13 01:46:57 2007
@@ -0,0 +1,33 @@
+/**
+ *
+ * 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.spring;
+
+import org.apache.camel.management.InstrumentationAgentImpl;
+import org.springframework.beans.factory.DisposableBean;
+import org.springframework.beans.factory.InitializingBean;
+
+public class SpringInstrumentationAgent extends InstrumentationAgentImpl
+        implements InitializingBean, DisposableBean {
+
+ public void afterPropertiesSet() throws Exception {
+ start();
+ }
+
+ public void destroy() throws Exception {
+ }
+}

Propchange: activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringInstrumentationAgent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/managment/JmxInstrumentationWithConnectorTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/managment/JmxInstrumentationWithConnectorTest.java?view=auto&rev=565270
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/managment/JmxInstrumentationWithConnectorTest.java (added)
+++ activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/managment/JmxInstrumentationWithConnectorTest.java Mon Aug 13 01:46:57 2007
@@ -0,0 +1,37 @@
+/**
+ *
+ * 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.spring.managment;
+
+import org.apache.camel.InstrumentationAgent;
+import org.apache.camel.spring.EndpointReferenceTest;
+import org.apache.camel.spring.SpringInstrumentationAgent;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class JmxInstrumentationWithConnectorTest extends EndpointReferenceTest {
+
+    public void testJmxConfiguration() throws Exception {
+        InstrumentationAgent agent = getMandatoryBean(SpringInstrumentationAgent.class, "agent");
+        assertNotNull("SpringInstrumentationAgent must be configured for JMX support", agent);
+        assertNotNull("MBeanServer must be configured for JMX support", agent.getMBeanServer());
+    }
+
+    @Override
+ protected ClassPathXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/camel/spring/management/jmxInstrumentationWithConnector.xml");
+ }
+}

Propchange: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/managment/JmxInstrumentationWithConnectorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/management/jmxInstrumentationWithConnector.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/management/jmxInstrumentationWithConnector.xml?view=auto&rev=565270
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/management/jmxInstrumentationWithConnector.xml (added)
+++ activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/management/jmxInstrumentationWithConnector.xml Mon Aug 13 01:46:57 2007
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
+       http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
+    ">
+
+  <!-- START SNIPPET: example -->
+  <bean id="mybean" class="org.apache.camel.spring.example.DummyBean">
+    <property name="endpoint" ref="endpoint1"/>
+  </bean>
+  <camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring">
+    <beanPostProcessor/>
+    <endpoint id="endpoint1" uri="direct:start"/>
+    <endpoint id="endpoint2" uri="mock:end"/>
+
+    <route>
+      <from ref="endpoint1"/>
+      <to ref="endpoint2"/>
+    </route>
+  </camelContext>
+
+  <bean id="agent" class="org.apache.camel.spring.SpringInstrumentationAgent">
+    <property name="camelContext" ref="camel"/>
+    <property name="MBeanServer" ref="mbeanServer"/>
+  </bean>
+  <!--
+    this bean needs to be eagerly pre-instantiated in order for the exporting to occur;
+    this means that it must not be marked as lazily initialized
+  -->
+  <bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean">
+    <property name="defaultDomain" value="org.apache.camel.test"/>
+  </bean>
+  <bean id="registry" class="org.springframework.remoting.rmi.RmiRegistryFactoryBean">
+    <property name="port" value="1099"/>
+  </bean>
+  <bean id="serverConnector"
+      class="org.springframework.jmx.support.ConnectorServerFactoryBean" depends-on="registry">
+    <property name="objectName" value="connector:name=rmi"/>
+    <property name="serviceUrl"
+      value="service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi"/>
+    <property name="threaded" value="true"/>
+    <property name="daemon" value="true"/>
+  </bean>
+  <!-- END SNIPPET: example -->
+
+</beans>

Propchange: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/management/jmxInstrumentationWithConnector.xml
------------------------------------------------------------------------------
    svn:eol-style = native