You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2011/03/01 20:29:18 UTC

svn commit: r1075991 - in /tapestry/tapestry5/trunk/tapestry-core/src: main/java/org/apache/tapestry5/internal/services/ main/java/org/apache/tapestry5/internal/services/assets/ main/java/org/apache/tapestry5/services/ main/java/org/apache/tapestry5/se...

Author: hlship
Date: Tue Mar  1 19:29:17 2011
New Revision: 1075991

URL: http://svn.apache.org/viewvc?rev=1075991&view=rev
Log:
TAP5-73: Rename ResourceCache (an internal service) to ResourceDigestManager
Extend StreamableResource to track the lastModified time of the underlying resource

Added:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceDigestManager.java
      - copied, changed from r1075990, tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceCache.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceDigestManagerImpl.java
      - copied, changed from r1075990, tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceCacheImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ResourceDigestManagerTest.java
      - copied, changed from r1075990, tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ResourceCacheImplTest.java
Removed:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceCache.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceCacheImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ResourceCacheImplTest.java
Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AssetDispatcher.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AssetResourceLocatorImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ClasspathAssetFactory.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/InternalModule.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceStreamerImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/SRSCachingInterceptor.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/SRSCompressingInterceptor.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StackAssetRequestHandler.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StreamableResourceImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StreamableResourceSourceImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/AssetsModule.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/StreamableResource.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ClasspathAssetFactoryTest.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/test/InternalBaseTestCase.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AssetDispatcher.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AssetDispatcher.java?rev=1075991&r1=1075990&r2=1075991&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AssetDispatcher.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AssetDispatcher.java Tue Mar  1 19:29:17 2011
@@ -1,4 +1,4 @@
-// Copyright 2006, 2008, 2009, 2010 The Apache Software Foundation
+// Copyright 2006, 2008, 2009, 2010, 2011 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -34,7 +34,6 @@ import org.apache.tapestry5.services.ass
  * 
  * @see ResourceStreamer
  * @see ClasspathAssetAliasManager
