Initial code drop of yang model driven configuration system
[controller.git] / opendaylight / config / config-manager / src / main / java / org / opendaylight / controller / config / manager / impl / osgi / ConfigManagerActivator.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.osgi;
9
10 import java.lang.management.ManagementFactory;
11
12 import javax.management.MBeanServer;
13
14 import org.opendaylight.controller.config.manager.impl.ConfigRegistryImpl;
15 import org.opendaylight.controller.config.manager.impl.jmx.ConfigRegistryJMXRegistrator;
16 import org.osgi.framework.BundleActivator;
17 import org.osgi.framework.BundleContext;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 public class ConfigManagerActivator implements BundleActivator {
22     private static final Logger logger = LoggerFactory
23             .getLogger(ConfigManagerActivator.class);
24
25     private ExtenderBundleTracker extenderBundleTracker;
26     private ConfigRegistryImpl configRegistry;
27     private ConfigRegistryJMXRegistrator configRegistryJMXRegistrator;
28
29     @Override
30     public void start(BundleContext context) throws Exception {
31         extenderBundleTracker = new ExtenderBundleTracker(context);
32         extenderBundleTracker.open();
33         BundleContextBackedModuleFactoriesResolver bundleContextBackedModuleFactoriesResolver = new BundleContextBackedModuleFactoriesResolver(
34                 context);
35
36         MBeanServer configMBeanServer = ManagementFactory
37                 .getPlatformMBeanServer();
38         configRegistry = new ConfigRegistryImpl(
39                 bundleContextBackedModuleFactoriesResolver, context,
40                 configMBeanServer);
41         // register config registry to jmx
42
43         configRegistryJMXRegistrator = new ConfigRegistryJMXRegistrator(
44                 configMBeanServer);
45         configRegistryJMXRegistrator.registerToJMX(configRegistry);
46     }
47
48     @Override
49     public void stop(BundleContext context) throws Exception {
50         try {
51             configRegistry.close();
52         } catch (Exception e) {
53             logger.warn("Exception while closing config registry", e);
54         }
55         try {
56             extenderBundleTracker.close();
57         } catch (Exception e) {
58             logger.warn("Exception while closing extender", e);
59         }
60         try {
61             configRegistryJMXRegistrator.close();
62         } catch (Exception e) {
63             logger.warn(
64                     "Exception while closing config registry jmx registrator",
65                     e);
66         }
67     }
68 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.