incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1347913 - in /sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/impl: JavaScriptEngineFactory.java ServletCache.java ServletWrapper.java
Date Fri, 08 Jun 2012 07:45:49 GMT
Author: cziegeler
Date: Fri Jun  8 07:45:49 2012
New Revision: 1347913

URL: http://svn.apache.org/viewvc?rev=1347913&view=rev
Log:
SLING-2506 : Destroy wrapper as soon as java file changes

Modified:
    sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/impl/JavaScriptEngineFactory.java
    sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/impl/ServletCache.java
    sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/impl/ServletWrapper.java

Modified: sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/impl/JavaScriptEngineFactory.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/impl/JavaScriptEngineFactory.java?rev=1347913&r1=1347912&r2=1347913&view=diff
==============================================================================
--- sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/impl/JavaScriptEngineFactory.java
(original)
+++ sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/impl/JavaScriptEngineFactory.java
Fri Jun  8 07:45:49 2012
@@ -234,20 +234,13 @@ public class JavaScriptEngineFactory
             return wrapper;
         }
 
-        synchronized (this) {
-            wrapper = this.ioProvider.getServletCache().getWrapper(scriptName);
-            if (wrapper != null) {
-                return wrapper;
-            }
-
-            wrapper = new ServletWrapper(servletConfig,
-                                         ioProvider,
-                                         scriptName,
-                                         scriptHelper);
-            this.ioProvider.getServletCache().addWrapper(scriptName, wrapper);
+        wrapper = new ServletWrapper(servletConfig,
+                                     ioProvider,
+                                     scriptName,
+                                     scriptHelper);
+        wrapper = this.ioProvider.getServletCache().addWrapper(scriptName, wrapper);
 
-            return wrapper;
-        }
+        return wrapper;
     }
 
     /**
@@ -262,14 +255,7 @@ public class JavaScriptEngineFactory
     }
 
     private void handleModification(final String scriptName, final boolean remove) {
-        if ( remove ) {
-            this.ioProvider.getServletCache().removeWrapper(scriptName);
-        } else {
-            final ServletWrapper wrapper = this.ioProvider.getServletCache().getWrapper(scriptName);
-            if ( wrapper != null ) {
-                wrapper.handleModification();
-            }
-        }
+        this.ioProvider.getServletCache().removeWrapper(scriptName);
     }
 
     private static class JavaScriptEngine extends AbstractSlingScriptEngine {

Modified: sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/impl/ServletCache.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/impl/ServletCache.java?rev=1347913&r1=1347912&r2=1347913&view=diff
==============================================================================
--- sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/impl/ServletCache.java
(original)
+++ sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/impl/ServletCache.java
Fri Jun  8 07:45:49 2012
@@ -18,7 +18,6 @@
 package org.apache.sling.scripting.java.impl;
 
 import java.util.Iterator;
-import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
 /**
@@ -29,7 +28,7 @@ public final class ServletCache {
     /**
      * Maps servlet source urls to servlet wrappers.
      */
-    private Map<String, ServletWrapper> servlets = new ConcurrentHashMap<String,
ServletWrapper>();
+    private ConcurrentHashMap<String, ServletWrapper> servlets = new ConcurrentHashMap<String,
ServletWrapper>();
 
     /**
      * Add a new ServletWrapper.
@@ -37,8 +36,12 @@ public final class ServletCache {
      * @param servletUri Servlet URI
      * @param sw Servlet wrapper
      */
-    public void addWrapper(String servletUri, ServletWrapper sw) {
-        servlets.put(servletUri, sw);
+    public ServletWrapper addWrapper(final String servletUri, final ServletWrapper sw) {
+        ServletWrapper previous = servlets.putIfAbsent(servletUri, sw);
+        if ( previous != null ) {
+            return previous;
+        }
+        return sw;
     }
 
     /**
@@ -47,7 +50,7 @@ public final class ServletCache {
      * @param servletUri Servlet URI
      * @return ServletWrapper
      */
-    public ServletWrapper getWrapper(String servletUri) {
+    public ServletWrapper getWrapper(final String servletUri) {
         return servlets.get(servletUri);
     }
 
@@ -56,7 +59,7 @@ public final class ServletCache {
      *
      * @param servletUri Servlet URI
      */
-    public void removeWrapper(String servletUri) {
+    public void removeWrapper(final String servletUri) {
         final ServletWrapper wrapper = servlets.remove(servletUri);
         if ( wrapper != null ) {
             wrapper.destroy();

Modified: sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/impl/ServletWrapper.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/impl/ServletWrapper.java?rev=1347913&r1=1347912&r2=1347913&view=diff
==============================================================================
--- sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/impl/ServletWrapper.java
(original)
+++ sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/impl/ServletWrapper.java
Fri Jun  8 07:45:49 2012
@@ -64,9 +64,6 @@ public class ServletWrapper {
 
     private final SlingScriptHelper scriptHelper;
 
-    /** Flag for handling modifications. */
-    private volatile long lastModificationTest = 0L;
-
     /**
      * The compiled and instantiated servlet. This field may be null in which case a new
servlet
      * instance is created per request.
@@ -116,21 +113,6 @@ public class ServletWrapper {
                 available = 0;
             }
 
-            // check for compilation
-            if (this.lastModificationTest <= 0 ) {
-                synchronized (this) {
-                    if (this.lastModificationTest <= 0 ) {
-                        this.compile();
-                    } else if (compileException != null) {
-                        // Throw cached compilation exception
-                        throw compileException;
-                    }
-                }
-            } else if (compileException != null) {
-                // Throw cached compilation exception
-                throw compileException;
-            }
-
             final Servlet servlet = this.getServlet();
 
             // invoke the servlet
@@ -169,21 +151,13 @@ public class ServletWrapper {
     }
 
     /**
-     * Handle the modification.
-     */
-    public void handleModification() {
-        logger.debug("Received modification event for {}", this.sourcePath);
-        this.lastModificationTest = -1;
-    }
-
-    /**
      * Check if the used classloader is still valid
      */
     private boolean checkReload() {
         if ( theServlet != null && theServlet.getClass().getClassLoader() instanceof
DynamicClassLoader ) {
             return !((DynamicClassLoader)theServlet.getClass().getClassLoader()).isLive();
         }
-        return false;
+        return theServlet == null;
     }
 
     /**
@@ -192,6 +166,9 @@ public class ServletWrapper {
      */
     public Servlet getServlet()
     throws Exception {
+        if ( this.compileException != null ) {
+            throw this.compileException;
+        }
         // check if the used class loader is still alive
         if (this.checkReload()) {
             synchronized (this) {
@@ -265,7 +242,7 @@ public class ServletWrapper {
         // clear exception
         this.compileException = null;
         try {
-            final CompilerOptions opts = (this.lastModificationTest == -1 ? this.ioProvider.getForceCompileOptions()
: this.ioProvider.getOptions());
+            final CompilerOptions opts = this.ioProvider.getForceCompileOptions();
             final CompilationUnit unit = new CompilationUnit(this.sourcePath, className,
ioProvider);
             final CompilationResult result = this.ioProvider.getCompiler().compile(new org.apache.sling.commons.compiler.CompilationUnit[]
{unit},
                     opts);
@@ -287,8 +264,6 @@ public class ServletWrapper {
             // store exception for futher access attempts
             this.compileException = ex;
             throw ex;
-        } finally {
-            this.lastModificationTest = System.currentTimeMillis();
         }
     }
 



Mime
View raw message