camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1237666 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/component/seda/ camel-core/src/main/java/org/apache/camel/management/ camel-core/src/main/java/org/apache/camel/management/mbean/ camel-core/src/test/java/org/apache/came...
Date Mon, 30 Jan 2012 14:11:10 GMT
Author: davsclaus
Date: Mon Jan 30 14:11:10 2012
New Revision: 1237666

URL: http://svn.apache.org/viewvc?rev=1237666&view=rev
Log:
CAMEL-4938: Fixed seda endpoint with JMX not being able to invoke certain methods.

Added:
    camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedSedaEndpoint.java
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/management/SpringManagedSedaEndpointTest.java
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/management/SpringManagedSedaEndpointTest.xml
      - copied, changed from r1237572, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/management/SpringManagedNamePatternTest.xml
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/SedaEndpoint.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementObjectStrategy.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedSedaEndpointTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/SedaEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/SedaEndpoint.java?rev=1237666&r1=1237665&r2=1237666&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/SedaEndpoint.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/SedaEndpoint.java
Mon Jan 30 14:11:10 2012
@@ -32,9 +32,6 @@ import org.apache.camel.MultipleConsumer
 import org.apache.camel.Processor;
 import org.apache.camel.Producer;
 import org.apache.camel.WaitForTaskToComplete;
-import org.apache.camel.api.management.ManagedAttribute;
-import org.apache.camel.api.management.ManagedOperation;
-import org.apache.camel.api.management.ManagedResource;
 import org.apache.camel.impl.DefaultEndpoint;
 import org.apache.camel.processor.MulticastProcessor;
 import org.apache.camel.spi.BrowsableEndpoint;
@@ -45,7 +42,6 @@ import org.apache.camel.util.ServiceHelp
  * href="http://camel.apache.org/queue.html">Queue components</a> for
  * asynchronous SEDA exchanges on a {@link BlockingQueue} within a CamelContext
  */
-@ManagedResource(description = "Managed SedaEndpoint")
 public class SedaEndpoint extends DefaultEndpoint implements BrowsableEndpoint, MultipleConsumersSupport
{
     private volatile BlockingQueue<Exchange> queue;
     private int size;
@@ -137,7 +133,6 @@ public class SedaEndpoint extends Defaul
         this.size = queue.remainingCapacity();
     }
 
-    @ManagedAttribute(description = "Queue max capacity")
     public int getSize() {
         return size;
     }
@@ -146,7 +141,6 @@ public class SedaEndpoint extends Defaul
         this.size = size;
     }
 
-    @ManagedAttribute(description = "Current queue size")
     public int getCurrentQueueSize() {
         return queue.size();
     }
@@ -155,7 +149,6 @@ public class SedaEndpoint extends Defaul
         this.blockWhenFull = blockWhenFull;
     }
 
-    @ManagedAttribute(description = "Whether the caller will block sending to a full queue")
     public boolean isBlockWhenFull() {
         return blockWhenFull;
     }
@@ -164,12 +157,10 @@ public class SedaEndpoint extends Defaul
         this.concurrentConsumers = concurrentConsumers;
     }
 
-    @ManagedAttribute(description = "Number of concurrent consumers")
     public int getConcurrentConsumers() {
         return concurrentConsumers;
     }
 
-    @ManagedAttribute
     public WaitForTaskToComplete getWaitForTaskToComplete() {
         return waitForTaskToComplete;
     }
@@ -178,7 +169,6 @@ public class SedaEndpoint extends Defaul
         this.waitForTaskToComplete = waitForTaskToComplete;
     }
 
-    @ManagedAttribute
     public long getTimeout() {
         return timeout;
     }
@@ -187,7 +177,6 @@ public class SedaEndpoint extends Defaul
         this.timeout = timeout;
     }
 
-    @ManagedAttribute
     public boolean isMultipleConsumers() {
         return multipleConsumers;
     }
@@ -207,7 +196,6 @@ public class SedaEndpoint extends Defaul
         return new ArrayList<Exchange>(getQueue());
     }
 
-    @ManagedAttribute
     public boolean isMultipleConsumersSupported() {
         return isMultipleConsumers();
     }
@@ -215,7 +203,6 @@ public class SedaEndpoint extends Defaul
     /**
      * Purges the queue
      */
-    @ManagedOperation(description = "Purges the seda queue")
     public void purgeQueue() {
         queue.clear();
     }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementObjectStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementObjectStrategy.java?rev=1237666&r1=1237665&r2=1237666&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementObjectStrategy.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementObjectStrategy.java
