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.util.Collections;
12 import javax.management.InstanceAlreadyExistsException;
13 import javax.management.ObjectName;
15 import org.opendaylight.controller.config.api.ModuleIdentifier;
16 import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
17 import org.opendaylight.controller.config.api.runtime.RootRuntimeBeanRegistrator;
18 import org.opendaylight.controller.config.api.runtime.RuntimeBean;
20 public class RootRuntimeBeanRegistratorImpl implements
21 RootRuntimeBeanRegistrator {
22 private final InternalJMXRegistrator internalJMXRegistrator;
23 private final ModuleIdentifier moduleIdentifier;
24 private final ObjectName defaultRuntimeON;
26 public RootRuntimeBeanRegistratorImpl(
27 InternalJMXRegistrator internalJMXRegistrator,
28 ModuleIdentifier moduleIdentifier) {
29 this.internalJMXRegistrator = internalJMXRegistrator;
30 this.moduleIdentifier = moduleIdentifier;
31 defaultRuntimeON = ObjectNameUtil.createRuntimeBeanName(
32 moduleIdentifier.getFactoryName(),
33 moduleIdentifier.getInstanceName(),
34 Collections.<String, String> emptyMap());
38 public HierarchicalRuntimeBeanRegistrationImpl registerRoot(
41 internalJMXRegistrator.registerMBean(mxBean, defaultRuntimeON);
42 } catch (InstanceAlreadyExistsException e) {
43 throw sanitize(e, moduleIdentifier, defaultRuntimeON);
45 return new HierarchicalRuntimeBeanRegistrationImpl(moduleIdentifier,
46 internalJMXRegistrator, Collections.<String, String> emptyMap());
51 internalJMXRegistrator.close();
54 static IllegalStateException sanitize(InstanceAlreadyExistsException e,
55 ModuleIdentifier moduleIdentifier, ObjectName on) {
56 throw new IllegalStateException("Could not register runtime bean in "
57 + moduleIdentifier + " under name " + on, e);