incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r695889 - /incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/BundleResourceProcessor.java
Date Tue, 16 Sep 2008 14:13:59 GMT
Author: bdelacretaz
Date: Tue Sep 16 07:13:59 2008
New Revision: 695889

URL: http://svn.apache.org/viewvc?rev=695889&view=rev
Log:
SLING-659 - avoid ConcurrentModificationException in OsgiControllerImpl.run

Modified:
    incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/BundleResourceProcessor.java

Modified: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/BundleResourceProcessor.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/BundleResourceProcessor.java?rev=695889&r1=695888&r2=695889&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/BundleResourceProcessor.java
(original)
+++ incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/BundleResourceProcessor.java
Tue Sep 16 07:13:59 2008
@@ -23,9 +23,9 @@
 
 import java.io.InputStream;
 import java.util.HashMap;
-import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
 import java.util.Map;
-import java.util.Set;
 
 import org.apache.sling.jcr.jcrinstall.osgi.OsgiResourceProcessor;
 import org.osgi.framework.Bundle;
@@ -47,6 +47,7 @@
     private final PackageAdmin packageAdmin;
     private final Map<Long, Bundle> pendingBundles;
     private final Logger log = LoggerFactory.getLogger(this.getClass());
+    private final Object refreshLock = new Object();
     
     BundleResourceProcessor(BundleContext ctx, PackageAdmin packageAdmin) {
         this.ctx = ctx;
@@ -79,11 +80,15 @@
         }
         
         if(refresh) {
-            packageAdmin.resolveBundles(null);
-            packageAdmin.refreshPackages(null);
+            synchronized(refreshLock) {
+                packageAdmin.resolveBundles(null);
+                packageAdmin.refreshPackages(null);
+            }
         }
         
-        pendingBundles.put(new Long(b.getBundleId()), b);
+        synchronized(pendingBundles) {
+            pendingBundles.put(new Long(b.getBundleId()), b);
+        }
         
         return updated ? UPDATED : INSTALLED; 
     }
@@ -97,7 +102,9 @@
             if(b == null) {
                 log.debug("Bundle having id {} not found, cannot uninstall");
             } else {
-                pendingBundles.remove(new Long(b.getBundleId()));
+                synchronized(pendingBundles) {
+                    pendingBundles.remove(new Long(b.getBundleId()));
+                }
                 b.uninstall();
             }
         }
@@ -113,24 +120,30 @@
             return;
         }
         
-        final Iterator<Long> iter = pendingBundles.keySet().iterator(); 
-        while(iter.hasNext()) {
-            final Long id = iter.next();
+        final List<Long> toRemove = new LinkedList<Long>();
+        final List<Long> idList = new LinkedList<Long>();
+        synchronized(pendingBundles) {
+            for(Long id : pendingBundles.keySet()) {
+                idList.add(id);
+            }
+        }
+        
+        for(Long id : idList) {
             final Bundle bundle = ctx.getBundle(id.longValue());
             if(bundle == null) {
                 log.debug("Bundle id {} disappeared (bundle removed from framework?), removed
from pending bundles queue");
-                iter.remove();
+                toRemove.add(id);
                 continue;
             }
             final int state = bundle.getState();
             
             if(bundle == null) {
                 log.debug("Bundle id {} not found in processResourceQueue(), removed from
pending bundles queue");
-                iter.remove();
+                toRemove.add(id);
                 
             } else if ((state & Bundle.ACTIVE) > 0) {
                 log.info("Bundle {} is active, removed from pending bundles queue", bundle.getLocation());
-                iter.remove();
+                toRemove.add(id);
             
             } else if ((state & Bundle.STARTING) > 0) {
                 log.info("Bundle {} is starting.", bundle.getLocation());
@@ -140,17 +153,25 @@
                 
             } else if ((state & Bundle.UNINSTALLED) > 0) {
                 log.info("Bundle {} is uninstalled, removed from pending bundles queue",
bundle.getLocation());
-                iter.remove();
+                toRemove.add(id);
                 
             } else if ((state & Bundle.RESOLVED) > 0) {
                 log.info("Bundle {} is resolved, trying to start it.", bundle.getLocation());
                 bundle.start();
-                packageAdmin.resolveBundles(null);
-                packageAdmin.refreshPackages(null);
-                
+                synchronized(refreshLock) {
+                    packageAdmin.resolveBundles(null);
+                    packageAdmin.refreshPackages(null);
+                }
+
             } else if ((state & Bundle.INSTALLED) > 0) {
                 log.debug("Bundle {} is installed but not resolved.", bundle.getLocation());
             }
         }
+        
+        synchronized(pendingBundles) {
+            for(Long id : toRemove) {
+                pendingBundles.remove(id);
+            }
+        }
     }
 }



Mime
View raw message