sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r938445 - in /sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl: ./ helper/ parameters/ request/
Date Tue, 27 Apr 2010 13:11:51 GMT
Author: cziegeler
Date: Tue Apr 27 13:11:50 2010
New Revision: 938445

URL: http://svn.apache.org/viewvc?rev=938445&view=rev
Log:
Code clean up and avoid calling deprecated stuff - no functional changes.

Modified:
    sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/ProfilingResourceResolver.java
    sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
    sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/helper/SlingFilterConfig.java
    sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/parameters/ParameterMap.java
    sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/parameters/SlingUnsupportedEncodingException.java
    sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/request/RequestData.java

Modified: sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/ProfilingResourceResolver.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/ProfilingResourceResolver.java?rev=938445&r1=938444&r2=938445&view=diff
==============================================================================
--- sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/ProfilingResourceResolver.java
(original)
+++ sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/ProfilingResourceResolver.java
Tue Apr 27 13:11:50 2010
@@ -18,6 +18,7 @@
  */
 package org.apache.sling.engine.impl;
 
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
 
@@ -25,44 +26,66 @@ import javax.servlet.http.HttpServletReq
 
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.apache.sling.api.resource.ResourceWrapper;
 
 public class ProfilingResourceResolver implements ResourceResolver {
 
     private final ResourceResolver delegatee;
 
-    private final Logger logger = LoggerFactory.getLogger(this.getClass());
+//    private final Logger logger = LoggerFactory.getLogger(this.getClass());
 
-    int getResource;
+//    int getResource;
+
+//    int adaptToCount;
+
+//    int adaptToCountCacheHit;
+
+    private final Map<String, Object> adaptToCache = new HashMap<String, Object>();
 
     public ProfilingResourceResolver(final ResourceResolver delegatee) {
         this.delegatee = delegatee;
     }
 
     public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
-        return delegatee.adaptTo(type);
+        final String key = type.getName();
+//        adaptToCount++;
+        Object obj = adaptToCache.get(key);
+        if ( obj == null ) {
+//            logger.info("Adapting to {}", type);
+            obj = delegatee.adaptTo(type);
+            adaptToCache.put(key, obj);
+//        } else {
+//            adaptToCountCacheHit++;
+        }
+        return (AdapterType) obj;
     }
 
     public void close() {
-        logger.info("* #getResource({})", getResource);
+//        logger.info("* #getResource({})", getResource);
+//        logger.info("* #adaptTo({})", adaptToCount);
+//        logger.info("* #adaptToCacheHit({})", adaptToCountCacheHit);
         delegatee.close();
     }
 
     public Iterator<Resource> findResources(String query, String language) {
-        return delegatee.findResources(query, language);
+        return new IteratorDecorator(delegatee.findResources(query, language), this);
     }
 
     public Resource getResource(Resource base, String path) {
-        getResource++;
-        logger.info("* getResource({}, {})", base.getPath(), path);
-        return delegatee.getResource(base, path);
+//        getResource++;
+//        logger.info("* getResource({}, {})", base.getPath(), path);
+        final Resource rsrc = delegatee.getResource(base, path);
+        return rsrc == null ? null : new InternalResource(rsrc, this);
     }
 
     public Resource getResource(String path) {
-        getResource++;
-        logger.info("* getResource({})", path);
-        return delegatee.getResource(path);
+//        getResource++;
+//        if ( path.startsWith("/apps") ) {
+//            logger.info("Who is calling this: " + path, new Exception());
+//        }
+//        logger.info("* getResource({})", path);
+        final Resource rsrc = delegatee.getResource(path);
+        return rsrc == null ? null : new InternalResource(rsrc, this);
     }
 
     public String[] getSearchPath() {
@@ -70,8 +93,8 @@ public class ProfilingResourceResolver i
     }
 
     public Iterator<Resource> listChildren(Resource parent) {
-        logger.info("* listChildren({})", parent.getPath());
-        return delegatee.listChildren(parent);
+//        logger.info("* listChildren({})", parent.getPath());
+        return  new IteratorDecorator(delegatee.listChildren(parent), this);
     }
 
     public String map(HttpServletRequest request, String resourcePath) {
@@ -88,15 +111,75 @@ public class ProfilingResourceResolver i
     }
 
     public Resource resolve(HttpServletRequest request, String absPath) {
-        return delegatee.resolve(request, absPath);
+        final Resource rsrc = delegatee.resolve(request, absPath);
+        return rsrc == null ? null : new InternalResource(rsrc, this);
     }
 
     public Resource resolve(HttpServletRequest request) {
-        return delegatee.resolve(request);
+        final Resource rsrc = delegatee.resolve(request);
+        return rsrc == null ? null : new InternalResource(rsrc, this);
     }
 
     public Resource resolve(String path) {
-        logger.info("* resolve({})", path);
-        return delegatee.resolve(path);
+//        logger.info("* resolve({})", path);
+        final Resource rsrc = delegatee.resolve(path);
+        return rsrc == null ? null : new InternalResource(rsrc, this);
+    }
+
+    public static final class InternalResource extends ResourceWrapper {
+
+        private final ResourceResolver resolver;
+
+        private final Map<String, Object> adaptToCache = new HashMap<String, Object>();
+
+        public InternalResource(Resource resource, final ResourceResolver resolver) {
+            super(resource);
+            this.resolver = resolver;
+        }
+
+        @Override
+        public ResourceResolver getResourceResolver() {
+            return this.resolver;
+        }
+
+        @SuppressWarnings("unchecked")
+        @Override
+        public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
+            final String key = type.getName();
+            Object obj = adaptToCache.get(key);
+            if ( obj == null ) {
+                obj = super.adaptTo(type);
+                if ( obj != null ) {
+                    adaptToCache.put(key, obj);
+                }
+            }
+            return (AdapterType) obj;
+        }
+
+    }
+
+    public static final class IteratorDecorator implements Iterator<Resource> {
+
+        private final Iterator<Resource> delegatee;
+        private final ResourceResolver resolver;
+
+        public IteratorDecorator(final Iterator<Resource> delegatee, final ResourceResolver
resolver) {
+            this.delegatee = delegatee;
+            this.resolver = resolver;
+        }
+
+        public boolean hasNext() {
+            return this.delegatee.hasNext();
+        }
+
+        public Resource next() {
+            final Resource rsrc = delegatee.next();
+            return rsrc == null ? null : new InternalResource(rsrc, resolver);
+        }
+
+        public void remove() {
+            delegatee.remove();
+        }
+
     }
 }

