felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pde...@apache.org
Subject svn commit: r1575640 - /felix/sandbox/pderop/dependencymanager-prototype/dm/src/dm/impl/ComponentImpl.java
Date Sun, 09 Mar 2014 00:29:34 GMT
Author: pderop
Date: Sun Mar  9 00:29:34 2014
New Revision: 1575640

URL: http://svn.apache.org/r1575640
Log:
Removed isInstantiated(). Added getComponentState().
Always start optional dependencies, before starting required dependencies. This is necessary
because
starting a required dependency may change the state to INSTANTIATED_AND_WAITING_FOR_REQUIRED
immediately before
other optional dependencies are started. (see ServiceDependencyInjectionTest integration test).

Modified:
    felix/sandbox/pderop/dependencymanager-prototype/dm/src/dm/impl/ComponentImpl.java

Modified: felix/sandbox/pderop/dependencymanager-prototype/dm/src/dm/impl/ComponentImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/dm/src/dm/impl/ComponentImpl.java?rev=1575640&r1=1575639&r2=1575640&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/dm/src/dm/impl/ComponentImpl.java (original)
+++ felix/sandbox/pderop/dependencymanager-prototype/dm/src/dm/impl/ComponentImpl.java Sun
Mar  9 00:29:34 2014
@@ -133,9 +133,7 @@ public class ComponentImpl implements Co
 						instanceBoundDeps.add(dc);
 					}
 				}
-				for (DependencyContext dc : instanceBoundDeps) {
-					dc.start();
-				}
+				startDependencies(instanceBoundDeps);
 				handleChange();
 			}
 		});
@@ -310,12 +308,7 @@ public class ComponentImpl implements Co
 	private boolean performTransition(ComponentState oldState, ComponentState newState) {
 //		System.out.println("transition from " + oldState + " to " + newState);
 		if (oldState == ComponentState.INACTIVE && newState == ComponentState.WAITING_FOR_REQUIRED)
{
-			for (DependencyContext d : m_dependencies) {
-			    if (d.needsInstance()) {
-			        instantiateComponent();
-			    }
-				d.start();
-			}
+		    startDependencies(m_dependencies);
 			notifyListeners(newState);
 			return true;
 		}
@@ -353,9 +346,7 @@ public class ComponentImpl implements Co
 			return true;
 		}
 		if (oldState == ComponentState.WAITING_FOR_REQUIRED && newState == ComponentState.INACTIVE)
{
-			for (DependencyContext d : m_dependencies) {
-				d.stop();
-			}
+		    stopDependencies();
             destroyComponent();
 			notifyListeners(newState);
 			return true;
@@ -363,6 +354,34 @@ public class ComponentImpl implements Co
 		return false;
 	}
 	
+    private void startDependencies(List<DependencyContext> dependencies) {
+        // Start first optional dependencies, then start required dependencies.
+        List<DependencyContext> requiredDeps = new ArrayList();
+        for (DependencyContext d : dependencies) {
+            if (d.isRequired()) {
+                requiredDeps.add(d);
+                continue;
+            }
+            if (d.needsInstance()) {
+                instantiateComponent();
+            }
+            d.start();
+        }
+        // now, start required dependencies.
+        for (DependencyContext d : requiredDeps) {
+            if (d.needsInstance()) {
+                instantiateComponent();
+            }
+            d.start();
+        }
+    }
+    
+    private void stopDependencies() {
+        for (DependencyContext d : m_dependencies) {
+            d.stop();
+        }
+    }
+
     private void registerService() {
         if (m_context != null && m_serviceName != null) {
             ServiceRegistrationImpl wrapper = new ServiceRegistrationImpl();
@@ -623,8 +642,8 @@ public class ComponentImpl implements Co
 		return m_state == TRACKING_OPTIONAL;
 	}
 	
-	public boolean isInstantiated() {
-	    return m_state == TRACKING_OPTIONAL || m_state == INSTANTIATED_AND_WAITING_FOR_REQUIRED;
+	public ComponentState getComponentState() {
+	    return m_state;
 	}
 
 	@Override



Mime
View raw message