Author: markt
Date: Mon Dec  9 23:34:25 2013
New Revision: 1549706

URL: http://svn.apache.org/r1549706
Log:
Use an int for the maximum object size to be cached in bytes since it is cached 
using a byte array and that is limited to Integer.MAX_VALUE.
Test objects to be cached against the maximum object size, not the maximum 
cache size.

Modified:
    tomcat/trunk/java/org/apache/catalina/WebResourceRoot.java
    tomcat/trunk/java/org/apache/catalina/webresources/Cache.java
    tomcat/trunk/java/org/apache/catalina/webresources/LocalStrings.properties
    tomcat/trunk/java/org/apache/catalina/webresources/StandardRoot.java
    
tomcat/trunk/test/org/apache/catalina/webresources/TesterWebResourceRoot.java

Modified: tomcat/trunk/java/org/apache/catalina/WebResourceRoot.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/WebResourceRoot.java?rev=1549706&r1=1549705&r2=1549706&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/WebResourceRoot.java (original)
+++ tomcat/trunk/java/org/apache/catalina/WebResourceRoot.java Mon Dec  9 
23:34:25 2013
@@ -346,19 +346,21 @@ public interface WebResourceRoot extends
     long getCacheMaxSize();
 
     /**
-     * Set the maximum permitted size for a single object in the cache.
+     * Set the maximum permitted size for a single object in the cache. Note
+     * that the maximum size in bytes may not exceed {@link Integer#MAX_VALUE}.
      *
      * @param cacheMaxObjectSize    Maximum size for a single cached object in
      *                              kilobytes
      */
-    void setCacheMaxObjectSize(long cacheMaxObjectSize);
+    void setCacheMaxObjectSize(int cacheMaxObjectSize);
 
     /**
-     * Get the maximum permitted size for a single object in the cache.
+     * Get the maximum permitted size for a single object in the cache. Note
+     * that the maximum size in bytes may not exceed {@link Integer#MAX_VALUE}.
      *
      * @return  Maximum size for a single cached object in kilobytes
      */
