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.HashMap;
12 import javax.management.InstanceAlreadyExistsException;
13 import javax.management.ObjectName;
14 import org.opendaylight.controller.config.api.ModuleIdentifier;
15 import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
16 import org.opendaylight.controller.config.api.runtime.HierarchicalRuntimeBeanRegistration;
17 import org.opendaylight.controller.config.api.runtime.RuntimeBean;
19 public class HierarchicalRuntimeBeanRegistrationImpl implements
20 HierarchicalRuntimeBeanRegistration {
21 private final ModuleIdentifier moduleIdentifier;
22 private final InternalJMXRegistrator internalJMXRegistrator;
23 private final Map<String, String> properties;
25 public HierarchicalRuntimeBeanRegistrationImpl(
26 ModuleIdentifier moduleIdentifier,
27 InternalJMXRegistrator internalJMXRegistrator,
28 Map<String, String> properties) {
29 this.moduleIdentifier = moduleIdentifier;
30 this.internalJMXRegistrator = internalJMXRegistrator;
31 this.properties = properties;
35 public ObjectName getObjectName() {
36 return ObjectNameUtil.createRuntimeBeanName(
37 moduleIdentifier.getFactoryName(),
38 moduleIdentifier.getInstanceName(), properties);
42 public HierarchicalRuntimeBeanRegistrationImpl register(String key,
43 String value, RuntimeBean mxBean) {
44 Map<String, String> currentProperties = new HashMap<>(properties);
45 currentProperties.put(key, value);
46 ObjectName on = ObjectNameUtil.createRuntimeBeanName(
47 moduleIdentifier.getFactoryName(),
48 moduleIdentifier.getInstanceName(), currentProperties);
49 InternalJMXRegistrator child = internalJMXRegistrator.createChild();
51 child.registerMBean(mxBean, on);
52 } catch (InstanceAlreadyExistsException e) {
53 throw RootRuntimeBeanRegistratorImpl.sanitize(e, moduleIdentifier,
56 return new HierarchicalRuntimeBeanRegistrationImpl(moduleIdentifier,
57 child, currentProperties);
62 internalJMXRegistrator.close();