Author: ningjiang
Date: Fri May 16 03:35:58 2008
New Revision: 657010

URL: http://svn.apache.org/viewvc?rev=657010&view=rev
Log:
CAMEL-512 added the spring configuration support for creating the JMX agent

Added:
    
activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelJMXAgentType.java
   (with props)
    
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/DefaultJMXAgentTest.java
   (with props)
    
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/JMXAgentTest.java
   (with props)
    
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/defaultJmxConfig.xml
   (with props)
    
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/jmxConfig.xml
   (with props)
Modified:
    
activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
    
activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
    
activemq/camel/trunk/components/camel-spring/src/main/resources/org/apache/camel/spring/jaxb.index

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?rev=657010&r1=657009&r2=657010&view=diff
==============================================================================
--- 
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
 Fri May 16 03:35:58 2008
@@ -70,12 +70,13 @@
     private Boolean autowireRouteBuilders = Boolean.TRUE;
     @XmlElement(name = "package", required = false)
     private String[] packages = {};
+    @XmlElement(name = "jmxAgent", type = CamelJMXAgentType.class, required = 
false)
+    private CamelJMXAgentType camelJMXAgent;
     @XmlElements({
         @XmlElement(name = "beanPostProcessor", type = 
CamelBeanPostProcessor.class, required = false),
         @XmlElement(name = "template", type = CamelTemplateFactoryBean.class, 
required = false),
         @XmlElement(name = "proxy", type = CamelProxyFactoryType.class, 
required = false),
-        @XmlElement(name = "export", type = CamelServiceExporterType.class, 
required = false),
-        @XmlElement(name = "jmxAgent", required = false)})
+        @XmlElement(name = "export", type = CamelServiceExporterType.class, 
required = false)})
     private List beans;
     @XmlElement(name = "routeBuilderRef", required = false)
     private List<RouteBuilderRef> builderRefs = new 
ArrayList<RouteBuilderRef>();
@@ -100,6 +101,7 @@
     @XmlTransient
     private BeanPostProcessor beanPostProcessor;
 
+
     public CamelContextFactoryBean() {
 
         // Lets keep track of the class loader for when we actually do start 
things up
@@ -131,9 +133,14 @@
         }
         // lets force any lazy creation
         getContext().addRouteDefinitions(routes);
-
+        // set the instrumentation agent here
         if (instrumentationAgent == null && isJmxEnabled()) {
             SpringInstrumentationAgent agent = new 
SpringInstrumentationAgent();
+            if (camelJMXAgent != null) {
+                agent.enableJmx(camelJMXAgent.getJmxDomainName(), 
camelJMXAgent.getConnectorPort());
+            } else {
+                agent.enableJmx(SpringInstrumentationAgent.DEFAULT_DOMAIN, 
SpringInstrumentationAgent.DEFAULT_PORT);
+            }
             agent.setCamelContext(getContext());
             String name = getMbeanServer();
             if (name != null) {
@@ -272,6 +279,14 @@
         this.useJmx = useJmx;
     }
 
+    public void setCamelJMXAgent(CamelJMXAgentType agent) {
+        camelJMXAgent = agent;
+    }
+
+    public CamelJMXAgentType getCamelJMXAgent() {
+        return camelJMXAgent;
+    }
+
     public List<RouteBuilderRef> getBuilderRefs() {
         return builderRefs;
     }

Added: 
activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelJMXAgentType.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelJMXAgentType.java?rev=657010&view=auto
==============================================================================
--- 
activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelJMXAgentType.java
 (added)
+++ 
activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelJMXAgentType.java
 Fri May 16 03:35:58 2008
@@ -0,0 +1,57 @@
+/**
+ * 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 javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.model.IdentifiedType;
+
+/**
+ * The JAXB type class for the configuration of jmxAgent
+ * @author Willem Jiang
+ *
+ * @version $Revision:$
+ */
[EMAIL PROTECTED](name = "jmxAgent")
[EMAIL PROTECTED](XmlAccessType.FIELD)
+public class CamelJMXAgentType extends IdentifiedType {
+    @XmlAttribute
+    private Integer connectorPort;
+    @XmlAttribute
+    private String jmxDomainName;
+
+    public void setConnectorPort(Integer port) {
+        connectorPort = port;
+    }
+
+    public Integer getConnectorPort() {
+        return connectorPort;
+    }
+
+    public void setJmxDomainName(String name) {
+        jmxDomainName = name;
+    }
+
+    public String getJmxDomainName() {
+        return jmxDomainName;
+    }
+
+}

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

Propchange: 
activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelJMXAgentType.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: 
activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java?rev=657010&r1=657009&r2=657010&view=diff
==============================================================================
--- 
activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
 (original)
+++ 
activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
 Fri May 16 03:35:58 2008
@@ -41,6 +41,7 @@
 import org.apache.camel.spi.NamespaceAware;
 import org.apache.camel.spring.CamelBeanPostProcessor;
 import org.apache.camel.spring.CamelContextFactoryBean;
+import org.apache.camel.spring.CamelJMXAgentType;
 import org.apache.camel.spring.CamelTemplateFactoryBean;
 import org.apache.camel.spring.EndpointFactoryBean;
 import org.apache.camel.spring.remoting.CamelProxyFactoryBean;
@@ -84,6 +85,9 @@
         addBeanDefinitionParser("sticky", StickyLoadBalanceStrategy.class);
         addBeanDefinitionParser("topic", TopicLoadBalanceStrategy.class);
 
+        // jmx agent
+        addBeanDefinitionParser("jmxAgent", CamelJMXAgentType.class);
+
         // TODO switch to use the above mechanism?
         registerParser("endpoint", endpointParser);
 
@@ -208,8 +212,12 @@
                             String id = childElement.getAttribute("id");
                             if (ObjectHelper.isNotNullAndNonEmpty(id)) {
                                 parserContext.registerComponent(new 
BeanComponentDefinition(definition, id));
+                                if (localName.equals("jmxAgent")) {
+                                    
builder.addPropertyReference("camelJMXAgent", id);
+                                }
                             }
                         }
