Proxy over MDSAL-provided IMDS
[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 package org.opendaylight.controller.md.sal.dom.store.impl.jmx;
9
10 import org.opendaylight.controller.md.sal.common.util.jmx.AbstractMXBean;
11 import org.opendaylight.controller.md.sal.common.util.jmx.QueuedNotificationManagerMXBeanImpl;
12 import org.opendaylight.controller.md.sal.common.util.jmx.ThreadExecutorStatsMXBeanImpl;
13 import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore;
14 import org.opendaylight.yangtools.concepts.AbstractRegistration;
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 extends AbstractRegistration {
23
24     private final AbstractMXBean notificationExecutorStatsBean;
25     private final QueuedNotificationManagerMXBeanImpl notificationManagerStatsBean;
26
27     public InMemoryDataStoreStats(final String beanType, final QueuedNotificationManager<?, ?> manager) {
28
29         notificationManagerStatsBean = new QueuedNotificationManagerMXBeanImpl(manager,
30                 "notification-manager", beanType, null);
31         notificationManagerStatsBean.registerMBean();
32
33         notificationExecutorStatsBean = ThreadExecutorStatsMXBeanImpl.create(manager.getExecutor(),
34                 "notification-executor", beanType, null);
35         if (notificationExecutorStatsBean != null) {
36             notificationExecutorStatsBean.registerMBean();
37         }
38     }
39
40     public InMemoryDataStoreStats(final String name, final InMemoryDOMDataStore dataStore) {
41         this(name, dataStore.getDataChangeListenerNotificationManager());
42     }
43
44     @Override
45     protected void removeRegistration() {
46         if (notificationExecutorStatsBean != null) {
47             notificationExecutorStatsBean.unregisterMBean();
48         }
49
50         if (notificationManagerStatsBean != null) {
51             notificationManagerStatsBean.unregisterMBean();
52         }
53     }
54 }