Author: cziegeler
Date: Fri Oct 14 12:08:22 2016
New Revision: 1764881

URL: http://svn.apache.org/viewvc?rev=1764881&view=rev
Log:
SLING-6153 : Improve MapEntries implementation

Added:
    
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesHandler.java
   (with props)
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/ResourceResolverFactoryActivator.java
    
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
    
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/console/ResourceResolverWebConsolePlugin.java
    
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapConfigurationProvider.java
    
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
    
sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.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=1764881&r1=1764880&r2=1764881&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
 Fri Oct 14 12:08:22 2016
@@ -39,6 +39,7 @@ import org.apache.sling.resourceresolver
 import org.apache.sling.resourceresolver.impl.helper.ResourceResolverControl;
 import org.apache.sling.resourceresolver.impl.mapping.MapConfigurationProvider;
 import org.apache.sling.resourceresolver.impl.mapping.MapEntries;
+import org.apache.sling.resourceresolver.impl.mapping.MapEntriesHandler;
 import org.apache.sling.resourceresolver.impl.mapping.Mapping;
 import 
org.apache.sling.resourceresolver.impl.providers.ResourceProviderTracker;
 import org.apache.sling.spi.resource.provider.ResourceProvider;
@@ -54,7 +55,7 @@ import org.slf4j.LoggerFactory;
 public class CommonResourceResolverFactoryImpl implements 
ResourceResolverFactory, MapConfigurationProvider {
 
     /** Helper for the resource resolver. */
-    private MapEntries mapEntries = MapEntries.EMPTY;
+    private MapEntriesHandler mapEntries = MapEntriesHandler.EMPTY;
 
     /** The web console plugin. */
     private ResourceResolverWebConsolePlugin plugin;
@@ -258,7 +259,7 @@ public class CommonResourceResolverFacto
         return new ResourceResolverImpl(this, isAdmin, authenticationInfo);
     }
 
-    public MapEntries getMapEntries() {
+    public MapEntriesHandler getMapEntries() {
         return mapEntries;
     }
 
@@ -291,8 +292,8 @@ public class CommonResourceResolverFacto
             plugin = null;
         }
 
-        if (mapEntries != null) {
-            mapEntries.dispose();
+        if (mapEntries instanceof MapEntries ) {
+            ((MapEntries)mapEntries).dispose();
             mapEntries = MapEntries.EMPTY;
         }
         resolverStackHolder = null;
@@ -316,6 +317,11 @@ public class CommonResourceResolverFacto
     }
 
     @Override
+    public boolean isMapConfiguration(String path) {
+        return this.activator.isMapConfiguration(path);
+    }
+
+    @Override
     public Mapping[] getMappings() {
         return this.activator.getMappings();
     }

Modified: 
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java?rev=1764881&r1=1764880&r2=1764881&view=diff
==============================================================================
--- 
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java
 (original)
+++ 
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java
 Fri Oct 14 12:08:22 2016
@@ -291,6 +291,8 @@ public class ResourceResolverFactoryActi
     /** the root location of the /etc/map entries */
     private volatile String mapRoot;
 
+    private volatile String mapRootPrefix;
+
     /** whether to mangle paths with namespaces or not */
     private volatile boolean mangleNamespacePrefixes;
 
@@ -394,6 +396,10 @@ public class ResourceResolverFactoryActi
         return mapRoot;
     }
 
+    public boolean isMapConfiguration(String path) {
+        return path.equals(this.mapRoot) || 
path.startsWith(this.mapRootPrefix);
+    }
+
     public int getDefaultVanityPathRedirectStatus() {
         return defaultVanityPathRedirectStatus;
     }
@@ -497,6 +503,8 @@ public class ResourceResolverFactoryActi
 
         // the root of the resolver mappings
         mapRoot = PropertiesUtil.toString(properties.get(PROP_MAP_LOCATION), 
MapEntries.DEFAULT_MAP_ROOT);
+        mapRootPrefix = mapRoot + '/';
+
         observationPaths = 
PropertiesUtil.toStringArray(properties.get(PROP_OBSERVATION_PATHS), new 
String[] {"/"});
 
         defaultVanityPathRedirectStatus = 