- * @see ResourceCache
  * @see AssetRequestHandler
  */
 @UsesMappedConfiguration(AssetRequestHandler.class)

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AssetResourceLocatorImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AssetResourceLocatorImpl.java?rev=1075991&r1=1075990&r2=1075991&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AssetResourceLocatorImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AssetResourceLocatorImpl.java Tue Mar  1 19:29:17 2011
@@ -1,4 +1,4 @@
-// Copyright 2009, 2010 The Apache Software Foundation
+// Copyright 2009, 2010, 2011 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -24,15 +24,15 @@ import org.apache.tapestry5.services.Res
 
 public class AssetResourceLocatorImpl implements AssetResourceLocator
 {
-    private final ResourceCache resourceCache;
+    private final ResourceDigestManager digestManager;
 
     private final Response response;
 
     private final AssetSource assetSource;
 
-    public AssetResourceLocatorImpl(ResourceCache resourceCache, Response response, AssetSource assetSource)
+    public AssetResourceLocatorImpl(ResourceDigestManager digestManager, Response response, AssetSource assetSource)
     {
-        this.resourceCache = resourceCache;
+        this.digestManager = digestManager;
         this.response = response;
         this.assetSource = assetSource;
     }
@@ -41,14 +41,14 @@ public class AssetResourceLocatorImpl im
     {
         Resource resource = assetSource.resourceForPath(path);
 
-        if (!resourceCache.requiresDigest(resource))
+        if (!digestManager.requiresDigest(resource))
             return resource;
 
         return validateChecksumOfClasspathResource(resource);
     }
 
     /**
-     * Validates the checksome encoded into the resource, and returns the true resource (with the checksum
+     * Validates the checksum encoded into the resource, and returns the true resource (with the checksum
      * portion removed from the file name).
      */
     private Resource validateChecksumOfClasspathResource(Resource resource) throws IOException
@@ -77,7 +77,7 @@ public class AssetResourceLocatorImpl im
 
                 result = resource.forFile(realFile);
 
-                String actualDigest = resourceCache.getDigest(result);
+                String actualDigest = digestManager.getDigest(result);
 
                 valid = requestDigest.equals(actualDigest);
             }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ClasspathAssetFactory.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ClasspathAssetFactory.java?rev=1075991&r1=1075990&r2=1075991&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ClasspathAssetFactory.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ClasspathAssetFactory.java Tue Mar  1 19:29:17 2011
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008, 2009 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2009, 2011 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -27,13 +27,13 @@ import java.util.Map;
 
 /**
  * Generates Assets for files on the classpath. Caches generated client URLs internally, and clears that cache when
- * notified to do so by the {@link ResourceCache}.
+ * notified to do so by the {@link ResourceDigestManager}.
  *
  * @see AssetDispatcher
  */
 public class ClasspathAssetFactory implements AssetFactory, InvalidationListener
 {
-    private final ResourceCache cache;
+    private final ResourceDigestManager digestManager;
 
     private final ClasspathAssetAliasManager aliasManager;
 
@@ -45,10 +45,10 @@ public class ClasspathAssetFactory imple
 
     private final boolean invariant;
 
-    public ClasspathAssetFactory(ResourceCache cache, ClasspathAssetAliasManager aliasManager,
+    public ClasspathAssetFactory(ResourceDigestManager digestManager, ClasspathAssetAliasManager aliasManager,
                                  AssetPathConverter converter)
     {
-        this.cache = cache;
+        this.digestManager = digestManager;
         this.aliasManager = aliasManager;
         this.converter = converter;
 
@@ -78,7 +78,7 @@ public class ClasspathAssetFactory imple
 
     private String buildDefaultPath(Resource resource)
     {
-        boolean requiresDigest = cache.requiresDigest(resource);
+        boolean requiresDigest = digestManager.requiresDigest(resource);
 
         String path = resource.getPath();
 
@@ -88,7 +88,7 @@ public class ClasspathAssetFactory imple
 
             int lastdotx = path.lastIndexOf('.');
 
-            path = path.substring(0, lastdotx + 1) + cache.getDigest(resource) + path.substring(lastdotx);
+            path = path.substring(0, lastdotx + 1) + digestManager.getDigest(resource) + path.substring(lastdotx);
         }
 
         return aliasManager.toClientURL(path);

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/InternalModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/InternalModule.java?rev=1075991&r1=1075990&r2=1075991&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/InternalModule.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/InternalModule.java Tue Mar  1 19:29:17 2011
@@ -101,7 +101,7 @@ public class InternalModule
         binder.bind(AssetResourceLocator.class);
         binder.bind(JavaScriptStackPathConstructor.class);
         binder.bind(AjaxFormUpdateController.class);
-        binder.bind(ResourceCache.class, ResourceCacheImpl.class);
+        binder.bind(ResourceDigestManager.class, ResourceDigestManagerImpl.class);
     }
 
     /**

Copied: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceDigestManager.java (from r1075990, tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceCache.java)
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceDigestManager.java?p2=tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceDigestManager.java&p1=tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceCache.java&r1=1075990&r2=1075991&rev=1075991&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceCache.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceDigestManager.java Tue Mar  1 19:29:17 2011
@@ -22,8 +22,10 @@ import org.apache.tapestry5.services.Res
  * Caches information about resources on the classpath. In addition, acts as an invalidation hub for any resources for
  * which information is obtained (when any of the resources are changed, invalidation listeners are notified so they can
  * clear their caches).
+ * <p>
+ * Note that the name and role of this class changed (and diminished) quite a bit in Tapestry 5.3. It is now focused on
  */
-public interface ResourceCache extends InvalidationEventHub
+public interface ResourceDigestManager extends InvalidationEventHub
 {
     /**
      * Returns true if the path requires that the client URL for the resource include a digest to validate that the
@@ -42,12 +44,4 @@ public interface ResourceCache extends I
      * @return the digest, or null if the resource does not exist
      */
     String getDigest(Resource resource);
-
-    /**
-     * Returns the time modified for the resource.
-     * 
-     * @param resource
-     * @return the date time modified for the path, or a negative value if the resource does not exist
-     */
-    long getTimeModified(Resource resource);
 }

Copied: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceDigestManagerImpl.java (from r1075990, tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceCacheImpl.java)
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceDigestManagerImpl.java?p2=tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceDigestManagerImpl.java&p1=tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceCacheImpl.java&r1=1075990&r2=1075991&rev=1075991&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceCacheImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceDigestManagerImpl.java Tue Mar  1 19:29:17 2011
@@ -24,7 +24,7 @@ import org.apache.tapestry5.ioc.internal
 import org.apache.tapestry5.services.InvalidationListener;
 import org.apache.tapestry5.services.ResourceDigestGenerator;
 
-public class ResourceCacheImpl implements ResourceCache, InvalidationListener
+public class ResourceDigestManagerImpl implements ResourceDigestManager, InvalidationListener
 {
     private final ResourceDigestGenerator digestGenerator;
 
@@ -54,7 +54,8 @@ public class ResourceCacheImpl implement
         }
     }
 
-    public ResourceCacheImpl(ResourceDigestGenerator digestGenerator, ResourceChangeTracker resourceChangeTracker)
+    public ResourceDigestManagerImpl(ResourceDigestGenerator digestGenerator,
+            ResourceChangeTracker resourceChangeTracker)
     {
         this.digestGenerator = digestGenerator;
         this.resourceChangeTracker = resourceChangeTracker;

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceStreamerImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceStreamerImpl.java?rev=1075991&r1=1075990&r2=1075991&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceStreamerImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceStreamerImpl.java Tue Mar  1 19:29:17 2011
@@ -28,6 +28,7 @@ import org.apache.tapestry5.services.Req
 import org.apache.tapestry5.services.Response;
 import org.apache.tapestry5.services.ResponseCompressionAnalyzer;
 import org.apache.tapestry5.services.assets.CompressionStatus;
+import org.apache.tapestry5.services.assets.StreamableResource;
 import org.apache.tapestry5.services.assets.StreamableResourceFeature;
 import org.apache.tapestry5.services.assets.StreamableResourceSource;
 
@@ -35,8 +36,6 @@ public class ResourceStreamerImpl implem
 {
     static final String IF_MODIFIED_SINCE_HEADER = "If-Modified-Since";
 
-    private final ResourceCache resourceCache;
-
     private final Request request;
 
     private final Response response;
@@ -53,8 +52,6 @@ public class ResourceStreamerImpl implem
 
     StreamableResourceSource streamableResourceSource,
 
-    ResourceCache resourceCache,
-
     ResponseCompressionAnalyzer analyzer,
 
     @Symbol(SymbolConstants.PRODUCTION_MODE)
@@ -64,7 +61,6 @@ public class ResourceStreamerImpl implem
         this.response = response;
         this.streamableResourceSource = streamableResourceSource;
 
-        this.resourceCache = resourceCache;
         this.analyzer = analyzer;
         this.productionMode = productionMode;
     }
@@ -79,7 +75,12 @@ public class ResourceStreamerImpl implem
 
         long ifModifiedSince = 0;
 
-        long modified = resourceCache.getTimeModified(resource);
+        Set<StreamableResourceFeature> features = analyzer.isGZipSupported() ? StreamableResourceFeature.ALL
+                : StreamableResourceFeature.NO_COMPRESSION;
+
+        StreamableResource streamable = streamableResourceSource.getStreamableResource(resource, features);
+
+        long lastModified = streamable.getLastModified();
 
         try
         {
@@ -94,28 +95,17 @@ public class ResourceStreamerImpl implem
 
         if (ifModifiedSince > 0)
         {
-            if (ifModifiedSince >= modified)
+            if (ifModifiedSince >= lastModified)
             {
                 response.sendError(HttpServletResponse.SC_NOT_MODIFIED, "");
                 return;
             }
         }
 
-        Set<StreamableResourceFeature> features = analyzer.isGZipSupported() ? StreamableResourceFeature.ALL
-                : StreamableResourceFeature.NO_COMPRESSION;
-
-        org.apache.tapestry5.services.assets.StreamableResource streamable = streamableResourceSource
-                .getStreamableResource(resource, features);
-
         // Prevent the upstream code from compressing when we don't want to.
 
         response.disableCompression();
 
-        // TODO: This may be broken, as we want the lastModified with only 1 second precision, which is
-        // as much as can be expressed via the HTTP header.
-
-        long lastModified = modified;
-
         response.setDateHeader("Last-Modified", lastModified);
 
         if (productionMode)

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/SRSCachingInterceptor.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/SRSCachingInterceptor.java?rev=1075991&r1=1075990&r2=1075991&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/SRSCachingInterceptor.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/SRSCachingInterceptor.java Tue Mar  1 19:29:17 2011
@@ -43,13 +43,6 @@ public class SRSCachingInterceptor imple
         this.delegate = delegate;
     }
 
-    // See Brian's thread safety book for why it's better for this logic to be outside the constructor
-    @PostInjection
-    public void registerAsInvalidationListener()
-    {
-        tracker.addInvalidationListener(this);
-    }
-
     public StreamableResource getStreamableResource(Resource baseResource, Set<StreamableResourceFeature> features)
             throws IOException
     {

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/SRSCompressingInterceptor.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/SRSCompressingInterceptor.java?rev=1075991&r1=1075990&r2=1075991&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/SRSCompressingInterceptor.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/SRSCompressingInterceptor.java Tue Mar  1 19:29:17 2011
@@ -70,6 +70,7 @@ public class SRSCompressingInterceptor i
 
         BytestreamCache cache = new BytestreamCache(bos);
 
-        return new StreamableResourceImpl(uncompressed.getContentType(), CompressionStatus.COMPRESSED, cache);
+        return new StreamableResourceImpl(uncompressed.getContentType(), CompressionStatus.COMPRESSED,
+                uncompressed.getLastModified(), cache);
     }
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StackAssetRequestHandler.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StackAssetRequestHandler.java?rev=1075991&r1=1075990&r2=1075991&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StackAssetRequestHandler.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StackAssetRequestHandler.java Tue Mar  1 19:29:17 2011
@@ -1,4 +1,4 @@
-// Copyright 2010 The Apache Software Foundation
+// Copyright 2010, 2011 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -28,7 +28,6 @@ import java.util.zip.GZIPOutputStream;
 import org.apache.tapestry5.Asset;
 import org.apache.tapestry5.SymbolConstants;
 import org.apache.tapestry5.internal.InternalConstants;
-import org.apache.tapestry5.internal.services.ResourceCache;
 import org.apache.tapestry5.ioc.Resource;
 import org.apache.tapestry5.ioc.annotations.PostInjection;
 import org.apache.tapestry5.ioc.annotations.Symbol;
@@ -119,7 +118,7 @@ public class StackAssetRequestHandler im
         return true;
     }
 
-    /** Notified by the {@link ResourceCache} when resource files change; the internal caches are cleared. */
+    /** Notified by the {@link ResourceChangeTracker} when (any) resource files change; the internal caches are cleared. */
     public synchronized void objectWasInvalidated()
     {
         uncompressedCache.clear();

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StreamableResourceImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StreamableResourceImpl.java?rev=1075991&r1=1075990&r2=1075991&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StreamableResourceImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StreamableResourceImpl.java Tue Mar  1 19:29:17 2011
@@ -26,12 +26,16 @@ public class StreamableResourceImpl impl
 
     private final CompressionStatus compression;
 
+    private final long lastModified;
+
     private final BytestreamCache bytestreamCache;
 
-    public StreamableResourceImpl(String contentType, CompressionStatus compression, BytestreamCache bytestreamCache)
+    public StreamableResourceImpl(String contentType, CompressionStatus compression, long lastModified,
+            BytestreamCache bytestreamCache)
     {
         this.contentType = contentType;
         this.compression = compression;
+        this.lastModified = lastModified;
         this.bytestreamCache = bytestreamCache;
     }
 
@@ -50,6 +54,11 @@ public class StreamableResourceImpl impl
         return bytestreamCache.size();
     }
 
+    public long getLastModified()
+    {
+        return lastModified;
+    }
+
     public void streamTo(OutputStream os) throws IOException
     {
         bytestreamCache.writeTo(os);
@@ -58,6 +67,7 @@ public class StreamableResourceImpl impl
     @Override
     public String toString()
     {
-        return String.format("StreamableResource<%s %s size: %d>", contentType, compression.name(), getSize());
+        return String.format("StreamableResource<%s %s lastModified: %tc size: %d>", contentType, compression.name(),
+                lastModified, getSize());
     }
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StreamableResourceSourceImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StreamableResourceSourceImpl.java?rev=1075991&r1=1075990&r2=1075991&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StreamableResourceSourceImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StreamableResourceSourceImpl.java Tue Mar  1 19:29:17 2011
@@ -40,12 +40,16 @@ public class StreamableResourceSourceImp
 
     private final CompressionAnalyzer compressionAnalyzer;
 
+    private final ResourceChangeTracker resourceChangeTracker;
+
     public StreamableResourceSourceImpl(Map<String, ResourceTransformer> configuration,
-            ContentTypeAnalyzer contentTypeAnalyzer, CompressionAnalyzer compressionAnalyzer)
+            ContentTypeAnalyzer contentTypeAnalyzer, CompressionAnalyzer compressionAnalyzer,
+            ResourceChangeTracker resourceChangeTracker)
     {
         this.configuration = configuration;
         this.contentTypeAnalyzer = contentTypeAnalyzer;
         this.compressionAnalyzer = compressionAnalyzer;
+        this.resourceChangeTracker = resourceChangeTracker;
     }
 
     public StreamableResource getStreamableResource(Resource baseResource, Set<StreamableResourceFeature> features)
@@ -78,8 +82,10 @@ public class StreamableResourceSourceImp
 
         boolean compressable = compressionAnalyzer.isCompressable(contentType);
 
+        long lastModified = resourceChangeTracker.trackResource(baseResource);
+
         return new StreamableResourceImpl(contentType, compressable ? CompressionStatus.COMPRESSABLE
-                : CompressionStatus.NOT_COMPRESSABLE, bytestreamCache);
+                : CompressionStatus.NOT_COMPRESSABLE, lastModified, bytestreamCache);
     }
 
     private BytestreamCache readStream(InputStream stream) throws IOException

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java?rev=1075991&r1=1075990&r2=1075991&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java Tue Mar  1 19:29:17 2011
@@ -597,13 +597,9 @@ public final class TapestryModule
     @Autobuild
     StackAssetRequestHandler stackAssetRequestHandler,
 
