james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adup...@apache.org
Subject [06/14] james-project git commit: JAMES-1950 Add dropwizard TimeMetric implementation
Date Fri, 03 Mar 2017 17:26:14 GMT
JAMES-1950 Add dropwizard TimeMetric implementation


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

Branch: refs/heads/master
Commit: f7ed8495166be6893236c27c45ddc5b47438af52
Parents: 8f7fbc2
Author: Antoine Duprat <aduprat@linagora.com>
Authored: Tue Feb 28 09:30:31 2017 +0100
Committer: Antoine Duprat <aduprat@linagora.com>
Committed: Fri Mar 3 18:17:20 2017 +0100

----------------------------------------------------------------------
 .../dropwizard/DropWizardMetricFactory.java     |  6 +++
 .../dropwizard/DropWizardTimeMetric.java        | 45 ++++++++++++++++++++
 .../modules/server/DropWizardMetricsModule.java |  2 +
 3 files changed, 53 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/f7ed8495/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/DropWizardMetricFactory.java
----------------------------------------------------------------------
diff --git a/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/DropWizardMetricFactory.java
b/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/DropWizardMetricFactory.java
index 4eee021..ad9015f 100644
--- a/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/DropWizardMetricFactory.java
+++ b/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/DropWizardMetricFactory.java
@@ -25,6 +25,7 @@ import javax.inject.Inject;
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.james.metrics.api.Metric;
 import org.apache.james.metrics.api.MetricFactory;
+import org.apache.james.metrics.api.TimeMetric;
 
 import com.codahale.metrics.JmxReporter;
 import com.codahale.metrics.MetricRegistry;
@@ -46,6 +47,11 @@ public class DropWizardMetricFactory implements MetricFactory {
         return new DropWizardMetric(metricRegistry.counter(name));
     }
 
+    @Override
+    public TimeMetric timer(String name) {
+        return new DropWizardTimeMetric(name, metricRegistry.timer(name).time());
+    }
+
     public void start() throws ConfigurationException {
         jmxReporter.start();
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/f7ed8495/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/DropWizardTimeMetric.java
----------------------------------------------------------------------
diff --git a/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/DropWizardTimeMetric.java
b/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/DropWizardTimeMetric.java
new file mode 100644
index 0000000..e5145fd
--- /dev/null
+++ b/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/DropWizardTimeMetric.java
@@ -0,0 +1,45 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.metrics.dropwizard;
+
+import org.apache.james.metrics.api.TimeMetric;
+
+import com.codahale.metrics.Timer;
+
+public class DropWizardTimeMetric implements TimeMetric {
+
+    private final String name;
+    private final Timer.Context time;
+
+    public DropWizardTimeMetric(String name, Timer.Context context) {
+        this.name = name;
+        this.time = context;
+    }
+
+    @Override
+    public String name() {
+        return name;
+    }
+
+    @Override
+    public long stopAndPublish() {
+        return time.stop();
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/f7ed8495/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/DropWizardMetricsModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/DropWizardMetricsModule.java
b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/DropWizardMetricsModule.java
index e3ac9f7..5c53876 100644
--- a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/DropWizardMetricsModule.java
+++ b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/DropWizardMetricsModule.java
@@ -28,6 +28,7 @@ import org.apache.james.metrics.api.MetricFactory;
 import org.apache.james.metrics.dropwizard.DropWizardMetricFactory;
 import org.apache.james.utils.ConfigurationPerformer;
 
+import com.codahale.metrics.MetricRegistry;
 import com.google.common.base.Throwables;
 import com.google.common.collect.ImmutableList;
 import com.google.inject.AbstractModule;
@@ -40,6 +41,7 @@ public class DropWizardMetricsModule extends AbstractModule {
 
     @Override
     protected void configure() {
+        bind(MetricRegistry.class).in(Scopes.SINGLETON);
         bind(DropWizardMetricFactory.class).in(Scopes.SINGLETON);
         bind(MetricFactory.class).to(DropWizardMetricFactory.class);
 


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message