camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1153158 - in /camel/trunk/components/camel-spring/src: main/java/org/apache/camel/spring/spi/ test/java/org/apache/camel/spring/management/ test/resources/org/apache/camel/spring/management/
Date Tue, 02 Aug 2011 15:10:27 GMT
Author: davsclaus
Date: Tue Aug  2 15:10:24 2011
New Revision: 1153158

URL: http://svn.apache.org/viewvc?rev=1153158&view=rev
Log:
CAMEL-4249: Camel now check if managed object has Spring JMX annotations and use those, if
not it fallback and use the default from camel-core.

Added:
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/management/SpringManagedCustomProcessorTest.java
      - copied, changed from r1153091, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/management/SpringJmxEndpointInjectBeanTest.java
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/management/SpringManagedCustomProcessorTest.xml
      - copied, changed from r1153091, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/management/SpringJmxRecipientListTest.xml
Modified:
    camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/SpringManagementMBeanAssembler.java

Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/SpringManagementMBeanAssembler.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/SpringManagementMBeanAssembler.java?rev=1153158&r1=1153157&r2=1153158&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/SpringManagementMBeanAssembler.java
(original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/SpringManagementMBeanAssembler.java
Tue Aug  2 15:10:24 2011
@@ -48,12 +48,6 @@ public class SpringManagementMBeanAssemb
     }
 
     public ModelMBean assemble(MBeanServer mBeanServer, Object obj, ObjectName name) throws
JMException {
-        // try the default first, and if it could assemble the object, then use that as is
-        ModelMBean mbean = super.assemble(mBeanServer, obj, name);
-        if (mbean != null) {
-            return mbean;
-        }
-
         ModelMBeanInfo mbi = null;
 
         // prefer to use the managed instance if it has been annotated with Spring JMX annotations
@@ -69,12 +63,19 @@ public class SpringManagementMBeanAssemb
         }
 
         if (mbi == null) {
-            // use the default provided mbean which has been annotated with Spring JMX annotations
-            log.trace("Assembling MBeanInfo for: {} from @ManagedResource object: {}", name,
obj);
-            mbi = assembler.getMBeanInfo(obj, name.toString());
+            if (ObjectHelper.hasAnnotation(obj.getClass().getAnnotations(), ManagedResource.class))
{
+                // the object has a Spring ManagedResource annotations so assemble the MBeanInfo
+                log.trace("Assembling MBeanInfo for: {} from @ManagedResource object: {}",
name, obj);
+                mbi = assembler.getMBeanInfo(obj, name.toString());
+            } else {
+                // fallback and let the default mbean assembler handle this instead
+                return super.assemble(mBeanServer, obj, name);
+            }
         }
 
