@Test public void testLifecycleManagerIgnoresBundlesWithoutContexttForContextCreation() throws Exception { this.testee.maybeCreateApplicationContextFor(createBundleWithoutBundleContext()); verifyContextCreationIsNotAttempted(); }
protected void maybeCreateApplicationContextFor(Bundle bundle) { boolean debug = log.isDebugEnabled(); String bundleString = "[" + OsgiStringUtils.nullSafeNameAndSymName(bundle) + "]"; final Long bundleId = new Long(bundle.getBundleId()); if (managedContexts.containsKey(bundleId)) { if (debug) { log.debug("Bundle " + bundleString + " is already managed; ignoring..."); } return; } if (!versionMatcher.matchVersion(bundle)) { return; } BundleContext localBundleContext = OsgiBundleUtils.getBundleContext(bundle); if (localBundleContext == null) { if (debug) log.debug("Bundle " + bundleString + " has no bundle context; skipping..."); return; } final DelegatedExecutionOsgiBundleApplicationContext localApplicationContext; if (debug) log.debug("Inspecting bundle " + bundleString); try { localApplicationContext = contextCreator.createApplicationContext(localBundleContext); } catch (Exception ex) { log.error("Cannot create application context for bundle " + bundleString, ex); return; } if (localApplicationContext == null) { log.debug("No application context created for bundle " + bundleString); return; } if (typeChecker != null) { if (!typeChecker.isTypeCompatible(localBundleContext)) { log.info("Bundle " + OsgiStringUtils.nullSafeName(bundle) + " is not type compatible with extender " + OsgiStringUtils.nullSafeName(bundleContext.getBundle()) + "; ignoring bundle..."); return; } } log.debug("Bundle " + OsgiStringUtils.nullSafeName(bundle) + " is type compatible with extender " + OsgiStringUtils.nullSafeName(bundleContext.getBundle()) + "; processing bundle..."); BeanFactoryPostProcessor processingHook = new OsgiBeanFactoryPostProcessorAdapter(localBundleContext, postProcessors); localApplicationContext.addBeanFactoryPostProcessor(processingHook); managedContexts.put(bundleId, localApplicationContext); localApplicationContext.setDelegatedEventMulticaster(multicaster); ApplicationContextConfiguration config = contextConfigurationFactory.createConfiguration(bundle); final boolean asynch = config.isCreateAsynchronously(); Runnable contextRefresh = new Runnable() { public void run() { if (log.isTraceEnabled()) { log.trace("Calling pre-refresh on processor " + processor); } processor.preProcessRefresh(localApplicationContext); localApplicationContext.refresh(); } }; TaskExecutor executor = null; String creationType; if (asynch) { executor = taskExecutor; creationType = "Asynchronous"; } else { executor = sameThreadTaskExecutor; creationType = "Synchronous"; } if (debug) { log.debug(creationType + " context creation for bundle " + bundleString); } if (config.isWaitForDependencies()) { DependencyWaiterApplicationContextExecutor appCtxExecutor = new DependencyWaiterApplicationContextExecutor(localApplicationContext, !asynch, extenderConfiguration.getDependencyFactories()); long timeout; if (config.isTimeoutDeclared()) { timeout = config.getTimeout(); if (debug) log.debug("Setting bundle-defined, wait-for-dependencies/graceperiod timeout value=" + timeout + " ms, for bundle " + bundleString); } else { timeout = extenderConfiguration.getDependencyWaitTime(); if (debug) log.debug("Setting globally defined wait-for-dependencies/graceperiod timeout value=" + timeout + " ms, for bundle " + bundleString); } appCtxExecutor.setTimeout(timeout); appCtxExecutor.setWatchdog(timer); appCtxExecutor.setTaskExecutor(executor); appCtxExecutor.setMonitoringCounter(contextsStarted); appCtxExecutor.setDelegatedMulticaster(this.multicaster); contextsStarted.increment(); } else { } executor.execute(contextRefresh); }
LifecycleManager implements DisposableBean { protected void maybeCreateApplicationContextFor(Bundle bundle) { boolean debug = log.isDebugEnabled(); String bundleString = "[" + OsgiStringUtils.nullSafeNameAndSymName(bundle) + "]"; final Long bundleId = new Long(bundle.getBundleId()); if (managedContexts.containsKey(bundleId)) { if (debug) { log.debug("Bundle " + bundleString + " is already managed; ignoring..."); } return; } if (!versionMatcher.matchVersion(bundle)) { return; } BundleContext localBundleContext = OsgiBundleUtils.getBundleContext(bundle); if (localBundleContext == null) { if (debug) log.debug("Bundle " + bundleString + " has no bundle context; skipping..."); return; } final DelegatedExecutionOsgiBundleApplicationContext localApplicationContext; if (debug) log.debug("Inspecting bundle " + bundleString); try { localApplicationContext = contextCreator.createApplicationContext(localBundleContext); } catch (Exception ex) { log.error("Cannot create application context for bundle " + bundleString, ex); return; } if (localApplicationContext == null) { log.debug("No application context created for bundle " + bundleString); return; } if (typeChecker != null) { if (!typeChecker.isTypeCompatible(localBundleContext)) { log.info("Bundle " + OsgiStringUtils.nullSafeName(bundle) + " is not type compatible with extender " + OsgiStringUtils.nullSafeName(bundleContext.getBundle()) + "; ignoring bundle..."); return; } } log.debug("Bundle " + OsgiStringUtils.nullSafeName(bundle) + " is type compatible with extender " + OsgiStringUtils.nullSafeName(bundleContext.getBundle()) + "; processing bundle..."); BeanFactoryPostProcessor processingHook = new OsgiBeanFactoryPostProcessorAdapter(localBundleContext, postProcessors); localApplicationContext.addBeanFactoryPostProcessor(processingHook); managedContexts.put(bundleId, localApplicationContext); localApplicationContext.setDelegatedEventMulticaster(multicaster); ApplicationContextConfiguration config = contextConfigurationFactory.createConfiguration(bundle); final boolean asynch = config.isCreateAsynchronously(); Runnable contextRefresh = new Runnable() { public void run() { if (log.isTraceEnabled()) { log.trace("Calling pre-refresh on processor " + processor); } processor.preProcessRefresh(localApplicationContext); localApplicationContext.refresh(); } }; TaskExecutor executor = null; String creationType; if (asynch) { executor = taskExecutor; creationType = "Asynchronous"; } else { executor = sameThreadTaskExecutor; creationType = "Synchronous"; } if (debug) { log.debug(creationType + " context creation for bundle " + bundleString); } if (config.isWaitForDependencies()) { DependencyWaiterApplicationContextExecutor appCtxExecutor = new DependencyWaiterApplicationContextExecutor(localApplicationContext, !asynch, extenderConfiguration.getDependencyFactories()); long timeout; if (config.isTimeoutDeclared()) { timeout = config.getTimeout(); if (debug) log.debug("Setting bundle-defined, wait-for-dependencies/graceperiod timeout value=" + timeout + " ms, for bundle " + bundleString); } else { timeout = extenderConfiguration.getDependencyWaitTime(); if (debug) log.debug("Setting globally defined wait-for-dependencies/graceperiod timeout value=" + timeout + " ms, for bundle " + bundleString); } appCtxExecutor.setTimeout(timeout); appCtxExecutor.setWatchdog(timer); appCtxExecutor.setTaskExecutor(executor); appCtxExecutor.setMonitoringCounter(contextsStarted); appCtxExecutor.setDelegatedMulticaster(this.multicaster); contextsStarted.increment(); } else { } executor.execute(contextRefresh); } }
LifecycleManager implements DisposableBean { protected void maybeCreateApplicationContextFor(Bundle bundle) { boolean debug = log.isDebugEnabled(); String bundleString = "[" + OsgiStringUtils.nullSafeNameAndSymName(bundle) + "]"; final Long bundleId = new Long(bundle.getBundleId()); if (managedContexts.containsKey(bundleId)) { if (debug) { log.debug("Bundle " + bundleString + " is already managed; ignoring..."); } return; } if (!versionMatcher.matchVersion(bundle)) { return; } BundleContext localBundleContext = OsgiBundleUtils.getBundleContext(bundle); if (localBundleContext == null) { if (debug) log.debug("Bundle " + bundleString + " has no bundle context; skipping..."); return; } final DelegatedExecutionOsgiBundleApplicationContext localApplicationContext; if (debug) log.debug("Inspecting bundle " + bundleString); try { localApplicationContext = contextCreator.createApplicationContext(localBundleContext); } catch (Exception ex) { log.error("Cannot create application context for bundle " + bundleString, ex); return; } if (localApplicationContext == null) { log.debug("No application context created for bundle " + bundleString); return; } if (typeChecker != null) { if (!typeChecker.isTypeCompatible(localBundleContext)) { log.info("Bundle " + OsgiStringUtils.nullSafeName(bundle) + " is not type compatible with extender " + OsgiStringUtils.nullSafeName(bundleContext.getBundle()) + "; ignoring bundle..."); return; } } log.debug("Bundle " + OsgiStringUtils.nullSafeName(bundle) + " is type compatible with extender " + OsgiStringUtils.nullSafeName(bundleContext.getBundle()) + "; processing bundle..."); BeanFactoryPostProcessor processingHook = new OsgiBeanFactoryPostProcessorAdapter(localBundleContext, postProcessors); localApplicationContext.addBeanFactoryPostProcessor(processingHook); managedContexts.put(bundleId, localApplicationContext); localApplicationContext.setDelegatedEventMulticaster(multicaster); ApplicationContextConfiguration config = contextConfigurationFactory.createConfiguration(bundle); final boolean asynch = config.isCreateAsynchronously(); Runnable contextRefresh = new Runnable() { public void run() { if (log.isTraceEnabled()) { log.trace("Calling pre-refresh on processor " + processor); } processor.preProcessRefresh(localApplicationContext); localApplicationContext.refresh(); } }; TaskExecutor executor = null; String creationType; if (asynch) { executor = taskExecutor; creationType = "Asynchronous"; } else { executor = sameThreadTaskExecutor; creationType = "Synchronous"; } if (debug) { log.debug(creationType + " context creation for bundle " + bundleString); } if (config.isWaitForDependencies()) { DependencyWaiterApplicationContextExecutor appCtxExecutor = new DependencyWaiterApplicationContextExecutor(localApplicationContext, !asynch, extenderConfiguration.getDependencyFactories()); long timeout; if (config.isTimeoutDeclared()) { timeout = config.getTimeout(); if (debug) log.debug("Setting bundle-defined, wait-for-dependencies/graceperiod timeout value=" + timeout + " ms, for bundle " + bundleString); } else { timeout = extenderConfiguration.getDependencyWaitTime(); if (debug) log.debug("Setting globally defined wait-for-dependencies/graceperiod timeout value=" + timeout + " ms, for bundle " + bundleString); } appCtxExecutor.setTimeout(timeout); appCtxExecutor.setWatchdog(timer); appCtxExecutor.setTaskExecutor(executor); appCtxExecutor.setMonitoringCounter(contextsStarted); appCtxExecutor.setDelegatedMulticaster(this.multicaster); contextsStarted.increment(); } else { } executor.execute(contextRefresh); } LifecycleManager(ExtenderConfiguration extenderConfiguration, VersionMatcher versionMatcher,
                     ApplicationContextConfigurationFactory appCtxCfgFactory, OsgiApplicationContextCreator osgiApplicationContextCreator, OsgiContextProcessor processor,
                     TypeCompatibilityChecker checker, BundleContext context); }
