From 6df7f2346ca75fe46f95427680aea32aba768cc7 Mon Sep 17 00:00:00 2001 From: Guangxu Cheng Date: Thu, 12 Apr 2018 17:40:57 +0800 Subject: [PATCH] HBASE-20396 Remove redundant metrics from thrift metrics --- .../MetricsThriftServerSourceFactoryImpl.java | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/thrift/MetricsThriftServerSourceFactoryImpl.java b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/thrift/MetricsThriftServerSourceFactoryImpl.java index 002985a071f..3ce2d5d1fdc 100644 --- a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/thrift/MetricsThriftServerSourceFactoryImpl.java +++ b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/thrift/MetricsThriftServerSourceFactoryImpl.java @@ -30,25 +30,31 @@ public class MetricsThriftServerSourceFactoryImpl implements MetricsThriftServer * A singleton used to make sure that only one thrift metrics source per server type is ever * created. */ - private static enum FactoryStorage { + private enum FactoryStorage { INSTANCE; - MetricsThriftServerSourceImpl thriftOne = new MetricsThriftServerSourceImpl(METRICS_NAME, - METRICS_DESCRIPTION, - THRIFT_ONE_METRICS_CONTEXT, - THRIFT_ONE_JMX_CONTEXT); - MetricsThriftServerSourceImpl thriftTwo = new MetricsThriftServerSourceImpl(METRICS_NAME, - METRICS_DESCRIPTION, - THRIFT_TWO_METRICS_CONTEXT, - THRIFT_TWO_JMX_CONTEXT); + MetricsThriftServerSourceImpl thriftOne; + MetricsThriftServerSourceImpl thriftTwo; } @Override public MetricsThriftServerSource createThriftOneSource() { + if (FactoryStorage.INSTANCE.thriftOne == null) { + FactoryStorage.INSTANCE.thriftOne = new MetricsThriftServerSourceImpl(METRICS_NAME, + METRICS_DESCRIPTION, + THRIFT_ONE_METRICS_CONTEXT, + THRIFT_ONE_JMX_CONTEXT); + } return FactoryStorage.INSTANCE.thriftOne; } @Override public MetricsThriftServerSource createThriftTwoSource() { + if (FactoryStorage.INSTANCE.thriftTwo == null) { + FactoryStorage.INSTANCE.thriftTwo = new MetricsThriftServerSourceImpl(METRICS_NAME, + METRICS_DESCRIPTION, + THRIFT_TWO_METRICS_CONTEXT, + THRIFT_TWO_JMX_CONTEXT); + } return FactoryStorage.INSTANCE.thriftTwo; } }