incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r931813 - in /sling/trunk/bundles: api/src/main/java/org/apache/sling/api/scripting/ engine/src/main/java/org/apache/sling/engine/impl/ scripting/core/src/main/java/org/apache/sling/scripting/core/ scripting/core/src/main/java/org/apache/sl...
Date Thu, 08 Apr 2010 07:32:04 GMT
Author: cziegeler
Date: Thu Apr  8 07:32:03 2010
New Revision: 931813

URL: http://svn.apache.org/viewvc?rev=931813&view=rev
Log:
SLING-1477 : Deprecate SlingScriptHelper.dispose and correct invocation

Added:
    sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/ProfilingResourceResolver.java
  (with props)
Modified:
    sling/trunk/bundles/api/src/main/java/org/apache/sling/api/scripting/SlingScriptHelper.java
    sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/ScriptHelper.java
    sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/DefaultSlingScript.java

Modified: sling/trunk/bundles/api/src/main/java/org/apache/sling/api/scripting/SlingScriptHelper.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/scripting/SlingScriptHelper.java?rev=931813&r1=931812&r2=931813&view=diff
==============================================================================
--- sling/trunk/bundles/api/src/main/java/org/apache/sling/api/scripting/SlingScriptHelper.java
(original)
+++ sling/trunk/bundles/api/src/main/java/org/apache/sling/api/scripting/SlingScriptHelper.java
Thu Apr  8 07:32:03 2010
@@ -203,6 +203,9 @@ public interface SlingScriptHelper {
     /**
      * Dispose the helper. This method can be used to clean up the script helper
      * after the script is run.
+     * @deprecated This method is deprecated since version 2.1 and will be removed.
+     *             It should never be called by clients.
      */
+    @Deprecated
     void dispose();
 }

Added: 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=931813&view=auto
==============================================================================
--- sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/ProfilingResourceResolver.java
(added)
+++ sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/ProfilingResourceResolver.java
Thu Apr  8 07:32:03 2010
@@ -0,0 +1,102 @@
+/*
+ * 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.engine.impl;
+
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ProfilingResourceResolver implements ResourceResolver {
+
+    private final ResourceResolver delegatee;
+
+    private final Logger logger = LoggerFactory.getLogger(this.getClass());
+
+    int getResource;
+
+    public ProfilingResourceResolver(final ResourceResolver delegatee) {
+        this.delegatee = delegatee;
+    }
+
+    public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
+        return delegatee.adaptTo(type);
+    }
+
+    public void close() {
+        logger.info("* #getResource({})", getResource);
+        delegatee.close();
+    }
+
+    public Iterator<Resource> findResources(String query, String language) {
+        return delegatee.findResources(query, language);
+    }
+
+    public Resource getResource(Resource base, String path) {
+        getResource++;
+        logger.info("* getResource({}, {})", base.getPath(), path);
+        return delegatee.getResource(base, path);
+    }
+
+    public Resource getResource(String path) {
+        getResource++;
+        logger.info("* getResource({})", path);
+        return delegatee.getResource(path);
+    }
+
+    public String[] getSearchPath() {
+        return delegatee.getSearchPath();
+    }
+
+    public Iterator<Resource> listChildren(Resource parent) {
+        logger.info("* listChildren({})", parent.getPath());
+        return delegatee.listChildren(parent);
+    }
+
+    public String map(HttpServletRequest request, String resourcePath) {
+        return delegatee.map(request, resourcePath);
+    }
+
+    public String map(String resourcePath) {
+        return delegatee.map(resourcePath);
+    }
+
+    public Iterator<Map<String, Object>> queryResources(String query,
+            String language) {
+        return delegatee.queryResources(query, language);
+    }
+
+    public Resource resolve(HttpServletRequest request, String absPath) {
+        return delegatee.resolve(request, absPath);
+    }
+
+    public Resource resolve(HttpServletRequest request) {
+        return delegatee.resolve(request);
+    }
+
+    public Resource resolve(String path) {
+        logger.info("* resolve({})", path);
+        return delegatee.resolve(path);
+    }
+}

Propchange: sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/ProfilingResourceResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Propchange: sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/ProfilingResourceResolver.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/ScriptHelper.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/ScriptHelper.java?rev=931813&r1=931812&r2=931813&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/ScriptHelper.java
(original)
+++ sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/ScriptHelper.java
Thu Apr  8 07:32:03 2010
@@ -41,6 +41,7 @@ import org.apache.sling.scripting.core.i
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
+import org.slf4j.LoggerFactory;
 
 /**
  * Simple script helper providing access to the (wrapped) response, the
@@ -208,9 +209,9 @@ public class ScriptHelper implements Sli
     }
 
     /**
-     * @see org.apache.sling.api.scripting.SlingScriptHelper#dispose()
+     * Clean up this instance.
      */
-    public void dispose() {
+    public void cleanup() {
         final Iterator<ServiceReference> i = this.references.iterator();
         while (i.hasNext()) {
             final ServiceReference ref = i.next();
@@ -219,4 +220,11 @@ public class ScriptHelper implements Sli
         this.references.clear();
         this.services.clear();
     }
+
+    /**
+     * @see org.apache.sling.api.scripting.SlingScriptHelper#dispose()
+     */
+    public void dispose() {
+        LoggerFactory.getLogger(this.getClass()).error("ScriptHelper#dispose has been called.
This method is deprecated and should never be called by clients!");
+    }
 }

Modified: sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/DefaultSlingScript.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/DefaultSlingScript.java?rev=931813&r1=931812&r2=931813&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/DefaultSlingScript.java
(original)
+++ sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/DefaultSlingScript.java
Thu Apr  8 07:32:03 2010
@@ -164,6 +164,7 @@ class DefaultSlingScript implements Slin
     public Object call(SlingBindings props, String method, Object... args) {
         Bindings bindings = null;
         Reader reader = null;
+        boolean disposeScriptHelper = !props.containsKey(SLING);
         try {
             bindings = verifySlingBindings(props);
 
@@ -248,13 +249,7 @@ class DefaultSlingScript implements Slin
                 cause);
 
         } finally {
-            // dispose of the SlingScriptHelper
-            if ( bindings != null ) {
-                final SlingScriptHelper helper = (SlingScriptHelper) bindings.get(SLING);
-                if ( helper != null ) {
-                    helper.dispose();
-                }
-            }
+            requestResourceResolver.remove();
 
             // close the script reader (SLING-380)
             if (reader != null) {
@@ -264,7 +259,15 @@ class DefaultSlingScript implements Slin
                     // don't care
                 }
             }
-            requestResourceResolver.remove();
+
+            // dispose of the SlingScriptHelper
+            if ( bindings != null && disposeScriptHelper ) {
+                final ScriptHelper helper = (ScriptHelper) bindings.get(SLING);
+                if ( helper != null ) {
+                    helper.cleanup();
+                }
+            }
+
         }
     }
 



Mime
View raw message