camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1239479 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/api/management/mbean/ camel-core/src/main/java/org/apache/camel/management/mbean/ components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/ components/camel-j...
Date Thu, 02 Feb 2012 08:25:55 GMT
Author: davsclaus
Date: Thu Feb  2 08:25:54 2012
New Revision: 1239479

URL: http://svn.apache.org/viewvc?rev=1239479&view=rev
Log:
CAMEL-4968: Expose transacted redeliveries as JMX stat

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedPerformanceCounterMBean.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedPerformanceCounter.java
    camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JMSTransactionIsTransactedRedeliveredTest.java
    camel/trunk/components/camel-jms/src/test/resources/log4j.properties
    camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JMSTransactionIsTransactedRedeliveredTest.xml

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedPerformanceCounterMBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedPerformanceCounterMBean.java?rev=1239479&r1=1239478&r2=1239479&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedPerformanceCounterMBean.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedPerformanceCounterMBean.java
Thu Feb  2 08:25:54 2012
@@ -35,9 +35,12 @@ public interface ManagedPerformanceCount
     @ManagedAttribute(description = "Number of failures handled")
     long getFailuresHandled() throws Exception;
 
-    @ManagedAttribute(description = "Number of redeliveries")
+    @ManagedAttribute(description = "Number of redeliveries (Camel error handler)")
     long getRedeliveries() throws Exception;
 
+    @ManagedAttribute(description = "Number of transacted redeliveries (from external transacted
source)")
+    long getTransactedRedeliveries() throws Exception;
+
     @ManagedAttribute(description = "Min Processing Time [milliseconds]")
     long getMinProcessingTime() throws Exception;
 

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=1239479&r1=1239478&r2=1239479&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
Thu Feb  2 08:25:54 2012
@@ -35,6 +35,7 @@ public abstract class ManagedPerformance
     private Statistic exchangesFailed;
     private Statistic failuresHandled;
     private Statistic redeliveries;
+    private Statistic transactedRedeliveries;
     private Statistic minProcessingTime;
     private Statistic maxProcessingTime;
     private Statistic totalProcessingTime;
@@ -57,6 +58,7 @@ public abstract class ManagedPerformance
 
         this.failuresHandled = new Statistic("org.apache.camel.failuresHandled", this, Statistic.UpdateMode.COUNTER);
         this.redeliveries = new Statistic("org.apache.camel.redeliveries", this, Statistic.UpdateMode.COUNTER);
+        this.transactedRedeliveries = new Statistic("org.apache.camel.transactedRedeliveries",
this, Statistic.UpdateMode.COUNTER);
 
         this.minProcessingTime = new Statistic("org.apache.camel.minimumProcessingTime",
this, Statistic.UpdateMode.MINIMUM);
         this.maxProcessingTime = new Statistic("org.apache.camel.maximumProcessingTime",
this, Statistic.UpdateMode.MAXIMUM);
@@ -77,6 +79,7 @@ public abstract class ManagedPerformance
         exchangesFailed.reset();
         failuresHandled.reset();
         redeliveries.reset();
+        transactedRedeliveries.reset();
         minProcessingTime.reset();
         maxProcessingTime.reset();
         totalProcessingTime.reset();
@@ -108,6 +111,10 @@ public abstract class ManagedPerformance
         return redeliveries.getValue();
     }
 
+    public long getTransactedRedeliveries() throws Exception {
+        return transactedRedeliveries.getValue();
+    }
+
     public long getMinProcessingTime() throws Exception {
         return minProcessingTime.getValue();
     }
@@ -179,6 +186,10 @@ public abstract class ManagedPerformance
         if (ExchangeHelper.isFailureHandled(exchange)) {
             failuresHandled.increment();
         }
+        Boolean transactedRedelivered = exchange.isTransactedRedelivered();
+        if (transactedRedelivered != null && transactedRedelivered) {
+            transactedRedeliveries.increment();
+        }
 
         minProcessingTime.updateValue(time);
         maxProcessingTime.updateValue(time);
@@ -209,6 +220,10 @@ public abstract class ManagedPerformance
         if (ExchangeHelper.isRedelivered(exchange)) {
             redeliveries.increment();
         }
