felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r1578844 - /felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java
Date Tue, 18 Mar 2014 12:34:51 GMT
Author: gnodet
Date: Tue Mar 18 12:34:51 2014
New Revision: 1578844

URL: http://svn.apache.org/r1578844
Log:
[FELIX-2702] Monitoring system state to check whether to reattempt
starting bundles.

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

Modified: felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java
URL: http://svn.apache.org/viewvc/felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java?rev=1578844&r1=1578843&r2=1578844&view=diff
==============================================================================
--- felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java
(original)
+++ felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java
Tue Mar 18 12:34:51 2014
@@ -147,6 +147,10 @@ public class DirectoryWatcher extends Th
     // Represents artifacts that could not be installed
     Map/* <File, Artifact> */ installationFailures = new HashMap/* <File, Artifact>
*/();
 
+    // flag (acces to which must be synchronized) that indicates wheter there's a change
in state of system,
+    // which may result in an attempt to start the watched bundles
+    private Boolean stateChanged = Boolean.FALSE;
+
     public DirectoryWatcher(Dictionary properties, BundleContext context)
     {
         super("fileinstall-" + getThreadName(properties));
@@ -335,7 +339,8 @@ public class DirectoryWatcher extends Th
 
     public void bundleChanged(BundleEvent bundleEvent)
     {
-        if (bundleEvent.getType() == BundleEvent.UNINSTALLED)
+        int type = bundleEvent.getType();
+        if (type == BundleEvent.UNINSTALLED)
         {
             for (Iterator it = getArtifacts().iterator(); it.hasNext();)
             {
@@ -349,6 +354,10 @@ public class DirectoryWatcher extends Th
                 }
             }
         }
+        if (type == BundleEvent.INSTALLED || type == BundleEvent.RESOLVED || type == BundleEvent.UNINSTALLED
||
+            type == BundleEvent.UNRESOLVED || type == BundleEvent.UPDATED) {
+            setStateChanged(true);
+        }
     }
 
     private void process(Set files) throws InterruptedException
@@ -510,10 +519,12 @@ public class DirectoryWatcher extends Th
             {
                 // Refresh if any bundle got uninstalled or updated.
                 refresh((Bundle[]) toRefresh.toArray(new Bundle[toRefresh.size()]));
+                // set the state to reattempt starting managed bundles which aren't already
STARTING or ACTIVE
+                setStateChanged(true);
             }
         }
 
-        if (startBundles)
+        if (startBundles && isStateChanged())
         {
             // Try to start all the bundles that are not persistently stopped
             startAllBundles();
@@ -522,6 +533,9 @@ public class DirectoryWatcher extends Th
             delayedStart.removeAll(uninstalledBundles);
             // Try to start newly installed bundles, or bundles which we missed on a previous
round
             startBundles(delayedStart);
+
+            // set the state as unchanged to not reattempt starting failed bundles
+            setStateChanged(false);
         }
     }
 
@@ -1490,5 +1504,17 @@ public class DirectoryWatcher extends Th
             currentManagedArtifacts.remove(file);
         }
     }
+    
+    private void setStateChanged(boolean changed) {
+        synchronized (stateChanged) {
+            this.stateChanged = Boolean.valueOf(changed);
+        }
+    }
+
+    private boolean isStateChanged() {
+        synchronized (stateChanged) {
+            return stateChanged.booleanValue();
+        }
+    }
 
 }



Mime
View raw message