camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From astefanu...@apache.org
Subject camel git commit: Use lambda expression to produce Metrics ratio gauge
Date Wed, 20 Apr 2016 15:36:17 GMT
Repository: camel
Updated Branches:
  refs/heads/master 86bb7d547 -> 01b411892


Use lambda expression to produce Metrics ratio gauge


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

Branch: refs/heads/master
Commit: 01b411892727b2ca1d49511bce2c6aef4ab64636
Parents: 86bb7d5
Author: Antonin Stefanutti <antonin@stefanutti.fr>
Authored: Wed Apr 20 17:36:09 2016 +0200
Committer: Antonin Stefanutti <antonin@stefanutti.fr>
Committed: Wed Apr 20 17:36:09 2016 +0200

----------------------------------------------------------------------
 examples/camel-example-cdi-metrics/pom.xml             |  9 +++++++++
 .../apache/camel/example/cdi/metrics/Application.java  | 13 +++----------
 2 files changed, 12 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/01b41189/examples/camel-example-cdi-metrics/pom.xml
----------------------------------------------------------------------
diff --git a/examples/camel-example-cdi-metrics/pom.xml b/examples/camel-example-cdi-metrics/pom.xml
index f1fd5d0..a88deb0 100755
--- a/examples/camel-example-cdi-metrics/pom.xml
+++ b/examples/camel-example-cdi-metrics/pom.xml
@@ -88,6 +88,15 @@
     <plugins>
 
       <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <configuration>
+          <!-- Enable metrics injection by method parameter names -->
+          <compilerArgument>-parameters</compilerArgument>
+        </configuration>
+      </plugin>
+
+      <plugin>
         <groupId>org.apache.camel</groupId>
         <artifactId>camel-maven-plugin</artifactId>
         <version>${project.version}</version>

http://git-wip-us.apache.org/repos/asf/camel/blob/01b41189/examples/camel-example-cdi-metrics/src/main/java/org/apache/camel/example/cdi/metrics/Application.java
----------------------------------------------------------------------
diff --git a/examples/camel-example-cdi-metrics/src/main/java/org/apache/camel/example/cdi/metrics/Application.java
b/examples/camel-example-cdi-metrics/src/main/java/org/apache/camel/example/cdi/metrics/Application.java
index 77c606c..2202d45 100644
--- a/examples/camel-example-cdi-metrics/src/main/java/org/apache/camel/example/cdi/metrics/Application.java
+++ b/examples/camel-example-cdi-metrics/src/main/java/org/apache/camel/example/cdi/metrics/Application.java
@@ -25,7 +25,7 @@ import javax.inject.Singleton;
 import com.codahale.metrics.Gauge;
 import com.codahale.metrics.Meter;
 import com.codahale.metrics.MetricRegistry;
-import com.codahale.metrics.RatioGauge;
+import com.codahale.metrics.RatioGauge.Ratio;
 import com.codahale.metrics.Slf4jReporter;
 import com.codahale.metrics.annotation.Metric;
 import io.astefanutti.metrics.cdi.MetricsConfiguration;
@@ -92,15 +92,8 @@ class Application {
     @Produces
     @Metric(name = "success-ratio")
     // Register a custom gauge that's the ratio of the 'success' meter on the 'generated'
meter
-    // TODO: use a lambda expression and parameter names when Java 8 is a pre-requisite
-    Gauge<Double> successRatio(@Metric(name = "success") final Meter success,
-                               @Metric(name = "generated") final Meter generated) {
-        return new RatioGauge() {
-            @Override
-            protected Ratio getRatio() {
-                return Ratio.of(success.getOneMinuteRate(), generated.getOneMinuteRate());
-            }
-        };
+    Gauge<Double> successRatio(Meter success, Meter generated) {
+        return () -> Ratio.of(success.getOneMinuteRate(), generated.getOneMinuteRate()).getValue();
     }
 
     @Produces


Mime
View raw message