BUG 2463 - Changing setting for shard-snapshot-data-threshold-percentage does not...
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / jmx / mbeans / shard / ShardStats.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
9 package org.opendaylight.controller.cluster.datastore.jmx.mbeans.shard;
10
11 import java.text.SimpleDateFormat;
12 import java.util.Date;
13 import java.util.List;
14 import java.util.concurrent.atomic.AtomicLong;
15 import org.opendaylight.controller.md.sal.common.util.jmx.AbstractMXBean;
16 import org.opendaylight.controller.md.sal.common.util.jmx.QueuedNotificationManagerMXBeanImpl;
17 import org.opendaylight.controller.md.sal.common.util.jmx.ThreadExecutorStats;
18 import org.opendaylight.controller.md.sal.common.util.jmx.ThreadExecutorStatsMXBeanImpl;
19 import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore;
20 import org.opendaylight.yangtools.util.concurrent.ListenerNotificationQueueStats;
21 import org.opendaylight.yangtools.util.concurrent.QueuedNotificationManager;
22
23 /**
24  * Maintains statistics for a shard.
25  *
26  * @author  Basheeruddin syedbahm@cisco.com
27  */
28 public class ShardStats extends AbstractMXBean implements ShardStatsMXBean {
29     public static String JMX_CATEGORY_SHARD = "Shards";
30
31     private final AtomicLong committedTransactionsCount = new AtomicLong();
32
33     private final AtomicLong readOnlyTransactionCount = new AtomicLong();
34
35     private final AtomicLong writeOnlyTransactionCount = new AtomicLong();
36
37     private final AtomicLong readWriteTransactionCount = new AtomicLong();
38
39     private String leader;
40
41     private String raftState;
42
43     private volatile long lastLogTerm = -1L;
44
45     private volatile long lastLogIndex = -1L;
46
47     private volatile long currentTerm = -1L;
48
49     private volatile long commitIndex = -1L;
50
51     private volatile long lastApplied = -1L;
52
53     private volatile long lastCommittedTransactionTime;
54
55     private final AtomicLong failedTransactionsCount = new AtomicLong();
56
57     private final AtomicLong failedReadTransactionsCount = new AtomicLong();
58
59     private final AtomicLong abortTransactionsCount = new AtomicLong();
60
61     private ThreadExecutorStatsMXBeanImpl notificationExecutorStatsBean;
62
63     private QueuedNotificationManagerMXBeanImpl notificationManagerStatsBean;
64
65     private volatile long dataSize = 0;
66
67     private final SimpleDateFormat sdf =
68         new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
69
70     public ShardStats(final String shardName, final String mxBeanType) {
71         super(shardName, mxBeanType, JMX_CATEGORY_SHARD);
72     }
73
74     public void setNotificationManager(final QueuedNotificationManager<?, ?> manager) {
75         this.notificationManagerStatsBean = new QueuedNotificationManagerMXBeanImpl(manager,
76                 "notification-manager", getMBeanType(), getMBeanCategory());
77
78         this.notificationExecutorStatsBean = ThreadExecutorStatsMXBeanImpl.create(manager.getExecutor());
79     }
80
81     @Override
82     public String getShardName() {
83         return getMBeanName();
84     }
85
86     @Override
87     public long getCommittedTransactionsCount() {
88         return committedTransactionsCount.get();
89     }
90
91     @Override
92     public String getLeader() {
93         return leader;
94     }
95
96     @Override
97     public String getRaftState() {
98         return raftState;
99     }
100
101     @Override
102     public long getReadOnlyTransactionCount() {
103         return readOnlyTransactionCount.get();
104     }
105
106     @Override
107     public long getWriteOnlyTransactionCount() {
108         return writeOnlyTransactionCount.get();
109     }
110
111     @Override
112     public long getReadWriteTransactionCount() {
113         return readWriteTransactionCount.get();
114     }
115
116     @Override
117     public long getLastLogIndex() {
118         return lastLogIndex;
119     }
120
121     @Override
122     public long getLastLogTerm() {
123         return lastLogTerm;
124     }
125
126     @Override
127     public long getCurrentTerm() {
128         return currentTerm;
129     }
130
131     @Override
132     public long getCommitIndex() {
133         return commitIndex;
134     }
135
136     @Override
137     public long getLastApplied() {
138         return lastApplied;
139     }
140
141     @Override
142     public String getLastCommittedTransactionTime() {
143
144         return sdf.format(new Date(lastCommittedTransactionTime));
145     }
146
147     @Override
148     public long getFailedTransactionsCount() {
149         return failedTransactionsCount.get();
150     }
151
152     @Override
153     public long getFailedReadTransactionsCount() {
154         return failedReadTransactionsCount.get();
155     }
156
157     @Override
158     public long getAbortTransactionsCount() {
159         return abortTransactionsCount.get();
160     }
161
162     public long incrementCommittedTransactionCount() {
163         return committedTransactionsCount.incrementAndGet();
164     }
165
166     public long incrementReadOnlyTransactionCount() {
167         return readOnlyTransactionCount.incrementAndGet();
168     }
169
170     public long incrementWriteOnlyTransactionCount() {
171         return writeOnlyTransactionCount.incrementAndGet();
172     }
173
174     public long incrementReadWriteTransactionCount() {
175         return readWriteTransactionCount.incrementAndGet();
176     }
177
178     public long incrementFailedTransactionsCount() {
179         return failedTransactionsCount.incrementAndGet();
180     }
181
182     public long incrementFailedReadTransactionsCount() {
183         return failedReadTransactionsCount.incrementAndGet();
184     }
185
186     public long incrementAbortTransactionsCount ()
187     {
188         return abortTransactionsCount.incrementAndGet();
189     }
190
191     public void setLeader(final String leader) {
192         this.leader = leader;
193     }
194
195     public void setRaftState(final String raftState) {
196         this.raftState = raftState;
197     }
198
199     public void setLastLogTerm(final long lastLogTerm) {
200         this.lastLogTerm = lastLogTerm;
201     }
202
203     public void setLastLogIndex(final long lastLogIndex) {
204         this.lastLogIndex = lastLogIndex;
205     }
206
207     public void setCurrentTerm(final long currentTerm) {
208         this.currentTerm = currentTerm;
209     }
210
211     public void setCommitIndex(final long commitIndex) {
212         this.commitIndex = commitIndex;
213     }
214
215     public void setLastApplied(final long lastApplied) {
216         this.lastApplied = lastApplied;
217     }
218
219     public void setLastCommittedTransactionTime(final long lastCommittedTransactionTime) {
220         this.lastCommittedTransactionTime = lastCommittedTransactionTime;
221     }
222
223     public void setInMemoryJournalDataSize(long dataSize){
224         this.dataSize = dataSize;
225     }
226
227     @Override
228     public long getInMemoryJournalDataSize(){
229         return dataSize;
230     }
231
232     @Override
233     public ThreadExecutorStats getDataStoreExecutorStats() {
234         // FIXME: this particular thing does not work, as it really is DS-specific
235         return null;
236     }
237
238     @Override
239     public ThreadExecutorStats getNotificationMgrExecutorStats() {
240         return notificationExecutorStatsBean.toThreadExecutorStats();
241     }
242
243     @Override
244     public List<ListenerNotificationQueueStats> getCurrentNotificationMgrListenerQueueStats() {
245         return notificationManagerStatsBean.getCurrentListenerQueueStats();
246     }
247
248     @Override
249     public int getMaxNotificationMgrListenerQueueSize() {
250         return notificationManagerStatsBean.getMaxListenerQueueSize();
251     }
252
253     /**
254      * resets the counters related to transactions
255      */
256     @Override
257     public void resetTransactionCounters(){
258         committedTransactionsCount.set(0);
259
260         readOnlyTransactionCount.set(0);
261
262         writeOnlyTransactionCount.set(0);
263
264         readWriteTransactionCount.set(0);
265
266         lastCommittedTransactionTime = 0;
267
268         failedTransactionsCount.set(0);
269
270         failedReadTransactionsCount.set(0);
271
272         abortTransactionsCount.set(0);
273
274     }
275
276     public void setDataStore(final InMemoryDOMDataStore store) {
277         setNotificationManager(store.getDataChangeListenerNotificationManager());
278     }
279 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.