LifecycleManager implements DisposableBean { protected void maybeCreateApplicationContextFor(Bundle bundle) { boolean debug = log.isDebugEnabled(); String bundleString = "[" + OsgiStringUtils.nullSafeNameAndSymName(bundle) + "]"; final Long bundleId = new Long(bundle.getBundleId()); if (managedContexts.containsKey(bundleId)) { if (debug) { log.debug("Bundle " + bundleString + " is already managed; ignoring..."); } return; } if (!versionMatcher.matchVersion(bundle)) { return; } BundleContext localBundleContext = OsgiBundleUtils.getBundleContext(bundle); if (localBundleContext == null) { if (debug) log.debug("Bundle " + bundleString + " has no bundle context; skipping..."); return; } final DelegatedExecutionOsgiBundleApplicationContext localApplicationContext; if (debug) log.debug("Inspecting bundle " + bundleString); try { localApplicationContext = contextCreator.createApplicationContext(localBundleContext); } catch (Exception ex) { log.error("Cannot create application context for bundle " + bundleString, ex); return; } if (localApplicationContext == null) { log.debug("No application context created for bundle " + bundleString); return; } if (typeChecker != null) { if (!typeChecker.isTypeCompatible(localBundleContext)) { log.info("Bundle " + OsgiStringUtils.nullSafeName(bundle) + " is not type compatible with extender " + OsgiStringUtils.nullSafeName(bundleContext.getBundle()) + "; ignoring bundle..."); return; } } log.debug("Bundle " + OsgiStringUtils.nullSafeName(bundle) + " is type compatible with extender " + OsgiStringUtils.nullSafeName(bundleContext.getBundle()) + "; processing bundle..."); BeanFactoryPostProcessor processingHook = new OsgiBeanFactoryPostProcessorAdapter(localBundleContext, postProcessors); localApplicationContext.addBeanFactoryPostProcessor(processingHook); managedContexts.put(bundleId, localApplicationContext); localApplicationContext.setDelegatedEventMulticaster(multicaster); ApplicationContextConfiguration config = contextConfigurationFactory.createConfiguration(bundle); final boolean asynch = config.isCreateAsynchronously(); Runnable contextRefresh = new Runnable() { public void run() { if (log.isTraceEnabled()) { log.trace("Calling pre-refresh on processor " + processor); } processor.preProcessRefresh(localApplicationContext); localApplicationContext.refresh(); } }; TaskExecutor executor = null; String creationType; if (asynch) { executor = taskExecutor; creationType = "Asynchronous"; } else { executor = sameThreadTaskExecutor; creationType = "Synchronous"; } if (debug) { log.debug(creationType + " context creation for bundle " + bundleString); } if (config.isWaitForDependencies()) { DependencyWaiterApplicationContextExecutor appCtxExecutor = new DependencyWaiterApplicationContextExecutor(localApplicationContext, !asynch, extenderConfiguration.getDependencyFactories()); long timeout; if (config.isTimeoutDeclared()) { timeout = config.getTimeout(); if (debug) log.debug("Setting bundle-defined, wait-for-dependencies/graceperiod timeout value=" + timeout + " ms, for bundle " + bundleString); } else { timeout = extenderConfiguration.getDependencyWaitTime(); if (debug) log.debug("Setting globally defined wait-for-dependencies/graceperiod timeout value=" + timeout + " ms, for bundle " + bundleString); } appCtxExecutor.setTimeout(timeout); appCtxExecutor.setWatchdog(timer); appCtxExecutor.setTaskExecutor(executor); appCtxExecutor.setMonitoringCounter(contextsStarted); appCtxExecutor.setDelegatedMulticaster(this.multicaster); contextsStarted.increment(); } else { } executor.execute(contextRefresh); } LifecycleManager(ExtenderConfiguration extenderConfiguration, VersionMatcher versionMatcher,
                     ApplicationContextConfigurationFactory appCtxCfgFactory, OsgiApplicationContextCreator osgiApplicationContextCreator, OsgiContextProcessor processor,
                     TypeCompatibilityChecker checker, BundleContext context); void destroy(); ConfigurableOsgiBundleApplicationContext getManagedContext(Bundle bundle); }
