Author: dkulp
Date: Thu Jun 7 19:26:00 2012
New Revision: 1347763
URL: http://svn.apache.org/viewvc?rev=1347763&view=rev
Log:
Use configuration from the ehcache config to create the caches
Since the token caches are per-endpoint, use smaller maxes for the heap
to avoid exploding the memory usage.
Modified:
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheManagerHolder.java
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheReplayCache.java
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/EHCacheTokenStore.java
cxf/trunk/rt/ws/security/src/main/resources/cxf-ehcache.xml
Modified:
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheManagerHolder.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheManagerHolder.java?rev=1347763&r1=1347762&r2=1347763&view=diff
==============================================================================
---
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheManagerHolder.java
(original)
+++
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheManagerHolder.java
Thu Jun 7 19:26:00 2012
@@ -25,6 +25,7 @@ import java.util.concurrent.ConcurrentHa
import java.util.concurrent.atomic.AtomicInteger;
import net.sf.ehcache.CacheManager;
+import net.sf.ehcache.config.CacheConfiguration;
import net.sf.ehcache.config.Configuration;
import net.sf.ehcache.config.ConfigurationFactory;
@@ -44,6 +45,24 @@ public final class EHCacheManagerHolder
}
+ public static CacheConfiguration getCacheConfiguration(String key,
+ CacheManager
cacheManager) {
+ CacheConfiguration cc =
cacheManager.getConfiguration().getCacheConfigurations().get(key);
+ if (cc == null && key.contains("-")) {
+ cc =
cacheManager.getConfiguration().getCacheConfigurations().get(key.substring(0,
key.indexOf('-')));
+ }
+ if (cc == null) {
+ cc =
cacheManager.getConfiguration().getDefaultCacheConfiguration();
+ }
+ if (cc == null) {
+ cc = new CacheConfiguration();
+ } else {
+ cc = (CacheConfiguration)cc.clone();
+ }
+ cc.setName(key);
+ return cc;
+ }
+
public static CacheManager getCacheManager(Bus bus, URL configFileURL) {
CacheManager cacheManager = null;
if (configFileURL == null) {
Modified:
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheReplayCache.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheReplayCache.java?rev=1347763&r1=1347762&r2=1347763&view=diff
==============================================================================
---
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheReplayCache.java
(original)
+++
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheReplayCache.java
Thu Jun 7 19:26:00 2012
@@ -26,6 +26,7 @@ import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Ehcache;
import net.sf.ehcache.Element;
+import net.sf.ehcache.config.CacheConfiguration;
import org.apache.cxf.Bus;
import org.apache.cxf.buslifecycle.BusLifeCycleListener;
@@ -52,7 +53,9 @@ public class EHCacheReplayCache implemen
}
cacheManager = EHCacheManagerHolder.getCacheManager(bus,
configFileURL);
- Ehcache newCache = new Cache(key, 50000, true, false, DEFAULT_TTL,
DEFAULT_TTL);
+ CacheConfiguration cc =
EHCacheManagerHolder.getCacheConfiguration(key, cacheManager);
+
+ Ehcache newCache = new Cache(cc);
cache = cacheManager.addCacheIfAbsent(newCache);
}
Modified:
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/EHCacheTokenStore.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/EHCacheTokenStore.java?rev=1347763&r1=1347762&r2=1347763&view=diff
==============================================================================
---
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/EHCacheTokenStore.java
(original)
+++
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/EHCacheTokenStore.java
Thu Jun 7 19:26:00 2012
@@ -31,6 +31,7 @@ import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Ehcache;
import net.sf.ehcache.Element;
+import net.sf.ehcache.config.CacheConfiguration;
import org.apache.cxf.Bus;
import org.apache.cxf.buslifecycle.BusLifeCycleListener;
@@ -46,7 +47,6 @@ public class EHCacheTokenStore implement
public static final long DEFAULT_TTL = 3600L;
public static final long MAX_TTL = DEFAULT_TTL * 12L;
- public static final int MAX_ELEMENTS = 1000000;
private Ehcache cache;
private Bus bus;
@@ -60,9 +60,11 @@ public class EHCacheTokenStore implement
}
cacheManager = EHCacheManagerHolder.getCacheManager(bus,
configFileURL);
-
// Cannot overflow to disk as SecurityToken Elements can't be
serialized
- Ehcache newCache = new Cache(key, MAX_ELEMENTS, false, false,
DEFAULT_TTL, DEFAULT_TTL);
+ CacheConfiguration cc =
EHCacheManagerHolder.getCacheConfiguration(key, cacheManager);
+ cc.overflowToDisk(false); //tokens not writable
+
+ Ehcache newCache = new Cache(cc);
cache = cacheManager.addCacheIfAbsent(newCache);
}
Modified: cxf/trunk/rt/ws/security/src/main/resources/cxf-ehcache.xml
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/resources/cxf-ehcache.xml?rev=1347763&r1=1347762&r2=1347763&view=diff
==============================================================================
--- cxf/trunk/rt/ws/security/src/main/resources/cxf-ehcache.xml (original)
+++ cxf/trunk/rt/ws/security/src/main/resources/cxf-ehcache.xml Thu Jun 7
19:26:00 2012
@@ -3,7 +3,7 @@
<diskStore path="java.io.tmpdir"/>
<defaultCache
- maxElementsInMemory="50000"
+ maxEntriesLocalHeap="5000"
eternal="false"
timeToIdleSeconds="3600"
timeToLiveSeconds="3600"
@@ -13,4 +13,17 @@
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU"
/>
+
+ <!--
+ Security Tokens are now writable to Disk so use a memory only
+ cache with a bit larger maxEntriesLocalHeap. However, this
+ cache is per-endpoint so not "too large" to not consume the
+ entire heap.
+ -->
+ <cache name="org.apache.cxf.ws.security.tokenstore.TokenStore"
+ overflowToDisk="false"
+ maxEntriesLocalHeap="10000"
+ timeToIdleSeconds="3600"
+ timeToLiveSeconds="3600"
+ />
</ehcache>