Remove raw references to Map in XSQL
[controller.git] / opendaylight / config / config-manager / src / main / java / org / opendaylight / controller / config / manager / impl / jmx / ModuleJMXRegistrator.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 java.io.Closeable;
11
12 import javax.annotation.concurrent.ThreadSafe;
13 import javax.management.InstanceAlreadyExistsException;
14 import javax.management.ObjectName;
15
16 import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
17 import org.opendaylight.controller.config.manager.impl.jmx.InternalJMXRegistrator.InternalJMXRegistration;
18
19 /**
20  * This subclass is used for registering readable module into JMX, it is also
21  * used as underlying provider in {@link RuntimeBeanRegistratorImpl}. Closing
22  * the instance thus unregisters all JMX beans related to the module excluding
23  * currently open transactions.
24  */
25 @ThreadSafe
26 public class ModuleJMXRegistrator implements Closeable {
27     private final InternalJMXRegistrator childJMXRegistrator;
28
29     public ModuleJMXRegistrator(InternalJMXRegistrator internalJMXRegistrator) {
30         this.childJMXRegistrator = internalJMXRegistrator.createChild();
31     }
32
33     static class ModuleJMXRegistration implements AutoCloseable {
34         private final InternalJMXRegistration internalJMXRegistration;
35
36         ModuleJMXRegistration(InternalJMXRegistration registration) {
37             this.internalJMXRegistration = registration;
38         }
39
40         @Override
41         public void close() {
42             internalJMXRegistration.close();
43         }
44     }
45
46     public ModuleJMXRegistration registerMBean(Object object, ObjectName on)
47             throws InstanceAlreadyExistsException {
48         ObjectNameUtil.checkType(on, ObjectNameUtil.TYPE_MODULE);
49         if (ObjectNameUtil.getTransactionName(on) != null) {
50             throw new IllegalArgumentException(
51                     "Transaction name not expected in " + on);
52         }
53         return new ModuleJMXRegistration(childJMXRegistrator.registerMBean(
54                 object, on));
55     }
56
57     @Override
58     public void close() {
59         childJMXRegistrator.close();
60     }
61
62 }