Fix followerDistributedDataStore tear down
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / databroker / 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 package org.opendaylight.controller.cluster.databroker;
9
10 import org.eclipse.jdt.annotation.NonNull;
11 import org.opendaylight.controller.cluster.datastore.jmx.mbeans.CommitStatsMXBean;
12 import org.opendaylight.controller.md.sal.common.util.jmx.AbstractMXBean;
13 import org.opendaylight.yangtools.util.DurationStatisticsTracker;
14
15 /**
16  * Implementation of the CommitStatsMXBean interface.
17  *
18  * @author Thomas Pantelis
19  */
20 final class CommitStatsMXBeanImpl extends AbstractMXBean implements CommitStatsMXBean {
21     private final DurationStatisticsTracker commitStatsTracker;
22
23     /**
24      * Constructor.
25      *
26      * @param commitStatsTracker the DurationStatsTracker used to obtain the stats.
27      * @param mbeantype mBeanType Used as the <code>type</code> property in the bean's ObjectName.
28      */
29     CommitStatsMXBeanImpl(final @NonNull DurationStatisticsTracker commitStatsTracker,
30             final @NonNull String mbeantype) {
31         super("CommitStats", mbeantype, null);
32         this.commitStatsTracker = commitStatsTracker;
33     }
34
35     @Override
36     public long getTotalCommits() {
37         return commitStatsTracker.getTotalDurations();
38     }
39
40     @Override
41     public String getLongestCommitTime() {
42         return commitStatsTracker.getDisplayableLongestDuration();
43     }
44
45     @Override
46     public String getShortestCommitTime() {
47         return commitStatsTracker.getDisplayableShortestDuration();
48     }
49
50     @Override
51     public String getAverageCommitTime() {
52         return commitStatsTracker.getDisplayableAverageDuration();
53     }
54
55     @Override
56     public void clearStats() {
57         commitStatsTracker.reset();
58     }
59 }