BUG-4514: clean children in InternalJMXRegistrator
[controller.git] / opendaylight / config / config-manager / src / main / java / org / opendaylight / controller / config / manager / impl / jmx / ConfigRegistryJMXRegistrator.java
1 /*
2  * Copyright (c) 2013 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 package org.opendaylight.controller.config.manager.impl.jmx;
9
10 import javax.management.InstanceAlreadyExistsException;
11 import javax.management.MBeanServer;
12 import org.opendaylight.controller.config.api.jmx.ConfigRegistryMXBean;
13 import org.opendaylight.controller.config.manager.impl.ConfigRegistryImplMXBean;
14
15 /**
16  * This registrator is used only to register Config Registry to JMX.
17  *
18  */
19 public class ConfigRegistryJMXRegistrator implements AutoCloseable {
20     private final InternalJMXRegistrator internalJMXRegistrator;
21
22     public ConfigRegistryJMXRegistrator(final MBeanServer configMBeanServer) {
23         internalJMXRegistrator = InternalJMXRegistrator.create(configMBeanServer);
24     }
25
26     public AutoCloseable registerToJMX(final ConfigRegistryImplMXBean configRegistry)
27             throws InstanceAlreadyExistsException {
28         return internalJMXRegistrator.registerMBean(configRegistry, ConfigRegistryMXBean.OBJECT_NAME);
29     }
30
31     public AutoCloseable registerToJMXNoNotifications(final ConfigRegistryImplMXBean configRegistry)
32             throws InstanceAlreadyExistsException {
33         return internalJMXRegistrator.registerMBean(configRegistry, ConfigRegistryMXBean.OBJECT_NAME_NO_NOTIFICATIONS);
34     }
35
36     @Override
37     public void close() {
38         internalJMXRegistrator.close();
39     }
40 }