Merge "Bug 1666: Fixing the clustering config file issue"
[controller.git] / opendaylight / md-sal / sal-dom-broker / src / main / java / org / opendaylight / controller / md / sal / dom / broker / impl / jmx / CommitStatsMXBeanImpl.java
1 /*
2  * Copyright (c) 2014 Brocade Communications 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
9 package org.opendaylight.controller.md.sal.dom.broker.impl.jmx;
10
11 import javax.annotation.Nonnull;
12
13 import org.opendaylight.controller.md.sal.common.util.jmx.AbstractMXBean;
14 import org.opendaylight.yangtools.util.DurationStatsTracker;
15
16 /**
17  * Implementation of the CommitStatsMXBean interface.
18  *
19  * @author Thomas Pantelis
20  */
21 public class CommitStatsMXBeanImpl extends AbstractMXBean implements CommitStatsMXBean {
22
23     private final DurationStatsTracker commitStatsTracker;
24
25     /**
26      * Constructor.
27      *
28      * @param commitStatsTracker the DurationStatsTracker used to obtain the stats.
29      * @param mBeanType mBeanType Used as the <code>type</code> property in the bean's ObjectName.
30      */
31     public CommitStatsMXBeanImpl(@Nonnull DurationStatsTracker commitStatsTracker,
32             @Nonnull String mBeanType) {
33         super("CommitStats", mBeanType, null);
34         this.commitStatsTracker = commitStatsTracker;
35     }
36
37     @Override
38     public long getTotalCommits() {
39         return commitStatsTracker.getTotalDurations();
40     }
41
42     @Override
43     public String getLongestCommitTime() {
44         return commitStatsTracker.getDisplayableLongestDuration();
45     }
46
47     @Override
48     public String getShortestCommitTime() {
49         return commitStatsTracker.getDisplayableShortestDuration();
50     }
51
52     @Override
53     public String getAverageCommitTime() {
54         return commitStatsTracker.getDisplayableAverageDuration();
55     }
56
57     @Override
58     public void clearStats() {
59         commitStatsTracker.reset();
60     }
61 }