Return-Path: Delivered-To: apmail-sling-commits-archive@www.apache.org Received: (qmail 2322 invoked from network); 2 Sep 2010 13:28:52 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 2 Sep 2010 13:28:52 -0000 Received: (qmail 77498 invoked by uid 500); 2 Sep 2010 13:28:52 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 77433 invoked by uid 500); 2 Sep 2010 13:28:50 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 77425 invoked by uid 99); 2 Sep 2010 13:28:50 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 02 Sep 2010 13:28:50 +0000 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; Thu, 02 Sep 2010 13:28:46 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 0ACF423889FA; Thu, 2 Sep 2010 13:27:27 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r991929 - in /sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base: AbstractSlingRepository.java internal/loader/Loader.java Date: Thu, 02 Sep 2010 13:27:26 -0000 To: commits@sling.apache.org From: justin@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100902132727.0ACF423889FA@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: justin Date: Thu Sep 2 13:27:26 2010 New Revision: 991929 URL: http://svn.apache.org/viewvc?rev=991929&view=rev Log: SLING-1548 - applying modified patch Modified: sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepository.java sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/internal/loader/Loader.java Modified: sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepository.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepository.java?rev=991929&r1=991928&r2=991929&view=diff ============================================================================== --- sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepository.java (original) +++ sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepository.java Thu Sep 2 13:27:26 2010 @@ -36,9 +36,7 @@ import org.apache.sling.jcr.api.SlingRep import org.apache.sling.jcr.base.internal.loader.Loader; import org.apache.sling.jcr.base.util.RepositoryAccessor; import org.osgi.framework.BundleContext; -import org.osgi.framework.BundleEvent; import org.osgi.framework.ServiceRegistration; -import org.osgi.framework.SynchronousBundleListener; import org.osgi.service.component.ComponentContext; import org.osgi.service.log.LogService; import org.osgi.util.tracker.ServiceTracker; @@ -54,7 +52,7 @@ import org.osgi.util.tracker.ServiceTrac * @scr.component metatype="no" */ public abstract class AbstractSlingRepository implements SlingRepository, - SynchronousBundleListener, Runnable { + Runnable { /** @scr.property value="" */ public static final String PROPERTY_DEFAULT_WORKSPACE = "defaultWorkspace"; @@ -442,7 +440,7 @@ public abstract class AbstractSlingRepos */ protected void setupRepository(Repository repository) { BundleContext bundleContext = componentContext.getBundleContext(); - this.namespaceHandler = new Loader(this, bundleContext.getBundles()); + this.namespaceHandler = new Loader(this, bundleContext); this.sessionProxyHandler = new SessionProxyHandler(this); } @@ -567,36 +565,6 @@ public abstract class AbstractSlingRepos // nothing to do here ... } - // ---------- SynchronousBundleListener ------------------------------------ - - /** - * Loads and unloads any components provided by the bundle whose state - * changed. If the bundle has been started, the components are loaded. If - * the bundle is about to stop, the components are unloaded. - * - * @param event The BundleEvent representing the bundle state - * change. - */ - public void bundleChanged(BundleEvent event) { - // Take care: This is synchronous - take care to not block the system !! - Loader theLoader = this.namespaceHandler; - if (theLoader != null) { - switch (event.getType()) { - case BundleEvent.INSTALLED: - // register types when the bundle gets installed - theLoader.registerBundle(event.getBundle()); - break; - - case BundleEvent.UNINSTALLED: - theLoader.unregisterBundle(event.getBundle()); - break; - - case BundleEvent.UPDATED: - theLoader.updateBundle(event.getBundle()); - } - } - } - // --------- SCR integration ----------------------------------------------- protected ComponentContext getComponentContext() { @@ -632,8 +600,6 @@ public abstract class AbstractSlingRepos setPollTimeActive(getIntProperty(properties, PROPERTY_POLL_ACTIVE)); setPollTimeInActive(getIntProperty(properties, PROPERTY_POLL_INACTIVE)); - componentContext.getBundleContext().addBundleListener(this); - // immediately try to start the repository while activating // this component instance try { @@ -660,8 +626,6 @@ public abstract class AbstractSlingRepos protected void deactivate(ComponentContext componentContext) { this.namespaceMapperTracker.close(); - componentContext.getBundleContext().removeBundleListener(this); - // stop the background thread stopRepositoryPinger(); Modified: sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/internal/loader/Loader.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/internal/loader/Loader.java?rev=991929&r1=991928&r2=991929&view=diff ============================================================================== --- sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/internal/loader/Loader.java (original) +++ sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/internal/loader/Loader.java Thu Sep 2 13:27:26 2010 @@ -25,7 +25,6 @@ import java.net.URL; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.StringTokenizer; @@ -38,6 +37,9 @@ import org.apache.sling.jcr.api.Namespac import org.apache.sling.jcr.base.AbstractSlingRepository; import org.apache.sling.jcr.base.NodeTypeLoader; import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.BundleEvent; +import org.osgi.framework.BundleListener; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -45,7 +47,7 @@ import org.slf4j.LoggerFactory; /** * The Loader TODO */ -public class Loader implements NamespaceMapper { +public class Loader implements NamespaceMapper, BundleListener { public static final String NODETYPES_BUNDLE_HEADER = "Sling-Nodetypes"; @@ -53,23 +55,26 @@ public class Loader implements Namespace /** default log */ private static final Logger log = LoggerFactory.getLogger(Loader.class); + + private final BundleContext bundleContext; - private AbstractSlingRepository slingRepository; + private final AbstractSlingRepository slingRepository; // bundles whose registration failed and should be retried - private List delayedBundles; + private final List delayedBundles; /** Namespace prefix table. */ private final Map namespaceTable = new HashMap(); - public Loader(AbstractSlingRepository repository, Bundle[] existingBundles) { + public Loader(AbstractSlingRepository repository, BundleContext bundleContext) { + this.bundleContext = bundleContext; this.slingRepository = repository; - this.delayedBundles = new LinkedList(); + this.delayedBundles = new ArrayList(); // scan existing bundles - for (Bundle bundle : existingBundles) { - // Ignore bundles which are in an inactive state - if ((bundle.getState() & (Bundle.UNINSTALLED | Bundle.STOP_TRANSIENT | Bundle.STOPPING )) == 0) { + bundleContext.addBundleListener(this); + for (Bundle bundle : bundleContext.getBundles()) { + if (bundle.getState() != Bundle.UNINSTALLED) { registerBundle(bundle); } } @@ -77,14 +82,86 @@ public class Loader implements Namespace } public void dispose() { - if (this.delayedBundles != null) { - this.delayedBundles.clear(); - this.delayedBundles = null; + bundleContext.removeBundleListener(this); + + synchronized (delayedBundles) { + delayedBundles.clear(); + } + } + + //---------- NamespaceMapper interface + + public void defineNamespacePrefixes(Session session) + throws RepositoryException { + final Iterator iter = this.namespaceTable.values().iterator(); + while ( iter.hasNext() ) { + final NamespaceEntry[] entries = iter.next(); + for(int i=0; iBundleEvent representing the bundle state + * change. + */ + public final void bundleChanged(BundleEvent event) { + // Take care: This is synchronous - take care to not block the system !! + switch (event.getType()) { + case BundleEvent.INSTALLED: + // register types when the bundle gets installed + registerBundle(event.getBundle()); + break; + + case BundleEvent.UNINSTALLED: + unregisterBundle(event.getBundle()); + break; + + case BundleEvent.UPDATED: + updateBundle(event.getBundle()); + } + } + + //---------- internal + + private void registerBundle(Bundle bundle) { this.registerNamespaces(bundle); if (this.registerBundleInternal(bundle, false)) { // handle delayed bundles, might help now @@ -99,19 +176,20 @@ public class Loader implements Namespace currentSize = this.delayedBundles.size(); } } else { - // add to delayed bundles - this.delayedBundles.add(bundle); + synchronized (delayedBundles) { + delayedBundles.add(bundle); + } } } - public void unregisterBundle(Bundle bundle) { + private void unregisterBundle(Bundle bundle) { this.unregisterNamespaces(bundle); - if ( this.delayedBundles.contains(bundle) ) { - this.delayedBundles.remove(bundle); + synchronized (delayedBundles) { + delayedBundles.remove(bundle); } } - public void updateBundle(Bundle bundle) { + private void updateBundle(Bundle bundle) { unregisterBundle(bundle); registerBundle(bundle); } @@ -120,7 +198,7 @@ public class Loader implements Namespace * Register namespaces defined in the bundle in the namespace table. * @param bundle The bundle. */ - protected void registerNamespaces(Bundle bundle) { + private void registerNamespaces(Bundle bundle) { final String definition = (String) bundle.getHeaders().get(NAMESPACES_BUNDLE_HEADER); if ( definition != null ) { log.debug("registerNamespaces: Bundle {} tries to register: {}", @@ -263,49 +341,8 @@ public class Loader implements Namespace session.logout(); } } - - public void defineNamespacePrefixes(Session session) - throws RepositoryException { - final Iterator iter = this.namespaceTable.values().iterator(); - while ( iter.hasNext() ) { - final NamespaceEntry[] entries = iter.next(); - for(int i=0; i