@Test public void testSuccessfulAsynchronousDestruction() throws Exception { withAsynchronousShutdownEnabled(); addContextToLifecycleManager(); destroy(); yield(); verifyContextIsClosed(); verifyOsgiContextProcessorInteractions(); }
public void destroy() { stopTimer(); List<Bundle> bundles = new ArrayList<Bundle>(managedContexts.size()); for (ConfigurableOsgiBundleApplicationContext context : managedContexts.values()) { bundles.add(context.getBundle()); } boolean debug = log.isDebugEnabled(); if (debug) { log.debug("Starting shutdown procedure for bundles " + bundles); } while (!bundles.isEmpty()) { Collection<Bundle> candidates = ShutdownSorter.getBundles(bundles); if (debug) log.debug("Staging shutdown for bundles " + candidates); final List<Runnable> taskList = new ArrayList<Runnable>(candidates.size()); final List<ConfigurableOsgiBundleApplicationContext> closedContexts = Collections.synchronizedList(new ArrayList<ConfigurableOsgiBundleApplicationContext>()); final Object[] contextClosingDown = new Object[1]; for (Bundle shutdownBundle : candidates) { final ConfigurableOsgiBundleApplicationContext context = getManagedContext(shutdownBundle); if (context != null) { closedContexts.add(context); taskList.add(new Runnable() { private final String toString = "Closing runnable for context " + context.getDisplayName(); public void run() { contextClosingDown[0] = context; closedContexts.remove(context); closeApplicationContext(context); } public String toString() { return toString; } }); } } final Runnable[] tasks = taskList.toArray(new Runnable[taskList.size()]); for (Runnable task : tasks) { if (extenderConfiguration.shouldShutdownAsynchronously()) { if (execute(task, extenderConfiguration.getShutdownWaitTime(), shutdownTaskExecutor)) { if (debug) { log.debug(contextClosingDown[0] + " context did not close successfully; forcing shutdown..."); } } } else { try { task.run(); } catch (Exception e) { log.error(contextClosingDown[0] + " context close failed.", e); } } } } this.managedContexts.clear(); stopTaskExecutor(); }
LifecycleManager implements DisposableBean { public void destroy() { stopTimer(); List<Bundle> bundles = new ArrayList<Bundle>(managedContexts.size()); for (ConfigurableOsgiBundleApplicationContext context : managedContexts.values()) { bundles.add(context.getBundle()); } boolean debug = log.isDebugEnabled(); if (debug) { log.debug("Starting shutdown procedure for bundles " + bundles); } while (!bundles.isEmpty()) { Collection<Bundle> candidates = ShutdownSorter.getBundles(bundles); if (debug) log.debug("Staging shutdown for bundles " + candidates); final List<Runnable> taskList = new ArrayList<Runnable>(candidates.size()); final List<ConfigurableOsgiBundleApplicationContext> closedContexts = Collections.synchronizedList(new ArrayList<ConfigurableOsgiBundleApplicationContext>()); final Object[] contextClosingDown = new Object[1]; for (Bundle shutdownBundle : candidates) { final ConfigurableOsgiBundleApplicationContext context = getManagedContext(shutdownBundle); if (context != null) { closedContexts.add(context); taskList.add(new Runnable() { private final String toString = "Closing runnable for context " + context.getDisplayName(); public void run() { contextClosingDown[0] = context; closedContexts.remove(context); closeApplicationContext(context); } public String toString() { return toString; } }); } } final Runnable[] tasks = taskList.toArray(new Runnable[taskList.size()]); for (Runnable task : tasks) { if (extenderConfiguration.shouldShutdownAsynchronously()) { if (execute(task, extenderConfiguration.getShutdownWaitTime(), shutdownTaskExecutor)) { if (debug) { log.debug(contextClosingDown[0] + " context did not close successfully; forcing shutdown..."); } } } else { try { task.run(); } catch (Exception e) { log.error(contextClosingDown[0] + " context close failed.", e); } } } } this.managedContexts.clear(); stopTaskExecutor(); } }
LifecycleManager implements DisposableBean { public void destroy() { stopTimer(); List<Bundle> bundles = new ArrayList<Bundle>(managedContexts.size()); for (ConfigurableOsgiBundleApplicationContext context : managedContexts.values()) { bundles.add(context.getBundle()); } boolean debug = log.isDebugEnabled(); if (debug) { log.debug("Starting shutdown procedure for bundles " + bundles); } while (!bundles.isEmpty()) { Collection<Bundle> candidates = ShutdownSorter.getBundles(bundles); if (debug) log.debug("Staging shutdown for bundles " + candidates); final List<Runnable> taskList = new ArrayList<Runnable>(candidates.size()); final List<ConfigurableOsgiBundleApplicationContext> closedContexts = Collections.synchronizedList(new ArrayList<ConfigurableOsgiBundleApplicationContext>()); final Object[] contextClosingDown = new Object[1]; for (Bundle shutdownBundle : candidates) { final ConfigurableOsgiBundleApplicationContext context = getManagedContext(shutdownBundle); if (context != null) { closedContexts.add(context); taskList.add(new Runnable() { private final String toString = "Closing runnable for context " + context.getDisplayName(); public void run() { contextClosingDown[0] = context; closedContexts.remove(context); closeApplicationContext(context); } public String toString() { return toString; } }); } } final Runnable[] tasks = taskList.toArray(new Runnable[taskList.size()]); for (Runnable task : tasks) { if (extenderConfiguration.shouldShutdownAsynchronously()) { if (execute(task, extenderConfiguration.getShutdownWaitTime(), shutdownTaskExecutor)) { if (debug) { log.debug(contextClosingDown[0] + " context did not close successfully; forcing shutdown..."); } } } else { try { task.run(); } catch (Exception e) { log.error(contextClosingDown[0] + " context close failed.", e); } } } } this.managedContexts.clear(); stopTaskExecutor(); } LifecycleManager(ExtenderConfiguration extenderConfiguration, VersionMatcher versionMatcher,
                     ApplicationContextConfigurationFactory appCtxCfgFactory, OsgiApplicationContextCreator osgiApplicationContextCreator, OsgiContextProcessor processor,
                     TypeCompatibilityChecker checker, BundleContext context); }
