svn commit: r666948 - in /activemq/camel/trunk/camel-core/src: main/java/org/apache/camel/management/ test/java/org/apache/camel/component/file/ test/java/org/apache/camel/management/

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

svn commit: r666948 - in /activemq/camel/trunk/camel-core/src: main/java/org/apache/camel/management/ test/java/org/apache/camel/component/file/ test/java/org/apache/camel/management/

davsclaus-2
Author: davsclaus
Date: Wed Jun 11 21:07:59 2008
New Revision: 666948

URL: http://svn.apache.org/viewvc?rev=666948&view=rev
Log:
CAMEL-582: Added total processed time. Applied patch with thanks to William Tam.

Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationProcessor.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/PerformanceCounter.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileProduceGeneratedFileNameTest.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingDefaultsTest.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationProcessor.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationProcessor.java?rev=666948&r1=666947&r2=666948&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationProcessor.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationProcessor.java Wed Jun 11 21:07:59 2008
@@ -37,13 +37,14 @@
     public void setCounter(PerformanceCounter counter) {
         this.counter = counter;
     }
-    
+
     public void process(Exchange exchange) throws Exception {
-        long startTime = System.currentTimeMillis();
+        long startTime = System.nanoTime();
         super.process(exchange);
         if (counter != null) {
             if (!exchange.isFailed()) {
-                counter.completedExchange(System.currentTimeMillis() - startTime);
+                // convert nanoseconds to milliseconds
+                counter.completedExchange((System.nanoTime() - startTime) / 1000000.0);
             } else {
                 counter.completedExchange();
             }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/PerformanceCounter.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/PerformanceCounter.java?rev=666948&r1=666947&r2=666948&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/PerformanceCounter.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/PerformanceCounter.java Wed Jun 11 21:07:59 2008
@@ -27,8 +27,8 @@
 public class PerformanceCounter extends Counter {
 
     private AtomicLong numCompleted = new AtomicLong(0L);
-    private long minProcessingTime = -1L;
-    private long maxProcessingTime = -1L;
+    private double minProcessingTime = -1.0;
+    private double maxProcessingTime;
     private double totalProcessingTime;
     private Date lastExchangeCompletionTime;
     private Date firstExchangeCompletionTime;
@@ -38,9 +38,9 @@
     public synchronized void reset() {
         super.reset();
         numCompleted.set(0L);
-        minProcessingTime = 0L;
-        maxProcessingTime = 0L;
-        totalProcessingTime = 0;
+        minProcessingTime = -1.0;
+        maxProcessingTime = 0.0;
+        totalProcessingTime = 0.0;
         lastExchangeCompletionTime = null;
         firstExchangeCompletionTime = null;
 
@@ -56,22 +56,27 @@
         return numExchanges.get() - numCompleted.get();
     }
 
-    @ManagedAttribute(description = "Min Processing Time [milli-seconds]")
-    public synchronized long getMinProcessingTime() throws Exception {
+    @ManagedAttribute(description = "Min Processing Time [milliseconds]")
+    public synchronized double getMinProcessingTimeMillis() throws Exception {
         return minProcessingTime;
     }
 
-    @ManagedAttribute(description = "Mean Processing Time [milli-seconds]")
-    public synchronized long getMeanProcessingTime() throws Exception {
+    @ManagedAttribute(description = "Mean Processing Time [milliseconds]")
+    public synchronized double getMeanProcessingTimeMillis() throws Exception {
         long count = numCompleted.get();
-        return count > 0 ? (long)totalProcessingTime / count : 0L;
+        return count > 0 ? totalProcessingTime / count : 0.0;
     }
 
-    @ManagedAttribute(description = "Max Processing Time [milli-seconds]")
-    public synchronized long getMaxProcessingTime() throws Exception {
+    @ManagedAttribute(description = "Max Processing Time [milliseconds]")
+    public synchronized double getMaxProcessingTimeMillis() throws Exception {
         return maxProcessingTime;
     }
 
+    @ManagedAttribute(description = "Total Processing Time [milliseconds]")
+    public synchronized double getTotalProcessingTimeMillis() throws Exception {
+        return totalProcessingTime;
+    }
+
     @ManagedAttribute(description = "Last Exchange Completed Timestamp")
     public synchronized Date getLastExchangeCompletionTime() {
         return lastExchangeCompletionTime;
@@ -82,7 +87,12 @@
         return firstExchangeCompletionTime;
     }
 
-    public synchronized void completedExchange(long time) {
+    /**
+     * This method is called when an exchange has been processed successfully.
+     *
+     * @param time in milliseconds it spent on processing the exchange
+     */
+    public synchronized void completedExchange(double time) {
         increment();
         numCompleted.incrementAndGet();
         totalProcessingTime += time;

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileProduceGeneratedFileNameTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileProduceGeneratedFileNameTest.java?rev=666948&r1=666947&r2=666948&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileProduceGeneratedFileNameTest.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileProduceGeneratedFileNameTest.java Wed Jun 11 21:07:59 2008
@@ -39,8 +39,8 @@
         template.send(endpoint, exchange);
 
         File file = new File("target/" + id);
+        // use absolute file to let unittest pass on all platforms
         file = file.getAbsoluteFile();
-        System.out.println("absolute file: " + file);
         assertEquals("The generated file should exists: " + file, true, file.exists());
     }
 

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingDefaultsTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingDefaultsTest.java?rev=666948&r1=666947&r2=666948&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingDefaultsTest.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingDefaultsTest.java Wed Jun 11 21:07:59 2008
@@ -84,36 +84,41 @@
         ObjectName pcob = (ObjectName)iter.next();
 
         Long valueofNumExchanges = (Long)mbs.getAttribute(pcob, "NumExchanges");
-        assertNotNull("Expected attribute not found. MBean registerred under a "
+        assertNotNull("Expected attribute found. MBean registered under a "
                       + "'<domain>:name=Stats,*' key must be of type PerformanceCounter.class",
                       valueofNumExchanges);
         assertTrue(valueofNumExchanges == 1);
         Long valueofNumCompleted = (Long)mbs.getAttribute(pcob, "NumCompleted");
-        assertNotNull("Expected attribute not found. MBean registerred under a "
+        assertNotNull("Expected attribute found. MBean registered under a "
                       + "'<domain>:name=Stats,*' key must be of type PerformanceCounter.class",
                       valueofNumCompleted);
         assertTrue(valueofNumCompleted == 1);
         Long valueofNumFailed = (Long)mbs.getAttribute(pcob, "NumFailed");
-        assertNotNull("Expected attribute not found. MBean registerred under a "
+        assertNotNull("Expected attribute found. MBean registered under a "
                       + "'<domain>:name=Stats,*' key must be of type PerformanceCounter.class",
                       valueofNumFailed);
         assertTrue(valueofNumFailed == 0);
-        Long valueofMinProcessingTime = (Long)mbs.getAttribute(pcob, "MinProcessingTime");
-        assertNotNull("Expected attribute not found. MBean registerred under a "
+        Double valueofMinProcessingTime = (Double)mbs.getAttribute(pcob, "MinProcessingTimeMillis");
+        assertNotNull("Expected attribute found. MBean registered under a "
                       + "'<domain>:name=Stats,*' key must be of type PerformanceCounter.class",
                       valueofMinProcessingTime);
-        assertTrue(valueofMinProcessingTime >= 0);
-        Long valueofMaxProcessingTime = (Long)mbs.getAttribute(pcob, "MaxProcessingTime");
-        assertNotNull("Expected attribute not found. MBean registerred under a "
+        assertTrue(valueofMinProcessingTime > 0);
+        Double valueofMaxProcessingTime = (Double)mbs.getAttribute(pcob, "MaxProcessingTimeMillis");
+        assertNotNull("Expected attribute found. MBean registered under a "
                       + "'<domain>:name=Stats,*' key must be of type PerformanceCounter.class",
                       valueofMaxProcessingTime);
-        assertTrue(valueofMaxProcessingTime >= 0);
-        Long valueofMeanProcessingTime = (Long)mbs.getAttribute(pcob, "MeanProcessingTime");
-        assertNotNull("Expected attribute not found. MBean registerred under a "
+        assertTrue(valueofMaxProcessingTime > 0);
+        Double valueofMeanProcessingTime = (Double)mbs.getAttribute(pcob, "MeanProcessingTimeMillis");
+        assertNotNull("Expected attribute found. MBean registered under a "
                       + "'<domain>:name=Stats,*' key must be of type PerformanceCounter.class",
                       valueofMeanProcessingTime);
         assertTrue(valueofMeanProcessingTime >= valueofMinProcessingTime
                    && valueofMeanProcessingTime <= valueofMaxProcessingTime);
+        Double totalProcessingTime = (Double)mbs.getAttribute(pcob, "TotalProcessingTimeMillis");
+        assertNotNull("Expected attribute found. MBean registered under a "
+                      + "'<domain>:name=Stats,*' key must be of type PerformanceCounter.class",
+                      totalProcessingTime);
+        assertTrue(totalProcessingTime > 0);
 
         assertNotNull("Expected first completion time to be available",
                 mbs.getAttribute(pcob, "FirstExchangeCompletionTime"));