tapestry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r991653 - in /tapestry/tapestry5/trunk/tapestry-ioc/src: main/java/org/apache/tapestry5/ioc/internal/ main/java/org/apache/tapestry5/ioc/internal/util/ test/java/org/apache/tapestry5/ioc/internal/util/
Date Wed, 01 Sep 2010 18:57:43 GMT
Author: hlship
Date: Wed Sep  1 18:57:43 2010
New Revision: 991653

URL: http://svn.apache.org/viewvc?rev=991653&view=rev
Log:
Add a number of optimizations to live service reloading logic, to reduce the number of file
time modified checks

Modified:
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/AbstractReloadableObjectCreator.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/URLChangeTracker.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/URLChangeTrackerTest.java

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/AbstractReloadableObjectCreator.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/AbstractReloadableObjectCreator.java?rev=991653&r1=991652&r2=991653&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/AbstractReloadableObjectCreator.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/AbstractReloadableObjectCreator.java
Wed Sep  1 18:57:43 2010
@@ -177,18 +177,6 @@ public abstract class AbstractReloadable
         }
     }
 
-    private URL getURLForClass(String className) throws ClassNotFoundException
-    {
-        String path = ClassFabUtils.getPathForClassNamed(className);
-
-        URL result = baseClassLoader.getResource(path);
-
-        if (result == null)
-            throw new ClassNotFoundException(String.format("Unable to locate URL for class
%s.", className));
-
-        return result;
-    }
-
     private boolean shouldLoadClassNamed(String name)
     {
         return classesToLoad.contains(name);
@@ -260,9 +248,8 @@ public abstract class AbstractReloadable
 
         URL url = baseClassLoader.getResource(path);
 
-        // This does nothing unless the URL is non-null and file protocol
-
-        changeTracker.add(url);
+        if (url != null && url.getProtocol().equals("file"))
+            changeTracker.add(url);
     }
 
     private boolean isInnerClassName(String className)
@@ -270,14 +257,6 @@ public abstract class AbstractReloadable
         return className.indexOf('$') >= 0;
     }
 
-    /** Is the class an inner class of some other class already marked to be loaded by the
special class loader? */
-    private boolean isInnerClass(String className)
-    {
-        int dollarx = className.indexOf("$");
-
-        return dollarx < 0 ? false : classesToLoad.contains(className.substring(0, dollarx));
-    }
-
     /** Does nothing. */
     public void start(ClassPool pool) throws NotFoundException, CannotCompileException
     {

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/URLChangeTracker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/URLChangeTracker.java?rev=991653&r1=991652&r2=991653&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/URLChangeTracker.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/URLChangeTracker.java
Wed Sep  1 18:57:43 2010
@@ -38,23 +38,25 @@ public class URLChangeTracker
 
     private final boolean granularitySeconds;
 
+    private final boolean trackFolderChanges;
+
     private final ClasspathURLConverter classpathURLConverter;
 
-    private static final ClasspathURLConverter DEFAULT_CONVERTER = new ClasspathURLConverterImpl();
+    public static final ClasspathURLConverter DEFAULT_CONVERTER = new ClasspathURLConverterImpl();
 
     /**
      * Creates a tracker using the default (does nothing) URL converter, with default (millisecond)
-     * granularity.
+     * granularity and folder tracking disabled.
      * 
      * @since 5.2.1
      */
     public URLChangeTracker()
     {
-        this(DEFAULT_CONVERTER);
+        this(DEFAULT_CONVERTER, false, false);
     }
 
     /**
-     * Creates a new URL change tracker with millisecond-level granularity.
+     * Creates a new URL change tracker with millisecond-level granularity and folder checking
enabled.
      * 
      * @param classpathURLConverter
      *            used to convert URLs from one protocol to another
@@ -66,7 +68,8 @@ public class URLChangeTracker
     }
 
     /**
-     * Creates a new URL change tracker, using either millisecond-level granularity or second-level
granularity.
+     * Creates a new URL change tracker, using either millisecond-level granularity or second-level
granularity and
+     * folder checking enabled.
      * 
      * @param classpathURLConverter
      *            used to convert URLs from one protocol to another
@@ -75,9 +78,27 @@ public class URLChangeTracker
      */
     public URLChangeTracker(ClasspathURLConverter classpathURLConverter, boolean granularitySeconds)
     {
-        this.granularitySeconds = granularitySeconds;
+        this(classpathURLConverter, granularitySeconds, true);
+    }
 
+    /**
+     * Creates a new URL change tracker, using either millisecond-level granularity or second-level
granularity.
+     * 
+     * @param classpathURLConverter
+     *            used to convert URLs from one protocol to another
+     * @param granularitySeconds
+     *            whether or not to use second granularity (as opposed to millisecond granularity)
+     * @param trackFolderChanges
+     *            if true, then adding a file URL will also track the folder containing the
file (this
+     *            is useful when concerned about additions to a folder)
+     * @since 5.2.1
+     */
+    public URLChangeTracker(ClasspathURLConverter classpathURLConverter, boolean granularitySeconds,
+            boolean trackFolderChanges)
+    {
+        this.granularitySeconds = granularitySeconds;
         this.classpathURLConverter = classpathURLConverter;
+        this.trackFolderChanges = trackFolderChanges;
     }
 
     /**
@@ -111,12 +132,15 @@ public class URLChangeTracker
 
         fileToTimestamp.put(resourceFile, timestamp);
 
-        File dir = resourceFile.getParentFile();
-
-        if (!fileToTimestamp.containsKey(dir))
+        if (trackFolderChanges)
         {
-            long dirTimestamp = readTimestamp(dir);
-            fileToTimestamp.put(dir, dirTimestamp);
+            File dir = resourceFile.getParentFile();
+
+            if (!fileToTimestamp.containsKey(dir))
+            {
+                long dirTimestamp = readTimestamp(dir);
+                fileToTimestamp.put(dir, dirTimestamp);
+            }
         }
 
         return timestamp;

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/URLChangeTrackerTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/URLChangeTrackerTest.java?rev=991653&r1=991652&r2=991653&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/URLChangeTrackerTest.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/URLChangeTrackerTest.java
Wed Sep  1 18:57:43 2010
@@ -177,7 +177,7 @@ public class URLChangeTrackerTest extend
     @Test
     public void second_level_granularity() throws Exception
     {
-        URLChangeTracker t = new URLChangeTracker(converter, true);
+        URLChangeTracker t = new URLChangeTracker(converter, true, true);
 
         File f = File.createTempFile("changetracker0", ".tmp");
         URL url = f.toURL();



Mime
View raw message