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.osgi;
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.sal.binding.generator.impl.ModuleInfoBackedContext;
18 import org.osgi.framework.BundleActivator;
19 import org.osgi.framework.BundleContext;
20 import org.osgi.util.tracker.ServiceTracker;
22 import javax.management.InstanceAlreadyExistsException;
23 import javax.management.MBeanServer;
24 import java.lang.management.ManagementFactory;
25 import java.util.Arrays;
26 import java.util.List;
28 import static org.opendaylight.controller.config.manager.impl.util.OsgiRegistrationUtil.registerService;
29 import static org.opendaylight.controller.config.manager.impl.util.OsgiRegistrationUtil.wrap;
31 public class ConfigManagerActivator implements BundleActivator {
32 private final MBeanServer configMBeanServer = ManagementFactory.getPlatformMBeanServer();
34 private AutoCloseable autoCloseable;
37 public void start(BundleContext context) {
39 ModuleInfoBackedContext moduleInfoBackedContext = ModuleInfoBackedContext.create();// the inner strategy is backed by thread context cl?
41 RefreshingSCPModuleInfoRegistry moduleInfoRegistryWrapper = new RefreshingSCPModuleInfoRegistry(
42 moduleInfoBackedContext, moduleInfoBackedContext, context);
44 ModuleInfoBundleTracker moduleInfoBundleTracker = new ModuleInfoBundleTracker(moduleInfoRegistryWrapper);
46 CodecRegistryProvider codecRegistryProvider = new CodecRegistryProvider(moduleInfoBackedContext, context);
48 // start config registry
49 BundleContextBackedModuleFactoriesResolver bundleContextBackedModuleFactoriesResolver = new BundleContextBackedModuleFactoriesResolver(
51 ConfigRegistryImpl configRegistry = new ConfigRegistryImpl(bundleContextBackedModuleFactoriesResolver, configMBeanServer,
52 codecRegistryProvider.getCodecRegistry());
54 // track bundles containing factories
55 BlankTransactionServiceTracker blankTransactionServiceTracker = new BlankTransactionServiceTracker(
57 ModuleFactoryBundleTracker primaryModuleFactoryBundleTracker = new ModuleFactoryBundleTracker(
58 blankTransactionServiceTracker);
60 // start extensible tracker
61 ExtensibleBundleTracker<?> bundleTracker = new ExtensibleBundleTracker<>(context,
62 primaryModuleFactoryBundleTracker, moduleInfoBundleTracker);
65 // register config registry to OSGi
66 AutoCloseable configRegReg = registerService(context, configRegistry, ConfigRegistryImpl.class);
68 // register config registry to jmx
69 ConfigRegistryJMXRegistrator configRegistryJMXRegistrator = new ConfigRegistryJMXRegistrator(configMBeanServer);
71 configRegistryJMXRegistrator.registerToJMX(configRegistry);
72 } catch (InstanceAlreadyExistsException e) {
73 throw new IllegalStateException("Config Registry was already registered to JMX", e);
76 // TODO wire directly via moduleInfoBundleTracker
77 ServiceTracker<ModuleFactory, Object> serviceTracker = new ServiceTracker<>(context, ModuleFactory.class,
78 blankTransactionServiceTracker);
79 serviceTracker.open();
81 List<AutoCloseable> list = Arrays.asList(
82 codecRegistryProvider, configRegistry, wrap(bundleTracker), configRegReg, configRegistryJMXRegistrator, wrap(serviceTracker));
83 autoCloseable = OsgiRegistrationUtil.aggregate(list);
87 public void stop(BundleContext context) throws Exception {
88 autoCloseable.close();