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