felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pde...@apache.org
Subject svn commit: r1441505 - in /felix/trunk/dependencymanager/runtime: doc/changelog.txt src/main/java/org/apache/felix/dm/runtime/Activator.java src/main/java/org/apache/felix/dm/runtime/DependencyManagerRuntime.java
Date Fri, 01 Feb 2013 16:17:14 GMT
Author: pderop
Date: Fri Feb  1 16:17:14 2013
New Revision: 1441505

URL: http://svn.apache.org/viewvc?rev=1441505&view=rev
Log:
FELIX-3869: Fragment support for DependencyManager-Component.

Modified:
    felix/trunk/dependencymanager/runtime/doc/changelog.txt
    felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/Activator.java
    felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/DependencyManagerRuntime.java

Modified: felix/trunk/dependencymanager/runtime/doc/changelog.txt
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/runtime/doc/changelog.txt?rev=1441505&r1=1441504&r2=1441505&view=diff
==============================================================================
--- felix/trunk/dependencymanager/runtime/doc/changelog.txt (original)
+++ felix/trunk/dependencymanager/runtime/doc/changelog.txt Fri Feb  1 16:17:14 2013
@@ -1,11 +1,19 @@
-Changes from 3.0.0 to 3.0.1
----------------------------
+Trunk
+------
+
+** Bug
+
+** Improvement
+    * [FELIX-3869] - Fragment support for DependencyManager-Component
+
+Release 3.1.0
+-------------
 
 ** Bug
 
 ** Improvement
     * Removed root changelog.txt
-    * [FELIX-2954 ] - annotated component factory does not allow to provide a component instance
explicitly
+    * [FELIX-2954] - annotated component factory does not allow to provide a component instance
explicitly
     * [FELIX-2966] - Annotations should automatically generate Import-Service/Export-Service
headers
     * [FELIX-2965] - Annotations should allow to enable or disable auto-configuration mode.
     * [FELIX-3866] - Added support for swap attribute in AspectService and AdpaterService
annotations.

Modified: felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/Activator.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/Activator.java?rev=1441505&r1=1441504&r2=1441505&view=diff
==============================================================================
--- felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/Activator.java
(original)
+++ felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/Activator.java
Fri Feb  1 16:17:14 2013
@@ -18,12 +18,17 @@
  */
 package org.apache.felix.dm.runtime;
 
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.felix.dm.Component;
 import org.apache.felix.dm.DependencyActivatorBase;
 import org.apache.felix.dm.DependencyManager;
 import org.apache.felix.dm.ServiceDependency;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.service.log.LogService;
+import org.osgi.service.packageadmin.PackageAdmin;
 
 /*
  * This is the Activator for our DependencyManager Component Runtime.
@@ -42,6 +47,12 @@ public class Activator extends Dependenc
     final static String CONF_LOG = "dm.runtime.log";
     
     /**
+     * Name of bundle context property telling if PackageAdmin service is required or not.
+     * (default = false)
+     */
+    private final static String CONF_PACKAGE_ADMIN = "dm.runtime.packageAdmin";
+    
+    /**
      * Name of bundle context property telling if Components must be auto configured
      * with BundleContext/ServiceRegistration etc .. (default = false) 
      */
@@ -52,32 +63,42 @@ public class Activator extends Dependenc
      * 
      * We depend on the OSGi LogService, and we track all started bundles which do have a

      * "DependencyManager-Component" Manifest header.
-     * If the "dm.runtime.log=true" parameter is configured in the Felix config.properties
-     * then we'll use a required/temporal service dependency over the log service.
-     * This temporal dependency allows to not being restarted if the log service is temporarily

-     * unavailable (that is: when the log service is updated).
-     * if the "dm.runtime.log" is not configured or it it is set to false, then we'll use

