Return-Path: Delivered-To: apmail-incubator-sling-commits-archive@locus.apache.org Received: (qmail 9151 invoked from network); 16 Sep 2008 14:14:51 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 16 Sep 2008 14:14:51 -0000 Received: (qmail 864 invoked by uid 500); 16 Sep 2008 14:14:48 -0000 Delivered-To: apmail-incubator-sling-commits-archive@incubator.apache.org Received: (qmail 836 invoked by uid 500); 16 Sep 2008 14:14:48 -0000 Mailing-List: contact sling-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: sling-dev@incubator.apache.org Delivered-To: mailing list sling-commits@incubator.apache.org Received: (qmail 827 invoked by uid 99); 16 Sep 2008 14:14:48 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 16 Sep 2008 07:14:48 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 16 Sep 2008 14:13:58 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id ABDFA2388A0F; Tue, 16 Sep 2008 07:14:00 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: sling-commits@incubator.apache.org From: bdelacretaz@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080916141400.ABDFA2388A0F@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 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 iter = pendingBundles.keySet().iterator(); - while(iter.hasNext()) { - final Long id = iter.next(); + final List toRemove = new LinkedList(); + final List idList = new LinkedList(); + 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); + } + } } }