|
17 | 17 | import java.util.ArrayList;
|
18 | 18 | import java.util.Collection;
|
19 | 19 | import java.util.Collections;
|
20 |
| -import java.util.Iterator; |
21 |
| -import java.util.LinkedHashSet; |
22 | 20 | import java.util.List;
|
23 | 21 | import java.util.Map;
|
24 |
| -import java.util.Set; |
25 | 22 | import java.util.Timer;
|
26 | 23 | import java.util.concurrent.ConcurrentHashMap;
|
27 | 24 |
|
28 | 25 | import org.apache.commons.logging.Log;
|
29 | 26 | import org.apache.commons.logging.LogFactory;
|
30 |
| -import org.osgi.framework.Bundle; |
31 |
| -import org.osgi.framework.BundleContext; |
32 |
| -import org.osgi.framework.BundleEvent; |
33 |
| -import org.osgi.framework.ServiceReference; |
34 |
| -import org.springframework.beans.factory.DisposableBean; |
35 |
| -import org.springframework.beans.factory.config.BeanFactoryPostProcessor; |
36 |
| -import org.springframework.core.task.SyncTaskExecutor; |
37 |
| -import org.springframework.core.task.TaskExecutor; |
38 | 27 | import org.eclipse.gemini.blueprint.context.ConfigurableOsgiBundleApplicationContext;
|
39 | 28 | import org.eclipse.gemini.blueprint.context.DelegatedExecutionOsgiBundleApplicationContext;
|
40 | 29 | import org.eclipse.gemini.blueprint.context.event.OsgiBundleApplicationContextEventMulticaster;
|
41 | 30 | import org.eclipse.gemini.blueprint.extender.OsgiApplicationContextCreator;
|
42 | 31 | import org.eclipse.gemini.blueprint.extender.OsgiBeanFactoryPostProcessor;
|
43 |
| -import org.eclipse.gemini.blueprint.extender.internal.dependencies.shutdown.BundleDependencyComparator; |
44 |
| -import org.eclipse.gemini.blueprint.extender.internal.dependencies.shutdown.ComparatorServiceDependencySorter; |
45 |
| -import org.eclipse.gemini.blueprint.extender.internal.dependencies.shutdown.ServiceDependencySorter; |
46 | 32 | import org.eclipse.gemini.blueprint.extender.internal.dependencies.shutdown.ShutdownSorter;
|
47 | 33 | import org.eclipse.gemini.blueprint.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor;
|
48 | 34 | import org.eclipse.gemini.blueprint.extender.internal.support.ExtenderConfiguration;
|
|
52 | 38 | import org.eclipse.gemini.blueprint.extender.support.ApplicationContextConfiguration;
|
53 | 39 | import org.eclipse.gemini.blueprint.util.OsgiBundleUtils;
|
54 | 40 | import org.eclipse.gemini.blueprint.util.OsgiStringUtils;
|
| 41 | +import org.osgi.framework.Bundle; |
| 42 | +import org.osgi.framework.BundleContext; |
| 43 | +import org.springframework.beans.factory.DisposableBean; |
| 44 | +import org.springframework.beans.factory.config.BeanFactoryPostProcessor; |
| 45 | +import org.springframework.core.task.SyncTaskExecutor; |
| 46 | +import org.springframework.core.task.TaskExecutor; |
55 | 47 |
|
56 | 48 | /**
|
57 | 49 | * Manager handling the startup/shutdown threading issues regarding OSGi contexts. Used by {@link ContextLoaderListener}
|
@@ -94,9 +86,6 @@ class LifecycleManager implements DisposableBean {
|
94 | 86 | */
|
95 | 87 | private final TaskExecutor sameThreadTaskExecutor = new SyncTaskExecutor();
|
96 | 88 |
|
97 |
| - /** Service-based dependency sorter for shutdown */ |
98 |
| - private final ServiceDependencySorter shutdownDependencySorter = new ComparatorServiceDependencySorter(); |
99 |
| - |
100 | 89 | private final OsgiBundleApplicationContextEventMulticaster multicaster;
|
101 | 90 |
|
102 | 91 | private final ExtenderConfiguration extenderConfiguration;
|
@@ -360,9 +349,7 @@ public void destroy() {
|
360 | 349 | final Object[] contextClosingDown = new Object[1];
|
361 | 350 |
|
362 | 351 | for (Bundle shutdownBundle : candidates) {
|
363 |
| - Long id = new Long(shutdownBundle.getBundleId()); |
364 |
| - final ConfigurableOsgiBundleApplicationContext context = |
365 |
| - (ConfigurableOsgiBundleApplicationContext) managedContexts.get(id); |
| 352 | + final ConfigurableOsgiBundleApplicationContext context = getManagedContext(shutdownBundle); |
366 | 353 | if (context != null) {
|
367 | 354 | closedContexts.add(context);
|
368 | 355 | // add a new runnable
|
@@ -405,6 +392,17 @@ public String toString() {
|
405 | 392 | stopTaskExecutor();
|
406 | 393 | }
|
407 | 394 |
|
| 395 | + public ConfigurableOsgiBundleApplicationContext getManagedContext(Bundle bundle) { |
| 396 | + ConfigurableOsgiBundleApplicationContext context = null; |
| 397 | + try { |
| 398 | + Long id = new Long(bundle.getBundleId()); |
| 399 | + context = (ConfigurableOsgiBundleApplicationContext) managedContexts.get(id); |
| 400 | + } catch (IllegalStateException _) { |
| 401 | + // ignore |
| 402 | + } |
| 403 | + return context; |
| 404 | + } |
| 405 | + |
408 | 406 | /**
|
409 | 407 | * Do some additional waiting so the service dependency listeners detect the shutdown.
|
410 | 408 | */
|
|
0 commit comments