felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r810854 - in /felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall: DirectoryWatcher.java FileInstall.java
Date Thu, 03 Sep 2009 09:50:22 GMT
Author: gnodet
Date: Thu Sep  3 09:50:22 2009
New Revision: 810854

URL: http://svn.apache.org/viewvc?rev=810854&view=rev
Log:
FELIX-1540:  [FileInstall] When removing/re-adding a bundle, all the dependent bundles don't
start anymore

Modified:
    felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/DirectoryWatcher.java
    felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/FileInstall.java

Modified: felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/DirectoryWatcher.java
URL: http://svn.apache.org/viewvc/felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/DirectoryWatcher.java?rev=810854&r1=810853&r2=810854&view=diff
==============================================================================
--- felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/DirectoryWatcher.java
(original)
+++ felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/DirectoryWatcher.java
Thu Sep  3 09:50:22 2009
@@ -99,9 +99,6 @@
     // Represents artifacts that could not be installed
     Map/* <File, Artifact> */ installationFailures = new HashMap/* <File, Artifact>
*/();
 
-    // Represents artifacts that could not be installed
-    Set/* <Bundle> */ startupFailures = new HashSet/* <Bundle> */();
-    
     public DirectoryWatcher(Dictionary properties, BundleContext context)
     {
         super(properties.toString());
@@ -298,12 +295,9 @@
 
                 if (startBundles)
                 {
-                    // Try to start all the bundles that we could not start last time.
-                    // Make a copy, because start() changes the underlying collection
-                    start(new HashSet(startupFailures));
-		            // Start updated bundles.
-		            start(updatedBundles);
-                    // Start newly installed bundles
+                    // Try to start all the bundles that are not persistently stopped
+                    startAllBundles();
+                    // Try to start newly installed bundles
                     start(installedBundles);
                 }
 
@@ -729,7 +723,6 @@
                 }
                 bundle.uninstall();
             }
-            startupFailures.remove(bundle);
             log("Uninstalled " + path, null);
         }
         catch (Exception e)
@@ -773,7 +766,6 @@
                     in.close();
                 }
             }
-            startupFailures.remove(bundle);
             artifact.setLastModified(Util.getLastModified(path));
             log("Updated " + path, null);
         }
@@ -784,6 +776,28 @@
         return bundle;
     }
 
+    private void startAllBundles()
+    {
+        List bundles = new ArrayList();
+        for (Iterator it = currentManagedArtifacts.values().iterator(); it.hasNext();)
+        {
+            Artifact artifact = (Artifact) it.next();
+            if (artifact.getBundleId() > 0)
+            {
+                Bundle bundle = context.getBundle(artifact.getBundleId());
+                if (bundle != null)
+                {
+                    if (bundle.getState() != Bundle.STARTING && bundle.getState()
!= Bundle.ACTIVE
+                            && FileInstall.getStartLevel().isBundlePersistentlyStarted(bundle))
+                    {
+                        bundles.add(bundle);
+                    }
+                }
+            }
+        }
+        start(bundles);
+    }
+
     private void start(Collection/* <Bundle> */ bundles)
     {
         for (Iterator b = bundles.iterator(); b.hasNext(); )
@@ -803,13 +817,11 @@
             try
             {
                 bundle.start();
-                startupFailures.remove(bundle);
                 log("Started bundle: " + bundle.getLocation(), null);
             }
             catch (BundleException e)
             {
                 log("Error while starting bundle: " + bundle.getLocation(), e);
-                startupFailures.add(bundle);
             }
         }
     }

Modified: felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/FileInstall.java
URL: http://svn.apache.org/viewvc/felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/FileInstall.java?rev=810854&r1=810853&r2=810854&view=diff
==============================================================================
--- felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/FileInstall.java (original)
+++ felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/FileInstall.java Thu
Sep  3 09:50:22 2009
@@ -39,6 +39,7 @@
 import org.osgi.service.cm.ConfigurationException;
 import org.osgi.service.cm.ManagedServiceFactory;
 import org.osgi.service.packageadmin.PackageAdmin;
+import org.osgi.service.startlevel.StartLevel;
 import org.osgi.util.tracker.ServiceTracker;
 
 /**
@@ -50,6 +51,7 @@
 public class FileInstall implements BundleActivator, ManagedServiceFactory
 {
     static ServiceTracker padmin;
+    static ServiceTracker startLevel;
     static ServiceTracker cmTracker;
     static List /* <ArtifactListener> */ listeners = new ArrayList /* <ArtifactListener>
*/();
     BundleContext context;
@@ -68,6 +70,8 @@
 
         padmin = new ServiceTracker(context, PackageAdmin.class.getName(), null);
         padmin.open();
+        startLevel = new ServiceTracker(context, StartLevel.class.getName(), null);
+        startLevel.open();
         cmTracker = new ServiceTracker(context, ConfigurationAdmin.class.getName(), null)
         {
             public Object addingService(ServiceReference serviceReference)
@@ -216,6 +220,24 @@
         }
     }
 
+    static StartLevel getStartLevel()
+    {
+        return getStartLevel(10000);
+    }
+
+    static StartLevel getStartLevel(long timeout)
+    {
+        try
+        {
+            return (StartLevel) startLevel.waitForService(timeout);
+        }
+        catch (InterruptedException e)
+        {
+            Thread.currentThread().interrupt();
+            return null;
+        }
+    }
+
     static ConfigurationAdmin getConfigurationAdmin()
     {
         return getConfigurationAdmin(10000);



Mime
View raw message