LifecycleManager implements DisposableBean { protected void maybeCreateApplicationContextFor(Bundle bundle) { boolean debug = log.isDebugEnabled(); String bundleString = "[" + OsgiStringUtils.nullSafeNameAndSymName(bundle) + "]"; final Long bundleId = new Long(bundle.getBundleId()); if (managedContexts.containsKey(bundleId)) { if (debug) { log.debug("Bundle " + bundleString + " is already managed; ignoring..."); } return; } if (!versionMatcher.matchVersion(bundle)) { return; } BundleContext localBundleContext = OsgiBundleUtils.getBundleContext(bundle); if (localBundleContext == null) { if (debug) log.debug("Bundle " + bundleString + " has no bundle context; skipping..."); return; } final DelegatedExecutionOsgiBundleApplicationContext localApplicationContext; if (debug) log.debug("Inspecting bundle " + bundleString); try { localApplicationContext = contextCreator.createApplicationContext(localBundleContext); } catch (Exception ex) { log.error("Cannot create application context for bundle " + bundleString, ex); return; } if (localApplicationContext == null) { log.debug("No application context created for bundle " + bundleString); return; } if (typeChecker != null) { if (!typeChecker.isTypeCompatible(localBundleContext)) { log.info("Bundle " + OsgiStringUtils.nullSafeName(bundle) + " is not type compatible with extender " + OsgiStringUtils.nullSafeName(bundleContext.getBundle()) + "; ignoring bundle..."); return; } } log.debug("Bundle " + OsgiStringUtils.nullSafeName(bundle) + " is type compatible with extender " + OsgiStringUtils.nullSafeName(bundleContext.getBundle()) + "; processing bundle..."); BeanFactoryPostProcessor processingHook = new OsgiBeanFactoryPostProcessorAdapter(localBundleContext, postProcessors); localApplicationContext.addBeanFactoryPostProcessor(processingHook); managedContexts.put(bundleId, localApplicationContext); localApplicationContext.setDelegatedEventMulticaster(multicaster); ApplicationContextConfiguration config = contextConfigurationFactory.createConfiguration(bundle); final boolean asynch = config.isCreateAsynchronously(); Runnable contextRefresh = new Runnable() { public void run() { if (log.isTraceEnabled()) { log.trace("Calling pre-refresh on processor " + processor); } processor.preProcessRefresh(localApplicationContext); localApplicationContext.refresh(); } }; TaskExecutor executor = null; String creationType; if (asynch) { executor = taskExecutor; creationType = "Asynchronous"; } else { executor = sameThreadTaskExecutor; creationType = "Synchronous"; } if (debug) { log.debug(creationType + " context creation for bundle " + bundleString); } if (config.isWaitForDependencies()) { DependencyWaiterApplicationContextExecutor appCtxExecutor = new DependencyWaiterApplicationContextExecutor(localApplicationContext, !asynch, extenderConfiguration.getDependencyFactories()); long timeout; if (config.isTimeoutDeclared()) { timeout = config.getTimeout(); if (debug) log.debug("Setting bundle-defined, wait-for-dependencies/graceperiod timeout value=" + timeout + " ms, for bundle " + bundleString); } else { timeout = extenderConfiguration.getDependencyWaitTime(); if (debug) log.debug("Setting globally defined wait-for-dependencies/graceperiod timeout value=" + timeout + " ms, for bundle " + bundleString); } appCtxExecutor.setTimeout(timeout); appCtxExecutor.setWatchdog(timer); appCtxExecutor.setTaskExecutor(executor); appCtxExecutor.setMonitoringCounter(contextsStarted); appCtxExecutor.setDelegatedMulticaster(this.multicaster); contextsStarted.increment(); } else { } executor.execute(contextRefresh); } LifecycleManager(ExtenderConfiguration extenderConfiguration, VersionMatcher versionMatcher,
                     ApplicationContextConfigurationFactory appCtxCfgFactory, OsgiApplicationContextCreator osgiApplicationContextCreator, OsgiContextProcessor processor,
                     TypeCompatibilityChecker checker, BundleContext context); void destroy(); ConfigurableOsgiBundleApplicationContext getManagedContext(Bundle bundle);  }