Author: coheigea
Date: Wed Jun 20 16:06:16 2012
New Revision: 1352192
URL: http://svn.apache.org/viewvc?rev=1352192&view=rev
Log:
Made Cache configuration configurable
Added:
cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/EHCacheUtil.java
Modified:
cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/EHCacheTokenReplayCache.java
cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/config/FederationContext.java
cxf/fediz/trunk/plugins/core/src/main/resources/fediz-ehcache.xml
Modified:
cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/EHCacheTokenReplayCache.java
URL:
http://svn.apache.org/viewvc/cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/EHCacheTokenReplayCache.java?rev=1352192&r1=1352191&r2=1352192&view=diff
==============================================================================
---
cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/EHCacheTokenReplayCache.java
(original)
+++
cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/EHCacheTokenReplayCache.java
Wed Jun 20 16:06:16 2012
@@ -26,6 +26,9 @@ 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 net.sf.ehcache.config.Configuration;
+import net.sf.ehcache.config.ConfigurationFactory;
import org.apache.ws.security.util.Loader;
@@ -55,10 +58,13 @@ public class EHCacheTokenReplayCache imp
if (configFileURL == null) {
cacheManager = CacheManager.create();
} else {
- cacheManager = CacheManager.create(configFileURL);
+ Configuration conf =
ConfigurationFactory.parseConfiguration(configFileURL);
+ cacheManager = CacheManager.create(conf);
}
- Ehcache newCache = new Cache(key, 50000, true, false, DEFAULT_TTL,
DEFAULT_TTL);
+ CacheConfiguration cc = EHCacheUtil.getCacheConfiguration(key,
cacheManager);
+
+ Ehcache newCache = new Cache(cc);
cache = cacheManager.addCacheIfAbsent(newCache);
}
Added:
cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/EHCacheUtil.java
URL:
http://svn.apache.org/viewvc/cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/EHCacheUtil.java?rev=1352192&view=auto
==============================================================================
---
cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/EHCacheUtil.java
(added)
+++
cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/EHCacheUtil.java
Wed Jun 20 16:06:16 2012
@@ -0,0 +1,51 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.fediz.core;
+
+import net.sf.ehcache.CacheManager;
+import net.sf.ehcache.config.CacheConfiguration;
+
+/**
+ */
+public final class EHCacheUtil {
+
+ private EHCacheUtil() {
+ //
+ }
+
+ 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.lastIndexOf('-') - 1));
+ }
+ if (cc == null) {
+ cc =
cacheManager.getConfiguration().getDefaultCacheConfiguration();
+ }
+ if (cc == null) {
+ cc = new CacheConfiguration();
+ } else {
+ cc = (CacheConfiguration)cc.clone();
+ }
+ cc.setName(key);
+ return cc;
+ }
+
+}
Modified:
cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/config/FederationContext.java
URL:
http://svn.apache.org/viewvc/cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/config/FederationContext.java?rev=1352192&r1=1352191&r2=1352192&view=diff
==============================================================================
---
cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/config/FederationContext.java
(original)
+++
cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/config/FederationContext.java
Wed Jun 20 16:06:16 2012
@@ -48,6 +48,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class FederationContext implements Closeable {
+
+ public static final String CACHE_KEY_PREFIX = "fediz.replay.cache";
private static final Logger LOG =
LoggerFactory.getLogger(FederationContext.class);
@@ -162,7 +164,7 @@ public class FederationContext implement
return replayCache;
}
String replayCacheString = config.getTokenReplayCache();
- String cacheKey = "fediz-replay-cache-" + config.getName();
+ String cacheKey = CACHE_KEY_PREFIX + "-" + config.getName();
if (replayCacheString == null || "".equals(replayCacheString)) {
replayCache = new EHCacheTokenReplayCache(cacheKey);
} else {
Modified: cxf/fediz/trunk/plugins/core/src/main/resources/fediz-ehcache.xml
URL:
http://svn.apache.org/viewvc/cxf/fediz/trunk/plugins/core/src/main/resources/fediz-ehcache.xml?rev=1352192&r1=1352191&r2=1352192&view=diff
==============================================================================
--- cxf/fediz/trunk/plugins/core/src/main/resources/fediz-ehcache.xml (original)
+++ cxf/fediz/trunk/plugins/core/src/main/resources/fediz-ehcache.xml Wed Jun
20 16:06:16 2012
@@ -3,7 +3,7 @@
<diskStore path="java.io.tmpdir"/>
<defaultCache
- maxElementsInMemory="50000"
+ maxEntriesLocalHeap="5000"
eternal="false"
timeToIdleSeconds="3600"
timeToLiveSeconds="3600"