Modified: sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java?rev=938445&r1=938444&r2=938445&view=diff
==============================================================================
--- sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
(original)
+++ sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
Tue Apr 27 13:11:50 2010
@@ -51,6 +51,7 @@ import org.apache.sling.api.SlingHttpSer
 import org.apache.sling.api.adapter.AdapterManager;
 import org.apache.sling.api.request.RequestPathInfo;
 import org.apache.sling.api.request.RequestProgressTracker;
+import org.apache.sling.api.request.ResponseUtil;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceNotFoundException;
 import org.apache.sling.api.resource.ResourceResolver;
@@ -58,7 +59,6 @@ import org.apache.sling.api.servlets.Ser
 import org.apache.sling.commons.auth.AuthenticationSupport;
 import org.apache.sling.commons.mime.MimeTypeService;
 import org.apache.sling.commons.osgi.OsgiUtil;
-import org.apache.sling.engine.ResponseUtil;
 import org.apache.sling.engine.impl.filter.RequestSlingFilterChain;
 import org.apache.sling.engine.impl.filter.SlingComponentFilterChain;
 import org.apache.sling.engine.impl.filter.SlingFilterChainHelper;
@@ -68,7 +68,6 @@ import org.apache.sling.engine.impl.log.
 import org.apache.sling.engine.impl.parameters.ParameterSupport;
 import org.apache.sling.engine.impl.request.ContentData;
 import org.apache.sling.engine.impl.request.RequestData;
-import org.apache.sling.engine.servlets.AbstractServiceReferenceConfig;
 import org.apache.sling.engine.servlets.ErrorHandler;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
@@ -699,7 +698,7 @@ public class SlingMainServlet extends Ge
         }
 
         // require a name for the filter