+
                     }
                 }
             }

Modified: 
activemq/camel/trunk/components/camel-spring/src/main/resources/org/apache/camel/spring/jaxb.index
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/main/resources/org/apache/camel/spring/jaxb.index?rev=657010&r1=657009&r2=657010&view=diff
==============================================================================
--- 
activemq/camel/trunk/components/camel-spring/src/main/resources/org/apache/camel/spring/jaxb.index
 (original)
+++ 
activemq/camel/trunk/components/camel-spring/src/main/resources/org/apache/camel/spring/jaxb.index
 Fri May 16 03:35:58 2008
@@ -20,3 +20,4 @@
 CamelServiceExporterType
 CamelTemplateFactoryBean
 EndpointFactoryBean
+CamelJMXAgentType

Added: 
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/DefaultJMXAgentTest.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/DefaultJMXAgentTest.java?rev=657010&view=auto
==============================================================================
--- 
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/DefaultJMXAgentTest.java
 (added)
+++ 
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/DefaultJMXAgentTest.java
 Fri May 16 03:35:58 2008
@@ -0,0 +1,51 @@
+/**
+ * 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 java.net.MalformedURLException;
+
+import javax.management.MBeanServerConnection;
+import javax.management.remote.JMXConnector;
+import javax.management.remote.JMXConnectorFactory;
+import javax.management.remote.JMXServiceURL;
+
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class DefaultJMXAgentTest extends SpringTestSupport {
+
+    protected String getPort() {
+        return "1099";
+    }
+
+    protected String getDomainName() {
+        return "org.apache.camel";
+    }
+
+    public void testGetJMXConnector() throws Exception {
+        JMXServiceURL url = new 
JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:" + getPort() + 
"/jmxrmi");
+        JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
+        MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
+        assertNotNull(mbsc);
+        assertEquals("Get the wrong domain name", mbsc.getDefaultDomain(), 
getDomainName());
+    }
+
+    @Override
+    protected ClassPathXmlApplicationContext createApplicationContext() {
+        return new 
ClassPathXmlApplicationContext("org/apache/camel/spring/defaultJmxConfig.xml");
+    }
+
+}

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

Propchange: 
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/DefaultJMXAgentTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/JMXAgentTest.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/JMXAgentTest.java?rev=657010&view=auto
==============================================================================
--- 
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/JMXAgentTest.java
 (added)
+++ 
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/JMXAgentTest.java
 Fri May 16 03:35:58 2008
@@ -0,0 +1,45 @@
+/**
+ * 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 java.net.MalformedURLException;
+
+import javax.management.MBeanServerConnection;
+import javax.management.remote.JMXConnector;
+import javax.management.remote.JMXConnectorFactory;
+import javax.management.remote.JMXServiceURL;
+
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class JMXAgentTest extends DefaultJMXAgentTest {
+
+    @Override
+    protected String getPort() {
+        return "20008";
+    }
+
+    @Override
+    protected String getDomainName() {
+        return "org.apache.camel.test";
+    }
+
+    @Override
+    protected ClassPathXmlApplicationContext createApplicationContext() {
+        return new 
ClassPathXmlApplicationContext("org/apache/camel/spring/jmxConfig.xml");
+    }
+
+}

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

Propchange: 
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/JMXAgentTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/defaultJmxConfig.xml
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/defaultJmxConfig.xml?rev=657010&view=auto
==============================================================================
--- 
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/defaultJmxConfig.xml
 (added)
+++ 
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/defaultJmxConfig.xml
 Fri May 16 03:35:58 2008
@@ -0,0 +1,34 @@
+<?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 -->
+  <camelContext id="camel" useJmx="true" 
xmlns="http://activemq.apache.org/camel/schema/spring";>
+    <route>
+      <from uri="seda:start"/>
+      <to uri="mock:result"/>
+    </route>
+  </camelContext>
+  <!-- END SNIPPET: example -->
+
+</beans>

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

Propchange: 
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/defaultJmxConfig.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: 
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/defaultJmxConfig.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: 
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/jmxConfig.xml
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/jmxConfig.xml?rev=657010&view=auto
==============================================================================
--- 
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/jmxConfig.xml
 (added)
+++ 
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/jmxConfig.xml
 Fri May 16 03:35:58 2008
@@ -0,0 +1,35 @@
+<?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 -->
+  <camelContext id="camel" useJmx="true" 
xmlns="http://activemq.apache.org/camel/schema/spring";>
+    <jmxAgent id="agent" connectorPort="20008" 
jmxDomainName="org.apache.camel.test"/>
+    <route>
+      <from uri="seda:start"/>
+      <to uri="mock:result"/>
+    </route>
+  </camelContext>
+  <!-- END SNIPPET: example -->
+
+</beans>

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

Propchange: 
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/jmxConfig.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: 
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/jmxConfig.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml


Reply via email to