- public void start(BundleContext context) throws Exception {
- BundleContextBackedModuleFactoriesResolver bundleContextBackedModuleFactoriesResolver =
- new BundleContextBackedModuleFactoriesResolver(context);
- MBeanServer configMBeanServer = ManagementFactory.getPlatformMBeanServer();
- configRegistry = new ConfigRegistryImpl(
- bundleContextBackedModuleFactoriesResolver, configMBeanServer);
-
- // register config registry to OSGi
- configRegistryServiceRegistration = context.registerService(ConfigRegistryImpl.class, configRegistry, null);
-
- // register config registry to jmx
- configRegistryJMXRegistrator = new ConfigRegistryJMXRegistrator(configMBeanServer);
- configRegistryJMXRegistrator.registerToJMX(configRegistry);
-
- // track bundles containing factories
- BlankTransactionServiceTracker blankTransactionServiceTracker = new BlankTransactionServiceTracker(configRegistry);
- extenderBundleTracker = new ExtenderBundleTracker(context, blankTransactionServiceTracker);
- extenderBundleTracker.open();
-
- ServiceTracker<?, ?> serviceTracker = new ServiceTracker(context, ModuleFactory.class, blankTransactionServiceTracker);
- serviceTracker.open();
+ public void start(final BundleContext context) {
+ try {
+ // the inner strategy is backed by thread context cl?
+ ModuleInfoBackedContext moduleInfoBackedContext = ModuleInfoBackedContext.create();
+
+ BindingContextProvider bindingContextProvider = new BindingContextProvider();
+
+ RefreshingSCPModuleInfoRegistry moduleInfoRegistryWrapper = new RefreshingSCPModuleInfoRegistry(
+ moduleInfoBackedContext, moduleInfoBackedContext, moduleInfoBackedContext, moduleInfoBackedContext, bindingContextProvider, context);
+
+ ModuleInfoBundleTracker moduleInfoBundleTracker = new ModuleInfoBundleTracker(context, moduleInfoRegistryWrapper);
+
+ // start config registry
+ BundleContextBackedModuleFactoriesResolver bundleContextBackedModuleFactoriesResolver = new BundleContextBackedModuleFactoriesResolver(
+ context);
+ configRegistry = new ConfigRegistryImpl(bundleContextBackedModuleFactoriesResolver, configMBeanServer,
+ bindingContextProvider);
+
+ // track bundles containing factories
+ BlankTransactionServiceTracker blankTransactionServiceTracker = new BlankTransactionServiceTracker(
+ configRegistry);
+ ModuleFactoryBundleTracker moduleFactoryTracker = new ModuleFactoryBundleTracker(
+ blankTransactionServiceTracker);
+
+ boolean scanResolvedBundlesForModuleInfo = true;
+ BundleTracker<Collection<ObjectRegistration<YangModuleInfo>>> moduleInfoResolvedBundleTracker = null;
+ ExtensibleBundleTracker<?> moduleFactoryBundleTracker;
+ if(scanResolvedBundlesForModuleInfo) {
+ moduleInfoResolvedBundleTracker = new BundleTracker<>(context, Bundle.RESOLVED | Bundle.STARTING |
+ Bundle.STOPPING | Bundle.ACTIVE, moduleInfoBundleTracker);
+ moduleFactoryBundleTracker = new ExtensibleBundleTracker<>(context, moduleFactoryTracker);
+ } else {
+ moduleFactoryBundleTracker = new ExtensibleBundleTracker<>(context,
+ moduleFactoryTracker, moduleInfoBundleTracker);
+ }
+
+ moduleInfoBundleTracker.open(moduleInfoResolvedBundleTracker);
+
+ // start extensible tracker
+ moduleFactoryBundleTracker.open();
+
+ // Wrap config registry with JMX notification publishing adapter
+ final JMXNotifierConfigRegistry notifyingConfigRegistry =
+ new JMXNotifierConfigRegistry(configRegistry, configMBeanServer);
+
+ // register config registry to OSGi
+ AutoCloseable clsReg = OsgiRegistrationUtil.registerService(context, moduleInfoBackedContext, ClassLoadingStrategy.class);
+ AutoCloseable configRegReg = OsgiRegistrationUtil.registerService(context, notifyingConfigRegistry, ConfigRegistry.class);
+
+ // register config registry to jmx
+ ConfigRegistryJMXRegistrator configRegistryJMXRegistrator = new ConfigRegistryJMXRegistrator(configMBeanServer);
+ try {
+ configRegistryJMXRegistrator.registerToJMXNoNotifications(configRegistry);
+ } catch (InstanceAlreadyExistsException e) {
+ configRegistryJMXRegistrator.close();
+ throw new IllegalStateException("Config Registry was already registered to JMX", e);
+ }
+
+ // register config registry to jmx
+ final ConfigRegistryJMXRegistrator configRegistryJMXRegistratorWithNotifications = new ConfigRegistryJMXRegistrator(configMBeanServer);
+ try {
+ configRegistryJMXRegistrator.registerToJMX(notifyingConfigRegistry);
+ } catch (InstanceAlreadyExistsException e) {
+ configRegistryJMXRegistrator.close();
+ configRegistryJMXRegistratorWithNotifications.close();
+ throw new IllegalStateException("Config Registry was already registered to JMX", e);
+ }
+
+ // TODO wire directly via moduleInfoBundleTracker
+ ServiceTracker<ModuleFactory, Object> serviceTracker = new ServiceTracker<>(context, ModuleFactory.class,
+ blankTransactionServiceTracker);
+ serviceTracker.open();
+
+ AutoCloseable configMgrReg = OsgiRegistrationUtil.registerService(context, this, ConfigSystemService.class);
+
+ List<AutoCloseable> list = Arrays.asList(bindingContextProvider, clsReg,
+ OsgiRegistrationUtil.wrap(moduleFactoryBundleTracker), moduleInfoBundleTracker,
+ configRegReg, configRegistryJMXRegistrator, configRegistryJMXRegistratorWithNotifications,
+ OsgiRegistrationUtil.wrap(serviceTracker), moduleInfoRegistryWrapper, notifyingConfigRegistry, configMgrReg);
+ autoCloseable = OsgiRegistrationUtil.aggregate(list);
+
+ context.addBundleListener(this);
+ } catch(Exception e) {
+ LOG.warn("Error starting config manager", e);
+ } catch(Error e) {
+ // Log JVM Error and re-throw. The OSGi container may silently fail the bundle and not always log
+ // the exception. This has been seen on initial feature install.
+ LOG.error("Error starting config manager", e);
+ throw e;
+ }