Merge "Add Enqueue validation check in FlowConfig"
[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 org.opendaylight.controller.config.manager.impl.ConfigRegistryImpl;
11 import org.opendaylight.controller.config.manager.impl.jmx.ConfigRegistryJMXRegistrator;
12 import org.opendaylight.controller.config.manager.impl.osgi.mapping.CodecRegistryProvider;
13 import org.opendaylight.controller.config.manager.impl.osgi.mapping.ModuleInfoBundleTracker;
14 import org.opendaylight.controller.config.manager.impl.osgi.mapping.RefreshingSCPModuleInfoRegistry;
15 import org.opendaylight.controller.config.manager.impl.util.OsgiRegistrationUtil;
16 import org.opendaylight.controller.config.spi.ModuleFactory;
17 import org.opendaylight.yangtools.concepts.ObjectRegistration;
18 import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext;
19 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
20 import org.osgi.framework.BundleActivator;
21 import org.osgi.framework.BundleContext;
22 import org.osgi.util.tracker.ServiceTracker;
23
24 import javax.management.InstanceAlreadyExistsException;
25 import javax.management.MBeanServer;
26 import java.lang.management.ManagementFactory;
27 import java.util.Arrays;
28 import java.util.Collection;
29 import java.util.List;
30
31 import static org.opendaylight.controller.config.manager.impl.util.OsgiRegistrationUtil.registerService;
32 import static org.opendaylight.controller.config.manager.impl.util.OsgiRegistrationUtil.wrap;
33
34 public class ConfigManagerActivator implements BundleActivator {
35     private final MBeanServer configMBeanServer = ManagementFactory.getPlatformMBeanServer();
36
37     private AutoCloseable autoCloseable;
38
39     @Override
40     public void start(BundleContext context) {
41
42         ModuleInfoBackedContext moduleInfoBackedContext = ModuleInfoBackedContext.create();// the inner strategy is backed by thread context cl?
43
44         RefreshingSCPModuleInfoRegistry moduleInfoRegistryWrapper = new RefreshingSCPModuleInfoRegistry(
45                 moduleInfoBackedContext, moduleInfoBackedContext, context);
46
47         ModuleInfoBundleTracker moduleInfoBundleTracker = new ModuleInfoBundleTracker(moduleInfoRegistryWrapper);
48
49         CodecRegistryProvider codecRegistryProvider = new CodecRegistryProvider(moduleInfoBackedContext, context);
50
51         // start config registry
52         BundleContextBackedModuleFactoriesResolver bundleContextBackedModuleFactoriesResolver = new BundleContextBackedModuleFactoriesResolver(
53                 context);
54         ConfigRegistryImpl configRegistry = new ConfigRegistryImpl(bundleContextBackedModuleFactoriesResolver, configMBeanServer,
55                 codecRegistryProvider.getCodecRegistry());
56
57         // track bundles containing factories
58         BlankTransactionServiceTracker blankTransactionServiceTracker = new BlankTransactionServiceTracker(
59                 configRegistry);
60         ModuleFactoryBundleTracker moduleFactoryBundleTracker = new ModuleFactoryBundleTracker(
61                 blankTransactionServiceTracker);
62
63         // start extensible tracker
64         ExtensibleBundleTracker<Collection<ObjectRegistration<YangModuleInfo>>> bundleTracker = new ExtensibleBundleTracker<>(context, moduleInfoBundleTracker, moduleFactoryBundleTracker);
65         bundleTracker.open();
66
67         // register config registry to OSGi
68         AutoCloseable configRegReg = registerService(context, configRegistry, ConfigRegistryImpl.class);
69
70         // register config registry to jmx
71         ConfigRegistryJMXRegistrator configRegistryJMXRegistrator = new ConfigRegistryJMXRegistrator(configMBeanServer);
72         try {
73             configRegistryJMXRegistrator.registerToJMX(configRegistry);
74         } catch (InstanceAlreadyExistsException e) {
75             throw new IllegalStateException("Config Registry was already registered to JMX", e);
76         }
77
78         // TODO wire directly via moduleInfoBundleTracker
79         ServiceTracker<ModuleFactory, Object> serviceTracker = new ServiceTracker<>(context, ModuleFactory.class,
80                 blankTransactionServiceTracker);
81         serviceTracker.open();
82
83         List<AutoCloseable> list = Arrays.asList(
84                 codecRegistryProvider, configRegistry, wrap(bundleTracker), configRegReg, configRegistryJMXRegistrator, wrap(serviceTracker));
85         autoCloseable = OsgiRegistrationUtil.aggregate(list);
86     }
87
88     @Override
89     public void stop(BundleContext context) throws Exception {
90         autoCloseable.close();
91     }
92 }

©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.