Author: manik.surtani(a)jboss.com
Date: 2008-10-26 17:31:15 -0400 (Sun, 26 Oct 2008)
New Revision: 7015
Modified:
core/trunk/src/main/java/org/jboss/cache/RegionImpl.java
Log:
Backward compatibility hack for a deprecated method that *really* should not be used!
Modified: core/trunk/src/main/java/org/jboss/cache/RegionImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RegionImpl.java 2008-10-25 23:50:03 UTC (rev
7014)
+++ core/trunk/src/main/java/org/jboss/cache/RegionImpl.java 2008-10-26 21:31:15 UTC (rev
7015)
@@ -28,13 +28,11 @@
import org.jboss.cache.config.EvictionAlgorithmConfig;
import org.jboss.cache.config.EvictionPolicyConfig;
import org.jboss.cache.config.EvictionRegionConfig;
-import org.jboss.cache.eviction.EvictedEventNode;
-import org.jboss.cache.eviction.EvictionActionPolicy;
-import org.jboss.cache.eviction.EvictionAlgorithm;
-import org.jboss.cache.eviction.EvictionEvent;
-import org.jboss.cache.eviction.EvictionPolicy;
+import org.jboss.cache.eviction.*;
import org.jboss.cache.util.Util;
+import java.util.HashMap;
+import java.util.Map;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
@@ -321,10 +319,68 @@
@SuppressWarnings("deprecation")
public void setEvictionPolicy(EvictionPolicyConfig evictionPolicyConfig)
{
- //TODO: Autogenerated. Implement me properly
+ try
+ {
+ // need to create an EvictionRegionConfig from this.
+ EvictionRegionConfig erc = new EvictionRegionConfig(getFqn());
+ String epClassName = evictionPolicyConfig.getEvictionPolicyClass();
+ EvictionAlgorithmConfig eac = getEvictionAlgorithmConfig(epClassName);
+ erc.setEvictionAlgorithmConfig(eac);
+ if (!erc.isDefaultRegion())
+ {
+
erc.setDefaults(regionManager.getConfiguration().getEvictionConfig().getDefaultEvictionRegionConfig());
+ }
+ setEvictionRegionConfig(erc);
+ }
+ catch (Exception e)
+ {
+ throw new CacheException(e);
+ }
}
+ /**
+ * This is to provide backward compatibility and is not guaranteed to work for every
type of eviction policy out
+ * there, particularly custom ones.
+ *
+ * @param evictionPolicyClass
+ * @return An eviction algorithm config.
+ */
@Deprecated
+ private EvictionAlgorithmConfig getEvictionAlgorithmConfig(String evictionPolicyClass)
throws Exception
+ {
+ Map<String, Class<? extends EvictionAlgorithmConfig>> legacyConfigMap =
new HashMap<String, Class<? extends EvictionAlgorithmConfig>>();
+ legacyConfigMap.put(FIFOPolicy.class.getName(), FIFOAlgorithmConfig.class);
+ legacyConfigMap.put(LRUPolicy.class.getName(), LRUAlgorithmConfig.class);
+ legacyConfigMap.put(LFUPolicy.class.getName(), LFUAlgorithmConfig.class);
+ legacyConfigMap.put(MRUPolicy.class.getName(), MRUAlgorithmConfig.class);
+ legacyConfigMap.put(ExpirationPolicy.class.getName(),
ExpirationAlgorithmConfig.class);
+ legacyConfigMap.put(ElementSizePolicy.class.getName(),
ElementSizeAlgorithmConfig.class);
+ legacyConfigMap.put(NullEvictionPolicy.class.getName(),
NullEvictionAlgorithmConfig.class);
+
+ Class<? extends EvictionAlgorithmConfig> c =
legacyConfigMap.get(evictionPolicyClass);
+ if (c != null)
+ {
+ // this is one of our "shipped" policies. Easy mapping!
+ return Util.getInstance(c);
+ }
+ else
+ {
+ // tougher. This is a custom policy.
+ // lets default to LRUPolicy first...
+ final EvictionPolicy ep = (EvictionPolicy)
Util.getInstance(evictionPolicyClass);
+ ep.getEvictionAlgorithm();
+ return new LRUAlgorithmConfig()
+ {
+ @Override
+ public String getEvictionAlgorithmClassName()
+ {
+ return ep.getEvictionAlgorithm().getClass().getName();
+ }
+ };
+ }
+ }
+
+ @Deprecated
@Compat
@SuppressWarnings("deprecation")
public EvictionPolicyConfig getEvictionPolicyConfig()
Show replies by date