2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.config.manager.impl.jmx;
10 import java.io.Closeable;
12 import javax.annotation.concurrent.ThreadSafe;
13 import javax.management.InstanceAlreadyExistsException;
14 import javax.management.ObjectName;
16 import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
17 import org.opendaylight.controller.config.manager.impl.jmx.InternalJMXRegistrator.InternalJMXRegistration;
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.
26 public class ModuleJMXRegistrator implements Closeable {
27 private final InternalJMXRegistrator childJMXRegistrator;
29 public ModuleJMXRegistrator(InternalJMXRegistrator internalJMXRegistrator) {
30 this.childJMXRegistrator = internalJMXRegistrator.createChild();
33 static class ModuleJMXRegistration implements AutoCloseable {
34 private final InternalJMXRegistration internalJMXRegistration;
36 ModuleJMXRegistration(InternalJMXRegistration registration) {
37 this.internalJMXRegistration = registration;
42 internalJMXRegistration.close();
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 return new ModuleJMXRegistration(childJMXRegistrator.registerMBean(
58 childJMXRegistrator.close();