Optimize MetricsReporter class 02/14502/4
authorRobert Varga <rovarga@cisco.com>
Mon, 26 Jan 2015 16:00:59 +0000 (17:00 +0100)
committerRobert Varga <rovarga@cisco.com>
Wed, 28 Jan 2015 16:18:59 +0000 (17:18 +0100)
Constants should really be static, singleton instance should be static
and the inner field should never be exposed to outside world.

Change-Id: I37776b190cef6b0402f1478b22c47746d547619d
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/reporting/MetricsReporter.java

index 0f227779ddf01c3e8205ad0c605ae4660a920c79..b400fcab7d93fac0aa67fa6a7a1bd1862b4a6888 100644 (file)
@@ -18,29 +18,28 @@ import com.codahale.metrics.MetricRegistry;
  * The consumers of this class will only be interested in {@code MetricsRegistry}
  * where metrics for that consumer gets stored.
  */
-public class MetricsReporter implements AutoCloseable{
+public class MetricsReporter implements AutoCloseable {
 
-    private final MetricRegistry METRICS_REGISTRY = new MetricRegistry();
-    private final String DOMAIN = "org.opendaylight.controller.actor.metric";
+    private static final MetricRegistry METRICS_REGISTRY = new MetricRegistry();
+    private static final String DOMAIN = "org.opendaylight.controller.actor.metric";
+    private static final MetricsReporter INSTANCE = new MetricsReporter();
 
-    public final JmxReporter jmxReporter = JmxReporter.forRegistry(METRICS_REGISTRY).inDomain(DOMAIN).build();
+    private final JmxReporter jmxReporter = JmxReporter.forRegistry(METRICS_REGISTRY).inDomain(DOMAIN).build();
 
-    private static MetricsReporter inst = new MetricsReporter();
-
-    private MetricsReporter(){
+    private MetricsReporter() {
         jmxReporter.start();
     }
 
-    public static MetricsReporter getInstance(){
-        return inst;
+    public static MetricsReporter getInstance() {
+        return INSTANCE;
     }
 
-    public MetricRegistry getMetricsRegistry(){
+    public MetricRegistry getMetricsRegistry() {
         return METRICS_REGISTRY;
     }
 
     @Override
-    public void close() throws Exception {
+    public void close() {
         jmxReporter.close();
     }
 }