cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject svn commit: r1336658 - in /cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security: cache/EHCacheReplayCache.java tokenstore/EHCacheTokenStore.java
Date Thu, 10 May 2012 13:07:39 GMT
Author: coheigea
Date: Thu May 10 13:07:38 2012
New Revision: 1336658

URL: http://svn.apache.org/viewvc?rev=1336658&view=rev
Log:
[CXF-4294] - Fix for race condition in EhCache stores

Modified:
    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

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=1336658&r1=1336657&r2=1336658&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 May 10 13:07:38 2012
@@ -25,6 +25,7 @@ import java.net.URL;
 
 import net.sf.ehcache.Cache;
 import net.sf.ehcache.CacheManager;
+import net.sf.ehcache.Ehcache;
 import net.sf.ehcache.Element;
 
 import org.apache.ws.security.cache.ReplayCache;
@@ -37,18 +38,15 @@ public class EHCacheReplayCache implemen
     
     public static final long DEFAULT_TTL = 3600L;
     public static final long MAX_TTL = DEFAULT_TTL * 12L;
-    private Cache cache;
+    private Ehcache cache;
     private CacheManager cacheManager;
     private long ttl = DEFAULT_TTL;
     
     public EHCacheReplayCache(String key, URL configFileURL) {
         cacheManager = EHCacheManagerHolder.getCacheManager(configFileURL);
-        if (!cacheManager.cacheExists(key)) {
-            cache = new Cache(key, 50000, true, false, DEFAULT_TTL, DEFAULT_TTL);
-            cacheManager.addCache(cache);
-        } else {
-            cache = cacheManager.getCache(key);
-        }
+        
+        Ehcache newCache = new Cache(key, 50000, true, false, DEFAULT_TTL, DEFAULT_TTL);
+        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=1336658&r1=1336657&r2=1336658&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 May 10 13:07:38 2012
@@ -29,6 +29,7 @@ import java.util.List;
 
 import net.sf.ehcache.Cache;
 import net.sf.ehcache.CacheManager;
+import net.sf.ehcache.Ehcache;
 import net.sf.ehcache.Element;
 
 import org.apache.cxf.common.util.StringUtils;
@@ -44,19 +45,16 @@ public class EHCacheTokenStore implement
     public static final long MAX_TTL = DEFAULT_TTL * 12L;
     public static final int MAX_ELEMENTS = 1000000;
     
-    private Cache cache;
+    private Ehcache cache;
     private CacheManager cacheManager;
     private long ttl = DEFAULT_TTL;
     
     public EHCacheTokenStore(String key, URL configFileURL) {
         cacheManager = EHCacheManagerHolder.getCacheManager(configFileURL);
-        if (!cacheManager.cacheExists(key)) {
-            // Cannot overflow to disk as SecurityToken Elements can't be serialized
-            cache = new Cache(key, MAX_ELEMENTS, false, false, DEFAULT_TTL, DEFAULT_TTL);
-            cacheManager.addCache(cache);
-        } else {
-            cache = cacheManager.getCache(key);
-        }
+
+        // Cannot overflow to disk as SecurityToken Elements can't be serialized
+        Ehcache newCache = new Cache(key, MAX_ELEMENTS, false, false, DEFAULT_TTL, DEFAULT_TTL);
+        cache = cacheManager.addCacheIfAbsent(newCache);
     }
     
     /**



Mime
View raw message