portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwat...@apache.org
Subject svn commit: r806306 - /portals/jetspeed-2/portal/branches/JETSPEED-2.1.3-POSTRELEASE/components/capability/src/java/org/apache/jetspeed/capabilities/impl/JetspeedCapabilities.java
Date Thu, 20 Aug 2009 19:08:41 GMT
Author: rwatler
Date: Thu Aug 20 19:08:41 2009
New Revision: 806306

URL: http://svn.apache.org/viewvc?rev=806306&view=rev
Log:
bound capabilities by user agent map size, use LRU strategy to evict

Modified:
    portals/jetspeed-2/portal/branches/JETSPEED-2.1.3-POSTRELEASE/components/capability/src/java/org/apache/jetspeed/capabilities/impl/JetspeedCapabilities.java

Modified: portals/jetspeed-2/portal/branches/JETSPEED-2.1.3-POSTRELEASE/components/capability/src/java/org/apache/jetspeed/capabilities/impl/JetspeedCapabilities.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JETSPEED-2.1.3-POSTRELEASE/components/capability/src/java/org/apache/jetspeed/capabilities/impl/JetspeedCapabilities.java?rev=806306&r1=806305&r2=806306&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JETSPEED-2.1.3-POSTRELEASE/components/capability/src/java/org/apache/jetspeed/capabilities/impl/JetspeedCapabilities.java
(original)
+++ portals/jetspeed-2/portal/branches/JETSPEED-2.1.3-POSTRELEASE/components/capability/src/java/org/apache/jetspeed/capabilities/impl/JetspeedCapabilities.java
Thu Aug 20 19:08:41 2009
@@ -19,6 +19,7 @@
 import java.util.Collection;
 import java.util.Hashtable;
 import java.util.Iterator;
+import java.util.LinkedList;
 import java.util.Properties;
 import java.util.Vector;
 
@@ -55,9 +56,12 @@
     public static final String DEFAULT_AGENT = "Mozilla/4.0";
 
     public static final String AGENT_XML = "agentxml/1.0";
+    
+    public static final int MAX_CACHE_SIZE = 500;
 
     // Cache for the capability maps
-    Hashtable capabilityMapCache = new Hashtable();
+    private Hashtable capabilityMapCache = new Hashtable();
+    private LinkedList capabilityMapCacheKeyList = new LinkedList();
 
     private Collection clients = null;
 
@@ -172,7 +176,15 @@
 
         // Check the cache if we have already a capability map for
         // the given Agent
-        map = (CapabilityMap) capabilityMapCache.get(userAgent);
+        synchronized (capabilityMapCache)
+        {
+            map = (CapabilityMap) capabilityMapCache.get(userAgent);
+            if (map != null)
+            {
+                capabilityMapCacheKeyList.remove(userAgent);
+                capabilityMapCacheKeyList.addFirst(userAgent);
+            }
+        }
 
         if (map != null)
         {
@@ -246,9 +258,27 @@
                 map.setPreferredMediaType(mtEntry);
 
                 // Add map to cache
-                capabilityMapCache.put(userAgent, map);
-                if (defaultAgent != null)
-                    capabilityMapCache.put(defaultAgent, map);
+                synchronized (capabilityMapCache)
+                {
+                    if (capabilityMapCache.put(userAgent, map) != null)
+                    {
+                        capabilityMapCacheKeyList.remove(userAgent);
+                    }
+                    capabilityMapCacheKeyList.addFirst(userAgent);
+                    if (defaultAgent != null)
+                    {
+                        if (capabilityMapCache.put(defaultAgent, map) != null)
+                        {
+                            capabilityMapCacheKeyList.remove(defaultAgent);
+                        }
+                        capabilityMapCacheKeyList.addFirst(defaultAgent);
+                    }
+                    while (capabilityMapCache.size() > MAX_CACHE_SIZE)
+                    {
+                        String reapAgent = (String)capabilityMapCacheKeyList.removeLast();
+                        capabilityMapCache.remove(reapAgent);
+                    }
+                }
                 return map;
             }
 
@@ -416,7 +446,11 @@
      */
     public void deleteCapabilityMapCache()
     {
-        capabilityMapCache.clear();
+        synchronized (capabilityMapCache)
+        {
+            capabilityMapCache.clear();
+            capabilityMapCacheKeyList.clear();
+        }
         clients = null;
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message