felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r1348921 - in /felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal: DirectoryWatcher.java FileInstall.java
Date Mon, 11 Jun 2012 16:02:39 GMT
Author: gnodet
Date: Mon Jun 11 16:02:38 2012
New Revision: 1348921

URL: http://svn.apache.org/viewvc?rev=1348921&view=rev
Log:
[FELIX-3414] Fix problems with the refreshPackages which does not wait for the refresh to
be completed.
This is a simple workaround (which may not always work) that should improve the situation
waiting to leverage the new osgi wiring api.

Modified:
    felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java
    felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/FileInstall.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=1348921&r1=1348920&r2=1348921&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
Mon Jun 11 16:02:38 2012
@@ -674,11 +674,7 @@ public class DirectoryWatcher extends Th
      */
     void refresh(Bundle[] bundles)
     {
-        PackageAdmin padmin = FileInstall.getPackageAdmin();
-        if (padmin != null)
-        {
-            padmin.refreshPackages(bundles);
-        }
+        FileInstall.refresh(bundles);
     }
 
     /**

Modified: felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/FileInstall.java
URL: http://svn.apache.org/viewvc/felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/FileInstall.java?rev=1348921&r1=1348920&r2=1348921&view=diff
==============================================================================
--- felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/FileInstall.java
(original)
+++ felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/FileInstall.java
Mon Jun 11 16:02:38 2012
@@ -37,9 +37,12 @@ import org.apache.felix.fileinstall.Arti
 import org.apache.felix.fileinstall.internal.Util.Logger;
 import org.apache.felix.utils.collections.DictionaryAsMap;
 import org.apache.felix.utils.properties.InterpolationHelper;
+import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
+import org.osgi.framework.FrameworkEvent;
+import org.osgi.framework.FrameworkListener;
 import org.osgi.framework.FrameworkUtil;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.cm.ConfigurationAdmin;
@@ -56,7 +59,7 @@ import org.osgi.util.tracker.ServiceTrac
  * fragment).
  *
  */
-public class FileInstall implements BundleActivator, ServiceTrackerCustomizer
+public class FileInstall implements BundleActivator, ServiceTrackerCustomizer, FrameworkListener
 {
     static ServiceTracker padmin;
     static ServiceTracker startLevel;
@@ -68,10 +71,12 @@ public class FileInstall implements Bund
     ServiceTracker listenersTracker;
     static boolean initialized;
     static final Object barrier = new Object();
+    static final Object refreshLock = new Object();
 
     public void start(BundleContext context) throws Exception
     {
         this.context = context;
+        context.addFrameworkListener(this);
 
         Hashtable props = new Hashtable();
         props.put("url.handler.protocol", JarDirUrlHandler.PROTOCOL);
@@ -296,7 +301,7 @@ public class FileInstall implements Bund
         for (Iterator w = toNotify.iterator(); w.hasNext();)
         {
             DirectoryWatcher dir = (DirectoryWatcher) w.next();
-            dir.removeListener( listener );
+            dir.removeListener(listener);
         }
     }
 
@@ -311,6 +316,37 @@ public class FileInstall implements Bund
         }
     }
 
+    /**
+     * Convenience to refresh the packages
+     */
+    static void refresh(Bundle[] bundles)
+    {
+        PackageAdmin padmin = getPackageAdmin();
+        if (padmin != null)
+        {
+            synchronized (refreshLock) {
+                padmin.refreshPackages(bundles);
+                try {
+                    refreshLock.wait(30000);
+                } catch (InterruptedException e) {
+                    throw new RuntimeException(e);
+                }
+            }
+        }
+    }
+
+    public void frameworkEvent(FrameworkEvent event)
+    {
+        if (event.getType() == FrameworkEvent.PACKAGES_REFRESHED
+                || event.getType() == FrameworkEvent.ERROR)
+        {
+            synchronized (refreshLock)
+            {
+                refreshLock.notifyAll();
+            }
+        }
+    }
+
     static PackageAdmin getPackageAdmin()
     {
         return getPackageAdmin(10000);



Mime
View raw message