portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwat...@apache.org
Subject svn commit: r920519 - /portals/jetspeed-2/portal/trunk/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/impl/JetspeedCapabilities.java
Date Mon, 08 Mar 2010 21:20:57 GMT
Author: rwatler
Date: Mon Mar  8 21:20:57 2010
New Revision: 920519

URL: http://svn.apache.org/viewvc?rev=920519&view=rev
Log:
JS2-1056: forward port bounded capabilities cache patch from 2.1.3-POST-RELEASE

Modified:
    portals/jetspeed-2/portal/trunk/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/impl/JetspeedCapabilities.java

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/impl/JetspeedCapabilities.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/impl/JetspeedCapabilities.java?rev=920519&r1=920518&r2=920519&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/impl/JetspeedCapabilities.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/impl/JetspeedCapabilities.java
Mon Mar  8 21:20:57 2010
@@ -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