camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r812052 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/impl/ main/java/org/apache/camel/management/ main/java/org/apache/camel/management/mbean/ test/java/org/apache/camel/management/
Date Mon, 07 Sep 2009 09:22:18 GMT
Author: davsclaus
Date: Mon Sep  7 09:22:18 2009
New Revision: 812052

URL: http://svn.apache.org/viewvc?rev=812052&view=rev
Log:
CAMEL-1933: Statistics can now be enabled/disabled from JMX management.

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedStatisticsDisabledTest.java
      - copied, changed from r812001, camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedDelayerTest.java
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ProducerCache.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationProcessor.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedPerformanceCounter.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ProducerCache.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ProducerCache.java?rev=812052&r1=812051&r2=812052&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ProducerCache.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ProducerCache.java Mon Sep
 7 09:22:18 2009
@@ -29,10 +29,10 @@
 import org.apache.camel.ServicePoolAware;
 import org.apache.camel.spi.ServicePool;
 import org.apache.camel.util.LRUCache;
-import static org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException;
 import org.apache.camel.util.ServiceHelper;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import static org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException;
 
 /**
  * Cache containing created {@link Producer}.

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationProcessor.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationProcessor.java?rev=812052&r1=812051&r2=812052&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationProcessor.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationProcessor.java
Mon Sep  7 09:22:18 2009
@@ -57,8 +57,8 @@
     public void process(Exchange exchange) throws Exception {
         if (processor != null) {
 
-            long startTime = 0;
-            if (counter != null) {
+            long startTime = -1;
+            if (counter != null && counter.isStatisticsEnabled()) {
                 startTime = System.currentTimeMillis();
             }
 
@@ -68,7 +68,7 @@
                 exchange.setException(e);
             }
 
-            if (counter != null) {
+            if (startTime != -1) {
                 recordTime(exchange, System.currentTimeMillis() - startTime);
             }
         }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedPerformanceCounter.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedPerformanceCounter.java?rev=812052&r1=812051&r2=812052&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedPerformanceCounter.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedPerformanceCounter.java
Mon Sep  7 09:22:18 2009
@@ -37,6 +37,7 @@
     private Statistic firstExchangeFailureTime;
     private Statistic lastExchangeCompletedTime;
     private Statistic lastExchangeFailureTime;
+    private boolean statisticsEnabled = true;
 
     public ManagedPerformanceCounter(ManagementStrategy strategy) {
         super(strategy);
@@ -129,6 +130,16 @@
         return value > 0 ? new Date(value) : null;
     }
 
+    @ManagedAttribute(description = "Statistics enabled")
+    public boolean isStatisticsEnabled() {
+        return statisticsEnabled;
+    }
+
+    @ManagedAttribute(description = "Statistics enabled")
+    public void setStatisticsEnabled(boolean statisticsEnabled) {
+        this.statisticsEnabled = statisticsEnabled;
+    }
+
     /**
      * This method is called when an exchange has been processed successfully.
      * 
@@ -166,4 +177,5 @@
         lastExchangeFailureTime.updateValue(now);
     }
 
+
 }

Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedStatisticsDisabledTest.java
(from r812001, camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedDelayerTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedStatisticsDisabledTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedStatisticsDisabledTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedDelayerTest.java&r1=812001&r2=812052&rev=812052&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedDelayerTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedStatisticsDisabledTest.java
Mon Sep  7 09:22:18 2009
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.management;
 
+import java.util.Set;
+import javax.management.Attribute;
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
 
@@ -26,7 +28,7 @@
 /**
  * @version $Revision$
  */
-public class ManagedDelayerTest extends ContextTestSupport {
+public class ManagedStatisticsDisabledTest extends ContextTestSupport {
 
     @Override
     protected CamelContext createCamelContext() throws Exception {
@@ -38,46 +40,51 @@
     }
 
     @SuppressWarnings("unchecked")
-    public void testManageDelay() throws Exception {
-        getMockEndpoint("mock:result").expectedMessageCount(1);
-
+    public void testManageStatisticsDisabled() throws Exception {
         template.sendBody("direct:start", "Hello World");
-
-        assertMockEndpointsSatisfied();
+        template.sendBody("direct:start", "Bye World");
 
         // get the stats for the route
         MBeanServer mbeanServer = context.getManagementStrategy().getManagementAgent().getMBeanServer();
 
-        // get the object name for the delayer
-        ObjectName delayerName = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=processors,name=\"mydelayer\"");
+        Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"),
null);
+        assertEquals(1, set.size());
+
+        ObjectName on = set.iterator().next();
 
         // use route to get the total time
-        ObjectName routeName = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=routes,name=\"route1\"");
-        Long completed = (Long) mbeanServer.getAttribute(routeName, "ExchangesCompleted");
-        assertEquals(1, completed.longValue());
+        Long completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
+        assertEquals(2, completed.longValue());
+        
+        // disable statistics
+        mbeanServer.setAttribute(on, new Attribute("StatisticsEnabled", false));
 
-        Long last = (Long) mbeanServer.getAttribute(routeName, "LastProcessingTime");
-        Long total = (Long) mbeanServer.getAttribute(routeName, "TotalProcessingTime");
+        // send in another message
+        template.sendBody("direct:start", "Goodday World");
 
-        assertTrue("Should take around 1 sec: was " + last, last > 900);
-        assertTrue("Should take around 1 sec: was " + total, total > 900);
+        // should stay at 2
+        completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
+        assertEquals(2, completed.longValue());
 
-        // change the delay time using JMX
-        mbeanServer.invoke(delayerName, "constantDelay", new Object[]{2000}, new String[]{"java.lang.Integer"});
+        // enable statistics
+        mbeanServer.setAttribute(on, new Attribute("StatisticsEnabled", true));
 
         // send in another message
-        template.sendBody("direct:start", "Bye World");
+        template.sendBody("direct:start", "Hi World");
 
-        Long delay = (Long) mbeanServer.getAttribute(delayerName, "Delay");
-        assertNotNull(delay);
+        // should now be 3
+        completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
+        assertEquals(3, completed.longValue());
 
-        completed = (Long) mbeanServer.getAttribute(routeName, "ExchangesCompleted");
-        assertEquals(2, completed.longValue());
-        last = (Long) mbeanServer.getAttribute(routeName, "LastProcessingTime");
-        total = (Long) mbeanServer.getAttribute(routeName, "TotalProcessingTime");
+        // now reset it
+        mbeanServer.invoke(on, "reset", null, null);
 
-        assertTrue("Should take around 2 sec: was " + last, last > 1900);
-        assertTrue("Should be around 3 sec now: was " + total, total > 2900);
+        // send in another message
+        template.sendBody("direct:start", "Hallo World");
+
+        // should now be 1
+        completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
+        assertEquals(1, completed.longValue());
     }
 
     @Override
@@ -85,12 +92,9 @@
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("direct:start")
-                    .to("log:foo")
-                    .delay(1000).id("mydelayer")
-                    .to("mock:result");
+                from("direct:start").to("mock:result");
             }
         };
     }
 
-}
+}
\ No newline at end of file



Mime
View raw message