-    ResourceCache resourceCache,
-
     ClasspathAssetAliasManager classpathAssetAliasManager, ResourceStreamer streamer,
             AssetResourceLocator assetResourceLocator)
     {
-        resourceCache.addInvalidationListener(stackAssetRequestHandler);
-
         Map<String, String> mappings = classpathAssetAliasManager.getMappings();
 
         for (String folder : mappings.keySet())
@@ -1347,12 +1343,12 @@ public final class TapestryModule
     }
 
     @Marker(ClasspathProvider.class)
-    public AssetFactory buildClasspathAssetFactory(ResourceCache resourceCache,
+    public AssetFactory buildClasspathAssetFactory(ResourceDigestManager resourceDigestManager,
             ClasspathAssetAliasManager aliasManager, AssetPathConverter converter)
     {
-        ClasspathAssetFactory factory = new ClasspathAssetFactory(resourceCache, aliasManager, converter);
+        ClasspathAssetFactory factory = new ClasspathAssetFactory(resourceDigestManager, aliasManager, converter);
 
-        resourceCache.addInvalidationListener(factory);
+        resourceDigestManager.addInvalidationListener(factory);
 
         return factory;
     }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/AssetsModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/AssetsModule.java?rev=1075991&r1=1075990&r2=1075991&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/AssetsModule.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/AssetsModule.java Tue Mar  1 19:29:17 2011
@@ -64,7 +64,15 @@ public class AssetsModule
             @Symbol(SymbolConstants.GZIP_COMPRESSION_ENABLED)
             boolean gzipEnabled, ResourceChangeTracker tracker)
     {
-        return gzipEnabled ? new SRSCompressedCachingInterceptor(tracker, delegate) : null;
+        if (!gzipEnabled)
+            return null;
+
+        SRSCompressedCachingInterceptor interceptor = new SRSCompressedCachingInterceptor(tracker,
+                delegate);
+
+        tracker.addInvalidationListener(interceptor);
+
+        return interceptor;
     }
 
     @Decorate(id = "Cache", serviceInterface = StreamableResourceSource.class)
