Author: gnodet
Date: Wed Mar 20 10:25:52 2013
New Revision: 1458722

URL: http://svn.apache.org/r1458722
Log:
[KARAF-2244] BundleWatcher should wait for refresh to be finished before 
updating another bundle

Modified:
    
karaf/trunk/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/BundleWatcherImpl.java
    karaf/trunk/bundle/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml

Modified: 
karaf/trunk/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/BundleWatcherImpl.java
URL: 
http://svn.apache.org/viewvc/karaf/trunk/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/BundleWatcherImpl.java?rev=1458722&r1=1458721&r2=1458722&view=diff
==============================================================================
--- 
karaf/trunk/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/BundleWatcherImpl.java
 (original)
+++ 
karaf/trunk/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/BundleWatcherImpl.java
 Wed Mar 20 10:25:52 2013
@@ -27,6 +27,7 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
 
@@ -38,6 +39,9 @@ import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleEvent;
 import org.osgi.framework.BundleException;
 import org.osgi.framework.BundleListener;
+import org.osgi.framework.FrameworkEvent;
+import org.osgi.framework.FrameworkListener;
+import org.osgi.framework.wiring.FrameworkWiring;
 import org.osgi.service.packageadmin.PackageAdmin;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -51,7 +55,6 @@ public class BundleWatcherImpl implement
     private final Logger logger = 
LoggerFactory.getLogger(BundleWatcherImpl.class);
 
     private BundleContext bundleContext;
-    private final PackageAdmin packageAdmin;
        private final BundleService bundleService;
        private final MavenConfigService localRepoDetector;
 
@@ -64,9 +67,8 @@ public class BundleWatcherImpl implement
      * Constructor
      */
     @SuppressWarnings("deprecation")
-    public BundleWatcherImpl(BundleContext bundleContext, PackageAdmin 
packageAdmin, MavenConfigService mavenConfigService, BundleService 
bundleService) {
+    public BundleWatcherImpl(BundleContext bundleContext, MavenConfigService 
mavenConfigService, BundleService bundleService) {
         this.bundleContext = bundleContext;
-        this.packageAdmin = packageAdmin;
                this.localRepoDetector = mavenConfigService;
         this.bundleService = bundleService;
     }
@@ -107,7 +109,18 @@ public class BundleWatcherImpl implement
                         logger.error("Error updating bundle.", ex);
                     }
                 }
-                packageAdmin.refreshPackages(updated.toArray(new 
Bundle[updated.size()]));
+                try {
+                    final CountDownLatch latch = new CountDownLatch(1);
+                    FrameworkWiring wiring = 
bundleContext.getBundle(0).adapt(FrameworkWiring.class);
+                    wiring.refreshBundles(updated, new FrameworkListener() {
+                        public void frameworkEvent(FrameworkEvent event) {
+                            latch.countDown();
+                        }
+                    });
+                    latch.await();
+                } catch (InterruptedException e) {
+                    running.set(false);
+                }
             }
             try {
                 Thread.sleep(interval);

Modified: 
karaf/trunk/bundle/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
URL: 
http://svn.apache.org/viewvc/karaf/trunk/bundle/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml?rev=1458722&r1=1458721&r2=1458722&view=diff
==============================================================================
--- karaf/trunk/bundle/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml 
(original)
+++ karaf/trunk/bundle/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml 
Wed Mar 20 10:25:52 2013
@@ -23,7 +23,6 @@
     <ext:property-placeholder placeholder-prefix="$[" placeholder-suffix="]"/>
     
     <reference id="configurationAdmin" 
interface="org.osgi.service.cm.ConfigurationAdmin"/>
-    <reference id="packageAdmin" 
interface="org.osgi.service.packageadmin.PackageAdmin"/>
     <reference-list id="bundleStateServices" 
interface="org.apache.karaf.bundle.core.BundleStateService" 
availability="optional" />
 
     <bean id="bundleService" 
class="org.apache.karaf.bundle.core.internal.BundleServiceImpl">
@@ -41,7 +40,6 @@
 
     <bean id="watcher" 
class="org.apache.karaf.bundle.core.internal.BundleWatcherImpl" 
init-method="start" destroy-method="stop">
         <argument ref="blueprintBundleContext"/>
-        <argument ref="packageAdmin"/>
         <argument ref="mavenConfigService"/>
         <argument ref="bundleService"/>
     </bean>


Reply via email to