Merge "Make sure write transaction cancellation is propagated"
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / main / java / org / opendaylight / controller / cluster / reporting / MetricsReporter.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.cluster.reporting;
9
10 import com.codahale.metrics.JmxReporter;
11 import com.codahale.metrics.MetricRegistry;
12
13 /**
14  * Maintains metrics registry that is provided to reporters.
15  * At the moment only one reporter exists {@code JmxReporter}.
16  * More reporters can be added.
17  * <p/>
18  * The consumers of this class will only be interested in {@code MetricsRegistry}
19  * where metrics for that consumer gets stored.
20  */
21 public class MetricsReporter implements AutoCloseable {
22
23     private static final MetricRegistry METRICS_REGISTRY = new MetricRegistry();
24     private static final String DOMAIN = "org.opendaylight.controller.actor.metric";
25     private static final MetricsReporter INSTANCE = new MetricsReporter();
26
27     private final JmxReporter jmxReporter = JmxReporter.forRegistry(METRICS_REGISTRY).inDomain(DOMAIN).build();
28
29     private MetricsReporter() {
30         jmxReporter.start();
31     }
32
33     public static MetricsReporter getInstance() {
34         return INSTANCE;
35     }
36
37     public MetricRegistry getMetricsRegistry() {
38         return METRICS_REGISTRY;
39     }
40
41     @Override
42     public void close() {
43         jmxReporter.close();
44     }
45 }