@@ -72,7 +80,11 @@ public class AssetsModule
     public StreamableResourceSource enableUncompressedCaching(StreamableResourceSource delegate,
             ResourceChangeTracker tracker)
     {
-        return new SRSCachingInterceptor(tracker, delegate);
+        SRSCachingInterceptor interceptor = new SRSCachingInterceptor(tracker, delegate);
+
+        tracker.addInvalidationListener(interceptor);
+
+        return interceptor;
     }
 
     /**

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/StreamableResource.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/StreamableResource.java?rev=1075991&r1=1075990&r2=1075991&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/StreamableResource.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/StreamableResource.java Tue Mar  1 19:29:17 2011
@@ -43,4 +43,10 @@ public interface StreamableResource
      * the output stream.
      */
     void streamTo(OutputStream os) throws IOException;
+
+    /**
+     * Returns the time the resource was last modified, with accuracy to one second (so as to match
+     * the HTTP request/response date headers.
+     */
+    long getLastModified();
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ClasspathAssetFactoryTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ClasspathAssetFactoryTest.java?rev=1075991&r1=1075990&r2=1075991&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ClasspathAssetFactoryTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ClasspathAssetFactoryTest.java Tue Mar  1 19:29:17 2011
@@ -1,10 +1,10 @@
-// Copyright 2006, 2007, 2008, 2009 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2009, 2011 The Apache Software Foundation
 //
 // Licensed 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
