Initial code drop of yang model driven configuration system
[controller.git] / opendaylight / config / config-manager / src / main / java / org / opendaylight / controller / config / manager / impl / jmx / RootRuntimeBeanRegistratorImpl.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.config.manager.impl.jmx;
9
10 import java.util.Collections;
11
12 import javax.management.InstanceAlreadyExistsException;
13 import javax.management.ObjectName;
14
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;
19
20 public class RootRuntimeBeanRegistratorImpl implements
21         RootRuntimeBeanRegistrator {
22     private final InternalJMXRegistrator internalJMXRegistrator;
23     private final ModuleIdentifier moduleIdentifier;
24     private final ObjectName defaultRuntimeON;
25
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());
35     }
36
37     @Override
38     public HierarchicalRuntimeBeanRegistrationImpl registerRoot(
39             RuntimeBean mxBean) {
40         try {
41             internalJMXRegistrator.registerMBean(mxBean, defaultRuntimeON);
42         } catch (InstanceAlreadyExistsException e) {
43             throw sanitize(e, moduleIdentifier, defaultRuntimeON);
44         }
45         return new HierarchicalRuntimeBeanRegistrationImpl(moduleIdentifier,
46                 internalJMXRegistrator, Collections.<String, String> emptyMap());
47     }
48
49     @Override
50     public void close() {
51         internalJMXRegistrator.close();
52     }
53
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);
58
59     }
60 }