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 com.google.common.base.Preconditions;
11 import java.io.Closeable;
12 import javax.annotation.concurrent.ThreadSafe;
13 import javax.management.InstanceAlreadyExistsException;
14 import javax.management.ObjectName;
15 import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
18 * This subclass is used for registering readable module into JMX, it is also
19 * used as underlying provider in {@link RuntimeBeanRegistratorImpl}. Closing
20 * the instance thus unregisters all JMX beans related to the module excluding
21 * currently open transactions.
24 public class ModuleJMXRegistrator implements Closeable {
25 private final InternalJMXRegistrator childJMXRegistrator;
27 ModuleJMXRegistrator(final InternalJMXRegistrator internalJMXRegistrator) {
28 this.childJMXRegistrator = Preconditions.checkNotNull(internalJMXRegistrator);
31 static class ModuleJMXRegistration implements AutoCloseable {
32 private final InternalJMXRegistration internalJMXRegistration;
34 ModuleJMXRegistration(final InternalJMXRegistration registration) {
35 this.internalJMXRegistration = registration;
40 internalJMXRegistration.close();
44 public ModuleJMXRegistration registerMBean(final Object object, final ObjectName on)
45 throws InstanceAlreadyExistsException {
46 ObjectNameUtil.checkType(on, ObjectNameUtil.TYPE_MODULE);
47 if (ObjectNameUtil.getTransactionName(on) != null) {
48 throw new IllegalArgumentException(
49 "Transaction name not expected in " + on);
51 return new ModuleJMXRegistration(childJMXRegistrator.registerMBean(
57 childJMXRegistrator.close();