-     * an optional dependency over the log service, in order to use a NullObject in case
-     * the log service is not available.
+     * If the "dm.runtime.log=true" or "dm.runtime.packageAdmin=true" parameter is configured
in the Felix config.properties
+     * then we'll use a required/temporal service dependency over the respective service.
+     * These temporal dependencies avoid us to be restarted if the respective service is
temporarily
+     * unavailable (that is: when the service is updating).
+     * if the "dm.runtime.log" or "dm.runtime.packageAdmin" is not configured or it it is
set to false, then we'll use
+     * an optional dependency over the respective service, in order to use a NullObject in
case
+     * the service is not available.  
      */
     @Override
     public void init(BundleContext context, DependencyManager dm) throws Exception
     {
-        boolean logActive = "true".equalsIgnoreCase(context.getProperty(CONF_LOG));
-        ServiceDependency logDep = logActive ?
-            createTemporalServiceDependency() : createServiceDependency().setRequired(false);
       
-        logDep.setService(LogService.class).setAutoConfig(true);              
-        
-        dm.add(createComponent()
-               .setImplementation(DependencyManagerRuntime.class)
-               .setComposition("getComposition")
-               .add(logDep)
-               .add(createBundleDependency()
-                    .setRequired(false)
-                    .setAutoConfig(false)
-                    .setStateMask(Bundle.ACTIVE)
-                    .setFilter("(DependencyManager-Component=*)")
-                    .setCallbacks("bundleStarted", "bundleStopped")));
+        Component component = createComponent()
+            .setImplementation( DependencyManagerRuntime.class )
+            .setComposition( "getComposition" )
+            .add(createBundleDependency()
+                .setRequired( false )
+                .setAutoConfig( false )
+                .setStateMask( Bundle.ACTIVE )
+                .setFilter( "(DependencyManager-Component=*)" )
+                .setCallbacks( "bundleStarted", "bundleStopped" ) );
+                
+        Map<String, Class<?>> services = new HashMap<String, Class<?>>(
2 );
+        services.put( CONF_LOG, LogService.class );
+        services.put( CONF_PACKAGE_ADMIN, PackageAdmin.class );
+        for (Map.Entry<String, Class<?>> entry : services.entrySet())
+        {
+            String serviceProperty = entry.getKey();
+            Class<?> service = entry.getValue();
+            boolean serviceActive = "true".equalsIgnoreCase(context.getProperty(serviceProperty));
+            ServiceDependency serviceDep =
+                    serviceActive ? createTemporalServiceDependency()
+                                 : createServiceDependency().setRequired(false);
+            serviceDep.setService(service).setAutoConfig(true);
+            component.add(serviceDep);
+        }
+        dm.add( component );
     }
 
     /**

Modified: felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/DependencyManagerRuntime.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/DependencyManagerRuntime.java?rev=1441505&r1=1441504&r2=1441505&view=diff
==============================================================================
--- felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/DependencyManagerRuntime.java
(original)
+++ felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/DependencyManagerRuntime.java
Fri Feb  1 16:17:14 2013
@@ -29,6 +29,7 @@ import java.util.concurrent.ConcurrentHa
 import org.apache.felix.dm.Component;
 import org.apache.felix.dm.DependencyManager;
 import org.osgi.framework.Bundle;
+import org.osgi.service.packageadmin.PackageAdmin;
 
 /**
  * This class parses service descriptors generated by the annotation bnd processor.
@@ -42,6 +43,7 @@ public class DependencyManagerRuntime
     private ConcurrentHashMap<Bundle, DependencyManager> m_managers =
             new ConcurrentHashMap<Bundle, DependencyManager>();
     private DescriptorParser m_parser;
+    private PackageAdmin m_packageAdmin; // Possibly a NullObject
 
     /**
      * Our constructor. We'll initialize here our DM component builders.
@@ -96,31 +98,26 @@ public class DependencyManagerRuntime
     }
 
     /**
-     * Checks if a started bundle have some DependencyManager descriptors 
-     * referenced in the "DependencyManager-Component" OSGi header.
-     * @param b the started bundle.
-     */
-    protected void bundleStarted(Bundle b)
-    {
-        String descriptorPaths = (String) b.getHeaders().get("DependencyManager-Component");
-        if (descriptorPaths == null)
-        {
-            return;
-        }
-
-        for (String descriptorPath : descriptorPaths.split(","))
-        {
-            URL descriptorURL = b.getEntry(descriptorPath);
-            if (descriptorURL == null)
-            {
-                Log.instance().error("Runtime: " + "DependencyManager component descriptor
not found: %s",
-                                     descriptorPath);
-                continue;
+     * Load the DM descriptors from the started bundle. We also check possible fragments

+     * attached to the bundle, which might also contain some DM descriptors. 
+     * @param bundle the started bundle which contains a DependencyManager-Component header
+     */
+    protected void bundleStarted(Bundle bundle)
+    {
+        Log.instance().info("Scanning started bundle %s", bundle.getSymbolicName());    
   
+        List<URL> descriptorURLs = new ArrayList<URL>();
+        collectDescriptors(bundle, descriptorURLs);                
+        Bundle[] fragments = m_packageAdmin.getFragments(bundle);
+        if (fragments != null) {
+            for (Bundle fragment : fragments) {
+                collectDescriptors(fragment, descriptorURLs);
             }
-            loadDescriptor(b, descriptorURL);
+        }
+        for (URL descriptorURL: descriptorURLs) {
+            loadDescriptor(bundle, descriptorURL);
         }
     }
-
+    
     /**
      * Unregisters all services for a stopping bundle.
      * @param b
@@ -132,7 +129,7 @@ public class DependencyManagerRuntime
         DependencyManager dm = m_managers.remove(b);
         if (dm != null)
         {
-            List<Component> services = new ArrayList(dm.getComponents());
+            List<Component> services = new ArrayList<Component>(dm.getComponents());
             for (Component service : services)
             {
                 Log.instance().info("Runtime: Removing service: %s", service);
@@ -142,15 +139,40 @@ public class DependencyManagerRuntime
     }
 
     /**
+     * Collect all descriptors found from a given bundle, including its possible attached
fragments.
+     * @param bundle a started bundle containing some DM descriptors
+     * @param out the list of descriptors' URLS found from the started bundle, as well as
from possibly
+     *        attached fragments.
+     */
+    private void collectDescriptors(Bundle bundle, List<URL> out) {
+        String descriptorPaths = (String) bundle.getHeaders().get("DependencyManager-Component");
+        if (descriptorPaths == null)
+        {
+            return;
+        }
+
+        for (String descriptorPath : descriptorPaths.split(","))
+        {
+            URL descriptorURL = bundle.getEntry(descriptorPath);
+            if (descriptorURL == null)
+            {
+                Log.instance()
+                        .error("Runtime: " + "DependencyManager component descriptor not
found: %s",
+                               descriptorPath);
+                continue;
+            }
+            out.add(descriptorURL);
+        }        
+    }
+    
+    /**
      * Load a DependencyManager component descriptor from a given bundle.
      * @param b
      * @param descriptorURL
      */
     private void loadDescriptor(Bundle b, URL descriptorURL)
     {
-        Log.instance().debug("Runtime: ++++ Parsing descriptor %s from bundle %s",
-                             descriptorURL,
-                             b.getSymbolicName());
+        Log.instance().debug("Parsing descriptor %s from bundle %s", descriptorURL, b.getSymbolicName());
 
         BufferedReader in = null;
         try
@@ -164,7 +186,6 @@ public class DependencyManagerRuntime
             }
 
             m_parser.parse(in, b, dm);
-            m_managers.put(b, dm);
         }
 
         catch (Throwable t)



Mime
View raw message