felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pde...@apache.org
Subject svn commit: r953669 - /felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/
Date Fri, 11 Jun 2010 11:35:25 GMT
Author: pderop
Date: Fri Jun 11 11:35:24 2010
New Revision: 953669

URL: http://svn.apache.org/viewvc?rev=953669&view=rev
Log:
fixed bug: unamed dependencies must be injected before the init() method, not after. 


Modified:
    felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/AdapterServiceBuilder.java
    felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/AspectServiceBuilder.java
    felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/BundleAdapterServiceBuilder.java
    felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/FactoryConfigurationAdapterServiceBuilder.java
    felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ResourceAdapterServiceBuilder.java
    felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ServiceBuilder.java
    felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ServiceComponentBuilder.java
    felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ServiceFactory.java
    felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ServiceLifecycleHandler.java

Modified: felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/AdapterServiceBuilder.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/AdapterServiceBuilder.java?rev=953669&r1=953668&r2=953669&view=diff
==============================================================================
--- felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/AdapterServiceBuilder.java
(original)
+++ felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/AdapterServiceBuilder.java
Fri Jun 11 11:35:24 2010
@@ -55,6 +55,8 @@ public class AdapterServiceBuilder exten
         ServiceLifecycleHandler lfcleHandler = new ServiceLifecycleHandler(service, b, dm,
srvMeta, depsMeta);
         // The dependencies will be plugged by our lifecycle handler.
         service.setCallbacks(lfcleHandler, "init", "start", "stop", "destroy");
+        // Adds dependencies (except named dependencies, which are managed by the lifecycle
handler).
+        addUnamedDependencies(b, dm, service, srvMeta, depsMeta);
         dm.add(service);
     }
 }

Modified: felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/AspectServiceBuilder.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/AspectServiceBuilder.java?rev=953669&r1=953668&r2=953669&view=diff
==============================================================================
--- felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/AspectServiceBuilder.java
(original)
+++ felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/AspectServiceBuilder.java
Fri Jun 11 11:35:24 2010
@@ -58,6 +58,8 @@ public class AspectServiceBuilder extend
         ServiceLifecycleHandler lfcleHandler = new ServiceLifecycleHandler(service, b, dm,
srvMeta, depsMeta);
         // The dependencies will be plugged by our lifecycle handler.
         service.setCallbacks(lfcleHandler, "init", "start", "stop", "destroy");
+        // Adds dependencies (except named dependencies, which are managed by the lifecycle
handler).
+        addUnamedDependencies(b, dm, service, srvMeta, depsMeta);
         dm.add(service);
     }
 }

Modified: felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/BundleAdapterServiceBuilder.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/BundleAdapterServiceBuilder.java?rev=953669&r1=953668&r2=953669&view=diff
==============================================================================
--- felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/BundleAdapterServiceBuilder.java
(original)
+++ felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/BundleAdapterServiceBuilder.java
Fri Jun 11 11:35:24 2010
@@ -22,7 +22,6 @@ import java.util.Dictionary;
 import java.util.List;
 
 import org.apache.felix.dm.DependencyManager;
-import org.apache.felix.dm.dependencies.Dependency;
 import org.apache.felix.dm.service.Service;
 import org.osgi.framework.Bundle;
 
@@ -53,6 +52,8 @@ public class BundleAdapterServiceBuilder
         ServiceLifecycleHandler lfcleHandler = new ServiceLifecycleHandler(srv, b, dm, srvMeta,
depsMeta);
         // The dependencies will be plugged by our lifecycle handler.
         srv.setCallbacks(lfcleHandler, "init", "start", "stop", "destroy");
+        // Adds dependencies (except named dependencies, which are managed by the lifecycle
handler).
+        addUnamedDependencies(b, dm, srv, srvMeta, depsMeta);
         dm.add(srv);
     }    
 }

Modified: felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/FactoryConfigurationAdapterServiceBuilder.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/FactoryConfigurationAdapterServiceBuilder.java?rev=953669&r1=953668&r2=953669&view=diff
==============================================================================
--- felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/FactoryConfigurationAdapterServiceBuilder.java
(original)
+++ felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/FactoryConfigurationAdapterServiceBuilder.java
Fri Jun 11 11:35:24 2010
@@ -22,7 +22,6 @@ import java.util.Dictionary;
 import java.util.List;
 
 import org.apache.felix.dm.DependencyManager;
-import org.apache.felix.dm.dependencies.Dependency;
 import org.apache.felix.dm.service.Service;
 import org.osgi.framework.Bundle;
 
@@ -53,6 +52,8 @@ public class FactoryConfigurationAdapter
         ServiceLifecycleHandler lfcleHandler = new ServiceLifecycleHandler(srv, b, dm, srvMeta,
depsMeta);
         // The dependencies will be plugged by our lifecycle handler.
         srv.setCallbacks(lfcleHandler, "init", "start", "stop", "destroy");