Mon Jan 30 14:11:10 2012
@@ -29,6 +29,7 @@ import org.apache.camel.Producer;
 import org.apache.camel.Route;
 import org.apache.camel.Service;
 import org.apache.camel.component.bean.BeanProcessor;
+import org.apache.camel.component.seda.SedaEndpoint;
 import org.apache.camel.impl.ScheduledPollConsumer;
 import org.apache.camel.management.mbean.ManagedBeanProcessor;
 import org.apache.camel.management.mbean.ManagedBrowsableEndpoint;
@@ -43,6 +44,7 @@ import org.apache.camel.management.mbean
 import org.apache.camel.management.mbean.ManagedProducer;
 import org.apache.camel.management.mbean.ManagedRoute;
 import org.apache.camel.management.mbean.ManagedScheduledPollConsumer;
+import org.apache.camel.management.mbean.ManagedSedaEndpoint;
 import org.apache.camel.management.mbean.ManagedSendProcessor;
 import org.apache.camel.management.mbean.ManagedService;
 import org.apache.camel.management.mbean.ManagedSuspendableRoute;
@@ -90,6 +92,10 @@ public class DefaultManagementObjectStra
 
         if (endpoint instanceof org.apache.camel.spi.ManagementAware) {
             return ((org.apache.camel.spi.ManagementAware<Endpoint>) endpoint).getManagedObject(endpoint);
+        } else if (endpoint instanceof SedaEndpoint) {
+            ManagedSedaEndpoint me = new ManagedSedaEndpoint((SedaEndpoint) endpoint);
+            me.init(context.getManagementStrategy());
+            return me;
         } else if (endpoint instanceof BrowsableEndpoint) {
             ManagedBrowsableEndpoint me = new ManagedBrowsableEndpoint((BrowsableEndpoint)
endpoint);
             me.init(context.getManagementStrategy());

Added: camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedSedaEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedSedaEndpoint.java?rev=1237666&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedSedaEndpoint.java
(added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedSedaEndpoint.java
Mon Jan 30 14:11:10 2012
@@ -0,0 +1,107 @@
+/**
+ * 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.api.management.ManagedAttribute;
+import org.apache.camel.api.management.ManagedOperation;
+import org.apache.camel.api.management.ManagedResource;
+import org.apache.camel.component.seda.SedaEndpoint;
+
+/**
+ *
+ */
+@ManagedResource(description = "Managed SedaEndpoint")
+public class ManagedSedaEndpoint extends ManagedBrowsableEndpoint {
+
+    public ManagedSedaEndpoint(SedaEndpoint endpoint) {
+        super(endpoint);
+    }
+
+    @Override
+    public SedaEndpoint getInstance() {
+        return getEndpoint();
+    }
+
+    @Override
+    public SedaEndpoint getEndpoint() {
+        return (SedaEndpoint) super.getEndpoint();
+    }
+
+    @ManagedAttribute(description = "Queue max capacity")
+    public int getSize() {
+        return getEndpoint().getSize();
+    }
+
+    public void setSize(int size) {
+        getEndpoint().setSize(size);
+    }
+
+    @ManagedAttribute(description = "Current queue size")
+    public int getCurrentQueueSize() {
+        return getEndpoint().getCurrentQueueSize();
+    }
+
+    public void setBlockWhenFull(boolean blockWhenFull) {
+        getEndpoint().setBlockWhenFull(blockWhenFull);
+    }
+
+    @ManagedAttribute(description = "Whether the caller will block sending to a full queue")
+    public boolean isBlockWhenFull() {
+        return getEndpoint().isBlockWhenFull();
+    }
+
+    public void setConcurrentConsumers(int concurrentConsumers) {
+        getEndpoint().setConcurrentConsumers(concurrentConsumers);
+    }
+
+    @ManagedAttribute(description = "Number of concurrent consumers")
+    public int getConcurrentConsumers() {
+        return getEndpoint().getConcurrentConsumers();
+    }
+
+    @ManagedAttribute
+    public long getTimeout() {
+        return getEndpoint().getTimeout();
+    }
+
+    public void setTimeout(long timeout) {
+        getEndpoint().setTimeout(timeout);
+    }
+
+    @ManagedAttribute
+    public boolean isMultipleConsumers() {
+        return getEndpoint().isMultipleConsumers();
+    }
+
+    @ManagedAttribute
+    public boolean isMultipleConsumersSupported() {
+        return isMultipleConsumers();
+    }
+
+    public void setMultipleConsumers(boolean multipleConsumers) {
+        getEndpoint().setMultipleConsumers(multipleConsumers);
+    }
+
+    /**
+     * Purges the queue
+     */
+    @ManagedOperation(description = "Purges the seda queue")
+    public void purgeQueue() {
+        getEndpoint().purgeQueue();
+    }
+
+}

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedSedaEndpointTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedSedaEndpointTest.java?rev=1237666&r1=1237665&r2=1237666&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedSedaEndpointTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedSedaEndpointTest.java
Mon Jan 30 14:11:10 2012
@@ -55,6 +55,13 @@ public class ManagedSedaEndpointTest ext
         size = (Integer) mbeanServer.getAttribute(name, "CurrentQueueSize");
         assertEquals(1, size.intValue());
 
+        Long size2 = (Long) mbeanServer.invoke(name, "queueSize", null, null);
+        assertEquals(1, size2.longValue());
+
+        String out = (String) mbeanServer.invoke(name, "browseExchange", new Object[]{0},
new String[]{"java.lang.Integer"});
+        assertNotNull(out);
+        assertTrue(out.contains("Hi World"));
+
         mbeanServer.invoke(name, "purgeQueue", null, null);
 
         size = (Integer) mbeanServer.getAttribute(name, "CurrentQueueSize");

Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/management/SpringManagedSedaEndpointTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/management/SpringManagedSedaEndpointTest.java?rev=1237666&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/management/SpringManagedSedaEndpointTest.java
(added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/management/SpringManagedSedaEndpointTest.java
Mon Jan 30 14:11:10 2012
@@ -0,0 +1,81 @@
+/**
+ * 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.management;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.apache.camel.spring.SpringTestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ *
+ */
+public class SpringManagedSedaEndpointTest extends SpringTestSupport {
+
+    @Override
+    protected AbstractXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/camel/spring/management/SpringManagedSedaEndpointTest.xml");
+    }
+
+    protected MBeanServer getMBeanServer() {
+        return context.getManagementStrategy().getManagementAgent().getMBeanServer();
+    }
+
+    public void testSedaEndpoint() throws Exception {
+        getMockEndpoint("mock:result").expectedMessageCount(2);
+
+        template.sendBody("seda:start", "Hello World");
+        template.sendBody("seda:start", "Bye World");
+
+        assertMockEndpointsSatisfied();
+
+        MBeanServer mbeanServer = getMBeanServer();
+
+        ObjectName name = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=endpoints,name=\"seda://start\"");
+        String uri = (String) mbeanServer.getAttribute(name, "EndpointUri");
+        assertEquals("seda://start", uri);
+
+        Long timeout = (Long) mbeanServer.getAttribute(name, "Timeout");
+        assertEquals(30000, timeout.intValue());
+
+        Integer size = (Integer) mbeanServer.getAttribute(name, "CurrentQueueSize");
+        assertEquals(0, size.intValue());
+
+        // stop route
+        context.stopRoute("foo");
+
+        // send a message to queue
+        template.sendBody("seda:start", "Hi World");
+
+        size = (Integer) mbeanServer.getAttribute(name, "CurrentQueueSize");
+        assertEquals(1, size.intValue());
+
+        Long size2 = (Long) mbeanServer.invoke(name, "queueSize", null, null);
+        assertEquals(1, size2.longValue());
+
+        String out = (String) mbeanServer.invoke(name, "browseExchange", new Object[]{0},
new String[]{"java.lang.Integer"});
+        assertNotNull(out);
+        assertTrue(out.contains("Hi World"));
+
+        mbeanServer.invoke(name, "purgeQueue", null, null);
+
+        size = (Integer) mbeanServer.getAttribute(name, "CurrentQueueSize");
+        assertEquals(0, size.intValue());
+    }
+}

Copied: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/management/SpringManagedSedaEndpointTest.xml
(from r1237572, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/management/SpringManagedNamePatternTest.xml)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/management/SpringManagedSedaEndpointTest.xml?p2=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/management/SpringManagedSedaEndpointTest.xml&p1=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/management/SpringManagedNamePatternTest.xml&r1=1237572&r2=1237666&rev=1237666&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/management/SpringManagedNamePatternTest.xml
(original)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/management/SpringManagedSedaEndpointTest.xml
Mon Jan 30 14:11:10 2012
@@ -27,15 +27,14 @@
     <property name="domainName" value="org.apache.camel"/>
   </bean>
 
-  <!-- START SNIPPET: example -->
-  <camelContext managementNamePattern="cool-#name#" xmlns="http://camel.apache.org/schema/spring">
+  <camelContext xmlns="http://camel.apache.org/schema/spring">
     <jmxAgent id="agent"/>
 
-    <route>
-      <from uri="direct:start"/>
+    <route id="foo">
+      <from uri="seda:start"/>
+      <to uri="log:foo"/>
       <to uri="mock:result"/>
     </route>
   </camelContext>
-  <!-- END SNIPPET: example -->
 
 </beans>



Mime
View raw message