accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From els...@apache.org
Subject accumulo git commit: ACCUMULO-3388 Ensure that DefaultMetricsSystem is only initialized once.
Date Sat, 06 Dec 2014 23:29:33 GMT
Repository: accumulo
Updated Branches:
  refs/heads/master ef909d5fb -> 175401f9e


ACCUMULO-3388 Ensure that DefaultMetricsSystem is only initialized once.

Use the initialization-on-demand holder idiom to make sure that we
only have one instance of the MetricsSystem per process.


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

Branch: refs/heads/master
Commit: 175401f9e35df1a9f55fa378c57e71262679dcb5
Parents: ef909d5
Author: Josh Elser <elserj@apache.org>
Authored: Sat Dec 6 18:10:19 2014 -0500
Committer: Josh Elser <elserj@apache.org>
Committed: Sat Dec 6 18:27:23 2014 -0500

----------------------------------------------------------------------
 .../accumulo/server/metrics/MetricsFactory.java |  3 +-
 .../server/metrics/MetricsSystemHelper.java     | 35 ++++++++++++++++++++
 .../master/metrics/MasterMetricsFactory.java    |  4 +--
 .../metrics/TabletServerMetricsFactory.java     |  4 +--
 4 files changed, 40 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/175401f9/server/base/src/main/java/org/apache/accumulo/server/metrics/MetricsFactory.java
----------------------------------------------------------------------
diff --git a/server/base/src/main/java/org/apache/accumulo/server/metrics/MetricsFactory.java
b/server/base/src/main/java/org/apache/accumulo/server/metrics/MetricsFactory.java
index 7c06971..ce2ae31 100644
--- a/server/base/src/main/java/org/apache/accumulo/server/metrics/MetricsFactory.java
+++ b/server/base/src/main/java/org/apache/accumulo/server/metrics/MetricsFactory.java
@@ -19,7 +19,6 @@ package org.apache.accumulo.server.metrics;
 import org.apache.accumulo.core.conf.AccumuloConfiguration;
 import org.apache.accumulo.core.conf.Property;
 import org.apache.hadoop.metrics2.MetricsSystem;
-import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
 
 import com.google.common.base.Preconditions;
 
@@ -38,7 +37,7 @@ public class MetricsFactory {
     if (useOldMetrics) {
       metricsSystem = null;
     } else {
-      metricsSystem = DefaultMetricsSystem.initialize(Metrics.PREFIX);
+      metricsSystem = MetricsSystemHelper.getInstance();
     }
   }
 

http://git-wip-us.apache.org/repos/asf/accumulo/blob/175401f9/server/base/src/main/java/org/apache/accumulo/server/metrics/MetricsSystemHelper.java
----------------------------------------------------------------------
diff --git a/server/base/src/main/java/org/apache/accumulo/server/metrics/MetricsSystemHelper.java
b/server/base/src/main/java/org/apache/accumulo/server/metrics/MetricsSystemHelper.java
new file mode 100644
index 0000000..42deb7e
--- /dev/null
+++ b/server/base/src/main/java/org/apache/accumulo/server/metrics/MetricsSystemHelper.java
@@ -0,0 +1,35 @@
+/*
+ * 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.accumulo.server.metrics;
+
+import org.apache.hadoop.metrics2.MetricsSystem;
+import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
+
+/**
+ *
+ */
+public class MetricsSystemHelper {
+
+  private static class MetricsSystemHolder {
+    // Singleton, rely on JVM to initialize the MetricsSystem only when it is accessed.
+    private static final MetricsSystem metricsSystem = DefaultMetricsSystem.initialize(Metrics.PREFIX);
+  }
+
+  public static MetricsSystem getInstance() {
+    return MetricsSystemHolder.metricsSystem;
+  }
+}

http://git-wip-us.apache.org/repos/asf/accumulo/blob/175401f9/server/master/src/main/java/org/apache/accumulo/master/metrics/MasterMetricsFactory.java
----------------------------------------------------------------------
diff --git a/server/master/src/main/java/org/apache/accumulo/master/metrics/MasterMetricsFactory.java
b/server/master/src/main/java/org/apache/accumulo/master/metrics/MasterMetricsFactory.java
index 6d86d09..649a6cd 100644
--- a/server/master/src/main/java/org/apache/accumulo/master/metrics/MasterMetricsFactory.java
+++ b/server/master/src/main/java/org/apache/accumulo/master/metrics/MasterMetricsFactory.java
@@ -20,8 +20,8 @@ import org.apache.accumulo.core.conf.AccumuloConfiguration;
 import org.apache.accumulo.core.conf.Property;
 import org.apache.accumulo.master.Master;
 import org.apache.accumulo.server.metrics.Metrics;
+import org.apache.accumulo.server.metrics.MetricsSystemHelper;
 import org.apache.hadoop.metrics2.MetricsSystem;
-import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
 
 import com.google.common.base.Preconditions;
 
@@ -42,7 +42,7 @@ public class MasterMetricsFactory {
     if (useOldMetrics) {
       metricsSystem = null;
     } else {
-      metricsSystem = DefaultMetricsSystem.initialize(Metrics.PREFIX);
+      metricsSystem = MetricsSystemHelper.getInstance();
     }
   }
 

http://git-wip-us.apache.org/repos/asf/accumulo/blob/175401f9/server/tserver/src/main/java/org/apache/accumulo/tserver/metrics/TabletServerMetricsFactory.java
----------------------------------------------------------------------
diff --git a/server/tserver/src/main/java/org/apache/accumulo/tserver/metrics/TabletServerMetricsFactory.java
b/server/tserver/src/main/java/org/apache/accumulo/tserver/metrics/TabletServerMetricsFactory.java
index 7ca9486..56b1c42 100644
--- a/server/tserver/src/main/java/org/apache/accumulo/tserver/metrics/TabletServerMetricsFactory.java
+++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/metrics/TabletServerMetricsFactory.java
@@ -19,9 +19,9 @@ package org.apache.accumulo.tserver.metrics;
 import org.apache.accumulo.core.conf.AccumuloConfiguration;
 import org.apache.accumulo.core.conf.Property;
 import org.apache.accumulo.server.metrics.Metrics;
+import org.apache.accumulo.server.metrics.MetricsSystemHelper;
 import org.apache.accumulo.tserver.TabletServer;
 import org.apache.hadoop.metrics2.MetricsSystem;
-import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
 
 import com.google.common.base.Preconditions;
 
@@ -42,7 +42,7 @@ public class TabletServerMetricsFactory {
     if (useOldMetrics) {
       metricsSystem = null;
     } else {
-      metricsSystem = DefaultMetricsSystem.initialize(Metrics.PREFIX);
+      metricsSystem = MetricsSystemHelper.getInstance();
     }
   }
 


Mime
View raw message