Various fixes for problems with when to invoke instance bound dependency callbacks.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1022551 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/ComponentImpl.java b/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/ComponentImpl.java
index 2a62535..688203d 100644
--- a/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/ComponentImpl.java
+++ b/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/ComponentImpl.java
@@ -269,6 +269,7 @@
}
synchronized (m_dependencies) {
+ oldState = m_state;
// starting the dependency above might have triggered another state change, so
// we have to fetch the current state again
newState = new State((List) m_dependencies.clone(), !oldState.isInactive(), m_isInstantiated, m_isBound);
@@ -323,7 +324,7 @@
oldState = m_state;
m_dependencies.remove(dependency);
}
- if (oldState.isAllRequiredAvailable() || (oldState.isWaitingForRequired() && dependency.isRequired())) {
+ if (oldState.isAllRequiredAvailable() || ((oldState.isWaitingForRequired() || oldState.isWaitingForRequiredInstantiated()) && dependency.isRequired())) {
((DependencyActivation) dependency).stop(this);
}
synchronized (m_dependencies) {
@@ -599,30 +600,17 @@
// then we invoke the init callback so the service can further initialize
// itself
invoke(init);
-// // start extra/required dependencies which might have been added from the init() method.
-// startExtraRequiredDependencies();
// see if any of this caused further state changes
calculateStateChanges();
}
- private void startExtraRequiredDependencies() {
- Iterator i = m_dependencies.iterator();
- while (i.hasNext()) {
- Dependency dependency = (Dependency) i.next();
- if (dependency.isInstanceBound() && dependency.isRequired()) {
- // Optional extra dependencies will be started later, once our service is started.
- ((DependencyActivation) dependency).start(this);
- }
- }
- }
-
private void bindService(State state) {
String start;
synchronized (this) {
start = m_callbackStart;
}
-// // configure service with extra-dependencies which might have been added from init() method.
+ // configure service with extra-dependencies which might have been added from init() method.
configureServiceWithExtraDependencies(state);
// inform the state listeners we're starting
stateListenersStarting();
@@ -636,17 +624,13 @@
stateListenersStarted();
}
- private void configureServiceWithExtraDependencies(State state)
- {
+ private void configureServiceWithExtraDependencies(State state) {
Iterator i = state.getDependencies().iterator();
while (i.hasNext()) {
Dependency dependency = (Dependency) i.next();
if (dependency.isAutoConfig() && dependency.isInstanceBound()) {
configureImplementation(dependency.getAutoConfigType(), dependency.getAutoConfigInstance(), dependency.getAutoConfigName());
}
- if (dependency.isRequired() && dependency.isInstanceBound()) {
- dependency.invokeAdded(this);
- }
}
}
@@ -1056,6 +1040,14 @@
return (state.isAllRequiredAvailable());
}
+ public boolean isInstantiated() {
+ State state;
+ synchronized (m_dependencies) {
+ state = m_state;
+ }
+ return (state.isTrackingOptional() || state.isBound() || state.isWaitingForRequiredInstantiated());
+ }
+
// ServiceComponent interface
static class SCDImpl implements ComponentDependencyDeclaration {