-    long getCacheMaxObjectSize();
+    int getCacheMaxObjectSize();
 
     /**
      * Controls whether the trace locked files feature is enabled. If enabled,

Modified: tomcat/trunk/java/org/apache/catalina/webresources/Cache.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/webresources/Cache.java?rev=1549706&r1=1549705&r2=1549706&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/webresources/Cache.java (original)
+++ tomcat/trunk/java/org/apache/catalina/webresources/Cache.java Mon Dec  9 
23:34:25 2013
@@ -46,7 +46,8 @@ public class Cache {
 
     private long ttl = 5000;
     private long maxSize = 10 * 1024 * 1024;
-    private long maxObjectSize = maxSize / 20;
+    private int maxObjectSize =
+            (int) (maxSize / 20 > Integer.MAX_VALUE ? Integer.MAX_VALUE : 
maxSize / 20);
 
     private final ConcurrentMap<String,CachedResource> resourceCache =
             new ConcurrentHashMap<>();
@@ -78,7 +79,7 @@ public class Cache {
                 // newCacheEntry was inserted into the cache - validate it
                 cacheEntry = newCacheEntry;
                 cacheEntry.validate(useClassLoaderResources);
-                if (cacheEntry.getContentLength() > getMaxSizeBytes()) {
+                if (cacheEntry.getContentLength() > getMaxObjectSizeBytes()) {
                     // Cache size has not been updated at this point
                     removeCacheEntry(path, false);
                     // Return the original resource not the one wrapped in the
@@ -199,27 +200,32 @@ public class Cache {
         return maxSize / 1024;
     }
 
-    public long getMaxSizeBytes() {
-        // Internally bytes, externally kilobytes
-        return maxSize;
-    }
-
     public void setMaxSize(long maxSize) {
         // Internally bytes, externally kilobytes
         this.maxSize = maxSize * 1024;
     }
 
 
-    public void setMaxObjectSize(long maxObjectSize) {
+    public void setMaxObjectSize(int maxObjectSize) {
+        if (maxObjectSize * 1024L > Integer.MAX_VALUE) {
+            log.warn(sm.getString("cache.maxObjectSizeTooBig",
+                    Integer.valueOf(maxObjectSize)));
+            this.maxObjectSize = Integer.MAX_VALUE;
+        }
         // Internally bytes, externally kilobytes
         this.maxObjectSize = maxObjectSize * 1024;
     }
 
-    public long getMaxObjectSize() {
+    public int getMaxObjectSize() {
         // Internally bytes, externally kilobytes
         return maxObjectSize / 1024;
     }
 
+    public long getMaxObjectSizeBytes() {
+        // Internally bytes, externally kilobytes
+        return maxObjectSize;
+    }
+
     public void clear() {
         resourceCache.clear();
     }

Modified: 
tomcat/trunk/java/org/apache/catalina/webresources/LocalStrings.properties
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/webresources/LocalStrings.properties?rev=1549706&r1=1549705&r2=1549706&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/webresources/LocalStrings.properties 
(original)
+++ tomcat/trunk/java/org/apache/catalina/webresources/LocalStrings.properties 
Mon Dec  9 23:34:25 2013
@@ -18,6 +18,7 @@ abstractResource.getContentTooLarge=Unab
 
 cache.addFail=Unable to add the resource at [{0}] to the cache because there 
was insufficient free space available after evicting expired cache entries - 
consider increasing the maximum size of the cache
 cache.backgroundEvictFail=The background cache eviction process was unable to 
free [{0}] percent of the cache for Context [{1}] - consider increasing the 
maximum size of the cache. After eviction approximately [{2}] KB of data 
remained in the cache.
+cache.maxObjectSizeTooBig=The value specified for the maximum object size to 
cache [{0}]kB is greater than Integer.MAX_VALUE bytes which is the maximum size 
that can be cached. The limit will be set to Integer.MAX_VALUE bytes.
 
 dirResourceSet.writeExists=The target of the write already exists
 dirResourceSet.writeNpe=The input stream may not be null

Modified: tomcat/trunk/java/org/apache/catalina/webresources/StandardRoot.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/webresources/StandardRoot.java?rev=1549706&r1=1549705&r2=1549706&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/webresources/StandardRoot.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/webresources/StandardRoot.java Mon 
Dec  9 23:34:25 2013
@@ -455,12 +455,12 @@ public class StandardRoot extends Lifecy
     }
 
     @Override
-    public void setCacheMaxObjectSize(long cacheMaxObjectSize) {
+    public void setCacheMaxObjectSize(int cacheMaxObjectSize) {
         cache.setMaxObjectSize(cacheMaxObjectSize);
     }
 
     @Override
-    public long getCacheMaxObjectSize() {
+    public int getCacheMaxObjectSize() {
         return cache.getMaxObjectSize();
     }
 

Modified: 
tomcat/trunk/test/org/apache/catalina/webresources/TesterWebResourceRoot.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/webresources/TesterWebResourceRoot.java?rev=1549706&r1=1549705&r2=1549706&view=diff
==============================================================================
--- 
tomcat/trunk/test/org/apache/catalina/webresources/TesterWebResourceRoot.java 
(original)
+++ 
tomcat/trunk/test/org/apache/catalina/webresources/TesterWebResourceRoot.java 
Mon Dec  9 23:34:25 2013
@@ -143,12 +143,12 @@ public class TesterWebResourceRoot exten
     }
 
     @Override
-    public void setCacheMaxObjectSize(long cacheMaxObjectSize) {
+    public void setCacheMaxObjectSize(int cacheMaxObjectSize) {
         // NO-OP
     }
 
     @Override
-    public long getCacheMaxObjectSize() {
+    public int getCacheMaxObjectSize() {
         return 0;
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to