X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-manager%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fmanager%2Fimpl%2Fosgi%2FConfigManagerActivator.java;h=eba7ad1a05314b572081fdd41c98b541f11f220c;hp=b2f7a6dd20e299190ffd51af6422f668d5e8f316;hb=b8e58ad33db2a15162d548ba13f241409ffaadd9;hpb=6227570f6482136b72a26675d43c8bb88279503e diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/ConfigManagerActivator.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/ConfigManagerActivator.java index b2f7a6dd20..eba7ad1a05 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/ConfigManagerActivator.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/ConfigManagerActivator.java @@ -23,9 +23,9 @@ import org.opendaylight.controller.config.manager.impl.osgi.mapping.ModuleInfoBu import org.opendaylight.controller.config.manager.impl.osgi.mapping.RefreshingSCPModuleInfoRegistry; import org.opendaylight.controller.config.manager.impl.util.OsgiRegistrationUtil; import org.opendaylight.controller.config.spi.ModuleFactory; +import org.opendaylight.mdsal.binding.generator.api.ClassLoadingStrategy; +import org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext; import org.opendaylight.yangtools.concepts.ObjectRegistration; -import org.opendaylight.yangtools.sal.binding.generator.api.ClassLoadingStrategy; -import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext; import org.opendaylight.yangtools.yang.binding.YangModuleInfo; import org.osgi.framework.Bundle; import org.osgi.framework.BundleActivator; @@ -51,41 +51,36 @@ public class ConfigManagerActivator implements BundleActivator, SynchronousBundl @Override public void start(final BundleContext context) { + LOG.info("Config manager starting..."); try { // the inner strategy is backed by thread context cl? - ModuleInfoBackedContext moduleInfoBackedContext = ModuleInfoBackedContext.create(); + final ModuleInfoBackedContext moduleInfoBackedContext = ModuleInfoBackedContext.create(); - BindingContextProvider bindingContextProvider = new BindingContextProvider(); + final BindingContextProvider bindingContextProvider = new BindingContextProvider(); - RefreshingSCPModuleInfoRegistry moduleInfoRegistryWrapper = new RefreshingSCPModuleInfoRegistry( - moduleInfoBackedContext, moduleInfoBackedContext, moduleInfoBackedContext, moduleInfoBackedContext, bindingContextProvider, context); + final RefreshingSCPModuleInfoRegistry moduleInfoRegistryWrapper = new RefreshingSCPModuleInfoRegistry( + moduleInfoBackedContext, moduleInfoBackedContext, moduleInfoBackedContext, moduleInfoBackedContext, + bindingContextProvider, context); - ModuleInfoBundleTracker moduleInfoBundleTracker = new ModuleInfoBundleTracker(context, moduleInfoRegistryWrapper); + final ModuleInfoBundleTracker moduleInfoBundleTracker = new ModuleInfoBundleTracker(moduleInfoRegistryWrapper); // start config registry - BundleContextBackedModuleFactoriesResolver bundleContextBackedModuleFactoriesResolver = new BundleContextBackedModuleFactoriesResolver( - context); - configRegistry = new ConfigRegistryImpl(bundleContextBackedModuleFactoriesResolver, configMBeanServer, - bindingContextProvider); + final BundleContextBackedModuleFactoriesResolver bundleContextBackedModuleFactoriesResolver = + new BundleContextBackedModuleFactoriesResolver(context); + this.configRegistry = new ConfigRegistryImpl(bundleContextBackedModuleFactoriesResolver, + this.configMBeanServer, bindingContextProvider); // track bundles containing factories - BlankTransactionServiceTracker blankTransactionServiceTracker = new BlankTransactionServiceTracker( - configRegistry); - ModuleFactoryBundleTracker moduleFactoryTracker = new ModuleFactoryBundleTracker( + final BlankTransactionServiceTracker blankTransactionServiceTracker = new BlankTransactionServiceTracker( + this.configRegistry); + final ModuleFactoryBundleTracker moduleFactoryTracker = new ModuleFactoryBundleTracker( blankTransactionServiceTracker); - boolean scanResolvedBundlesForModuleInfo = true; - BundleTracker>> 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); - } - + BundleTracker>> moduleInfoResolvedBundleTracker = + new BundleTracker<>(context, Bundle.RESOLVED | Bundle.STARTING | Bundle.STOPPING | Bundle.ACTIVE, + moduleInfoBundleTracker); + ExtensibleBundleTracker moduleFactoryBundleTracker = new ExtensibleBundleTracker<>(context, + moduleFactoryTracker); moduleInfoBundleTracker.open(moduleInfoResolvedBundleTracker); // start extensible tracker @@ -93,78 +88,87 @@ public class ConfigManagerActivator implements BundleActivator, SynchronousBundl // Wrap config registry with JMX notification publishing adapter final JMXNotifierConfigRegistry notifyingConfigRegistry = - new JMXNotifierConfigRegistry(configRegistry, configMBeanServer); + new JMXNotifierConfigRegistry(this.configRegistry, this.configMBeanServer); // register config registry to OSGi - AutoCloseable clsReg = OsgiRegistrationUtil.registerService(context, moduleInfoBackedContext, ClassLoadingStrategy.class); - AutoCloseable configRegReg = OsgiRegistrationUtil.registerService(context, notifyingConfigRegistry, ConfigRegistry.class); + final AutoCloseable clsReg = OsgiRegistrationUtil.registerService(context, moduleInfoBackedContext, + ClassLoadingStrategy.class); + final AutoCloseable configRegReg = OsgiRegistrationUtil.registerService(context, notifyingConfigRegistry, + ConfigRegistry.class); // register config registry to jmx - ConfigRegistryJMXRegistrator configRegistryJMXRegistrator = new ConfigRegistryJMXRegistrator(configMBeanServer); + final ConfigRegistryJMXRegistrator configRegistryJMXRegistrator = + new ConfigRegistryJMXRegistrator(this.configMBeanServer); try { - configRegistryJMXRegistrator.registerToJMXNoNotifications(configRegistry); - } catch (InstanceAlreadyExistsException e) { + configRegistryJMXRegistrator.registerToJMXNoNotifications(this.configRegistry); + } catch (final 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); + final ConfigRegistryJMXRegistrator configRegistryJMXRegistratorWithNotifications = + new ConfigRegistryJMXRegistrator(this.configMBeanServer); try { configRegistryJMXRegistrator.registerToJMX(notifyingConfigRegistry); - } catch (InstanceAlreadyExistsException e) { + } catch (final InstanceAlreadyExistsException e) { configRegistryJMXRegistrator.close(); configRegistryJMXRegistratorWithNotifications.close(); throw new IllegalStateException("Config Registry was already registered to JMX", e); } // TODO wire directly via moduleInfoBundleTracker - ServiceTracker serviceTracker = new ServiceTracker<>(context, ModuleFactory.class, - blankTransactionServiceTracker); + final ServiceTracker serviceTracker = new ServiceTracker<>(context, + ModuleFactory.class, blankTransactionServiceTracker); serviceTracker.open(); - AutoCloseable configMgrReg = OsgiRegistrationUtil.registerService(context, this, ConfigSystemService.class); + final AutoCloseable configMgrReg = OsgiRegistrationUtil.registerService(context, this, + ConfigSystemService.class); - List list = Arrays.asList(bindingContextProvider, clsReg, + final List list = Arrays.asList(bindingContextProvider, clsReg, OsgiRegistrationUtil.wrap(moduleFactoryBundleTracker), moduleInfoBundleTracker, configRegReg, configRegistryJMXRegistrator, configRegistryJMXRegistratorWithNotifications, - OsgiRegistrationUtil.wrap(serviceTracker), moduleInfoRegistryWrapper, notifyingConfigRegistry, configMgrReg); - autoCloseable = OsgiRegistrationUtil.aggregate(list); + OsgiRegistrationUtil.wrap(serviceTracker), moduleInfoRegistryWrapper, notifyingConfigRegistry, + configMgrReg); + this.autoCloseable = OsgiRegistrationUtil.aggregate(list); context.addBundleListener(this); - } catch(Exception e) { - LOG.warn("Error starting config manager", e); - } catch(Error e) { + } catch(final Exception e) { + LOG.error("Error starting config manager", e); + } catch(final 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; } + + LOG.info("Config manager start complete"); } @Override public void stop(final BundleContext context) throws Exception { + LOG.info("Config manager stopping"); context.removeBundleListener(this); - autoCloseable.close(); + this.autoCloseable.close(); } @Override - public void bundleChanged(BundleEvent event) { - if(configRegistry == null) { + public void bundleChanged(final BundleEvent event) { + if(this.configRegistry == null) { return; } // If the system bundle (id 0) is stopping close the ConfigRegistry so it destroys all modules. On // shutdown the system bundle is stopped first. if(event.getBundle().getBundleId() == SYSTEM_BUNDLE_ID && event.getType() == BundleEvent.STOPPING) { - configRegistry.close(); + this.configRegistry.close(); } } @Override public void closeAllConfigModules() { - if(configRegistry != null) { - configRegistry.close(); + if(this.configRegistry != null) { + this.configRegistry.close(); } } }