-        String filterName = AbstractServiceReferenceConfig.getName(ref);
+        final String filterName = SlingFilterConfig.getName(ref);
         if (filterName == null) {
             log.error("initFilter: Missing name for filter {}", ref);
             return;
@@ -707,7 +706,7 @@ public class SlingMainServlet extends Ge
 
         // initialize the filter first
         try {
-            FilterConfig config = new SlingFilterConfig(slingServletContext,
+            final FilterConfig config = new SlingFilterConfig(slingServletContext,
                 ref, filterName);
             filter.init(config);
 

Modified: sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/helper/SlingFilterConfig.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/helper/SlingFilterConfig.java?rev=938445&r1=938444&r2=938445&view=diff
==============================================================================
--- sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/helper/SlingFilterConfig.java
(original)
+++ sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/helper/SlingFilterConfig.java
Tue Apr 27 13:11:50 2010
@@ -18,21 +18,97 @@
  */
 package org.apache.sling.engine.impl.helper;
 
+import static org.osgi.framework.Constants.SERVICE_ID;
+import static org.osgi.framework.Constants.SERVICE_PID;
+import static org.osgi.service.component.ComponentConstants.COMPONENT_NAME;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.List;
+
 import javax.servlet.FilterConfig;
 import javax.servlet.ServletContext;
 
-import org.apache.sling.engine.servlets.AbstractServiceReferenceConfig;
 import org.osgi.framework.ServiceReference;
 
-public class SlingFilterConfig extends AbstractServiceReferenceConfig implements
-        FilterConfig {
+public class SlingFilterConfig implements FilterConfig {
+
+    /** The list of property names checked by {@link #getName(ServiceReference)} */
+    private static final String[] NAME_PROPERTIES = { "sling.core.servletName",
+        COMPONENT_NAME, SERVICE_PID, SERVICE_ID };
+
+    /** The <code>ServletContext</code> of this configuration object */
+    private ServletContext servletContext;
+
+    /** The <code>ServiceReference</code> providing the properties */
+    private ServiceReference reference;
+
+    /** The name of this configuration object */
+    private String name;
+
+
+    /**
+     * Sets up this base configuration object.
+     *
+     * @param servletContext The <code>ServletContext</code> attached to this
+     *            configuration.
+     * @param reference The service reference providing the initialization
+     *            parameter values.
+     * @param filterName The name of this configuration.
+     */
+    public SlingFilterConfig(final ServletContext servletContext,
+                             final ServiceReference reference,
+                             final String filterName) {
+        this.servletContext = servletContext;
+        this.reference = reference;
+        this.name = filterName;
+    }
+
+    /**
+     * @see javax.servlet.FilterConfig#getInitParameter(java.lang.String)
+     */
+    public String getInitParameter(String name) {
+        Object prop = reference.getProperty(name);
+        return (prop == null) ? null : String.valueOf(prop);
+    }
+
+    /**
+     * @see javax.servlet.FilterConfig#getInitParameterNames()
+     */
+    public Enumeration<?> getInitParameterNames() {
+        List<?> keys = Arrays.asList(reference.getPropertyKeys());
+        return Collections.enumeration(keys);
+    }
+
+    /**
+     * @see javax.servlet.FilterConfig#getServletContext()
+     */
+    public ServletContext getServletContext() {
+        return servletContext;
+    }
 
-    public SlingFilterConfig(ServletContext servletContext,
-            ServiceReference reference, String filterName) {
-        super(servletContext, reference, filterName);
+    /**
+     * Looks for a name value in the service reference properties. See the
+     * class comment at the top for the list of properties checked by this
+     * method.
+     */
+    public static String getName(ServiceReference reference) {
+        String servletName = null;
+        for (int i = 0; i < NAME_PROPERTIES.length
+            && (servletName == null || servletName.length() == 0); i++) {
+            Object prop = reference.getProperty(NAME_PROPERTIES[i]);
+            if (prop != null) {
+                servletName = String.valueOf(prop);
+            }
+        }
+        return servletName;
     }
 
+    /**
+     * @see javax.servlet.FilterConfig#getFilterName()
+     */
     public String getFilterName() {
-        return getName();
+        return name;
     }
 }
\ No newline at end of file

Modified: sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/parameters/ParameterMap.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/parameters/ParameterMap.java?rev=938445&r1=938444&r2=938445&view=diff
==============================================================================
--- sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/parameters/ParameterMap.java
(original)
+++ sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/parameters/ParameterMap.java
Tue Apr 27 13:11:50 2010
@@ -31,6 +31,8 @@ import org.apache.sling.api.request.Requ
 class ParameterMap extends LinkedHashMap<String, RequestParameter[]> implements
         RequestParameterMap {
 
+    private static final long serialVersionUID = -3984737679401682171L;
+
     private Map<String, String[]> stringParameterMap;
 
     ParameterMap() {

Modified: sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/parameters/SlingUnsupportedEncodingException.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/parameters/SlingUnsupportedEncodingException.java?rev=938445&r1=938444&r2=938445&view=diff
==============================================================================
--- sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/parameters/SlingUnsupportedEncodingException.java
(original)
+++ sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/parameters/SlingUnsupportedEncodingException.java
Tue Apr 27 13:11:50 2010
@@ -24,8 +24,10 @@ import org.apache.sling.api.SlingIOExcep
 
 public class SlingUnsupportedEncodingException extends SlingIOException {
 
+    private static final long serialVersionUID = -4482276105859280247L;
+
     SlingUnsupportedEncodingException(UnsupportedEncodingException uee) {
         super(uee);
     }
-    
+
 }

Modified: sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/request/RequestData.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/request/RequestData.java?rev=938445&r1=938444&r2=938445&view=diff
==============================================================================
--- sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/request/RequestData.java
(original)
+++ sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/request/RequestData.java
Tue Apr 27 13:11:50 2010
@@ -44,13 +44,13 @@ import org.apache.sling.api.adapter.Adap
 import org.apache.sling.api.request.RecursionTooDeepException;
 import org.apache.sling.api.request.RequestPathInfo;
 import org.apache.sling.api.request.RequestProgressTracker;
+import org.apache.sling.api.request.RequestUtil;
 import org.apache.sling.api.request.TooManyCallsException;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.api.servlets.ServletResolver;
 import org.apache.sling.api.wrappers.SlingHttpServletRequestWrapper;
 import org.apache.sling.api.wrappers.SlingHttpServletResponseWrapper;
-import org.apache.sling.engine.RequestUtil;
 import org.apache.sling.engine.impl.SlingHttpServletRequestImpl;
 import org.apache.sling.engine.impl.SlingHttpServletResponseImpl;
 import org.apache.sling.engine.impl.SlingMainServlet;



Mime
View raw message