+// 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,
@@ -29,13 +29,13 @@ public class ClasspathAssetFactoryTest e
     @Test
     public void asset_client_URL_is_cached()
     {
-        ResourceCache cache = mockResourceCache();
+        ResourceDigestManager digestManager = mockResourceResourceDigestManager();
 
         Resource r = new ClasspathResource("foo/Bar.txt");
 
         ClasspathAssetAliasManager aliasManager = mockClasspathAssetAliasManager();
 
-        train_requiresDigest(cache, r, false);
+        train_requiresDigest(digestManager, r, false);
 
         String expectedClientURL = "/context/asset/foo/Bar.txt";
 
@@ -43,8 +43,7 @@ public class ClasspathAssetFactoryTest e
 
         replay();
 
-        ClasspathAssetFactory factory = new ClasspathAssetFactory(cache, aliasManager,
-                                                                  converter);
+        ClasspathAssetFactory factory = new ClasspathAssetFactory(digestManager, aliasManager, converter);
 
         Asset asset = factory.createAsset(r);
 
@@ -57,7 +56,7 @@ public class ClasspathAssetFactoryTest e
         verify();
 
         // Now, to test cache clearing:
-        train_requiresDigest(cache, r, false);
+        train_requiresDigest(digestManager, r, false);
 
         train_toClientURL(aliasManager, "foo/Bar.txt", expectedClientURL);
 
@@ -73,12 +72,12 @@ public class ClasspathAssetFactoryTest e
     @Test
     public void simple_asset_client_URL()
     {
-        ResourceCache cache = mockResourceCache();
+        ResourceDigestManager digestManager = mockResourceResourceDigestManager();
         ClasspathAssetAliasManager aliasManager = mockClasspathAssetAliasManager();
 
         Resource r = new ClasspathResource("foo/Bar.txt");
 
-        train_requiresDigest(cache, r, false);
+        train_requiresDigest(digestManager, r, false);
 
         String expectedClientURL = "/context/asset/foo/Bar.txt";
 
@@ -86,7 +85,7 @@ public class ClasspathAssetFactoryTest e
 
         replay();
 
-        AssetFactory factory = new ClasspathAssetFactory(cache, aliasManager, new IdentityAssetPathConverter());
+        AssetFactory factory = new ClasspathAssetFactory(digestManager, aliasManager, new IdentityAssetPathConverter());
 
         Asset asset = factory.createAsset(r);
 
@@ -100,14 +99,14 @@ public class ClasspathAssetFactoryTest e
     @Test
     public void protected_asset_client_URL()
     {
-        ResourceCache cache = mockResourceCache();
+        ResourceDigestManager digestManager = mockResourceResourceDigestManager();
         ClasspathAssetAliasManager aliasManager = mockClasspathAssetAliasManager();
 
         Resource r = new ClasspathResource("foo/Bar.txt");
 
-        train_requiresDigest(cache, r, true);
+        train_requiresDigest(digestManager, r, true);
 
-        expect(cache.getDigest(r)).andReturn("ABC123");
+        expect(digestManager.getDigest(r)).andReturn("ABC123");
 
         String expectedClientURL = "/context/asset/foo/Bar.ABC123.txt";
 
@@ -115,7 +114,7 @@ public class ClasspathAssetFactoryTest e
 
         replay();
 
-        AssetFactory factory = new ClasspathAssetFactory(cache, aliasManager, new IdentityAssetPathConverter());
+        AssetFactory factory = new ClasspathAssetFactory(digestManager, aliasManager, new IdentityAssetPathConverter());
 
         Asset asset = factory.createAsset(r);
 

Copied: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ResourceDigestManagerTest.java (from r1075990, tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ResourceCacheImplTest.java)
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ResourceDigestManagerTest.java?p2=tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ResourceDigestManagerTest.java&p1=tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ResourceCacheImplTest.java&r1=1075990&r2=1075991&rev=1075991&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ResourceCacheImplTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ResourceDigestManagerTest.java Tue Mar  1 19:29:17 2011
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2011 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -28,7 +28,7 @@ import org.testng.annotations.AfterClass
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
-public class ResourceCacheImplTest extends InternalBaseTestCase
+public class ResourceDigestManagerTest extends InternalBaseTestCase
 {
     private static final String PATH = "foo/Bar.gif";
 
@@ -67,7 +67,7 @@ public class ResourceCacheImplTest exten
 
         replay();
 
-        ResourceCacheImpl cache = new ResourceCacheImpl(generator, resourceChangeTracker);
+        ResourceDigestManagerImpl cache = new ResourceDigestManagerImpl(generator, resourceChangeTracker);
 
         assertEquals(cache.requiresDigest(r), false);
         assertEquals(cache.getTimeModified(r), lastUpdated);
@@ -90,10 +90,10 @@ public class ResourceCacheImplTest exten
 
         replay();
 
-        ResourceCacheImpl cache = new ResourceCacheImpl(generator, null);
+        ResourceDigestManagerImpl cache = new ResourceDigestManagerImpl(generator, null);
 
         assertEquals(cache.requiresDigest(r), true);
-        assertEquals(cache.getTimeModified(r), ResourceCacheImpl.MISSING_RESOURCE_TIME_MODIFIED);
+        assertEquals(cache.getTimeModified(r), ResourceDigestManagerImpl.MISSING_RESOURCE_TIME_MODIFIED);
         assertEquals(cache.getDigest(r), null);
 
         verify();
@@ -119,7 +119,7 @@ public class ResourceCacheImplTest exten
 
         replay();
 
-        ResourceCacheImpl cache = new ResourceCacheImpl(generator, resourceChangeTracker);
+        ResourceDigestManagerImpl cache = new ResourceDigestManagerImpl(generator, resourceChangeTracker);
 
         assertEquals(cache.requiresDigest(r), true);
         assertEquals(cache.getTimeModified(r), lastUpdated);
@@ -149,7 +149,7 @@ public class ResourceCacheImplTest exten
 
         replay();
 
-        ResourceCacheImpl cache = new ResourceCacheImpl(generator, resourceChangeTracker);
+        ResourceDigestManagerImpl cache = new ResourceDigestManagerImpl(generator, resourceChangeTracker);
         cache.listenForInvalidations();
         cache.addInvalidationListener(listener);
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/test/InternalBaseTestCase.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/test/InternalBaseTestCase.java?rev=1075991&r1=1075990&r2=1075991&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/test/InternalBaseTestCase.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/test/InternalBaseTestCase.java Tue Mar  1 19:29:17 2011
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008, 2009, 2010 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2009, 2010, 2011 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -351,14 +351,14 @@ public class InternalBaseTestCase extend
         expect(page.getRootComponent()).andReturn(component).atLeastOnce();
     }
 
-    protected final ResourceCache mockResourceCache()
+    protected final ResourceDigestManager mockResourceResourceDigestManager()
     {
-        return newMock(ResourceCache.class);
+        return newMock(ResourceDigestManager.class);
     }
 
-    protected final void train_requiresDigest(ResourceCache cache, Resource resource, boolean requiresChecksum)
+    protected final void train_requiresDigest(ResourceDigestManager manager, Resource resource, boolean requiresChecksum)
     {
-        expect(cache.requiresDigest(resource)).andReturn(requiresChecksum);
+        expect(manager.requiresDigest(resource)).andReturn(requiresChecksum);
     }
 
     protected final InvalidationListener mockInvalidationListener()
@@ -366,11 +366,6 @@ public class InternalBaseTestCase extend
         return newMock(InvalidationListener.class);
     }
 
-    protected final void train_getTimeModified(ResourceCache cache, Resource resource, long timeModified)
-    {
-        expect(cache.getTimeModified(resource)).andReturn(timeModified).atLeastOnce();
-    }
-
     protected final ResourceStreamer mockResourceStreamer()
     {
         return newMock(ResourceStreamer.class);