+        Boolean transactedRedelivered = exchange.isTransactedRedelivered();
+        if (transactedRedelivered != null && transactedRedelivered) {
+            transactedRedeliveries.increment();
+        }
 
         long now = new Date().getTime();
         if (firstExchangeFailureTimestamp.getUpdateCount() == 0) {
@@ -229,6 +244,7 @@ public abstract class ManagedPerformance
         sb.append(String.format(" exchangesFailed=\"%s\"", exchangesFailed.getValue()));
         sb.append(String.format(" failuresHandled=\"%s\"", failuresHandled.getValue()));
         sb.append(String.format(" redeliveries=\"%s\"", redeliveries.getValue()));
+        sb.append(String.format(" transactedRedeliveries=\"%s\"", transactedRedeliveries.getValue()));
         sb.append(String.format(" minProcessingTime=\"%s\"", minProcessingTime.getValue()));
         sb.append(String.format(" maxProcessingTime=\"%s\"", maxProcessingTime.getValue()));
         sb.append(String.format(" totalProcessingTime=\"%s\"", totalProcessingTime.getValue()));

Modified: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JMSTransactionIsTransactedRedeliveredTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JMSTransactionIsTransactedRedeliveredTest.java?rev=1239479&r1=1239478&r2=1239479&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JMSTransactionIsTransactedRedeliveredTest.java
(original)
+++ camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JMSTransactionIsTransactedRedeliveredTest.java
Thu Feb  2 08:25:54 2012
@@ -16,6 +16,9 @@
  */
 package org.apache.camel.component.jms.tx;
 
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.AdviceWithRouteBuilder;
@@ -45,6 +48,10 @@ public class JMSTransactionIsTransactedR
         return true;
     }
 
+    protected MBeanServer getMBeanServer() {
+        return context.getManagementStrategy().getManagementAgent().getMBeanServer();
+    }
+
     @Test
     public void testTransactionSuccess() throws Exception {
         context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder()
{
@@ -69,6 +76,28 @@ public class JMSTransactionIsTransactedR
 
         mock.assertIsSatisfied();
         error.assertIsSatisfied();
+
+        // check JMX stats
+
+        ObjectName name = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=routes,name=\"myRoute\"");
+
+        Long total = (Long) getMBeanServer().getAttribute(name, "ExchangesTotal");
+        assertEquals(3, total.intValue());
+
+        Long completed = (Long) getMBeanServer().getAttribute(name, "ExchangesCompleted");
+        assertEquals(1, completed.intValue());
+
+        Long failed = (Long) getMBeanServer().getAttribute(name, "ExchangesFailed");
+        assertEquals(2, failed.intValue());
+
+        // Camel error handler redeliveries (we do not use that in this example)
+        Long redeliveries = (Long) getMBeanServer().getAttribute(name, "Redeliveries");
+        assertEquals(0, redeliveries.intValue());
+        // Camel error handler redeliveries (we do not use that in this example)
+
+        // there should be 2 transacted redeliveries
+        Long transactedRedeliveries = (Long) getMBeanServer().getAttribute(name, "TransactedRedeliveries");
+        assertEquals(2, transactedRedeliveries.intValue());
     }
 
     public static class MyProcessor implements Processor {

Modified: camel/trunk/components/camel-jms/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/resources/log4j.properties?rev=1239479&r1=1239478&r2=1239479&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/test/resources/log4j.properties (original)
+++ camel/trunk/components/camel-jms/src/test/resources/log4j.properties Thu Feb  2 08:25:54
2012
@@ -26,6 +26,7 @@ log4j.rootLogger=INFO, out
 #log4j.logger.org.apache.camel.component.jms.reply=TRACE
 #log4j.logger.org.apache.camel=DEBUG
 #log4j.logger.org.springframework.jms.listener=TRACE
+#log4j.logger.org.apache.camel.management=DEBUG
 
 # CONSOLE appender not used by default
 log4j.appender.stdout=org.apache.log4j.ConsoleAppender

Modified: camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JMSTransactionIsTransactedRedeliveredTest.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JMSTransactionIsTransactedRedeliveredTest.xml?rev=1239479&r1=1239478&r2=1239479&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JMSTransactionIsTransactedRedeliveredTest.xml
(original)
+++ camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JMSTransactionIsTransactedRedeliveredTest.xml
Thu Feb  2 08:25:54 2012
@@ -44,14 +44,22 @@
         <property name="errorHandlerLogStackTrace" value="false"/>
     </bean>
 
+    <bean id="naming" class="org.apache.camel.management.DefaultManagementNamingStrategy">
+        <property name="hostName" value="localhost"/>
+        <property name="domainName" value="org.apache.camel"/>
+    </bean>
+
     <camelContext xmlns="http://camel.apache.org/schema/spring">
+      
+      <!-- enable JMX -->
+      <jmxAgent id="agent" disabled="false"/>
 
       <!-- we do not want any exceptions to be logged, neither that a rollback occurred
-->
       <errorHandler id="txEH" type="TransactionErrorHandler" rollbackLoggingLevel="OFF">
         <redeliveryPolicy logStackTrace="false" logExhausted="false"/>
       </errorHandler>
 
-        <route errorHandlerRef="txEH">
+        <route id="myRoute" errorHandlerRef="txEH">
             <from uri="activemq:queue:okay"/>
             <transacted/>
             <to uri="mock:before"/>



Mime
View raw message