incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r952552 - /sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/SlingServletResolver.java
Date Tue, 08 Jun 2010 06:57:21 GMT
Author: cziegeler
Date: Tue Jun  8 06:57:21 2010
New Revision: 952552

URL: http://svn.apache.org/viewvc?rev=952552&view=rev
Log:
SLING-1549 : Servlet cache can grow infinitely

Modified:
    sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/SlingServletResolver.java

Modified: sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/SlingServletResolver.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/SlingServletResolver.java?rev=952552&r1=952551&r2=952552&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/SlingServletResolver.java
(original)
+++ sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/SlingServletResolver.java
Tue Jun  8 06:57:21 2010
@@ -186,6 +186,12 @@ public class SlingServletResolver implem
     /** The script resolution cache. */
     private Map<AbstractResourceCollector, Servlet> cache;
 
+    /** The cache size. */
+    private int cacheSize;
+
+    /** Flag to log warning if cache size exceed only once. */
+    private volatile boolean logCacheSizeWarning;
+
     /** Registration as event handler. */
     private ServiceRegistration eventHandlerReg;
 
@@ -633,7 +639,13 @@ public class SlingServletResolver implem
                 boolean servletAcceptsRequest = !isOptingServlet || (request != null &&
((OptingServlet) candidate).accepts(request));
                 if (servletAcceptsRequest) {
                     if (!hasOptingServlet && !isOptingServlet && this.cache
!= null) {
-                        this.cache.put(locationUtil, candidate);
+                        if ( this.cache.size() < this.cacheSize ) {
+                            this.cache.put(locationUtil, candidate);
+                        } else if ( this.logCacheSizeWarning ) {
+                            this.logCacheSizeWarning = false;
+                            log.warn("Script cache has reached its limit of {}. You might
want to increase the cache size for the servlet resolver.",
+                                    this.cacheSize);
+                        }
                     }
                     log.debug("Using servlet provided by candidate resource {}", candidateResource.getPath());
                     return candidate;
@@ -833,9 +845,12 @@ public class SlingServletResolver implem
         }
 
         // create cache - if a cache size is configured
-        final int cacheSize = OsgiUtil.toInteger(properties.get(PROP_CACHE_SIZE), DEFAULT_CACHE_SIZE);
-        if (cacheSize > 5) {
+        this.cacheSize = OsgiUtil.toInteger(properties.get(PROP_CACHE_SIZE), DEFAULT_CACHE_SIZE);
+        if (this.cacheSize > 5) {
             this.cache = new ConcurrentHashMap<AbstractResourceCollector, Servlet>(cacheSize);
+            this.logCacheSizeWarning = true;
+        } else {
+            this.cacheSize = 0;
         }
 
         // and finally register as event listener
@@ -1025,6 +1040,7 @@ public class SlingServletResolver implem
             }
             if (flushCache) {
                 this.cache.clear();
+                this.logCacheSizeWarning = true;
             }
         }
     }



Mime
View raw message