b3608eceef13d7006c007a90e6c715323d693221
[controller.git] / opendaylight / md-sal / sal-inmemory-datastore / src / main / java / org / opendaylight / controller / md / sal / dom / store / impl / jmx / InMemoryDataStoreStats.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.store.impl.jmx;
10
11 import java.util.concurrent.ExecutorService;
12
13 import org.opendaylight.controller.md.sal.common.util.jmx.QueuedNotificationManagerMXBeanImpl;
14 import org.opendaylight.controller.md.sal.common.util.jmx.ThreadExecutorStatsMXBeanImpl;
15 import org.opendaylight.yangtools.util.concurrent.QueuedNotificationManager;
16
17 /**
18  * Wrapper class for data store MXbeans.
19  *
20  * @author Thomas Pantelis
21  */
22 public class InMemoryDataStoreStats implements AutoCloseable {
23
24     private final ThreadExecutorStatsMXBeanImpl notificationExecutorStatsBean;
25     private final ThreadExecutorStatsMXBeanImpl dataStoreExecutorStatsBean;
26     private final QueuedNotificationManagerMXBeanImpl notificationManagerStatsBean;
27
28     public InMemoryDataStoreStats(String mBeanType, QueuedNotificationManager<?, ?> manager,
29             ExecutorService dataStoreExecutor) {
30
31         this.notificationManagerStatsBean = new QueuedNotificationManagerMXBeanImpl(manager,
32                 "notification-manager", mBeanType, null);
33         notificationManagerStatsBean.registerMBean();
34
35         this.notificationExecutorStatsBean = new ThreadExecutorStatsMXBeanImpl(manager.getExecutor(),
36                 "notification-executor", mBeanType, null);
37         this.notificationExecutorStatsBean.registerMBean();
38
39         this.dataStoreExecutorStatsBean = new ThreadExecutorStatsMXBeanImpl(dataStoreExecutor,
40                 "data-store-executor", mBeanType, null);
41         this.dataStoreExecutorStatsBean.registerMBean();
42     }
43
44     @Override
45     public void close() throws Exception {
46         if(notificationExecutorStatsBean != null) {
47             notificationExecutorStatsBean.unregisterMBean();
48         }
49
50         if(dataStoreExecutorStatsBean != null) {
51             dataStoreExecutorStatsBean.unregisterMBean();
52         }
53
54         if(notificationManagerStatsBean != null) {
55             notificationManagerStatsBean.unregisterMBean();
56         }
57     }
58 }