camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [6/6] camel git commit: CAMEL-9389: camel-metrics - Allow to capture message history easily
Date Sat, 05 Dec 2015 08:29:29 GMT
CAMEL-9389: camel-metrics - Allow to capture message history easily


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/a2370214
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a2370214
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a2370214

Branch: refs/heads/master
Commit: a23702140c7a99551c73d6091da52702648fa54d
Parents: 31e988c
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sat Dec 5 09:26:06 2015 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sat Dec 5 09:26:06 2015 +0100

----------------------------------------------------------------------
 .../MetricsMessageHistoryMBean.java               |  3 +++
 .../MetricsMessageHistoryService.java             | 14 ++++++++++++--
 .../messagehistory/ManagedMessageHistoryTest.java | 18 ++++++++++++++++++
 3 files changed, 33 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/a2370214/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/messagehistory/MetricsMessageHistoryMBean.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/messagehistory/MetricsMessageHistoryMBean.java
b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/messagehistory/MetricsMessageHistoryMBean.java
index 05ae2f6..6b4d398 100644
--- a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/messagehistory/MetricsMessageHistoryMBean.java
+++ b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/messagehistory/MetricsMessageHistoryMBean.java
@@ -26,4 +26,7 @@ public interface MetricsMessageHistoryMBean {
     @ManagedOperation(description = "Dumps the statistics as json using seconds for time
units")
     String dumpStatisticsAsJsonTimeUnitSeconds();
 
+    @ManagedOperation(description = "Reset all counters")
+    void reset();
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/a2370214/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/messagehistory/MetricsMessageHistoryService.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/messagehistory/MetricsMessageHistoryService.java
b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/messagehistory/MetricsMessageHistoryService.java
index f875355..593dd28 100644
--- a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/messagehistory/MetricsMessageHistoryService.java
+++ b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/messagehistory/MetricsMessageHistoryService.java
@@ -20,6 +20,8 @@ import java.util.concurrent.TimeUnit;
 import javax.management.MBeanServer;
 
 import com.codahale.metrics.JmxReporter;
+import com.codahale.metrics.Metric;
+import com.codahale.metrics.MetricFilter;
 import com.codahale.metrics.MetricRegistry;
 import com.codahale.metrics.json.MetricsModule;
 import com.fasterxml.jackson.core.JsonProcessingException;
@@ -30,7 +32,6 @@ import org.apache.camel.CamelContextAware;
 import org.apache.camel.StaticService;
 import org.apache.camel.api.management.ManagedResource;
 import org.apache.camel.component.metrics.MetricsComponent;
-import org.apache.camel.component.metrics.routepolicy.MetricsRegistryMBean;
 import org.apache.camel.spi.ManagementAgent;
 import org.apache.camel.spi.Registry;
 import org.apache.camel.support.ServiceSupport;
@@ -40,7 +41,7 @@ import org.apache.camel.util.ObjectHelper;
  * Service holding the {@link MetricsMessageHistory} which registers all message history
metrics.
  */
 @ManagedResource(description = "MetricsMessageHistory")
-public final class MetricsMessageHistoryService extends ServiceSupport implements CamelContextAware,
StaticService, MetricsRegistryMBean {
+public final class MetricsMessageHistoryService extends ServiceSupport implements CamelContextAware,
StaticService, MetricsMessageHistoryMBean {
 
     private CamelContext camelContext;
     private MetricRegistry metricsRegistry;
@@ -176,4 +177,13 @@ public final class MetricsMessageHistoryService extends ServiceSupport
implement
         }
     }
 
+    public void reset() {
+        // remove all
+        metricsRegistry.removeMatching(new MetricFilter() {
+            @Override
+            public boolean matches(String name, Metric metric) {
+                return true;
+            }
+        });
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/a2370214/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/messagehistory/ManagedMessageHistoryTest.java
----------------------------------------------------------------------
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/messagehistory/ManagedMessageHistoryTest.java
b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/messagehistory/ManagedMessageHistoryTest.java
index cb62393..b2bd459 100644
--- a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/messagehistory/ManagedMessageHistoryTest.java
+++ b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/messagehistory/ManagedMessageHistoryTest.java
@@ -95,6 +95,24 @@ public class ManagedMessageHistoryTest extends CamelTestSupport {
         assertTrue(json.contains("foo.history"));
         assertTrue(json.contains("bar.history"));
         assertTrue(json.contains("baz.history"));
+
+        // reset
+        getMBeanServer().invoke(on, "reset", null, null);
+
+        resetMocks();
+        getMockEndpoint("mock:foo").expectedMessageCount(1);
+
+        template.sendBody("seda:foo", "Hello Again");
+
+        assertMockEndpointsSatisfied();
+
+        json = (String) getMBeanServer().invoke(on, "dumpStatisticsAsJson", null, null);
+        assertNotNull(json);
+        log.info(json);
+
+        assertTrue(json.contains("foo.history"));
+        assertFalse(json.contains("bar.history"));
+        assertFalse(json.contains("baz.history"));
     }
 
     @Override


Mime
View raw message