FELIX-5054: clean-up instance bound dependencies when the component is destroyed.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1705147 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ComponentImpl.java b/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ComponentImpl.java
index e14e445..4016a2c 100644
--- a/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ComponentImpl.java
+++ b/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ComponentImpl.java
@@ -996,6 +996,7 @@
}
if (oldState == ComponentState.INSTANTIATED_AND_WAITING_FOR_REQUIRED && newState == ComponentState.WAITING_FOR_REQUIRED) {
invoke(m_callbackDestroy);
+ removeInstanceBoundDependencies();
invokeRemoveRequiredDependencies();
notifyListeners(newState);
if (! someDependenciesNeedInstance()) {
@@ -1437,6 +1438,19 @@
}
/**
+ * Removes and closes all instance bound dependencies.
+ * This method is called when a component is destroyed.
+ */
+ private void removeInstanceBoundDependencies() {
+ for (DependencyContext dep : m_dependencies) {
+ if (dep.isInstanceBound()) {
+ m_dependencies.remove(dep);
+ dep.stop();
+ }
+ }
+ }
+
+ /**
* Clears the cache of invoked components callbacks.
* We only clear the cache when the state machine is not running.
* The cache is used to avoid calling the same bind callback twice.