+        // Adds dependencies (except named dependencies, which are managed by the lifecycle
handler).
+        addUnamedDependencies(b, dm, srv, srvMeta, depsMeta);
         dm.add(srv);
     }    
 }

Modified: felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ResourceAdapterServiceBuilder.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ResourceAdapterServiceBuilder.java?rev=953669&r1=953668&r2=953669&view=diff
==============================================================================
--- felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ResourceAdapterServiceBuilder.java
(original)
+++ felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ResourceAdapterServiceBuilder.java
Fri Jun 11 11:35:24 2010
@@ -22,7 +22,6 @@ import java.util.Dictionary;
 import java.util.List;
 
 import org.apache.felix.dm.DependencyManager;
-import org.apache.felix.dm.dependencies.Dependency;
 import org.apache.felix.dm.service.Service;
 import org.osgi.framework.Bundle;
 
@@ -52,6 +51,8 @@ public class ResourceAdapterServiceBuild
         ServiceLifecycleHandler lfcleHandler = new ServiceLifecycleHandler(srv, b, dm, srvMeta,
depsMeta);
         // The dependencies will be plugged by our lifecycle handler.
         srv.setCallbacks(lfcleHandler, "init", "start", "stop", "destroy");
+        // Adds dependencies (except named dependencies, which are managed by the lifecycle
handler).
+        addUnamedDependencies(b, dm, srv, srvMeta, depsMeta);
         dm.add(srv);
     }    
 }

Modified: felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ServiceBuilder.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ServiceBuilder.java?rev=953669&r1=953668&r2=953669&view=diff
==============================================================================
--- felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ServiceBuilder.java
(original)
+++ felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ServiceBuilder.java
Fri Jun 11 11:35:24 2010
@@ -24,7 +24,6 @@ import java.util.List;
 import java.util.Set;
 
 import org.apache.felix.dm.DependencyManager;
-import org.apache.felix.dm.dependencies.Dependency;
 import org.apache.felix.dm.service.Service;
 import org.osgi.framework.Bundle;
 import org.osgi.service.log.LogService;
@@ -64,6 +63,8 @@ public class ServiceBuilder extends Serv
             // Creates a ServiceHandler, which will filter all service lifecycle callbacks.
             ServiceLifecycleHandler lfcleHandler = new ServiceLifecycleHandler(service, b,
dm, srvMeta, depsMeta);
             service.setCallbacks(lfcleHandler, "init", "start", "stop", "destroy");
+            // Adds dependencies (except named dependencies, which are managed by the lifecycle
handler).
+            addUnamedDependencies(b, dm, service, srvMeta, depsMeta);
         }
         else
         {

Modified: felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ServiceComponentBuilder.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ServiceComponentBuilder.java?rev=953669&r1=953668&r2=953669&view=diff
==============================================================================
--- felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ServiceComponentBuilder.java
(original)
+++ felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ServiceComponentBuilder.java
Fri Jun 11 11:35:24 2010
@@ -21,8 +21,10 @@ package org.apache.felix.dm.runtime;
 import java.util.List;
 
 import org.apache.felix.dm.DependencyManager;
+import org.apache.felix.dm.dependencies.Dependency;
 import org.apache.felix.dm.service.Service;
 import org.osgi.framework.Bundle;
+import org.osgi.service.log.LogService;
 
 /**
  * The builder which creates a DependencyManager Service (a Service and all its derived classes
(Aspect/Adapters).
@@ -60,4 +62,28 @@ public abstract class ServiceComponentBu
             service.setComposition(composition);
         }
     }
+    
+    /**
+     * Registers all unamed dependencies into a given service. Named dependencies are
+     * handled differently, and are managed by the ServiceLifecycleHandler class.
+     * @throws Exception 
+     */
+    protected static void addUnamedDependencies(Bundle b, DependencyManager dm, Service s,

+                                                MetaData srvMeta, List<MetaData> depsMeta)

+        throws Exception
+    {
+        for (MetaData dependency : depsMeta) 
+        {
+            String name = dependency.getString(Params.name, null);
+            if (name == null) {
+                DependencyBuilder depBuilder = new DependencyBuilder(dependency);
+                Log.instance().log(LogService.LOG_INFO, 
+                                   "ServiceLifecycleHandler.init: adding dependency %s into
service %s",
+                                   dependency, srvMeta);
+                Dependency d = depBuilder.build(b, dm, false);
+                s.add(d);
+            }
+        }
+
+    }
 }

Modified: felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ServiceFactory.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ServiceFactory.java?rev=953669&r1=953668&r2=953669&view=diff
==============================================================================
--- felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ServiceFactory.java
(original)
+++ felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ServiceFactory.java
Fri Jun 11 11:35:24 2010
@@ -28,6 +28,7 @@ import java.util.List;
 import java.util.concurrent.ConcurrentHashMap;
 
 import org.apache.felix.dm.DependencyManager;
