/*
 * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */
package org.opendaylight.controller.cluster.reporting;

import com.codahale.metrics.JmxReporter;
import com.codahale.metrics.MetricRegistry;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;

/**
 * Maintains metrics registry that is provided to reporters.
 * At the moment only one reporter exists {@code JmxReporter}.
 * More reporters can be added.
 *
 * <p>
 * The consumers of this class will only be interested in {@code MetricsRegistry}
 * where metrics for that consumer gets stored.
 */
public class MetricsReporter implements AutoCloseable {

    private static LoadingCache<String, MetricsReporter> METRIC_REPORTERS = CacheBuilder.newBuilder().build(
            new CacheLoader<String, MetricsReporter>() {
                @Override
                public MetricsReporter load(String domainName) {
                    return new MetricsReporter(domainName);
                }
            });

    private final String domainName;
    private final JmxReporter jmxReporter;
    private final MetricRegistry metricRegistry = new MetricRegistry();

    private MetricsReporter(String domainName) {
        this.domainName = domainName;
        jmxReporter = JmxReporter.forRegistry(metricRegistry).inDomain(domainName).build();
        jmxReporter.start();
    }

    public static MetricsReporter getInstance(String domainName) {
        return METRIC_REPORTERS.getUnchecked(domainName);
    }

    public MetricRegistry getMetricsRegistry() {
        return metricRegistry;
    }

    @Override
    public void close() {
        jmxReporter.close();

        METRIC_REPORTERS.invalidate(domainName);
    }
}

@@ -957,16 +957,22 @@
  static 
+final 
 LoadingC
@@ -1061,20 +1061,16 @@
         
-    
 new Cach
@@ -1118,20 +1118,16 @@
         
-    
 @Overrid
@@ -1128,20 +1128,16 @@
 verride%0A
-    
         
@@ -1168,16 +1168,22 @@
 er load(
+final 
 String d
@@ -1191,28 +1191,24 @@
 mainName) %7B%0A
-    
             
@@ -1267,18 +1267,10 @@
     
-    %7D%0A    
+%7D%0A
     
@@ -1459,16 +1459,22 @@
 eporter(
+final 
 String d
@@ -1644,32 +1644,32 @@
 start();%0A    %7D%0A%0A
-
     public stati
@@ -1698,16 +1698,22 @@
 nstance(
+final 
 String d

Make sure MetricsReporter cache is constant