You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2015/01/28 13:49:48 UTC

svn commit: r1655286 - in /sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl: CommonResourceResolverFactoryImpl.java ResourceResolverImpl.java

Author: cziegeler
Date: Wed Jan 28 12:49:48 2015
New Revision: 1655286

URL: http://svn.apache.org/r1655286
Log:
SLING-4360 : Mark ResourceResolver and ResourceResolverFactory as invalid if factory is unregistered

Modified:
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/CommonResourceResolverFactoryImpl.java
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java

Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/CommonResourceResolverFactoryImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/CommonResourceResolverFactoryImpl.java?rev=1655286&r1=1655285&r2=1655286&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/CommonResourceResolverFactoryImpl.java (original)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/CommonResourceResolverFactoryImpl.java Wed Jan 28 12:49:48 2015
@@ -24,6 +24,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Stack;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.apache.commons.collections.BidiMap;
 import org.apache.sling.api.resource.LoginException;
@@ -62,14 +63,23 @@ public class CommonResourceResolverFacto
      */
     private ThreadLocal<Stack<ResourceResolver>> resolverStackHolder = new ThreadLocal<Stack<ResourceResolver>>();
 
+    private final AtomicBoolean isActive = new AtomicBoolean(true);
+
     public CommonResourceResolverFactoryImpl(final ResourceResolverFactoryActivator activator) {
         this.activator = activator;
     }
 
     // ---------- Resource Resolver Factory ------------------------------------
 
+    /**
+     * @see org.apache.sling.api.resource.ResourceResolverFactory#getAdministrativeResourceResolver(java.util.Map)
+     */
     public ResourceResolver getAdministrativeResourceResolver(final Map<String, Object> passedAuthenticationInfo)
     throws LoginException {
+        if ( !isActive.get() ) {
+            throw new LoginException("ResourceResolverFactory is deactivated.");
+        }
+
         // create a copy of the passed authentication info as we modify the map
         final Map<String, Object> authenticationInfo = new HashMap<String, Object>();
         if ( passedAuthenticationInfo != null ) {
@@ -87,6 +97,10 @@ public class CommonResourceResolverFacto
      */
     public ResourceResolver getResourceResolver(final Map<String, Object> passedAuthenticationInfo)
     throws LoginException {
+        if ( !isActive.get() ) {
+            throw new LoginException("ResourceResolverFactory is deactivated.");
+        }
+
         // create a copy of the passed authentication info as we modify the map
         final Map<String, Object> authenticationInfo = new HashMap<String, Object>();
         if ( passedAuthenticationInfo != null ) {
@@ -111,6 +125,10 @@ public class CommonResourceResolverFacto
      * @see org.apache.sling.api.resource.ResourceResolverFactory#getThreadResourceResolver()
      */
     public ResourceResolver getThreadResourceResolver() {
+        if ( !isActive.get() ) {
+            return null;
+        }
+
         ResourceResolver result = null;
         final Stack<ResourceResolver> resolverStack = resolverStackHolder.get();
         if ( resolverStack != null && !resolverStack.isEmpty() ) {
@@ -147,6 +165,10 @@ public class CommonResourceResolverFacto
     public ResourceResolver getResourceResolverInternal(final Map<String, Object> authenticationInfo,
                     final boolean isAdmin)
     throws LoginException {
+        if ( !isActive.get() ) {
+            throw new LoginException("ResourceResolverFactory is deactivated.");
+        }
+
         // create context
         final ResourceResolverContext ctx = new ResourceResolverContext(isAdmin, authenticationInfo, this.activator.getResourceAccessSecurityTracker());
 
@@ -182,6 +204,7 @@ public class CommonResourceResolverFacto
      * Deactivates this component
      */
     protected void deactivate() {
+        isActive.set(false);
         if (plugin != null) {
             plugin.dispose();
             plugin = null;
@@ -241,11 +264,11 @@ public class CommonResourceResolverFacto
     public boolean isVanityPathEnabled() {
         return this.activator.isVanityPathEnabled();
     }
-    
+
     public long getMaxCachedVanityPathEntries() {
         return this.activator.getMaxCachedVanityPathEntries();
     }
-    
+
     public int getVanityBloomFilterMaxBytes() {
         return this.activator.getVanityBloomFilterMaxBytes();
     }
@@ -278,4 +301,8 @@ public class CommonResourceResolverFacto
         Collections.sort(configs);
         return configs;
     }
+
+    public boolean isLive() {
+        return this.isActive.get();
+    }
 }
\ No newline at end of file

Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java?rev=1655286&r1=1655285&r2=1655286&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java (original)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java Wed Jan 28 12:49:48 2015
@@ -132,7 +132,7 @@ public class ResourceResolverImpl extend
      * @see org.apache.sling.api.resource.ResourceResolver#isLive()
      */
     public boolean isLive() {
-        return !this.closed && this.context.isLive();
+        return !this.closed && this.context.isLive() && this.factory.isLive();
     }
 
     /**
@@ -439,8 +439,8 @@ public class ResourceResolverImpl extend
                 if (current != null && !path.endsWith(JCR_CONTENT_LEAF)) {
                     if (factory.getMapEntries().isOptimizeAliasResolutionEnabled()) {
                         logger.debug("map: Optimize Alias Resolution is Enabled");
-                        String parentPath = ResourceUtil.getParent(path);    
-                        if (parentPath != null) {         
+                        String parentPath = ResourceUtil.getParent(path);
+                        if (parentPath != null) {
                             final Map<String, String> aliases = factory.getMapEntries().getAliasMap(parentPath);
                             if (aliases!= null && aliases.containsValue(current.getName())) {
                                 for (String key:aliases.keySet()) {
@@ -449,12 +449,12 @@ public class ResourceResolverImpl extend
                                         break;
                                     }
                                 }
-                            } 
+                            }
                         }
                     } else {
                         logger.debug("map: Optimize Alias Resolution is Disabled");
                         alias = ResourceResolverContext.getProperty(current, PROP_ALIAS);
-                    }                    
+                    }
                 }
                 if (alias == null || alias.length() == 0) {
                     alias = ResourceUtil.getName(path);