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: [email protected]
For additional commands, e-mail: [email protected]