PropertiesUtil.toInteger(properties.get(PROP_DEFAULT_VANITY_PATH_REDIRECT_STATUS),

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=1764881&r1=1764880&r2=1764881&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
 Fri Oct 14 12:08:22 2016
@@ -485,7 +485,7 @@ public class ResourceResolverImpl extend
             while (path != null) {
                 String alias = null;
                 if (current != null && !path.endsWith(JCR_CONTENT_LEAF)) {
-                    if 
(factory.getMapEntries().isOptimizeAliasResolutionEnabled()) {
+                    if (factory.isOptimizeAliasResolutionEnabled()) {
                         logger.debug("map: Optimize Alias Resolution is 
Enabled");
                         String parentPath = ResourceUtil.getParent(path);
                         if (parentPath != null) {
@@ -917,11 +917,11 @@ public class ResourceResolverImpl extend
         } else {
 
             String tokenizedPath = absPath;
-            
+
             // no direct resource found, so we have to drill down into the
             // resource tree to find a match
             resource = getAbsoluteResourceInternal(null, "/", parameters, 
true);
-            
+
             //no read access on / drilling further down
             //SLING-5638
             if (resource == null) {
@@ -930,7 +930,7 @@ public class ResourceResolverImpl extend
                     tokenizedPath = 
tokenizedPath.substring(resource.getPath().length());
                 }
             }
-            
+
             final StringBuilder resolutionPath = new StringBuilder();
             final StringTokenizer tokener = new StringTokenizer(tokenizedPath, 
"/");
             while (resource != null && tokener.hasMoreTokens()) {
@@ -941,7 +941,7 @@ public class ResourceResolverImpl extend
 
                     resource = nextResource;
                     resolutionPath.append("/").append(childNameRaw);
-                    
+
                 } else {
 
                     String childName = null;
@@ -1005,7 +1005,7 @@ public class ResourceResolverImpl extend
 
         // we do not have a child with the exact name, so we look for
         // a child, whose alias matches the childName
-        if (factory.getMapEntries().isOptimizeAliasResolutionEnabled()){
+        if (factory.isOptimizeAliasResolutionEnabled()){
             logger.debug("getChildInternal: Optimize Alias Resolution is 
Enabled");
             //optimization made in SLING-2521
             final Map<String, String> aliases = 
factory.getMapEntries().getAliasMap(parent.getPath());
@@ -1074,30 +1074,30 @@ public class ResourceResolverImpl extend
         logger.debug("getResourceInternal: Cannot resolve path '{}' to a 
resource", path);
         return null;
     }
-    
+
     /**
      * Creates a resource, traversing bottom up, to the highest readable 
resource.
-     * 
+     *
      */
     private Resource getAbsoluteResourceInternal(String absPath, final 
Map<String, String> parameters, final boolean isResolved) {
-         
+
         if (!absPath.contains("/") || "/".equals(absPath)) {
             return null;
         }
-        
+
         absPath = absPath.substring(absPath.indexOf("/"));
         Resource resource = getAbsoluteResourceInternal(null, absPath, 
parameters, isResolved);
-        
+
         absPath = absPath.substring(0, absPath.lastIndexOf("/"));
 
         while (!absPath.equals("")) {
             Resource r = getAbsoluteResourceInternal(null, absPath, 
parameters, true);
-            
+
             if (r != null) {
                 resource = r;
-            }            
+            }
             absPath = absPath.substring(0, absPath.lastIndexOf("/"));
-        }        
+        }
         return resource;
     }
 

Modified: 
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/console/ResourceResolverWebConsolePlugin.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/console/ResourceResolverWebConsolePlugin.java?rev=1764881&r1=1764880&r2=1764881&view=diff
==============================================================================
--- 
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/console/ResourceResolverWebConsolePlugin.java
 (original)
+++ 
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/console/ResourceResolverWebConsolePlugin.java
 Fri Oct 14 12:08:22 2016
@@ -46,7 +46,7 @@ import org.apache.sling.api.resource.run
 import 
org.apache.sling.resourceresolver.impl.CommonResourceResolverFactoryImpl;
 import org.apache.sling.resourceresolver.impl.helper.URI;
 import org.apache.sling.resourceresolver.impl.helper.URIException;
-import org.apache.sling.resourceresolver.impl.mapping.MapEntries;
+import org.apache.sling.resourceresolver.impl.mapping.MapEntriesHandler;
 import org.apache.sling.resourceresolver.impl.mapping.MapEntry;
 import org.apache.sling.spi.resource.provider.ResourceProvider;
 import org.osgi.framework.BundleContext;
@@ -119,7 +119,7 @@ public class ResourceResolverWebConsoleP
 
         pw.println("<table class='content' cellpadding='0' cellspacing='0' 
width='100%'>");
 
-        final MapEntries mapEntries = resolverFactory.getMapEntries();
+        final MapEntriesHandler mapEntries = resolverFactory.getMapEntries();
 
         titleHtml(pw, "Configuration", null);
         pw.println("<tr class='content'>");
@@ -278,7 +278,7 @@ public class ResourceResolverWebConsoleP
 
         separatorText(pw);
 
-        final MapEntries mapEntries = resolverFactory.getMapEntries();
+        final MapEntriesHandler mapEntries = resolverFactory.getMapEntries();
 
         dumpMapText(pw, "Resolver Map Entries", mapEntries.getResolveMaps());
 

Modified: 
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapConfigurationProvider.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapConfigurationProvider.java?rev=1764881&r1=1764880&r2=1764881&view=diff
==============================================================================
--- 
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapConfigurationProvider.java
 (original)
+++ 
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapConfigurationProvider.java
 Fri Oct 14 12:08:22 2016
@@ -32,6 +32,8 @@ public interface MapConfigurationProvide
 
     String getMapRoot();
 
+    boolean isMapConfiguration(String path);
+
     String[] getObservationPaths();
 
     Map<?, ?> getVirtualURLMap();

Modified: 
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java?rev=1764881&r1=1764880&r2=1764881&view=diff
==============================================================================
--- 
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
 (original)
+++ 
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
 Fri Oct 14 12:08:22 2016
@@ -45,6 +45,7 @@ import java.util.TreeMap;
 import java.util.TreeSet;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicLong;
 import java.util.concurrent.locks.ReentrantLock;
 
@@ -71,7 +72,10 @@ import org.osgi.service.event.EventAdmin
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class MapEntries implements ResourceChangeListener, 
ExternalResourceChangeListener {
+public class MapEntries implements
+    MapEntriesHandler,
+    ResourceChangeListener,
+    ExternalResourceChangeListener {
 
     public static final String JCR_CONTENT = "jcr:content";
 
@@ -79,8 +83,6 @@ public class MapEntries implements Resou
 
     public static final String JCR_CONTENT_SUFFIX = "/jcr:content";
 
-    public static final MapEntries EMPTY = new MapEntries();
-
     private static final String PROP_REG_EXP = "sling:match";
 
     public static final String PROP_REDIRECT_EXTERNAL = "sling:redirect";
@@ -111,11 +113,13 @@ public class MapEntries implements Resou
     /** default log */
     private final Logger log = LoggerFactory.getLogger(getClass());
 
-    private MapConfigurationProvider factory;
+    private volatile MapConfigurationProvider factory;
 
     private volatile ResourceResolver resolver;
 
-    private final String mapRoot;
+    private volatile EventAdmin eventAdmin;
+
+    private volatile ServiceRegistration<ResourceChangeListener> registration;
 
     private Map<String, List<MapEntry>> resolveMapsMap;
 
@@ -125,26 +129,8 @@ public class MapEntries implements Resou
 
     private Map<String, Map<String, String>> aliasMap;
 
-    private ServiceRegistration<ResourceChangeListener> registration;
-
-    private EventAdmin eventAdmin;
-
     private final ReentrantLock initializing = new ReentrantLock();
 
-    private final boolean enabledVanityPaths;
-
-    private final long maxCachedVanityPathEntries;
-
-    private final boolean maxCachedVanityPathEntriesStartup;
-
-    private final int vanityBloomFilterMaxBytes;
-
-    private final boolean enableOptimizeAliasResolution;
-
-    private final boolean vanityPathPrecedence;
-
-    private final List<VanityPathConfig> vanityPathConfig;
-
     private final AtomicLong vanityCounter;
 
     private final File vanityBloomFilterFile;
@@ -155,44 +141,14 @@ public class MapEntries implements Resou
 
     private boolean updateBloomFilterFile = false;
 
-    @SuppressWarnings("unchecked")
-    private MapEntries() {
-        this.factory = null;
-        this.resolver = null;
-        this.mapRoot = DEFAULT_MAP_ROOT;
-
-        this.resolveMapsMap = Collections.singletonMap(GLOBAL_LIST_KEY, 
(List<MapEntry>)Collections.EMPTY_LIST);
-        this.mapMaps = Collections.<MapEntry> emptyList();
-        this.vanityTargets = Collections.<String,List <String>>emptyMap();
-        this.aliasMap = Collections.<String, Map<String, String>>emptyMap();
-        this.registration = null;
-        this.eventAdmin = null;
-        this.enabledVanityPaths = true;
-        this.maxCachedVanityPathEntries = -1;
-        this.maxCachedVanityPathEntriesStartup = true;
-        this.vanityBloomFilterMaxBytes = 0;
-        this.enableOptimizeAliasResolution = true;
-        this.vanityPathConfig = null;
-        this.vanityPathPrecedence = false;
-        this.vanityCounter = new AtomicLong(0);
-        this.vanityBloomFilterFile = null;
-    }
-
     @SuppressWarnings({ "unchecked", "deprecation" })
     public MapEntries(final MapConfigurationProvider factory, final 
BundleContext bundleContext, final EventAdmin eventAdmin)
-                    throws LoginException, IOException {
+        throws LoginException, IOException {
+
         final Map<String, Object> authInfo = new HashMap<String, Object>();
         authInfo.put(ResourceProvider.AUTH_SERVICE_BUNDLE, 
bundleContext.getBundle());
         this.resolver = factory.getAdministrativeResourceResolver(authInfo);
         this.factory = factory;
-        this.mapRoot = factory.getMapRoot();
-        this.enabledVanityPaths = factory.isVanityPathEnabled();
-        this.maxCachedVanityPathEntries = 
factory.getMaxCachedVanityPathEntries();
-        this.maxCachedVanityPathEntriesStartup = 
factory.isMaxCachedVanityPathEntriesStartup();
-        this.vanityBloomFilterMaxBytes = 
factory.getVanityBloomFilterMaxBytes();
-        this.vanityPathConfig = factory.getVanityPathConfig();
-        this.enableOptimizeAliasResolution = 
factory.isOptimizeAliasResolutionEnabled();
-        this.vanityPathPrecedence = factory.hasVanityPathPrecedence();
         this.eventAdmin = eventAdmin;
 
         this.resolveMapsMap = Collections.singletonMap(GLOBAL_LIST_KEY, 
(List<MapEntry>)Collections.EMPTY_LIST);
@@ -232,7 +188,7 @@ public class MapEntries implements Resou
             final Map<String, List<MapEntry>> newResolveMapsMap = new 
ConcurrentHashMap<String, List<MapEntry>>();
 
             //optimization made in SLING-2521
-            if (enableOptimizeAliasResolution){
+            if (this.factory.isOptimizeAliasResolutionEnabled()){
                 final Map<String, Map<String, String>> aliasMap = 
this.loadAliases(resolver);
                 this.aliasMap = aliasMap;
             }
@@ -263,7 +219,7 @@ public class MapEntries implements Resou
     protected void initializeVanityPaths() throws IOException {
         this.initializing.lock();
         try {
-            if (this.enabledVanityPaths) {
+            if (this.factory.isVanityPathEnabled()) {
 
                 if (vanityBloomFilterFile == null) {
                     throw new RuntimeException(
@@ -304,12 +260,9 @@ public class MapEntries implements Resou
 
     }
 
-    private boolean doNodeAdded(String path, boolean refreshed) {
-        boolean newRefreshed = refreshed;
-        if (!newRefreshed) {
-            resolver.refresh();
-            newRefreshed = true;
-        }
+    private void doNodeAdded(String path, final AtomicBoolean 
resolverRefreshed) {
+        this.refreshResolverIfNecessary(resolverRefreshed);
+
         this.initializing.lock();
         try {
             Resource resource = resolver.getResource(path);
@@ -321,7 +274,7 @@ public class MapEntries implements Resou
                 if (props.containsKey(ResourceResolverImpl.PROP_ALIAS)) {
                     doAddAlias(path);
                 }
-                if (path.startsWith(this.mapRoot)) {
+                if (path.startsWith(this.factory.getMapRoot())) {
                     doUpdateConfiguration();
                 }
             }
@@ -330,7 +283,6 @@ public class MapEntries implements Resou
         } finally {
             this.initializing.unlock();
         }
-        return newRefreshed;
     }
 
     /**
@@ -340,7 +292,7 @@ public class MapEntries implements Resou
      * @param path Optional sub path of the vanity path
      * @return
      */
-    private boolean doRemoveAllAliases(final String vanityPath, boolean 
refreshed, final String path) {
+    private boolean doRemoveAllAliases(final String vanityPath, AtomicBoolean 
resolverRefreshed, final String path) {
         // if path is specified we first need to find out if it is
         // a direct child of vanity path but not jcr:content, or a jcr:content 
child of a direct child
         // otherwise we can discard the event
@@ -363,48 +315,34 @@ public class MapEntries implements Resou
         if ( !handle ) {
             return false;
         }
-        boolean newRefreshed = refreshed;
-        if (!newRefreshed) {
-            resolver.refresh();
-            newRefreshed = true;
-        }
+
         this.initializing.lock();
         try {
-            if (enableOptimizeAliasResolution) {
+            if (this.factory.isOptimizeAliasResolutionEnabled()) {
                 final Map<String, String> aliasMapEntry = 
aliasMap.remove(vanityPath);
                 if (aliasMapEntry != null && path != null && 
path.endsWith(JCR_CONTENT_SUFFIX) ) {
+                    this.refreshResolverIfNecessary(resolverRefreshed);
                     // we need to re-add
                     // from a potential parent
                     doAddAlias(ResourceUtil.getParent(path));
                 }
-                if ( aliasMapEntry != null ) {
-                    sendChangeEvent();
-                }
+                return aliasMapEntry != null;
             }
 
-            // TODO we should not handle this here
-            if (vanityPath.startsWith(this.mapRoot)) {
-                doUpdateConfiguration();
-                sendChangeEvent();
-            }
         } finally {
             this.initializing.unlock();
         }
-        return newRefreshed;
+        return false;
     }
 
-    private boolean doRemoveAttributes(String path, String removedAttribute, 
boolean refreshed) {
-        boolean newRefreshed = refreshed;
-        if (!newRefreshed) {
-            resolver.refresh();
-            newRefreshed = true;
-        }
+    private void doRemoveAttributes(String path, String removedAttribute, 
final AtomicBoolean resolverRefreshed) {
+        this.refreshResolverIfNecessary(resolverRefreshed);
         this.initializing.lock();
         try {
             if (PROP_VANITY_PATH.equals(removedAttribute)){
                 doRemoveVanity(path);
             } else if 
(ResourceResolverImpl.PROP_ALIAS.equals(removedAttribute)) {
-                if (enableOptimizeAliasResolution) {
+                if (this.factory.isOptimizeAliasResolutionEnabled()) {
                     doRemoveAlias(path, true);
                     if ( path.endsWith("/jcr:content") ) {
                         // as doRemoveAlias removes all aliases we need to 
re-add
@@ -414,22 +352,17 @@ public class MapEntries implements Resou
                 }
             }
 
-            if (path.startsWith(this.mapRoot)) {
+            if (path.startsWith(this.factory.getMapRoot())) {
                 doUpdateConfiguration();
             }
             sendChangeEvent();
         } finally {
             this.initializing.unlock();
         }
-        return newRefreshed;
     }
 
-    private boolean doUpdateConfiguration(boolean refreshed){
-        boolean newRefreshed = refreshed;
-        if (!newRefreshed) {
-            resolver.refresh();
-            newRefreshed = true;
-        }
+    private void doUpdateConfiguration(final AtomicBoolean resolverRefreshed) {
+        this.refreshResolverIfNecessary(resolverRefreshed);
         this.initializing.lock();
         try {
             doUpdateConfiguration();
@@ -437,10 +370,13 @@ public class MapEntries implements Resou
         } finally {
             this.initializing.unlock();
         }
-        return newRefreshed;
     }
 
-    private void doUpdateConfiguration(){
+    /**
+     * Update the configuration.
+     * Does no locking and does not send an event at the end
+     */
+    private void doUpdateConfiguration() {
         final List<MapEntry> globalResolveMap = new ArrayList<MapEntry>();
         final SortedMap<String, MapEntry> newMapMaps = new TreeMap<String, 
MapEntry>();
         // load the /etc/map entries into the maps
@@ -459,7 +395,7 @@ public class MapEntries implements Resou
         log.debug("doAddVanity getting {}", path);
         Resource resource = resolver.getResource(path);
         boolean needsUpdate = false;
-        if (isAllVanityPathEntriesCached() || vanityCounter.longValue() < 
maxCachedVanityPathEntries) {
+        if (isAllVanityPathEntriesCached() || vanityCounter.longValue() < 
this.factory.getMaxCachedVanityPathEntries()) {
             // fill up the cache and the bloom filter
             needsUpdate = loadVanityPath(resource, resolveMapsMap, 
vanityTargets, true, true);
         } else {
@@ -606,10 +542,6 @@ public class MapEntries implements Resou
         return false;
     }
 
-    public boolean isOptimizeAliasResolutionEnabled() {
-        return this.enableOptimizeAliasResolution;
-    }
-
     /**
      * Cleans up this class.
      */
@@ -672,6 +604,7 @@ public class MapEntries implements Resou
     /**
      * This is for the web console plugin
      */
+    @Override
     public List<MapEntry> getResolveMaps() {
         final List<MapEntry> entries = new ArrayList<MapEntry>();
         for (final List<MapEntry> list : this.resolveMapsMap.values()) {
@@ -685,6 +618,7 @@ public class MapEntries implements Resou
      * Calculate the resolve maps. As the entries have to be sorted by pattern
      * length, we have to create a new list containing all relevant entries.
      */
+    @Override
     public Iterator<MapEntry> getResolveMapsIterator(final String requestPath) 
{
         String key = null;
         final int firstIndex = requestPath.indexOf('/');
@@ -693,13 +627,15 @@ public class MapEntries implements Resou
             key = requestPath.substring(secondIndex);
         }
 
-        return new MapEntryIterator(key, resolveMapsMap, vanityPathPrecedence);
+        return new MapEntryIterator(key, resolveMapsMap, 
this.factory.hasVanityPathPrecedence());
     }
 
+    @Override
     public Collection<MapEntry> getMapMaps() {
         return mapMaps;
     }
 
+    @Override
     public Map<String, String> getAliasMap(final String parentPath) {
         return aliasMap.get(parentPath);
     }
@@ -721,6 +657,23 @@ public class MapEntries implements Resou
         return mapEntries;
     }
 
+    private void refreshResolverIfNecessary(final AtomicBoolean 
resolverRefreshed) {
+        if ( resolverRefreshed.compareAndSet(false, true) ) {
+            this.resolver.refresh();
+        }
+    }
+
+    private boolean handleConfigurationUpdate(final String path, final 
AtomicBoolean resolverRefreshed) {
+        if ( this.factory.isMapConfiguration(path) ) {
+            refreshResolverIfNecessary(resolverRefreshed);
+
+            doUpdateConfiguration();
+
+            return true;
+        }
+        return false;
+    }
+
     // ---------- ResourceChangeListener interface
 
     /**
@@ -731,10 +684,10 @@ public class MapEntries implements Resou
      */
     @Override
     public void onChange(final List<ResourceChange> changes) {
-        boolean wasResolverRefreshed = false;
+        final AtomicBoolean resolverRefreshed = new AtomicBoolean(false);
+        boolean changed = false;
 
         for(final ResourceChange rc : changes) {
-            // check for path (used for some tests below
             final String path = rc.getPath();
             log.debug("onChange, type={}, path={}", rc.getType(), path);
 
@@ -745,41 +698,43 @@ public class MapEntries implements Resou
 
             // removal of a resource is handled differently
             if (rc.getType() == ResourceChange.ChangeType.REMOVED) {
-                final String actualContentPath = getActualContentPath(path);
-                final String actualContentPathPrefix = actualContentPath + "/";
 
-                for (final String target : this.vanityTargets.keySet()) {
-                    if (target.startsWith(actualContentPathPrefix) || 
target.equals(actualContentPath)) {
-                        wasResolverRefreshed = doRemoveAttributes(target, 
PROP_VANITY_PATH, wasResolverRefreshed);
+                if ( handleConfigurationUpdate(path, resolverRefreshed) ) {
+                    changed = true;
+                } else {
+
+                    final String actualContentPath = 
getActualContentPath(path);
+                    final String actualContentPathPrefix = actualContentPath + 
"/";
+
+                    for (final String target : this.vanityTargets.keySet()) {
+                        if (target.startsWith(actualContentPathPrefix) || 
target.equals(actualContentPath)) {
+                            doRemoveAttributes(target, PROP_VANITY_PATH, 
resolverRefreshed);
+                        }
                     }
-                }
-                for (final String target : this.aliasMap.keySet()) {
-                    if (path.startsWith(target + "/") || path.equals(target)) {
-                        wasResolverRefreshed = doRemoveAllAliases(target, 
wasResolverRefreshed, null);
-                    } else if ( target.startsWith(actualContentPathPrefix) ) {
-                        wasResolverRefreshed = doRemoveAllAliases(target, 
wasResolverRefreshed, path);
+                    for (final String target : this.aliasMap.keySet()) {
+                        if (path.startsWith(target + "/") || 
path.equals(target)) {
+                            changed |= doRemoveAllAliases(target, 
resolverRefreshed, null);
+                        } else if ( target.startsWith(actualContentPathPrefix) 
) {
+                            changed |= doRemoveAllAliases(target, 
resolverRefreshed, path);
+                        }
+                    }
+                    if (path.startsWith(this.factory.getMapRoot())) {
+                        //need to update the configuration
+                        doUpdateConfiguration(resolverRefreshed);
                     }
-                }
-                if (path.startsWith(this.mapRoot)) {
-                    //need to update the configuration
-                    wasResolverRefreshed = 
doUpdateConfiguration(wasResolverRefreshed);
                 }
             //session.move() is handled differently see also SLING-3713 and
             } else if (rc.getType() == ResourceChange.ChangeType.ADDED ) {
-                wasResolverRefreshed = doNodeAdded(path, wasResolverRefreshed);
+               doNodeAdded(path, resolverRefreshed);
             } else {
-                if (path.startsWith(this.mapRoot)) {
-                    wasResolverRefreshed = 
doUpdateConfiguration(wasResolverRefreshed);
+                if (handleConfigurationUpdate(path, resolverRefreshed)) {
+                    changed = true;
                 } else {
-                    if ( !wasResolverRefreshed ) {
-                        wasResolverRefreshed = true;
-                        this.resolver.refresh();
-                    }
-                    boolean changed = false;
+                    this.refreshResolverIfNecessary(resolverRefreshed);
                     this.initializing.lock();
                     try {
                         changed |= doUpdateVanity(path);
-                        if (enableOptimizeAliasResolution) {
+                        if (this.factory.isOptimizeAliasResolutionEnabled()) {
                             changed |= doRemoveAlias(path, false);
                             changed |= doAddAlias(path);
                             changed |= doUpdateAlias(path, false);
@@ -795,6 +750,9 @@ public class MapEntries implements Resou
 
             }
         }
+        if ( changed ) {
+            this.sendChangeEvent();
+        }
     }
 
     // ---------- internal
@@ -802,7 +760,7 @@ public class MapEntries implements Resou
     private byte[] createVanityBloomFilter() throws IOException {
         byte bloomFilter[] = null;
         if (vanityBloomFilter == null) {
-            bloomFilter = 
BloomFilterUtils.createFilter(VANITY_BLOOM_FILTER_MAX_ENTRIES, 
this.vanityBloomFilterMaxBytes);
+            bloomFilter = 
BloomFilterUtils.createFilter(VANITY_BLOOM_FILTER_MAX_ENTRIES, 
this.factory.getVanityBloomFilterMaxBytes());
         }
         return bloomFilter;
     }
@@ -819,7 +777,7 @@ public class MapEntries implements Resou
     }
 
     private boolean isAllVanityPathEntriesCached() {
-        return maxCachedVanityPathEntries == -1;
+        return this.factory.getMaxCachedVanityPathEntries() == -1;
     }
 
     /**
@@ -868,7 +826,7 @@ public class MapEntries implements Resou
             final Iterator<Resource> i = 
queryResolver.findResources(queryString, "sql");
             while (i.hasNext()) {
                 final Resource resource = i.next();
-                if (maxCachedVanityPathEntriesStartup || 
vanityCounter.longValue() < maxCachedVanityPathEntries) {
+                if (this.factory.isMaxCachedVanityPathEntriesStartup() || 
vanityCounter.longValue() < this.factory.getMaxCachedVanityPathEntries()) {
                     loadVanityPath(resource, resolveMapsMap, vanityTargets, 
true, false);
                     entryMap = resolveMapsMap;
                 } else {
@@ -887,7 +845,7 @@ public class MapEntries implements Resou
     }
 
     /**
-     * Check if the resoruce is a valid vanity path resource
+     * Check if the resource is a valid vanity path resource
      * @param resource The resource to check
      * @return {@code true} if this is valid, {@code false} otherwise
      */
@@ -903,9 +861,9 @@ public class MapEntries implements Resou
         }
 
         // check white list
-        if ( this.vanityPathConfig != null ) {
+        if ( this.factory.getVanityPathConfig() != null ) {
             boolean allowed = false;
-            for(final VanityPathConfig config : this.vanityPathConfig) {
+            for(final VanityPathConfig config : 
this.factory.getVanityPathConfig()) {
                 if ( resource.getPath().startsWith(config.prefix) ) {
                     allowed = !config.isExclude;
                     break;
@@ -950,16 +908,17 @@ public class MapEntries implements Resou
      * Send an OSGi event
      */
     private void sendChangeEvent() {
-        if (this.eventAdmin != null) {
+        final EventAdmin local = this.eventAdmin;
+        if (local != null) {
             final Event event = new 
Event(SlingConstants.TOPIC_RESOURCE_RESOLVER_MAPPING_CHANGED,
                             (Dictionary<String, ?>) null);
-            this.eventAdmin.postEvent(event);
+            local.postEvent(event);
         }
     }
 
     private void loadResolverMap(final ResourceResolver resolver, final 
List<MapEntry> entries, final Map<String, MapEntry> mapEntries) {
         // the standard map configuration
-        final Resource res = resolver.getResource(mapRoot);
+        final Resource res = resolver.getResource(this.factory.getMapRoot());
         if (res != null) {
             gather(resolver, entries, mapEntries, res, "");
         }
@@ -1153,9 +1112,9 @@ public class MapEntries implements Resou
         final String queryString = "SELECT sling:vanityPath, sling:redirect, 
sling:redirectStatus FROM sling:VanityPath WHERE sling:vanityPath IS NOT NULL";
         final Iterator<Resource> i = resolver.findResources(queryString, 
"sql");
 
-        while (i.hasNext() && (createVanityBloomFilter || 
isAllVanityPathEntriesCached() || vanityCounter.longValue() < 
maxCachedVanityPathEntries)) {
+        while (i.hasNext() && (createVanityBloomFilter || 
isAllVanityPathEntriesCached() || vanityCounter.longValue() < 
this.factory.getMaxCachedVanityPathEntries())) {
             final Resource resource = i.next();
-            if (isAllVanityPathEntriesCached() || vanityCounter.longValue() < 
maxCachedVanityPathEntries) {
+            if (isAllVanityPathEntriesCached() || vanityCounter.longValue() < 
this.factory.getMaxCachedVanityPathEntries()) {
                 // fill up the cache and the bloom filter
                 loadVanityPath(resource, resolveMapsMap, targetPaths, true,
                         createVanityBloomFilter);

Added: 
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesHandler.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesHandler.java?rev=1764881&view=auto
==============================================================================
--- 
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesHandler.java
 (added)
+++ 
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesHandler.java
 Fri Oct 14 12:08:22 2016
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.resourceresolver.impl.mapping;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Interface for MapEntries to only expose the public methods
+ * used during resource resolving
+ */
+public interface MapEntriesHandler {
+
+    public MapEntriesHandler EMPTY = new MapEntriesHandler() {
+
+        @Override
+        public Iterator<MapEntry> getResolveMapsIterator(String requestPath) {
+            return Collections.emptyIterator();
+        }
+
+        @Override
+        public List<MapEntry> getResolveMaps() {
+            return Collections.emptyList();
+        }
+
+        @Override
+        public Collection<MapEntry> getMapMaps() {
+            return Collections.emptyList();
+        }
+
+        @Override
+        public Map<String, String> getAliasMap(String parentPath) {
+            return Collections.emptyMap();
+        }
+    };
+
+    Map<String, String> getAliasMap(String parentPath);
+
+    /**
+     * Calculate the resolve maps. As the entries have to be sorted by pattern
+     * length, we have to create a new list containing all relevant entries.
+     */
+    Iterator<MapEntry> getResolveMapsIterator(String requestPath);
+
+    Collection<MapEntry> getMapMaps();
+
+    /**
+     * This is for the web console plugin
+     */
+    List<MapEntry> getResolveMaps();
+}

Propchange: 
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesHandler.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Modified: 
sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java?rev=1764881&r1=1764880&r2=1764881&view=diff
==============================================================================
--- 
sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java
 (original)
+++ 
sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java
 Fri Oct 14 12:08:22 2016
@@ -44,6 +44,7 @@ import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicLong;
 
 import org.apache.sling.api.resource.Resource;
@@ -111,22 +112,13 @@ public class MapEntriesTest {
         
when(resourceResolverFactory.getVanityPathConfig()).thenReturn(configs);
         
when(resourceResolverFactory.isOptimizeAliasResolutionEnabled()).thenReturn(true);
         when(resourceResolverFactory.getObservationPaths()).thenReturn(new 
String[] {"/"});
+        
when(resourceResolverFactory.getMapRoot()).thenReturn(MapEntries.DEFAULT_MAP_ROOT);
+        
when(resourceResolverFactory.getMaxCachedVanityPathEntries()).thenReturn(-1L);
+        
when(resourceResolverFactory.isMaxCachedVanityPathEntriesStartup()).thenReturn(true);
         when(resourceResolver.findResources(anyString(), 
eq("sql"))).thenReturn(
                 Collections.<Resource> emptySet().iterator());
 
         mapEntries = new MapEntries(resourceResolverFactory, bundleContext, 
eventAdmin);
-        Field field0 = MapEntries.class.getDeclaredField("mapRoot");
-        field0.setAccessible(true);
-        field0.set(mapEntries, MapEntries.DEFAULT_MAP_ROOT);
-
-        Field field1 = 
MapEntries.class.getDeclaredField("maxCachedVanityPathEntries");
-        field1.setAccessible(true);
-        field1.set(mapEntries, -1);
-
-        Field field2 = 
MapEntries.class.getDeclaredField("maxCachedVanityPathEntriesStartup");
-        field2.setAccessible(true);
-        field2.set(mapEntries, true);
-
     }
 
     @After
@@ -454,9 +446,7 @@ public class MapEntriesTest {
     @SuppressWarnings("unchecked")
     @Test
     public void test_doAddVanity_1() throws Exception {
-        Field field1 = 
MapEntries.class.getDeclaredField("maxCachedVanityPathEntries");
-        field1.setAccessible(true);
-        field1.set(mapEntries, 10);
+        
when(this.resourceResolverFactory.getMaxCachedVanityPathEntries()).thenReturn(10L);
 
         List<MapEntry> entries = mapEntries.getResolveMaps();
         assertEquals(0, entries.size());
@@ -811,14 +801,12 @@ public class MapEntriesTest {
     //SLING-3727
     @Test
     public void test_doRemoveAttributessWithDisableAliasOptimization() throws 
Exception {
-        Method method = 
MapEntries.class.getDeclaredMethod("doRemoveAttributes", String.class, 
String.class, boolean.class);
+        Method method = 
MapEntries.class.getDeclaredMethod("doRemoveAttributes", String.class, 
String.class, AtomicBoolean.class);
         method.setAccessible(true);
 
         
when(resourceResolverFactory.isOptimizeAliasResolutionEnabled()).thenReturn(false);
+        
when(this.resourceResolverFactory.getMapRoot()).thenReturn(MapEntries.DEFAULT_MAP_ROOT);
         mapEntries = new MapEntries(resourceResolverFactory, bundleContext, 
eventAdmin);
-        Field field0 = MapEntries.class.getDeclaredField("mapRoot");
-        field0.setAccessible(true);
-        field0.set(mapEntries, MapEntries.DEFAULT_MAP_ROOT);
 
         Resource parent = mock(Resource.class);
         when(parent.getPath()).thenReturn("/parent");
@@ -830,7 +818,7 @@ public class MapEntriesTest {
         when(result.getName()).thenReturn("child");
         when(result.getValueMap()).thenReturn(buildValueMap("sling:alias", 
"alias"));
 
-        method.invoke(mapEntries, "/parent/child", "sling:alias", false);
+        method.invoke(mapEntries, "/parent/child", "sling:alias", new 
AtomicBoolean());
 
         Map<String, String> aliasMap = mapEntries.getAliasMap("/parent");
         assertNull(aliasMap);
@@ -1109,7 +1097,7 @@ public class MapEntriesTest {
         Method method = MapEntries.class.getDeclaredMethod("doAddAlias", 
String.class);
         method.setAccessible(true);
 
-        Method method1 = 
MapEntries.class.getDeclaredMethod("doRemoveAttributes", String.class, 
String.class, boolean.class);
+        Method method1 = 
MapEntries.class.getDeclaredMethod("doRemoveAttributes", String.class, 
String.class, AtomicBoolean.class);
         method1.setAccessible(true);
 
         Field field0 = MapEntries.class.getDeclaredField("aliasMap");
@@ -1137,7 +1125,7 @@ public class MapEntriesTest {
 
         assertEquals(1, aliasMap.size());
 
-        method1.invoke(mapEntries, "/parent/child", "sling:alias", false);
+        method1.invoke(mapEntries, "/parent/child", "sling:alias", new 
AtomicBoolean());
 
         aliasMapEntry = mapEntries.getAliasMap("/parent");
         assertNull(aliasMapEntry);
@@ -1155,7 +1143,7 @@ public class MapEntriesTest {
         assertEquals(1, aliasMap.size());
 
         when(resourceResolver.getResource("/parent/child")).thenReturn(null);
-        method1.invoke(mapEntries, "/parent/child", "sling:alias", false);
+        method1.invoke(mapEntries, "/parent/child", "sling:alias", new 
AtomicBoolean());
 
         aliasMapEntry = mapEntries.getAliasMap("/parent");
         assertNull(aliasMapEntry);
@@ -1169,7 +1157,7 @@ public class MapEntriesTest {
         Method method = MapEntries.class.getDeclaredMethod("doAddAlias", 
String.class);
         method.setAccessible(true);
 
-        Method method1 = 
MapEntries.class.getDeclaredMethod("doRemoveAttributes", String.class, 
String.class, boolean.class);
+        Method method1 = 
MapEntries.class.getDeclaredMethod("doRemoveAttributes", String.class, 
String.class, AtomicBoolean.class);
         method1.setAccessible(true);
 
         Field field0 = MapEntries.class.getDeclaredField("aliasMap");
@@ -1206,7 +1194,7 @@ public class MapEntriesTest {
 
         assertEquals(1, aliasMap.size());
 
-        method1.invoke(mapEntries, "/parent/child/jcr:content", "sling:alias", 
false);
+        method1.invoke(mapEntries, "/parent/child/jcr:content", "sling:alias", 
new AtomicBoolean());
 
         aliasMapEntry = mapEntries.getAliasMap("/parent");
         assertNull(aliasMapEntry);
@@ -1224,7 +1212,7 @@ public class MapEntriesTest {
         assertEquals(1, aliasMap.size());
         
when(resourceResolver.getResource("/parent/child/jcr:content")).thenReturn(null);
         when(result.getChild("jcr:content")).thenReturn(null);
-        method1.invoke(mapEntries, "/parent/child/jcr:content", "sling:alias", 
false);
+        method1.invoke(mapEntries, "/parent/child/jcr:content", "sling:alias", 
new AtomicBoolean());
 
         aliasMapEntry = mapEntries.getAliasMap("/parent");
         assertNull(aliasMapEntry);
@@ -1238,7 +1226,7 @@ public class MapEntriesTest {
         final Method doAddAlias = 
MapEntries.class.getDeclaredMethod("doAddAlias", String.class);
         doAddAlias.setAccessible(true);
 
-        final Method doRemoveAttributes = 
MapEntries.class.getDeclaredMethod("doRemoveAttributes", String.class, 
String.class, boolean.class);
+        final Method doRemoveAttributes = 
MapEntries.class.getDeclaredMethod("doRemoveAttributes", String.class, 
String.class, AtomicBoolean.class);
         doRemoveAttributes.setAccessible(true);
 
         final Field aliasMapField = 
MapEntries.class.getDeclaredField("aliasMap");
@@ -1278,7 +1266,7 @@ public class MapEntriesTest {
         assertEquals("child", aliasMapEntry.get("alias"));
 
         // remove child jcr:content node
-        doRemoveAttributes.invoke(mapEntries, "/parent/child/jcr:content", 
"sling:alias", false);
+        doRemoveAttributes.invoke(mapEntries, "/parent/child/jcr:content", 
"sling:alias", new AtomicBoolean());
 
         // test with one node
         assertEquals(1, aliasMap.size());
@@ -1297,7 +1285,7 @@ public class MapEntriesTest {
         assertEquals("child", aliasMapEntry.get("aliasJcrContent"));
         assertEquals("child", aliasMapEntry.get("alias"));
 
-        doRemoveAttributes.invoke(mapEntries, "/parent/child", "sling:alias", 
false);
+        doRemoveAttributes.invoke(mapEntries, "/parent/child", "sling:alias", 
new AtomicBoolean());
         doAddAlias.invoke(mapEntries, "/parent/child/jcr:content");
 
         assertEquals(1, aliasMap.size());
@@ -1317,7 +1305,7 @@ public class MapEntriesTest {
 
         
when(resourceResolver.getResource("/parent/child/jcr:content")).thenReturn(null);
         when(childRsrc.getChild("jcr:content")).thenReturn(null);
-        doRemoveAttributes.invoke(mapEntries, "/parent/child/jcr:content", 
"sling:alias", false);
+        doRemoveAttributes.invoke(mapEntries, "/parent/child/jcr:content", 
"sling:alias", new AtomicBoolean());
 
         assertEquals(1, aliasMap.size());
         aliasMapEntry = mapEntries.getAliasMap("/parent");
@@ -1336,7 +1324,7 @@ public class MapEntriesTest {
         assertEquals("child", aliasMapEntry.get("aliasJcrContent"));
         assertEquals(2, aliasMapEntry.size());
 
-        doRemoveAttributes.invoke(mapEntries, "/parent/child", "sling:alias", 
false);
+        doRemoveAttributes.invoke(mapEntries, "/parent/child", "sling:alias", 
new AtomicBoolean());
 
         assertEquals(0, aliasMap.size());
         aliasMapEntry = mapEntries.getAliasMap("/parent");
@@ -1349,7 +1337,7 @@ public class MapEntriesTest {
         Method method = MapEntries.class.getDeclaredMethod("doAddAlias", 
String.class);
         method.setAccessible(true);
 
-        Method method1 = 
MapEntries.class.getDeclaredMethod("doRemoveAttributes", String.class, 
String.class, boolean.class);
+        Method method1 = 
MapEntries.class.getDeclaredMethod("doRemoveAttributes", String.class, 
String.class, AtomicBoolean.class);
         method1.setAccessible(true);
 
         Field field0 = MapEntries.class.getDeclaredField("aliasMap");
@@ -1377,7 +1365,7 @@ public class MapEntriesTest {
 
         assertEquals(1, aliasMap.size());
 
-        method1.invoke(mapEntries, "/parent", "sling:alias", false);
+        method1.invoke(mapEntries, "/parent", "sling:alias", new 
AtomicBoolean());
 
         aliasMapEntry = mapEntries.getAliasMap("/");
         assertNull(aliasMapEntry);
@@ -1395,7 +1383,7 @@ public class MapEntriesTest {
         assertEquals(1, aliasMap.size());
 
         when(resourceResolver.getResource("/parent")).thenReturn(null);
-        method1.invoke(mapEntries, "/parent", "sling:alias", false);
+        method1.invoke(mapEntries, "/parent", "sling:alias", new 
AtomicBoolean());
 
         aliasMapEntry = mapEntries.getAliasMap("/");
         assertNull(aliasMapEntry);
@@ -1409,7 +1397,7 @@ public class MapEntriesTest {
         Method method = MapEntries.class.getDeclaredMethod("doAddAlias", 
String.class);
         method.setAccessible(true);
 
-        Method method1 = 
MapEntries.class.getDeclaredMethod("doRemoveAttributes", String.class, 
String.class, boolean.class);
+        Method method1 = 
MapEntries.class.getDeclaredMethod("doRemoveAttributes", String.class, 
String.class, AtomicBoolean.class);
         method1.setAccessible(true);
 
         Field field0 = MapEntries.class.getDeclaredField("aliasMap");
@@ -1446,7 +1434,7 @@ public class MapEntriesTest {
 
         assertEquals(1, aliasMap.size());
 
-        method1.invoke(mapEntries, "/parent/jcr:content", "sling:alias", 
false);
+        method1.invoke(mapEntries, "/parent/jcr:content", "sling:alias", new 
AtomicBoolean());
 
         aliasMapEntry = mapEntries.getAliasMap("/");
         assertNull(aliasMapEntry);
@@ -1464,7 +1452,7 @@ public class MapEntriesTest {
         assertEquals(1, aliasMap.size());
         
when(resourceResolver.getResource("/parent/jcr:content")).thenReturn(null);
         when(result.getChild("jcr:content")).thenReturn(null);
-        method1.invoke(mapEntries, "/parent/jcr:content", "sling:alias", 
false);
+        method1.invoke(mapEntries, "/parent/jcr:content", "sling:alias", new 
AtomicBoolean());
 
         aliasMapEntry = mapEntries.getAliasMap("/");
         assertNull(aliasMapEntry);
@@ -1491,19 +1479,18 @@ public class MapEntriesTest {
     @Test
     //SLING-4847
     public void test_doNodeAdded1() throws Exception {
-        Method method = MapEntries.class.getDeclaredMethod("doNodeAdded", 
String.class, boolean.class);
+        Method method = MapEntries.class.getDeclaredMethod("doNodeAdded", 
String.class, AtomicBoolean.class);
         method.setAccessible(true);
-        Boolean resfreshed = (Boolean ) method.invoke(mapEntries, "/node", 
true);
-        assertTrue(resfreshed.booleanValue());
+        final AtomicBoolean refreshed = new AtomicBoolean(true);
+        method.invoke(mapEntries, "/node", refreshed);
+        assertTrue(refreshed.get());
     }
 
     @Test
     //SLING-4891
     public void test_getVanityPaths_1() throws Exception {
 
-        Field field1 = 
MapEntries.class.getDeclaredField("maxCachedVanityPathEntries");
-        field1.setAccessible(true);
-        field1.set(mapEntries, 0);
+        
when(this.resourceResolverFactory.getMaxCachedVanityPathEntries()).thenReturn(0L);
 
         Method method = MapEntries.class.getDeclaredMethod("getVanityPaths", 
String.class);
         method.setAccessible(true);
@@ -1538,9 +1525,7 @@ public class MapEntriesTest {
             }
         });
 
-        Field field1 = 
MapEntries.class.getDeclaredField("maxCachedVanityPathEntries");
-        field1.setAccessible(true);
-        field1.set(mapEntries, 0);
+        
when(this.resourceResolverFactory.getMaxCachedVanityPathEntries()).thenReturn(0L);
 
         Method method = MapEntries.class.getDeclaredMethod("getVanityPaths", 
String.class);
         method.setAccessible(true);
@@ -1598,13 +1583,8 @@ public class MapEntriesTest {
             }
         });
 
-        Field field1 = 
MapEntries.class.getDeclaredField("maxCachedVanityPathEntries");
-        field1.setAccessible(true);
-        field1.set(mapEntries, 0);
-
-        Field field2 = 
MapEntries.class.getDeclaredField("maxCachedVanityPathEntriesStartup");
-        field2.setAccessible(true);
-        field2.set(mapEntries, false);
+        
when(this.resourceResolverFactory.getMaxCachedVanityPathEntries()).thenReturn(0L);
+        
when(this.resourceResolverFactory.isMaxCachedVanityPathEntriesStartup()).thenReturn(false);
 
         Method method = MapEntries.class.getDeclaredMethod("getVanityPaths", 
String.class);
         method.setAccessible(true);
@@ -1638,13 +1618,8 @@ public class MapEntriesTest {
             }
         });
 
-        Field field1 = 
MapEntries.class.getDeclaredField("maxCachedVanityPathEntries");
-        field1.setAccessible(true);
-        field1.set(mapEntries, 0);
-
-        Field field2 = 
MapEntries.class.getDeclaredField("maxCachedVanityPathEntriesStartup");
-        field2.setAccessible(true);
-        field2.set(mapEntries, true);
+        
when(this.resourceResolverFactory.getMaxCachedVanityPathEntries()).thenReturn(0L);
+        
when(this.resourceResolverFactory.isMaxCachedVanityPathEntriesStartup()).thenReturn(true);
 
         Method method = MapEntries.class.getDeclaredMethod("getVanityPaths", 
String.class);
         method.setAccessible(true);
@@ -1678,13 +1653,8 @@ public class MapEntriesTest {
             }
         });
 
-        Field field1 = 
MapEntries.class.getDeclaredField("maxCachedVanityPathEntries");
-        field1.setAccessible(true);
-        field1.set(mapEntries, 2);
-
-        Field field2 = 
MapEntries.class.getDeclaredField("maxCachedVanityPathEntriesStartup");
-        field2.setAccessible(true);
-        field2.set(mapEntries, false);
+        
when(this.resourceResolverFactory.getMaxCachedVanityPathEntries()).thenReturn(2L);
+        
when(this.resourceResolverFactory.isMaxCachedVanityPathEntriesStartup()).thenReturn(false);
 
         Method method = MapEntries.class.getDeclaredMethod("getVanityPaths", 
String.class);
         method.setAccessible(true);
@@ -1722,9 +1692,7 @@ public class MapEntriesTest {
     @Test
     //SLING-4891
     public void test_loadVanityPaths() throws Exception {
-        Field field1 = 
MapEntries.class.getDeclaredField("maxCachedVanityPathEntries");
-        field1.setAccessible(true);
-        field1.set(mapEntries, 2);
+        
when(this.resourceResolverFactory.getMaxCachedVanityPathEntries()).thenReturn(2L);
 
         final Resource justVanityPath = mock(Resource.class, "justVanityPath");
         
when(resourceResolver.getResource("/justVanityPath")).thenReturn(justVanityPath);
@@ -1869,9 +1837,7 @@ public class MapEntriesTest {
         });
 
 
-        Field field1 = 
MapEntries.class.getDeclaredField("maxCachedVanityPathEntries");
-        field1.setAccessible(true);
-        field1.set(mapEntries, 2);
+        
when(this.resourceResolverFactory.getMaxCachedVanityPathEntries()).thenReturn(2L);
 
         ArrayList<DataFuture> list = new ArrayList<DataFuture>();
         for (int i =0;i<10;i++) {


Reply via email to