JAMES-2599 Publishing metrics for completable futures

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

Branch: refs/heads/master
Commit: bcfb5b831b24224fa3b7faf8178c697458f4a7fd
Parents: 0ec5ccc
Author: tran tien duc <[email protected]>
Authored: Thu Nov 22 09:55:30 2018 +0700
Committer: Benoit Tellier <[email protected]>
Committed: Thu Nov 22 17:50:42 2018 +0700

----------------------------------------------------------------------
 .../main/java/org/apache/james/metrics/api/MetricFactory.java  | 6 ++++++
 1 file changed, 6 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/bcfb5b83/metrics/metrics-api/src/main/java/org/apache/james/metrics/api/MetricFactory.java
----------------------------------------------------------------------
diff --git 
a/metrics/metrics-api/src/main/java/org/apache/james/metrics/api/MetricFactory.java
 
b/metrics/metrics-api/src/main/java/org/apache/james/metrics/api/MetricFactory.java
index a472b53..e61064e 100644
--- 
a/metrics/metrics-api/src/main/java/org/apache/james/metrics/api/MetricFactory.java
+++ 
b/metrics/metrics-api/src/main/java/org/apache/james/metrics/api/MetricFactory.java
@@ -19,6 +19,7 @@
 
 package org.apache.james.metrics.api;
 
+import java.util.concurrent.CompletableFuture;
 import java.util.function.Supplier;
 
 public interface MetricFactory {
@@ -42,4 +43,9 @@ public interface MetricFactory {
             return null;
         });
     }
+
+    default <T> CompletableFuture<T> runPublishingTimerMetric(String name, 
CompletableFuture<T> future) {
+        TimeMetric timer = timer(name);
+        return future.whenComplete((result, throwable) -> 
timer.stopAndPublish());
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to