LifecycleManager implements DisposableBean { public void destroy() { stopTimer(); List<Bundle> bundles = new ArrayList<Bundle>(managedContexts.size()); for (ConfigurableOsgiBundleApplicationContext context : managedContexts.values()) { bundles.add(context.getBundle()); } boolean debug = log.isDebugEnabled(); if (debug) { log.debug("Starting shutdown procedure for bundles " + bundles); } while (!bundles.isEmpty()) { Collection<Bundle> candidates = ShutdownSorter.getBundles(bundles); if (debug) log.debug("Staging shutdown for bundles " + candidates); final List<Runnable> taskList = new ArrayList<Runnable>(candidates.size()); final List<ConfigurableOsgiBundleApplicationContext> closedContexts = Collections.synchronizedList(new ArrayList<ConfigurableOsgiBundleApplicationContext>()); final Object[] contextClosingDown = new Object[1]; for (Bundle shutdownBundle : candidates) { final ConfigurableOsgiBundleApplicationContext context = getManagedContext(shutdownBundle); if (context != null) { closedContexts.add(context); taskList.add(new Runnable() { private final String toString = "Closing runnable for context " + context.getDisplayName(); public void run() { contextClosingDown[0] = context; closedContexts.remove(context); closeApplicationContext(context); } public String toString() { return toString; } }); } } final Runnable[] tasks = taskList.toArray(new Runnable[taskList.size()]); for (Runnable task : tasks) { if (extenderConfiguration.shouldShutdownAsynchronously()) { if (execute(task, extenderConfiguration.getShutdownWaitTime(), shutdownTaskExecutor)) { if (debug) { log.debug(contextClosingDown[0] + " context did not close successfully; forcing shutdown..."); } } } else { try { task.run(); } catch (Exception e) { log.error(contextClosingDown[0] + " context close failed.", e); } } } } this.managedContexts.clear(); stopTaskExecutor(); } LifecycleManager(ExtenderConfiguration extenderConfiguration, VersionMatcher versionMatcher,
                     ApplicationContextConfigurationFactory appCtxCfgFactory, OsgiApplicationContextCreator osgiApplicationContextCreator, OsgiContextProcessor processor,
                     TypeCompatibilityChecker checker, BundleContext context); void destroy(); ConfigurableOsgiBundleApplicationContext getManagedContext(Bundle bundle); }
LifecycleManager implements DisposableBean { public void destroy() { stopTimer(); List<Bundle> bundles = new ArrayList<Bundle>(managedContexts.size()); for (ConfigurableOsgiBundleApplicationContext context : managedContexts.values()) { bundles.add(context.getBundle()); } boolean debug = log.isDebugEnabled(); if (debug) { log.debug("Starting shutdown procedure for bundles " + bundles); } while (!bundles.isEmpty()) { Collection<Bundle> candidates = ShutdownSorter.getBundles(bundles); if (debug) log.debug("Staging shutdown for bundles " + candidates); final List<Runnable> taskList = new ArrayList<Runnable>(candidates.size()); final List<ConfigurableOsgiBundleApplicationContext> closedContexts = Collections.synchronizedList(new ArrayList<ConfigurableOsgiBundleApplicationContext>()); final Object[] contextClosingDown = new Object[1]; for (Bundle shutdownBundle : candidates) { final ConfigurableOsgiBundleApplicationContext context = getManagedContext(shutdownBundle); if (context != null) { closedContexts.add(context); taskList.add(new Runnable() { private final String toString = "Closing runnable for context " + context.getDisplayName(); public void run() { contextClosingDown[0] = context; closedContexts.remove(context); closeApplicationContext(context); } public String toString() { return toString; } }); } } final Runnable[] tasks = taskList.toArray(new Runnable[taskList.size()]); for (Runnable task : tasks) { if (extenderConfiguration.shouldShutdownAsynchronously()) { if (execute(task, extenderConfiguration.getShutdownWaitTime(), shutdownTaskExecutor)) { if (debug) { log.debug(contextClosingDown[0] + " context did not close successfully; forcing shutdown..."); } } } else { try { task.run(); } catch (Exception e) { log.error(contextClosingDown[0] + " context close failed.", e); } } } } this.managedContexts.clear(); stopTaskExecutor(); } LifecycleManager(ExtenderConfiguration extenderConfiguration, VersionMatcher versionMatcher,
                     ApplicationContextConfigurationFactory appCtxCfgFactory, OsgiApplicationContextCreator osgiApplicationContextCreator, OsgiContextProcessor processor,
                     TypeCompatibilityChecker checker, BundleContext context); void destroy(); ConfigurableOsgiBundleApplicationContext getManagedContext(Bundle bundle);  }