-        mbean = (RequiredModelMBean) mBeanServer.instantiate(RequiredModelMBean.class.getName());
+        log.trace("Assembled MBeanInfo {}", mbi);
+
+        ModelMBean mbean = (RequiredModelMBean) mBeanServer.instantiate(RequiredModelMBean.class.getName());
         mbean.setModelMBeanInfo(mbi);
 
         try {

Copied: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/management/SpringManagedCustomProcessorTest.java
(from r1153091, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/management/SpringJmxEndpointInjectBeanTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/management/SpringManagedCustomProcessorTest.java?p2=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/management/SpringManagedCustomProcessorTest.java&p1=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/management/SpringJmxEndpointInjectBeanTest.java&r1=1153091&r2=1153158&rev=1153158&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/management/SpringJmxEndpointInjectBeanTest.java
(original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/management/SpringManagedCustomProcessorTest.java
Tue Aug  2 15:10:24 2011
@@ -16,41 +16,72 @@
  */
 package org.apache.camel.spring.management;
 
+import javax.management.Attribute;
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
 
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
 import org.apache.camel.spring.SpringTestSupport;
 import org.springframework.context.support.AbstractXmlApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.jmx.export.annotation.ManagedAttribute;
+import org.springframework.jmx.export.annotation.ManagedResource;
 
 /**
  * @version 
  */
-public class SpringJmxEndpointInjectBeanTest extends SpringTestSupport {
+public class SpringManagedCustomProcessorTest extends SpringTestSupport {
 
     @Override
     protected AbstractXmlApplicationContext createApplicationContext() {
-        return new ClassPathXmlApplicationContext("org/apache/camel/spring/management/SpringJmxEndpointInjectBeanTest.xml");
+        return new ClassPathXmlApplicationContext("org/apache/camel/spring/management/SpringManagedCustomProcessorTest.xml");
     }
 
     protected MBeanServer getMBeanServer() {
         return context.getManagementStrategy().getManagementAgent().getMBeanServer();
     }
 
-    public void testJmxEndpointInjectBean() throws Exception {
+    public void testManageCustomProcessor() throws Exception {
         MBeanServer mbeanServer = getMBeanServer();
+        ObjectName on = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=processors,name=\"custom\"");
 
-        ObjectName on = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=components,name=\"seda\"");
-        assertTrue(mbeanServer.isRegistered(on));
+        getMockEndpoint("mock:result").expectedMessageCount(1);
+        getMockEndpoint("mock:result").expectedHeaderReceived("foo", "hey");
+        template.sendBody("direct:start", "Hello World");
+        assertMockEndpointsSatisfied();
 
-        on = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=endpoints,name=\"seda://foo\"");
-        assertTrue(mbeanServer.isRegistered(on));
-        String uri = (String) mbeanServer.getAttribute(on, "EndpointUri");
-        assertEquals("seda://foo", uri);
+        String foo = (String) mbeanServer.getAttribute(on, "Foo");
+        assertEquals("hey", foo);
 
-        getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
-        template.sendBody("direct:start", "Hello World");
+        // change foo
+        mbeanServer.setAttribute(on, new Attribute("Foo", "changed"));
+
+        resetMocks();
+
+        getMockEndpoint("mock:result").expectedMessageCount(1);
+        getMockEndpoint("mock:result").expectedHeaderReceived("foo", "changed");
+        template.sendBody("direct:start", "Bye World");
         assertMockEndpointsSatisfied();
     }
 
+    @ManagedResource(description = "My Managed Component")
+    public static class MyCustomProcessor implements Processor {
+        private String foo = "hey";
+
+        @ManagedAttribute(description = "Foo is the foo")
+        public String getFoo() {
+            return foo;
+        }
+
+        @ManagedAttribute(description = "Foo is the foo")
+        public void setFoo(String foo) {
+            this.foo = foo;
+        }
+
+        public void process(Exchange exchange) throws Exception {
+            exchange.getIn().setHeader("foo", getFoo());
+        }
+    }
+
 }

Copied: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/management/SpringManagedCustomProcessorTest.xml
(from r1153091, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/management/SpringJmxRecipientListTest.xml)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/management/SpringManagedCustomProcessorTest.xml?p2=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/management/SpringManagedCustomProcessorTest.xml&p1=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/management/SpringJmxRecipientListTest.xml&r1=1153091&r2=1153158&rev=1153158&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/management/SpringJmxRecipientListTest.xml
(original)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/management/SpringManagedCustomProcessorTest.xml
Tue Aug  2 15:10:24 2011
@@ -22,26 +22,22 @@
        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
     ">
 
-    <bean id="naming" class="org.apache.camel.management.DefaultManagementNamingStrategy">
-        <property name="hostName" value="localhost"/>
-        <property name="domainName" value="org.apache.camel"/>
-    </bean>
+  <bean id="myProcessor" class="org.apache.camel.spring.management.SpringManagedCustomProcessorTest$MyCustomProcessor"/>
 
-    <!-- START SNIPPET: e1 -->
-    <camelContext xmlns="http://camel.apache.org/schema/spring">
-        <!-- enable JMX -->
-        <jmxAgent id="agent" disabled="false"/>
+  <bean id="naming" class="org.apache.camel.management.DefaultManagementNamingStrategy">
+    <property name="hostName" value="localhost"/>
+    <property name="domainName" value="org.apache.camel"/>
+  </bean>
 
-        <route>
-            <from uri="direct:a"/>
-            <!-- this is a dynamic EIP so we may register mbeans after the route has started
-                 such as new endpoints, and its associated producers. Camel does NOT do this
-                 by default, you would have to enable that on the jmxAgent if you want this.
-->
-            <recipientList>
-                <header>recipientListHeader</header>
-            </recipientList>
-        </route>
-    </camelContext>
-    <!-- END SNIPPET: e1 -->
+  <camelContext xmlns="http://camel.apache.org/schema/spring">
+    <!-- enable JMX -->
+    <jmxAgent id="agent" disabled="false"/>
+
+    <route>
+      <from uri="direct:start"/>
+      <process ref="myProcessor" id="custom"/>
+      <to uri="mock:result"/>
+    </route>
+  </camelContext>
 
 </beans>



Mime
View raw message