+import org.apache.felix.dm.dependencies.Dependency;
 import org.apache.felix.dm.service.Service;
 import org.osgi.framework.Bundle;
 import org.osgi.service.log.LogService;
@@ -364,6 +365,20 @@ public class ServiceFactory extends Abst
                 // The dependencies will be plugged by our lifecycle handler.
                 s.setCallbacks(lfcleHandler, "init", "start", "stop", "destroy");
 
+                // Adds dependencies (except named dependencies, which are managed by the
lifecycle handler).
+                for (MetaData dependency : m_depsMeta) 
+                {
+                    String name = dependency.getString(Params.name, null);
+                    if (name == null) {
+                        DependencyBuilder depBuilder = new DependencyBuilder(dependency);
+                        Log.instance().log(LogService.LOG_INFO, 
+                                           "ServiceLifecycleHandler.init: adding dependency
%s into service %s",
+                                           dependency, m_srvMeta);
+                        Dependency d = depBuilder.build(m_bundle, m_dm, false);
+                        s.add(d);
+                    }
+                }
+                
                 // Register the Service instance, and keep track of it.
                 Log.instance().log(LogService.LOG_INFO, "ServiceFactory: created service
%s", m_srvMeta);
                 m_dm.add(s);

Modified: felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ServiceLifecycleHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ServiceLifecycleHandler.java?rev=953669&r1=953668&r2=953669&view=diff
==============================================================================
--- felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ServiceLifecycleHandler.java
(original)
+++ felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ServiceLifecycleHandler.java
Fri Jun 11 11:35:24 2010
@@ -41,7 +41,7 @@ import org.osgi.service.log.LogService;
  * Allow Services to configure dynamically their dependency filters from their init() method.
  * Basically, this class acts as a service implementation lifecycle handler. When we detect
that the Service is
  * called in its init() method, and if its init() method returns a Map, then the Map is assumed
to contain
- * dependency filters, which will be applied to all service dependencies. The Map optionally
returned by
+ * dependency filters, which will be applied to all named service dependencies. The Map optionally
returned by
  * Service's init method has to contains the following keys:
  * <ul>
  *   <li>name.filter: the value must be a valid OSGi filter. the "name" prefix must
match a ServiceDependency 
@@ -50,7 +50,10 @@ import org.osgi.service.log.LogService;
  *   ServiceDependency name attribute</li>
  * </ul>
  * 
- * Example of a Service whose dependency filter is configured from ConfigAdmin:
+ * <p>Dependencies which provide a name attribute will be activated after the init
method returns. Other
+ * dependencies are injected before the init method.
+ * 
+ * <p>Example of a Service whose dependency filter is configured from ConfigAdmin:
  * 
  * <blockquote><pre>
  *  &#47;**
@@ -133,6 +136,7 @@ public class ServiceLifecycleHandler
         // Invoke the service instance init method, and check if it returns a dependency
         // customization map. This map will be used to configure some dependency filters
         // (or required flag).
+      
         Object o = invokeMethod(serviceInstance, m_init, dm, service);      
         Map<String, String> customization = (o != null && Map.class.isAssignableFrom(o.getClass()))
?
             (Map<String, String>) o : new HashMap<String, String>();
@@ -147,14 +151,14 @@ public class ServiceLifecycleHandler
             // customization map, then apply filters and required flag from the map into
it.
             
             String name = dependency.getString(Params.name, null);
-            if (name != null)
-            {
+            if (name != null) {
                 String filter = customization.get(name + ".filter");
                 String required = customization.get(name + ".required");
-                		
-                if (filter != null || required != null) {
+
+                if (filter != null || required != null)
+                {
                     dependency = (MetaData) dependency.clone();
-                    if (filter != null) 
+                    if (filter != null)
                     {
                         dependency.setString(Params.filter, filter);
                     }
@@ -163,14 +167,15 @@ public class ServiceLifecycleHandler
                         dependency.setString(Params.required, required);
                     }
                 }
+
+                DependencyBuilder depBuilder = new DependencyBuilder(dependency);
+                Log.instance().log(LogService.LOG_INFO,
+                                   "ServiceLifecycleHandler.init: adding dependency %s into
service %s",
+                                   dependency, m_srvMeta);
+                Dependency d = depBuilder.build(m_bundle, dm, true);
+                m_deps.add(d);
+                service.add(d);
             }
-            DependencyBuilder depBuilder = new DependencyBuilder(dependency);
-            Log.instance().log(LogService.LOG_INFO, 
-                               "ServiceLifecycleHandler.init: adding dependency %s into service
%s",
-                               dependency, m_srvMeta);
-            Dependency d = depBuilder.build(m_bundle, dm, true);
-            m_deps.add(d);
-            service.add(d);
         }
     }
 



Mime
View raw message