Author: cziegeler
Date: Wed Feb 10 09:21:58 2016
New Revision: 1729557

URL: http://svn.apache.org/viewvc?rev=1729557&view=rev
Log:
SLING-5506 : JcrResourceProvider must be stateless

Modified:
    
sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrModifiablePropertyMap.java
    
sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrResourceUtil.java
    
sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrModifiableValueMap.java
    
sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrValueMap.java
    
sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrProviderStateFactory.java
    
sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java

Modified: 
sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrModifiablePropertyMap.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrModifiablePropertyMap.java?rev=1729557&r1=1729556&r2=1729557&view=diff
==============================================================================
--- 
sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrModifiablePropertyMap.java
 (original)
+++ 
sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrModifiablePropertyMap.java
 Wed Feb 10 09:21:58 2016
@@ -38,6 +38,7 @@ import org.apache.sling.jcr.resource.int
  *
  * @deprecated Resources should be adapted to a modifiable value map instead
  */
+@SuppressWarnings("deprecation")
 @Deprecated
 public final class JcrModifiablePropertyMap
     extends JcrPropertyMap
@@ -142,6 +143,7 @@ public final class JcrModifiableProperty
     /**
      * @see org.apache.sling.api.resource.PersistableValueMap#reset()
      */
+    @Override
     public void reset() {
         if ( this.changedProperties != null ) {
             this.changedProperties = null;
@@ -154,6 +156,7 @@ public final class JcrModifiableProperty
     /**
      * @see org.apache.sling.api.resource.PersistableValueMap#save()
      */
+    @Override
     @SuppressWarnings("javadoc")
     public void save() throws PersistenceException {
         if ( this.changedProperties == null || this.changedProperties.size() 
== 0 ) {

Modified: 
sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrResourceUtil.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrResourceUtil.java?rev=1729557&r1=1729556&r2=1729557&view=diff
==============================================================================
--- 
sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrResourceUtil.java
 (original)
+++ 
sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrResourceUtil.java
 Wed Feb 10 09:21:58 2016
@@ -242,6 +242,7 @@ public class JcrResourceUtil {
      *         adapting to a string.
      * @deprecated Use {@link 
ResourceUtil#getResourceSuperType(ResourceResolver, String)}
      */
+    @SuppressWarnings("deprecation")
     @Deprecated
     public static String getResourceSuperType(
             ResourceResolver resourceResolver, String resourceType) {
@@ -266,6 +267,7 @@ public class JcrResourceUtil {
      *         described above does not yield a resource super type.
      * @deprecated Call {@link ResourceUtil#findResourceSuperType(Resource)}
      */
+    @SuppressWarnings("deprecation")
     @Deprecated
     public static String getResourceSuperType(Resource resource) {
         String resourceSuperType = resource.getResourceSuperType();

Modified: 
sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrModifiableValueMap.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrModifiableValueMap.java?rev=1729557&r1=1729556&r2=1729557&view=diff
==============================================================================
--- 
sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrModifiableValueMap.java
 (original)
+++ 
sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrModifiableValueMap.java
 Wed Feb 10 09:21:58 2016
@@ -74,13 +74,6 @@ public final class JcrModifiableValueMap
         this.helper = helper;
     }
 
-    /**
-     * Get the node.
-     */
-    private Node getNode() {
-        return node;
-    }
-
     // ---------- ValueMap
 
     private String checkKey(final String key) {
@@ -96,6 +89,7 @@ public final class JcrModifiableValueMap
     /**
      * @see org.apache.sling.api.resource.ValueMap#get(java.lang.String, 
java.lang.Class)
      */
+    @Override
     @SuppressWarnings("unchecked")
     public <T> T get(final String aKey, final Class<T> type) {
         final String key = checkKey(aKey);
@@ -113,6 +107,7 @@ public final class JcrModifiableValueMap
     /**
      * @see org.apache.sling.api.resource.ValueMap#get(java.lang.String, 
java.lang.Object)
      */
+    @Override
     @SuppressWarnings("unchecked")
     public <T> T get(final String aKey,final T defaultValue) {
         final String key = checkKey(aKey);
@@ -137,6 +132,7 @@ public final class JcrModifiableValueMap
     /**
      * @see java.util.Map#get(java.lang.Object)
      */
+    @Override
     public Object get(final Object aKey) {
         final String key = checkKey(aKey.toString());
         final JcrPropertyMapCacheEntry entry = this.read(key);
@@ -147,6 +143,7 @@ public final class JcrModifiableValueMap
     /**
      * @see java.util.Map#containsKey(java.lang.Object)
      */
+    @Override
     public boolean containsKey(final Object key) {
         return get(key) != null;
     }
@@ -154,6 +151,7 @@ public final class JcrModifiableValueMap
     /**
      * @see java.util.Map#containsValue(java.lang.Object)
      */
+    @Override
     public boolean containsValue(final Object value) {
         readFully();
         return valueCache.containsValue(value);
@@ -162,6 +160,7 @@ public final class JcrModifiableValueMap
     /**
      * @see java.util.Map#isEmpty()
      */
+    @Override
     public boolean isEmpty() {
         return size() == 0;
     }
@@ -169,6 +168,7 @@ public final class JcrModifiableValueMap
     /**
      * @see java.util.Map#size()
      */
+    @Override
     public int size() {
         readFully();
         return cache.size();
@@ -177,6 +177,7 @@ public final class JcrModifiableValueMap
     /**
      * @see java.util.Map#entrySet()
      */
+    @Override
     public Set<java.util.Map.Entry<String, Object>> entrySet() {
         readFully();
         final Map<String, Object> sourceMap;
@@ -191,6 +192,7 @@ public final class JcrModifiableValueMap
     /**
      * @see java.util.Map#keySet()
      */
+    @Override
     public Set<String> keySet() {
         readFully();
         return Collections.unmodifiableSet(cache.keySet());
@@ -199,6 +201,7 @@ public final class JcrModifiableValueMap
     /**
      * @see java.util.Map#values()
      */
+    @Override
     public Collection<Object> values() {
         readFully();
         final Map<String, Object> sourceMap;
@@ -419,6 +422,7 @@ public final class JcrModifiableValueMap
     /**
      * @see java.util.Map#clear()
      */
+    @Override
     public void clear() {
         throw new UnsupportedOperationException("clear");
     }
@@ -426,6 +430,7 @@ public final class JcrModifiableValueMap
     /**
      * @see java.util.Map#put(java.lang.Object, java.lang.Object)
      */
+    @Override
     public Object put(final String aKey, final Object value) {
         final String key = checkKey(aKey);
         if ( key.indexOf('/') != -1 ) {
@@ -460,6 +465,7 @@ public final class JcrModifiableValueMap
     /**
      * @see java.util.Map#putAll(java.util.Map)
      */
+    @Override
     public void putAll(final Map<? extends String, ? extends Object> t) {
         if ( t != null ) {
             final Iterator<?> i = t.entrySet().iterator();
@@ -474,6 +480,7 @@ public final class JcrModifiableValueMap
     /**
      * @see java.util.Map#remove(java.lang.Object)
      */
+    @Override
     public Object remove(final Object aKey) {
         final String key = checkKey(aKey.toString());
         readFully();

Modified: 
sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrValueMap.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrValueMap.java?rev=1729557&r1=1729556&r2=1729557&view=diff
==============================================================================
--- 
sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrValueMap.java
 (original)
+++ 
sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrValueMap.java
 Wed Feb 10 09:21:58 2016
@@ -23,6 +23,7 @@ import javax.jcr.RepositoryException;
 
 import org.apache.sling.jcr.resource.JcrPropertyMap;
 
+@SuppressWarnings("deprecation")
 public class JcrValueMap extends JcrPropertyMap {
 
     private final HelperData helper;

Modified: 
sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrProviderStateFactory.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrProviderStateFactory.java?rev=1729557&r1=1729556&r2=1729557&view=diff
==============================================================================
--- 
sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrProviderStateFactory.java
 (original)
+++ 
sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrProviderStateFactory.java
 Wed Feb 10 09:21:58 2016
@@ -32,6 +32,7 @@ import javax.jcr.SimpleCredentials;
 import org.apache.sling.api.resource.LoginException;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.api.resource.ResourceResolverFactory;
+import org.apache.sling.commons.classloader.DynamicClassLoaderManager;
 import org.apache.sling.jcr.api.SlingRepository;
 import org.apache.sling.jcr.resource.JcrResourceConstants;
 import org.apache.sling.jcr.resource.internal.HelperData;
@@ -44,20 +45,26 @@ import org.slf4j.LoggerFactory;
 
 public class JcrProviderStateFactory {
 
-    private static final Logger log = 
LoggerFactory.getLogger(JcrProviderStateFactory.class);
+    private final Logger logger = 
LoggerFactory.getLogger(JcrProviderStateFactory.class);
 
     private final ServiceReference repositoryReference;
 
     private final SlingRepository repository;
 
-    private final HelperData helperData;
+    private final DynamicClassLoaderManager dynamicClassLoaderManager;
 
-    public JcrProviderStateFactory(ServiceReference repositoryReference, 
SlingRepository repository, HelperData helperData) {
+    private final PathMapper pathMapper;
+
+    public JcrProviderStateFactory(final ServiceReference repositoryReference,
+            final SlingRepository repository,
+            final DynamicClassLoaderManager dynamicClassLoaderManager,
+            final PathMapper pathMapper) {
         this.repository = repository;
         this.repositoryReference = repositoryReference;
-        this.helperData = helperData;
+        this.dynamicClassLoaderManager = dynamicClassLoaderManager;
+        this.pathMapper = pathMapper;
     }
-    
+
     @SuppressWarnings("deprecation")
     JcrProviderState createProviderState(final @Nonnull Map<String, Object> 
authenticationInfo) throws LoginException {
         // by default any session used by the resource resolver returned is
@@ -87,7 +94,7 @@ public class JcrProviderStateFactory {
 
                         final SlingRepository repo = (SlingRepository) 
bc.getService(repositoryReference);
                         if (repo == null) {
-                            log.warn(
+                            logger.warn(
                                     "getResourceProviderInternal: Cannot login 
service because cannot get SlingRepository on behalf of bundle {} ({})",
                                     bc.getBundle().getSymbolicName(), 
bc.getBundle().getBundleId());
                             throw new LoginException(); // TODO: correct ??
@@ -158,10 +165,11 @@ public class JcrProviderStateFactory {
 
         session = handleImpersonation(session, authenticationInfo, 
logoutSession);
 
+        final HelperData data = new 
HelperData(this.dynamicClassLoaderManager.getDynamicClassLoader(), 
this.pathMapper);
         if (bc == null) {
-            return new JcrProviderState(session, helperData, logoutSession);
+            return new JcrProviderState(session, data, logoutSession);
         } else {
-            return new JcrProviderState(session, helperData, logoutSession, 
bc, repositoryReference);
+            return new JcrProviderState(session, data, logoutSession, bc, 
repositoryReference);
         }
     }
 
@@ -208,7 +216,7 @@ public class JcrProviderStateFactory {
      * exception is a {@link javax.jcr.LoginException} a {@link LoginException}
      * is created with the same information. Otherwise a {@link LoginException}
      * is created which wraps the repository exception.
-     * 
+     *
      * @param re
      *            The repository exception.
      * @return The login exception.
@@ -228,7 +236,7 @@ public class JcrProviderStateFactory {
      * <code>null</code> is returned. if a map is provided with a user name but
      * without a credentials object a new credentials object is created and all
      * values from the authentication info are added as attributes.
-     * 
+     *
      * @param authenticationInfo
      *            Optional authentication info
      * @return A credentials object or <code>null</code>
@@ -311,7 +319,7 @@ public class JcrProviderStateFactory {
     /**
      * Return the sudo user information. If the sudo user info is provided, it
      * is returned, otherwise <code>null</code> is returned.
-     * 
+     *
      * @param authenticationInfo
      *            Authentication info (not {@code null}).
      * @return The configured sudo user information or <code>null</code>
@@ -327,7 +335,7 @@ public class JcrProviderStateFactory {
     /**
      * Return the workspace name. If the workspace name is provided, it is
      * returned, otherwise <code>null</code> is returned.
-     * 
+     *
      * @param authenticationInfo
      *            Authentication info (not {@code null}).
      * @return The configured workspace name or <code>null</code>
@@ -344,7 +352,7 @@ public class JcrProviderStateFactory {
      * Returns the session provided as the user.jcr.session property of the
      * <code>authenticationInfo</code> map or <code>null</code> if the property
      * is not contained in the map or is not a <code>javax.jcr.Session</code>.
-     * 
+     *
      * @param authenticationInfo
      *            Authentication info (not {@code null}).
      * @return The user.jcr.session property or <code>null</code>

Modified: 
sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java?rev=1729557&r1=1729556&r2=1729557&view=diff
==============================================================================
--- 
sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java
 (original)
+++ 
sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java
 Wed Feb 10 09:21:58 2016
@@ -59,7 +59,6 @@ import org.apache.sling.commons.classloa
 import org.apache.sling.commons.osgi.PropertiesUtil;
 import org.apache.sling.jcr.api.SlingRepository;
 import org.apache.sling.jcr.resource.JcrResourceConstants;
-import org.apache.sling.jcr.resource.internal.HelperData;
 import org.apache.sling.jcr.resource.internal.JcrModifiableValueMap;
 import org.apache.sling.jcr.resource.internal.JcrResourceListener;
 import org.apache.sling.jcr.resource.internal.NodeUtil;
@@ -90,7 +89,7 @@ import org.slf4j.LoggerFactory;
 public class JcrResourceProvider extends ResourceProvider<JcrProviderState> {
 
     /** Logger */
-    private static final Logger log = 
LoggerFactory.getLogger(JcrResourceProvider.class);
+    private final Logger logger = 
LoggerFactory.getLogger(JcrResourceProvider.class);
 
     private static final String REPOSITORY_REFERNENCE_NAME = "repository";
 
@@ -152,7 +151,7 @@ public class JcrResourceProvider extends
             // concurrent unregistration of SlingRepository service
             // don't care, this component is going to be deactivated
             // so we just stop working
-            log.warn("activate: Activation failed because SlingRepository may 
have been unregistered concurrently");
+            logger.warn("activate: Activation failed because SlingRepository 
may have been unregistered concurrently");
             return;
         }
 
@@ -162,12 +161,13 @@ public class JcrResourceProvider extends
         this.root = 
PropertiesUtil.toString(context.getProperties().get(ResourceProvider.PROPERTY_ROOT),
 "/");
         this.bundleCtx = context.getBundleContext();
 
-        HelperData helperData = new 
HelperData(dynamicClassLoaderManager.getDynamicClassLoader(), pathMapper);
-        this.stateFactory = new JcrProviderStateFactory(repositoryReference, 
repository, helperData);
+        this.stateFactory = new JcrProviderStateFactory(repositoryReference, 
repository, dynamicClassLoaderManager, pathMapper);
     }
 
     @Deactivate
     protected void deactivate() {
+        this.bundleCtx = null;
+        this.stateFactory = null;
     }
 
     @Override
@@ -203,7 +203,7 @@ public class JcrResourceProvider extends
         }
     }
 
-    private void registerListener(ProviderContext ctx) {
+    private void registerListener(final ProviderContext ctx) {
         // check for Oak
         boolean isOak = false;
         if ( optimizeForOak ) {
@@ -212,7 +212,7 @@ public class JcrResourceProvider extends
                 if ( this.executor != null ) {
                     isOak = true;
                 } else {
-                   log.error("Detected Oak based repository but no executor 
service available! Unable to use improved JCR Resource listener");
+                    logger.error("Detected Oak based repository but no 
executor service available! Unable to use improved JCR Resource listener");
                 }
             }
         }
@@ -220,11 +220,11 @@ public class JcrResourceProvider extends
             if (isOak) {
                 try {
                     this.listener = new OakResourceListener(root, ctx, 
bundleCtx, executor, pathMapper, observationQueueLength, repository);
-                    log.info("Detected Oak based repository. Using improved 
JCR Resource Listener with observation queue length {}", 
observationQueueLength);
+                    logger.info("Detected Oak based repository. Using improved 
JCR Resource Listener with observation queue length {}", 
observationQueueLength);
                 } catch ( final RepositoryException re ) {
                     throw new SlingException("Can't create the 
OakResourceListener", re);
                 } catch ( final Throwable t ) {
-                    log.error("Unable to instantiate improved JCR Resource 
listener for Oak. Using fallback.", t);
+                    logger.error("Unable to instantiate improved JCR Resource 
listener for Oak. Using fallback.", t);
                 }
             }
             if (this.listener == null) {
@@ -324,7 +324,7 @@ public class JcrResourceProvider extends
                             ctx.getProviderState().getHelperData());
                 }
             } catch (RepositoryException e) {
-                log.warn("Can't get parent for {}", child, e);
+                logger.warn("Can't get parent for {}", child, e);
                 return null;
             }
         }
@@ -442,7 +442,7 @@ public class JcrResourceProvider extends
             if ( item == null ) {
                 final String jcrPath = 
pathMapper.mapResourcePathToJCRPath(resource.getPath());
                 if (jcrPath == null) {
-                    log.debug("delete: {} maps to an empty JCR path", 
resource.getPath());
+                    logger.debug("delete: {} maps to an empty JCR path", 
resource.getPath());
                     throw new PersistenceException("Unable to delete 
resource", null, resource.getPath(), null);
                 }
                 item = ctx.getProviderState().getSession().getItem(jcrPath);
@@ -458,7 +458,7 @@ public class JcrResourceProvider extends
         try {
             ctx.getProviderState().getSession().refresh(false);
         } catch (final RepositoryException ignore) {
-            log.warn("Unable to revert pending changes.", ignore);
+            logger.warn("Unable to revert pending changes.", ignore);
         }
     }
 
@@ -477,7 +477,7 @@ public class JcrResourceProvider extends
         try {
             return ctx.getProviderState().getSession().hasPendingChanges();
         } catch (final RepositoryException ignore) {
-            log.warn("Unable to check session for pending changes.", ignore);
+            logger.warn("Unable to check session for pending changes.", 
ignore);
         }
         return false;
     }
@@ -487,7 +487,7 @@ public class JcrResourceProvider extends
         try {
             ctx.getProviderState().getSession().refresh(true);
         } catch (final RepositoryException ignore) {
-            log.warn("Unable to refresh session.", ignore);
+            logger.warn("Unable to refresh session.", ignore);
         }
     }
 
@@ -510,9 +510,9 @@ public class JcrResourceProvider extends
                         }
                     }
                 }
-                log.debug("not able to adapto Resource to Principal, let the 
base class try to adapt");
+                logger.debug("not able to adapto Resource to Principal, let 
the base class try to adapt");
             } catch (RepositoryException e) {
-                log.warn("error while adapting Resource to Principal, let the 
base class try to adapt", e);
+                logger.warn("error while adapting Resource to Principal, let 
the base class try to adapt", e);
             }
         }
         return super.adaptTo(ctx, type);


Reply via email to