[jboss-cvs] JBossCache/src/org/jboss/cache/eviction ...
Brian Stansberry
brian.stansberry at jboss.com
Fri Oct 27 15:26:07 EDT 2006
User: bstansberry
Date: 06/10/27 15:26:07
Modified: src/org/jboss/cache/eviction
LRUAlgorithm.java FIFOAlgorithm.java
ElementSizeAlgorithm.java EvictionPolicy.java
LRUConfiguration.java LFUConfiguration.java
RegionManager.java MRUAlgorithm.java Region.java
MRUConfiguration.java EvictionConfiguration.java
LFUAlgorithm.java EvictionPolicyConfig.java
ElementSizeConfiguration.java
FIFOConfiguration.java
Added: src/org/jboss/cache/eviction
EvictionPolicyConfigBase.java
Removed: src/org/jboss/cache/eviction
DefaultEvictionPolicyConfig.java
Log:
[JBCACHE-823] Refactor eviction configuration away from EvictionConfiguration interface
Revision Changes Path
1.13 +2 -2 JBossCache/src/org/jboss/cache/eviction/LRUAlgorithm.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: LRUAlgorithm.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/eviction/LRUAlgorithm.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- LRUAlgorithm.java 8 Jun 2006 17:37:39 -0000 1.12
+++ LRUAlgorithm.java 27 Oct 2006 19:26:07 -0000 1.13
@@ -35,7 +35,7 @@
protected boolean shouldEvictNode(NodeEntry entry)
{
- LRUConfiguration config = (LRUConfiguration) region.getEvictionConfiguration();
+ LRUConfiguration config = (LRUConfiguration) region.getEvictionPolicyConfig();
// no idle or max time limit
if (config.getTimeToLiveSeconds() == 0 && config.getMaxAgeSeconds() == 0) return false;
@@ -174,7 +174,7 @@
protected LRUConfiguration getConfiguration()
{
- return (LRUConfiguration) region.getEvictionConfiguration();
+ return (LRUConfiguration) region.getEvictionPolicyConfig();
}
}
1.6 +2 -2 JBossCache/src/org/jboss/cache/eviction/FIFOAlgorithm.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: FIFOAlgorithm.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/eviction/FIFOAlgorithm.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- FIFOAlgorithm.java 7 May 2006 03:34:39 -0000 1.5
+++ FIFOAlgorithm.java 27 Oct 2006 19:26:07 -0000 1.6
@@ -14,7 +14,7 @@
*
* @author Daniel Huang - dhuang at jboss.org
* @author Morten Kvistgaard
- * @version $Revision: 1.5 $
+ * @version $Revision: 1.6 $
*/
public class FIFOAlgorithm extends BaseEvictionAlgorithm
{
@@ -36,7 +36,7 @@
*/
protected boolean shouldEvictNode(NodeEntry ne)
{
- FIFOConfiguration config = (FIFOConfiguration) region.getEvictionConfiguration();
+ FIFOConfiguration config = (FIFOConfiguration) region.getEvictionPolicyConfig();
if (log.isTraceEnabled())
{
log.trace("Deciding whether node in queue " + ne.getFqn() + " requires eviction.");
1.2 +2 -2 JBossCache/src/org/jboss/cache/eviction/ElementSizeAlgorithm.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ElementSizeAlgorithm.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/eviction/ElementSizeAlgorithm.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- ElementSizeAlgorithm.java 7 May 2006 03:34:39 -0000 1.1
+++ ElementSizeAlgorithm.java 27 Oct 2006 19:26:07 -0000 1.2
@@ -9,7 +9,7 @@
/**
* @author Daniel Huang
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public class ElementSizeAlgorithm extends BaseSortedEvictionAlgorithm
{
@@ -20,7 +20,7 @@
protected boolean shouldEvictNode(NodeEntry ne)
{
- ElementSizeConfiguration config = (ElementSizeConfiguration) region.getEvictionConfiguration();
+ ElementSizeConfiguration config = (ElementSizeConfiguration) region.getEvictionPolicyConfig();
int size = this.getEvictionQueue().getNumberOfNodes();
if (config.getMaxNodes() != 0 && size > config.getMaxNodes())
1.6 +2 -2 JBossCache/src/org/jboss/cache/eviction/EvictionPolicy.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: EvictionPolicy.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/eviction/EvictionPolicy.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- EvictionPolicy.java 12 Oct 2006 03:39:59 -0000 1.5
+++ EvictionPolicy.java 27 Oct 2006 19:26:07 -0000 1.6
@@ -63,9 +63,9 @@
EvictionAlgorithm getEvictionAlgorithm();
/**
- * The EvictionConfiguration implementation class used by this EvictionPolicy.
+ * The EvictionPolicyConfig implementation class used by this EvictionPolicy.
*
- * @return EvictionConfiguration implementation class.
+ * @return EvictionPolicyConfig implementation class.
*/
Class getEvictionConfigurationClass();
1.4 +56 -72 JBossCache/src/org/jboss/cache/eviction/LRUConfiguration.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: LRUConfiguration.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/eviction/LRUConfiguration.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- LRUConfiguration.java 18 Jul 2006 17:50:56 -0000 1.3
+++ LRUConfiguration.java 27 Oct 2006 19:26:07 -0000 1.4
@@ -6,34 +6,40 @@
*/
package org.jboss.cache.eviction;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.jboss.cache.config.ConfigurationException;
-import org.jboss.cache.xml.XmlHelper;
-import org.w3c.dom.Element;
+import org.jboss.cache.config.Dynamic;
/**
- * LRU Configuration implementation.
+ * Configuration implementation for {@link LRUPolicy}.
+ * <p/>
+ * If configured via XML, expects the following:
+ * <p/>
+ * <pre>
+ * <region name="/maxAgeTest/">
+ * <attribute name="maxNodes">10000</attribute>
+ * <attribute name="timeToLiveSeconds">8</attribute>
+ * <attribute name="maxAgeSeconds">10</attribute>
+ * </region>
+ * </pre>
*
* @author Daniel Huang (dhuang at jboss.org)
- * @version $Revision: 1.3 $
+ * @version $Revision: 1.4 $
*/
-public class LRUConfiguration implements EvictionConfiguration
+public class LRUConfiguration extends EvictionPolicyConfigBase
{
- private static final Log log = LogFactory.getLog(LRUConfiguration.class);
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -3426716488271559729L;
- private int maxNodes;
+ @Dynamic
private int timeToLiveSeconds;
+ @Dynamic
private int maxAgeSeconds;
- public int getMaxNodes()
- {
- return maxNodes;
- }
-
- public void setMaxNodes(int maxNodes)
+ public LRUConfiguration()
{
- this.maxNodes = maxNodes;
+ setEvictionPolicyClass(LRUPolicy.class.getName());
+ // Force config of ttls
+ setTimeToLiveSeconds(-1);
}
public int getTimeToLiveSeconds()
@@ -43,6 +49,7 @@
public void setTimeToLiveSeconds(int timeToLiveSeconds)
{
+ testImmutability("timeToLiveSeconds");
this.timeToLiveSeconds = timeToLiveSeconds;
}
@@ -53,72 +60,49 @@
public void setMaxAgeSeconds(int maxAgeSeconds)
{
+ testImmutability("maxAgeSeconds");
this.maxAgeSeconds = maxAgeSeconds;
}
/**
- * Configure the LRU Policy with XML.
- * <p/>
- * This method expects the following XML:
- * <p/>
- * <region name="/maxAgeTest/">
- * <attribute name="maxNodes">10000</attribute>
- * <attribute name="timeToLiveSeconds">8</attribute>
- * <attribute name="maxAgeSeconds">10</attribute>
- * </region>
- *
- * @param element DOM XML containing LFU Policy configuration.
- * @throws ConfigureException
+ * Requires a positive timeToLiveSeconds value or ConfigurationException
+ * is thrown.
*/
- public void parseXMLConfig(Element element) throws ConfigurationException
- {
- String name = element.getAttribute(EvictionConfiguration.NAME);
- if (name == null || name.equals(""))
+ @Override
+ public void validate() throws ConfigurationException
{
- throw new ConfigurationException("Name is required for the eviction region");
+ if (timeToLiveSeconds < 0)
+ throw new ConfigurationException("timeToLiveSeconds not configured");
}
- String maxNodes = XmlHelper.getTagContents(element, EvictionConfiguration.MAX_NODES,
- EvictionConfiguration.ATTR, EvictionConfiguration.NAME);
- if (maxNodes != null && !maxNodes.equals(""))
- {
- setMaxNodes(Integer.parseInt(maxNodes));
- }
- else
- {
- setMaxNodes(0);
- }
- String timeToLive = XmlHelper.getTagContents(element, EvictionConfiguration.TIME_TO_IDLE_SECONDS,
- EvictionConfiguration.ATTR, EvictionConfiguration.NAME);
- if (timeToLive == null)
+ public String toString()
{
- timeToLive = XmlHelper.getTagContents(element, EvictionConfiguration.TIME_TO_LIVE_SECONDS,
- EvictionConfiguration.ATTR, EvictionConfiguration.NAME);
- if (timeToLive == null)
- throw new ConfigurationException("LRUConfiguration.parseXMLConfig(): Null timeToLiveSeconds element");
+ StringBuffer str = new StringBuffer();
+ str.append("LRUConfiguration: timeToLiveSeconds = ").append(getTimeToLiveSeconds()).append(" maxAgeSeconds =");
+ str.append(getMaxAgeSeconds()).append(" maxNodes =").append(getMaxNodes());
+ return str.toString();
}
- setTimeToLiveSeconds(Integer.parseInt(timeToLive));
- String maxAge = XmlHelper.getTagContents(element, EvictionConfiguration.MAX_AGE_SECONDS,
- EvictionConfiguration.ATTR, EvictionConfiguration.NAME);
- if (maxAge != null && !maxAge.equals(""))
+ @Override
+ public boolean equals(Object obj)
{
- setMaxAgeSeconds(Integer.parseInt(maxAge));
- }
-
- if (log.isDebugEnabled())
+ if (obj instanceof LRUConfiguration && super.equals(obj))
{
- log.debug("parseConfig: name -- " + name + " maxNodes -- "
- + getMaxNodes() + " timeToLiveSeconds -- " + getTimeToLiveSeconds() + " maxAgeSeconds -- "
- + getMaxAgeSeconds());
+ LRUConfiguration other = (LRUConfiguration) obj;
+ return maxAgeSeconds == other.maxAgeSeconds
+ && timeToLiveSeconds == other.timeToLiveSeconds;
}
+ return false;
}
- public String toString()
+ @Override
+ public int hashCode()
{
- StringBuffer str = new StringBuffer();
- str.append("LRUConfiguration: timeToLiveSeconds = ").append(getTimeToLiveSeconds()).append(" maxAgeSeconds =");
- str.append(getMaxAgeSeconds()).append(" maxNodes =").append(getMaxNodes());
- return str.toString();
+ int result = super.hashCode();
+ result = 31 * result + maxAgeSeconds;
+ result = 31 * result + timeToLiveSeconds;
+ return result;
}
+
+
}
1.6 +40 -68 JBossCache/src/org/jboss/cache/eviction/LFUConfiguration.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: LFUConfiguration.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/eviction/LFUConfiguration.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- LFUConfiguration.java 18 Jul 2006 17:50:56 -0000 1.5
+++ LFUConfiguration.java 27 Oct 2006 19:26:07 -0000 1.6
@@ -6,24 +6,35 @@
*/
package org.jboss.cache.eviction;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.config.ConfigurationException;
-import org.jboss.cache.xml.XmlHelper;
-import org.w3c.dom.Element;
+import org.jboss.cache.config.Dynamic;
/**
- * LFU Configuration implementation for LFU Policy.
+ * Configuration implementation for {@link LFUPolicy}.
+ * <p/>
+ * If configured via XML, expects the following:
+ * <p/>
+ * <pre>
+ * <region name="abc">
+ * <attribute name="minNodes">10</attribute>
+ * <attribute name="maxNodes">20</attribute>
+ * </region>
+ * </pre>
*
* @author Daniel Huang (dhuang at jboss.org)
- * @version $Revision: 1.5 $
+ * @version $Revision: 1.6 $
*/
-public class LFUConfiguration implements EvictionConfiguration
+public class LFUConfiguration extends EvictionPolicyConfigBase
{
- private static final Log log = LogFactory.getLog(LFUConfiguration.class);
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 1865801530398969179L;
+ @Dynamic
private int minNodes;
- private int maxNodes;
+
+ public LFUConfiguration()
+ {
+ setEvictionPolicyClass(LFUPolicy.class.getName());
+ }
public int getMinNodes()
{
@@ -32,73 +43,34 @@
public void setMinNodes(int minNodes)
{
+ testImmutability("minNodes");
this.minNodes = minNodes;
}
- public int getMaxNodes()
+ public String toString()
{
- return maxNodes;
+ StringBuffer ret = new StringBuffer();
+ ret.append("LFUConfiguration: maxNodes = ").append(getMaxNodes()).append(" minNodes = ").append(getMinNodes());
+ return ret.toString();
}
- public void setMaxNodes(int maxNodes)
+ @Override
+ public boolean equals(Object obj)
{
- this.maxNodes = maxNodes;
- }
-
- /**
- * Configures the LFU Policy with XML.
- * <p/>
- * This method expects the following XML DOM:
- * <p/>
- * <region name="abc">
- * <attribute name="minNodes">10</attribute>
- * <attribute name="maxNodes">20</attribute>
- * </region>
- *
- * @param element XML DOM object containing LFU configuration.
- * @throws ConfigureException
- */
- public void parseXMLConfig(Element element) throws ConfigurationException
- {
- String name = element.getAttribute(EvictionConfiguration.NAME);
- if (name == null || name.equals(""))
- {
- throw new ConfigurationException("Name is required for the eviction region");
- }
-
- String maxNodes = XmlHelper.getTagContents(element,
- EvictionConfiguration.MAX_NODES, EvictionConfiguration.ATTR, EvictionConfiguration.NAME);
- if (maxNodes != null)
+ if (obj instanceof LFUConfiguration && super.equals(obj))
{
- setMaxNodes(Integer.parseInt(maxNodes));
+ return (this.minNodes == ((LFUConfiguration) obj).minNodes);
}
- else
- {
- setMaxNodes(0);
+ return false;
}
- String minNodes = XmlHelper.getTagContents(element, EvictionConfiguration.MIN_NODES,
- EvictionConfiguration.ATTR, EvictionConfiguration.NAME);
- if (minNodes != null)
- {
- setMinNodes(Integer.parseInt(minNodes));
- }
- else
+ @Override
+ public int hashCode()
{
- setMinNodes(0);
+ int result = super.hashCode();
+ result = 31 * result + minNodes;
+ return result;
}
- if (log.isDebugEnabled())
- {
- log.debug("parseConfig: name -- " + name + " maxNodes -- "
- + getMaxNodes() + " minNodes -- " + getMinNodes());
- }
- }
- public String toString()
- {
- StringBuffer ret = new StringBuffer();
- ret.append("LFUConfiguration: maxNodes = ").append(getMaxNodes()).append(" minNodes = ").append(getMinNodes());
- return ret.toString();
- }
}
1.27 +150 -57 JBossCache/src/org/jboss/cache/eviction/RegionManager.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: RegionManager.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/eviction/RegionManager.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -b -r1.26 -r1.27
--- RegionManager.java 25 Oct 2006 04:52:51 -0000 1.26
+++ RegionManager.java 27 Oct 2006 19:26:07 -0000 1.27
@@ -18,10 +18,12 @@
import org.jboss.cache.optimistic.FqnComparator;
import org.jboss.cache.util.Util;
+import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap;
+
+import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collections;
+import java.util.Collection;
import java.util.Comparator;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -35,21 +37,18 @@
*
* @author Ben Wang 02-2004
* @author Daniel Huang (dhuang at jboss.org)
- * @version $Id: RegionManager.java,v 1.26 2006/10/25 04:52:51 bstansberry Exp $
+ * @author Brian Stansberry
+ *
+ * @version $Id: RegionManager.java,v 1.27 2006/10/27 19:26:07 bstansberry Exp $
*/
public class RegionManager
{
- /**
- * Default region capacity.
- */
- public static int CAPACITY = EvictionConfiguration.EVENT_QUEUE_SIZE_DEFAULT;
-
// There is global cache wide default values if no region is found.
final static Fqn DEFAULT_REGION = new Fqn("_default_");
private static final Log log_ = LogFactory.getLog(RegionManager.class);
- private final Map regionMap_ = Collections.synchronizedMap(new HashMap());
+ private final Map regionMap_ = new ConcurrentReaderHashMap();
private int longestFqn = 0;
private Timer evictionThread_;
@@ -90,82 +89,139 @@
throw new RuntimeException("Deprecated API not properly setup for use. The MarshRegionManager must be constructed with a single Policy");
}
- EvictionConfiguration configuration;
+ EvictionPolicyConfig epc = null;
try
{
- configuration =
- (EvictionConfiguration) policy_.getEvictionConfigurationClass().newInstance();
+ epc = (EvictionPolicyConfig) policy_.getEvictionConfigurationClass().newInstance();
}
catch (Exception e)
{
- throw new RuntimeException("Could not instantiate EvictionConfigurationClass", e);
+ throw new RuntimeException("Could not instantiate EvictionPolicyConfig class", e);
}
- Region region = new Region(fqn, policy_, configuration);
- addRegion(fqn, region);
- evictionTimerTask_.addRegionToProcess(region);
- return region;
+ return createRegion(fqn, policy_, epc);
}
- private void addRegion(Fqn fqn, Region region) throws RegionNameConflictException
+ private void addRegion(Region region) throws RegionNameConflictException
{
+ // Even with ConcurrentReaderHashMap we want to synchronize
+ // so the following is atomic
synchronized (regionMap_)
{
+ Fqn fqn = region.getFqnObject();
checkConflict(fqn);
regionMap_.put(fqn, region);
longestFqn = Math.max(longestFqn, fqn.size());
}
- }
- public Region createRegion(EvictionRegionConfig config) throws RegionNameConflictException
+ // If the region was added programmatically, we need to update
+ // our config to include it
+ if (config_ != null)
{
- return createRegion(config.getRegionFqn(), config);
- }
-
- public Region createRegion(Fqn fqn, EvictionRegionConfig config) throws RegionNameConflictException
+ synchronized (config_)
{
- EvictionPolicy policy = null;
- try
+ List regionConfigs = config_.getEvictionRegionConfigs();
+ if (regionConfigs == null)
+ regionConfigs = new ArrayList();
+
+ if (!regionConfigs.contains(region.getEvictionRegionConfig()))
{
- policy = (EvictionPolicy) Util.loadClass(config.getEvictionPolicyClass()).newInstance();
+ regionConfigs.add(region.getEvictionRegionConfig());
+ config_.setEvictionRegionConfigs(regionConfigs);
}
- catch (RuntimeException e)
- {
- throw e;
}
- catch (Exception e)
- {
- throw new RuntimeException("Failed to create EvictionPolicy " +
- config.getEvictionPolicyClass(), e);
}
- policy.configure(cache_);
- return createRegion(fqn, policy, config.getEvictionConfiguration());
+ evictionTimerTask_.addRegionToProcess(region);
}
- public Region createRegion(String fqn, EvictionRegionConfig config) throws RegionNameConflictException
+ public Region createRegion(EvictionRegionConfig erc) throws RegionNameConflictException
{
- return createRegion(Fqn.fromString(fqn), config);
+ // Ensure we have defaults
+ erc.setDefaultEventQueueSize(config_ == null ? EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT :config_.getDefaultEventQueueSize());
+
+ EvictionPolicy policy = instantiatePolicy(erc.getEvictionPolicyConfig());
+ policy.configure(cache_);
+
+ Region region = new Region(policy, erc);
+ addRegion(region);
+
+ return region;
}
- public Region createRegion(String fqn, EvictionPolicy policy, EvictionConfiguration config) throws RegionNameConflictException
+ /**
+ * Supports programatic instantiation of a region from an Fqn and a policy config.
+ *
+ * @param fqn
+ * @param epc
+ * @return
+ * @throws RegionNameConflictException
+ */
+ public Region createRegion(Fqn fqn, EvictionPolicyConfig epc) throws RegionNameConflictException
{
- return createRegion(Fqn.fromString(fqn), policy, config);
+ EvictionRegionConfig erc = new EvictionRegionConfig();
+ erc.setRegionFqn(fqn);
+ erc.setEvictionPolicyConfig(epc);
+ erc.setDefaultEventQueueSize(config_ == null ? EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT : config_.getDefaultEventQueueSize());
+
+ return createRegion(erc);
}
- public Region createRegion(Fqn fqn, EvictionPolicy policy, EvictionConfiguration config) throws RegionNameConflictException
- {
- if (log_.isDebugEnabled())
+ /**
+ * Supports programatic instantiation of a region from an Fqn and a policy config.
+ *
+ * @param fqn
+ * @param epc
+ * @return
+ * @throws RegionNameConflictException
+ */
+ public Region createRegion(String fqn, EvictionPolicyConfig epc) throws RegionNameConflictException
{
- log_.debug("createRegion(): creating region for fqn- " + fqn);
+ return createRegion(Fqn.fromString(fqn), epc);
}
- Region region = new Region(fqn, policy, config);
- addRegion(fqn, region);
- evictionTimerTask_.addRegionToProcess(region);
+ /**
+ * Supports programatic instantiation of a region from an Fqn, EvictionPolicy
+ * and a policy config. Should only be used in a case where the caller needs
+ * to manipulate the EvictionPolicy; otherwise use the other overloaded versions
+ * of this method.
+ *
+ * @param fqn
+ * @param epc
+ * @return
+ * @throws RegionNameConflictException
+ */
+ public Region createRegion(Fqn fqn, EvictionPolicy policy, EvictionPolicyConfig epc) throws RegionNameConflictException
+ {
+ EvictionRegionConfig erc = new EvictionRegionConfig();
+ erc.setRegionFqn(fqn);
+ erc.setEvictionPolicyConfig(epc);
+ erc.setDefaultEventQueueSize(config_ == null ? EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT : config_.getDefaultEventQueueSize());
+
+ policy.configure(cache_);
+
+ Region region = new Region(policy, erc);
+ addRegion(region);
return region;
}
+ /**
+ * Supports programatic instantiation of a region from an Fqn, EvictionPolicy
+ * and a policy config. Should only be used in a case where the caller needs
+ * to manipulate the EvictionPolicy; otherwise use the other overloaded versions
+ * of this method.
+ *
+ * @param fqn
+ * @param policy
+ * @param config
+ * @return
+ * @throws RegionNameConflictException
+ */
+ public Region createRegion(String fqn, EvictionPolicy policy, EvictionPolicyConfig config) throws RegionNameConflictException
+ {
+ return createRegion(Fqn.fromString(fqn), policy, config);
+ }
+
public void configure(TreeCache cache)
{
if (log_.isTraceEnabled())
@@ -175,7 +231,6 @@
cache_ = cache;
config_ = cache_.getConfiguration().getEvictionConfig();
- CAPACITY = config_.getEventQueueSize();
// done for API 1.2 backwards compatibility for EJB3 integration.
String evictionClass = config_.getDefaultEvictionPolicyClass();
@@ -236,6 +291,26 @@
{
Region region = (Region) regionMap_.remove(fqn);
evictionTimerTask_.removeRegionToProcess(region);
+
+ if (region != null && config_ != null)
+ {
+ // Update the config to reflect the region's removal
+ synchronized (config_)
+ {
+ List regionConfigs = config_.getEvictionRegionConfigs();
+ for (Iterator it = regionConfigs.iterator(); it.hasNext();)
+ {
+ EvictionRegionConfig erc = (EvictionRegionConfig) it.next();
+ if (region.getFqnObject().equals(erc.getRegionFqn()))
+ {
+ regionConfigs.remove(erc);
+ config_.setEvictionRegionConfigs(regionConfigs);
+ break;
+ }
+ }
+ }
+ }
+
return region != null;
}
@@ -302,7 +377,9 @@
*/
public Region[] getRegions()
{
- Region r[] = (Region[]) regionMap_.values().toArray(new Region[]{});
+ Collection c = regionMap_.values();
+ Region r[] = new Region[c.size()];
+ r = (Region[]) regionMap_.values().toArray(r);
Arrays.sort(r, new RegionComparator());
return r;
}
@@ -408,4 +485,20 @@
}
}
+ private static EvictionPolicy instantiatePolicy(EvictionPolicyConfig config)
+ {
+ try
+ {
+ return (EvictionPolicy) Util.loadClass(config.getEvictionPolicyClass()).newInstance();
+ }
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Failed to create EvictionPolicy " +
+ config.getEvictionPolicyClass(), e);
+ }
+ }
}
1.3 +2 -2 JBossCache/src/org/jboss/cache/eviction/MRUAlgorithm.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: MRUAlgorithm.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/eviction/MRUAlgorithm.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- MRUAlgorithm.java 15 Apr 2006 00:21:13 -0000 1.2
+++ MRUAlgorithm.java 27 Oct 2006 19:26:07 -0000 1.3
@@ -17,7 +17,7 @@
* EvictionAlgorithm/EvictionQueue/EvictionConfiguration are only operated on by one thread at any given time.
*
* @author Daniel Huang (dhuang at jboss.org)
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
public class MRUAlgorithm extends BaseEvictionAlgorithm
{
@@ -28,7 +28,7 @@
protected boolean shouldEvictNode(NodeEntry ne)
{
- MRUConfiguration config = (MRUConfiguration) region.getEvictionConfiguration();
+ MRUConfiguration config = (MRUConfiguration) region.getEvictionPolicyConfig();
return evictionQueue.getNumberOfNodes() > config.getMaxNodes();
}
1.15 +54 -49 JBossCache/src/org/jboss/cache/eviction/Region.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Region.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/eviction/Region.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- Region.java 23 Oct 2006 17:39:01 -0000 1.14
+++ Region.java 27 Oct 2006 19:26:07 -0000 1.15
@@ -11,6 +11,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.Fqn;
+import org.jboss.cache.config.EvictionRegionConfig;
/**
@@ -20,16 +21,16 @@
*
* @author Ben Wang 2-2004
* @author Daniel Huang (dhuang at jboss.org)
- * @version $Revision: 1.14 $
+ * @author Brian Stansberry
+ *
+ * @version $Revision: 1.15 $
*/
public class Region
{
- // MarshRegion Fqn
- private Fqn fqn_;
// policy used by this region.
private EvictionPolicy policy_;
// Eviction configuration object used by this region.
- private EvictionConfiguration configuration_;
+ private EvictionRegionConfig configuration_;
// These queues can do put and take concurrently.
protected BoundedLinkedQueue nodeEventQueue_;
@@ -38,48 +39,37 @@
// Count of how many times between attempt to check capacity
protected int checkCapacityCount = 0;
- // Added capacity warning threshold constant with correct calculation. Plus 100 to be on the safe side.
- private final static int CAPACITY_WARN_THRESHOLD = (98 * RegionManager.CAPACITY) / 100 - 100;
-
- /**
- * Default to package namespace on purpose so no one outside the package can instantiate it,
- */
- Region()
- {
- if (CAPACITY_WARN_THRESHOLD <= 0)
- {
- throw new RuntimeException("MarshRegion.MarshRegion(): CAPACITY_WARN_THRESHOLD constant used in eviction is smaller than 1.");
- }
- createQueue();
- }
+ private int capacityWarnThreshold = 0;
- void createQueue()
+ Region(EvictionPolicy policy, EvictionRegionConfig config)
{
- nodeEventQueue_ = new BoundedLinkedQueue(RegionManager.CAPACITY);
- }
+ configuration_ = config;
+ policy_ = policy;
- Region(String fqn, EvictionPolicy policy, EvictionConfiguration config)
- {
- this(Fqn.fromString(fqn), policy, config);
+ createQueue();
}
- Region(Fqn fqn, EvictionPolicy policy, EvictionConfiguration config)
+ public EvictionRegionConfig getEvictionRegionConfig()
{
- fqn_ = fqn;
- policy_ = policy;
- configuration_ = config;
-
- createQueue();
+ return this.configuration_;
}
+ /**
+ * Gets the EvictionPolicyConfig for this region.
+ *
+ * @throws ClassCastException if the <code>EvictionPolicyConfig</code>
+ * does not implement <code>EvictionConfiguration</code>
+ *
+ * @deprecated use {@link #getEvictionPolicyConfig()}
+ */
public EvictionConfiguration getEvictionConfiguration()
{
- return this.configuration_;
+ return (EvictionConfiguration) getEvictionPolicyConfig();
}
- public void setEvictionConfiguration(EvictionConfiguration configuration)
+ public EvictionPolicyConfig getEvictionPolicyConfig()
{
- this.configuration_ = configuration;
+ return configuration_ == null ? null : configuration_.getEvictionPolicyConfig();
}
public EvictionPolicy getEvictionPolicy()
@@ -92,7 +82,7 @@
*/
public String getFqn()
{
- return fqn_.toString() + Fqn.SEPARATOR;
+ return configuration_.getRegionFqn().toString() + Fqn.SEPARATOR;
}
/**
@@ -100,7 +90,7 @@
*/
public Fqn getFqnObject()
{
- return fqn_;
+ return configuration_.getRegionFqn();
}
public void setAddedNode(Fqn fqn)
@@ -132,10 +122,10 @@
if (++checkCapacityCount > 100)
{
checkCapacityCount = 0;
- if (nodeEventQueue_.size() > (CAPACITY_WARN_THRESHOLD))
+ if (nodeEventQueue_.size() > capacityWarnThreshold)
{
log_.warn("putNodeEvent(): eviction node event queue size is at 98% threshold value of capacity: "
- + RegionManager.CAPACITY + " You will need to reduce the wakeUpIntervalSeconds parameter.");
+ + configuration_.getEventQueueSize() + " You will need to reduce the wakeUpIntervalSeconds parameter.");
}
}
nodeEventQueue_.put(event);
@@ -174,7 +164,7 @@
{
BoundedLinkedQueue q1 = nodeEventQueue_;
log_.info("reseteEvictionQueues(): node queue size: " + q1.size() +
- " region name: " + fqn_);
+ " region name: " + getFqn());
createQueue();
// Help to recycle
for (int i = 0; i < q1.size(); i++)
@@ -193,14 +183,17 @@
public boolean equals(Object o)
{
if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- final Region region = (Region) o;
- return fqn_.equals(region.fqn_);
+ if (o instanceof Region) {
+ Region region = (Region) o;
+ return getFqnObject().equals(region.getFqnObject());
+ }
+ return false;
+
}
public int hashCode()
{
- return fqn_.hashCode();
+ return getFqnObject().hashCode();
}
/**
@@ -208,10 +201,10 @@
*/
public void setTimeToLiveSeconds(long timeToLive)
{
- if (this.getEvictionConfiguration() instanceof LRUConfiguration)
+ if (this.getEvictionPolicyConfig() instanceof LRUConfiguration)
{
int ttl = new Long(timeToLive).intValue();
- ((LRUConfiguration) this.getEvictionConfiguration()).setTimeToLiveSeconds(ttl);
+ ((LRUConfiguration) this.getEvictionPolicyConfig()).setTimeToLiveSeconds(ttl);
}
else
{
@@ -224,9 +217,9 @@
*/
public void setMaxNodes(int maxSize)
{
- if (this.getEvictionConfiguration() instanceof LRUConfiguration)
+ if (this.getEvictionPolicyConfig() instanceof LRUConfiguration)
{
- ((LRUConfiguration) this.getEvictionConfiguration()).setMaxNodes(maxSize);
+ ((LRUConfiguration) this.getEvictionPolicyConfig()).setMaxNodes(maxSize);
}
else
{
@@ -234,4 +227,16 @@
}
}
+
+ private void createQueue()
+ {
+ capacityWarnThreshold = (98 * configuration_.getEventQueueSize()) / 100 - 100;
+ if (capacityWarnThreshold <= 0)
+ {
+ throw new RuntimeException("Capacity warn threshold used in eviction is smaller than 1.");
+ }
+ nodeEventQueue_ = new BoundedLinkedQueue(configuration_.getEventQueueSize());
+ }
+
+
}
1.5 +32 -53 JBossCache/src/org/jboss/cache/eviction/MRUConfiguration.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: MRUConfiguration.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/eviction/MRUConfiguration.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- MRUConfiguration.java 18 Jul 2006 17:50:56 -0000 1.4
+++ MRUConfiguration.java 27 Oct 2006 19:26:07 -0000 1.5
@@ -6,73 +6,45 @@
*/
package org.jboss.cache.eviction;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.jboss.cache.config.ConfigurationException;
-import org.jboss.cache.xml.XmlHelper;
-import org.w3c.dom.Element;
/**
- * MRUConfiguration EvictionConfiguration implementation for MRUPolicy.
+ * Configuration for {@link MRUPolicy}.
+ * <p/>
+ * If configured via XML, expects the following:
+ * <p/>
+ * <pre>
+ * <region name="abc">
+ * <attribute name="maxNodes">1000</attribute>
+ * </region>
+ * </pre>
+ *
+ * Requires a "maxNodes" attribute otherwise a ConfigurationException is thrown.
*
* @author Daniel Huang (dhuang at jboss.org)
- * @version $Revision: 1.4 $
+ * @version $Revision: 1.5 $
*/
-public class MRUConfiguration implements EvictionConfiguration
+public class MRUConfiguration extends EvictionPolicyConfigBase
{
- private static final Log log = LogFactory.getLog(MRUConfiguration.class);
- private int maxNodes;
-
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -8734577898966155218L;
public MRUConfiguration()
{
- }
-
- public int getMaxNodes()
- {
- return maxNodes;
- }
-
- public void setMaxNodes(int maxNodes)
- {
- this.maxNodes = maxNodes;
+ setEvictionPolicyClass(MRUPolicy.class.getName());
+ // We require that maxNodes is set
+ setMaxNodes(-1);
}
/**
- * Configure the MRU Policy with XML.
- * <p/>
- * This method expects a DOM XML object of something similar to:
- * <p/>
- * <region name="/Test/">
- * <attribute name="maxNodes">10000</attribute>
- * </region>
- *
- * @param element The MRUPolicy configuration XML DOM element.
+ * Requires a positive maxNodes value or ConfigurationException
+ * is thrown.
*/
- public void parseXMLConfig(Element element) throws ConfigurationException
+ @Override
+ public void validate() throws ConfigurationException
{
- String name = element.getAttribute(EvictionConfiguration.NAME);
- if (name == null || name.equals(""))
- {
- throw new ConfigurationException("Name is required for the eviction region");
- }
-
- String maxNodes = XmlHelper.getTagContents(element, EvictionConfiguration.MAX_NODES,
- EvictionConfiguration.ATTR, EvictionConfiguration.NAME);
- if (maxNodes != null && !maxNodes.equals(""))
- {
- setMaxNodes(Integer.parseInt(maxNodes));
- }
- else
- {
- throw new ConfigurationException("Cannot have 0 for maxNodes on a MRUAlgorithm");
- }
-
- if (log.isDebugEnabled())
- {
- log.debug("parseConfig: name -- " + name + " maxNodes -- "
- + getMaxNodes());
- }
+ if (getMaxNodes() < 0)
+ throw new ConfigurationException("maxNodes not configured");
}
public String toString()
@@ -82,4 +54,11 @@
append(" maxNodes =").append(getMaxNodes());
return str.toString();
}
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ return (obj instanceof MRUConfiguration && super.equals(obj));
+ }
+
}
1.7 +8 -2 JBossCache/src/org/jboss/cache/eviction/EvictionConfiguration.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: EvictionConfiguration.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/eviction/EvictionConfiguration.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- EvictionConfiguration.java 23 Oct 2006 17:39:01 -0000 1.6
+++ EvictionConfiguration.java 27 Oct 2006 19:26:07 -0000 1.7
@@ -7,6 +7,7 @@
package org.jboss.cache.eviction;
import org.jboss.cache.config.ConfigurationException;
+import org.jboss.cache.factories.XmlConfigurationParser;
import org.w3c.dom.Element;
/**
@@ -17,9 +18,14 @@
* It also encapsulates XML parsing and configuration of a given type of EvictionPolicy.
*
* @author Daniel Huang (dhuang at jboss.org)
- * @version $Revision: 1.6 $
+ * @version $Revision: 1.7 $
+ *
+ * @deprecated Used solely by {@link XmlConfigurationParser} to support legacy
+ * configurations. XmlConfigurationParser can also set configurations
+ * by mapping DOM elements to config bean properties via reflection,
+ * which is the preferred approach.
*/
-public interface EvictionConfiguration
+public interface EvictionConfiguration extends EvictionPolicyConfig
{
public static final int WAKEUP_DEFAULT = 5;
public static final int EVENT_QUEUE_SIZE_DEFAULT = 200000;
1.6 +2 -2 JBossCache/src/org/jboss/cache/eviction/LFUAlgorithm.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: LFUAlgorithm.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/eviction/LFUAlgorithm.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- LFUAlgorithm.java 12 Oct 2006 23:03:58 -0000 1.5
+++ LFUAlgorithm.java 27 Oct 2006 19:26:07 -0000 1.6
@@ -29,7 +29,7 @@
* a node is visited, the less likely it will be evicted.
*
* @author Daniel Huang - dhuang at jboss.org 10/2005
- * @version $Revision: 1.5 $
+ * @version $Revision: 1.6 $
*/
public class LFUAlgorithm extends BaseSortedEvictionAlgorithm implements EvictionAlgorithm
{
@@ -48,7 +48,7 @@
log.trace("Deciding whether node in queue " + ne.getFqn() + " requires eviction.");
}
- LFUConfiguration config = (LFUConfiguration) region.getEvictionConfiguration();
+ LFUConfiguration config = (LFUConfiguration) region.getEvictionPolicyConfig();
int size = this.getEvictionQueue().getNumberOfNodes();
if (config.getMaxNodes() != 0 && size > config.getMaxNodes())
{
1.4 +19 -9 JBossCache/src/org/jboss/cache/eviction/EvictionPolicyConfig.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: EvictionPolicyConfig.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/eviction/EvictionPolicyConfig.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- EvictionPolicyConfig.java 30 Aug 2006 19:31:23 -0000 1.3
+++ EvictionPolicyConfig.java 27 Oct 2006 19:26:07 -0000 1.4
@@ -6,10 +6,12 @@
*/
package org.jboss.cache.eviction;
+import org.jboss.cache.config.ConfigurationException;
+
/**
* This class encapsulates the configuration element for the eviction policies.
* <p/>
- * in it's most basic form, it is implemented by {@link DefaultEvictionPolicyConfig}, but
+ * In it's most basic form, it is implemented by {@link EvictionPolicyConfigBase}, but
* more specific eviction policies may subclass or re-implement this interface
* to provide access to more config variables.
*
@@ -17,13 +19,21 @@
*/
public interface EvictionPolicyConfig
{
+ /**
+ * Gets the class name of the {@link EvictionPolicy} implementation
+ * this object will be used to configure. Used by {@link RegionManager}
+ * to instantiate the policy.
+ *
+ * @return fully qualified class name
+ */
public String getEvictionPolicyClass();
- public int getWakeupIntervalSeconds();
-
- public int getMaxNodes();
-
- public int getTimeToLiveSeconds();
-
- public int getRegionCapacity();
+ /**
+ * Validate the configuration. Will be called after any configuration
+ * properties are set.
+ *
+ * @throws ConfigurationException if any values for the configuration
+ * properties are invalid
+ */
+ public void validate() throws ConfigurationException;
}
1.4 +58 -60 JBossCache/src/org/jboss/cache/eviction/ElementSizeConfiguration.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ElementSizeConfiguration.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/eviction/ElementSizeConfiguration.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- ElementSizeConfiguration.java 18 Jul 2006 17:50:56 -0000 1.3
+++ ElementSizeConfiguration.java 27 Oct 2006 19:26:07 -0000 1.4
@@ -6,21 +6,42 @@
*/
package org.jboss.cache.eviction;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.jboss.cache.config.ConfigurationException;
-import org.jboss.cache.xml.XmlHelper;
-import org.w3c.dom.Element;
+import org.jboss.cache.config.Dynamic;
/**
+ * Configuration for {@link ElementSizePolicy}.
+ * <p/>
+ * If configured via XML, expects the following:
+ * <p/>
+ * <pre>
+ * <region name="/region/">
+ * <attribute name="maxElementsPerNode">100</attribute>
+ * <attribute name="maxNodes">10000</attribute>
+ * </region>
+ * </pre>
+ *
+ * Requires a positive "maxElementsPerNode" value otherwise a ConfigurationException is thrown.
+ *
* @author Daniel Huang
- * @version $Revision: 1.3 $
+ * @author Brian Stansberry
+ *
+ * @version $Revision: 1.4 $
*/
-public class ElementSizeConfiguration implements EvictionConfiguration
+public class ElementSizeConfiguration extends EvictionPolicyConfigBase
{
- private static final Log log = LogFactory.getLog(ElementSizeConfiguration.class);
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 2510593544656833758L;
+
+ @Dynamic
private int maxElementsPerNode;
- private int maxNodes;
+
+ public ElementSizeConfiguration()
+ {
+ setEvictionPolicyClass(ElementSizePolicy.class.getName());
+ // Force configuration of maxElementsPerNode
+ setMaxElementsPerNode(-1);
+ }
public int getMaxElementsPerNode()
{
@@ -29,71 +50,48 @@
public void setMaxElementsPerNode(int maxElementsPerNode)
{
+ testImmutability("maxElementsPerNode");
this.maxElementsPerNode = maxElementsPerNode;
}
- public int getMaxNodes()
- {
- return maxNodes;
- }
-
- public void setMaxNodes(int maxNodes)
- {
- this.maxNodes = maxNodes;
- }
-
/**
- * Configure the Element Size Policy with XML.
- * <p/>
- * This method expects the following XML:
- * <p/>
- * <region name="/region/">
- * <attribute name="maxElementsPerNode">100</attribute>
- * <attribute name="maxNodes">10000</attribute>
- * </region>
- *
- * @param element DOM XML containing Element Size Policy configuration.
- * @throws ConfigureException
+ * Requires a positive maxElementsPerNode value or ConfigurationException
+ * is thrown.
*/
- public void parseXMLConfig(Element element) throws ConfigurationException
- {
- String name = element.getAttribute(EvictionConfiguration.NAME);
- if (name == null || name.equals(""))
+ @Override
+ public void validate() throws ConfigurationException
{
- throw new ConfigurationException("Name is required for the eviction region");
+ if (maxElementsPerNode < 0)
+ throw new ConfigurationException("maxElementsPerNode must be configured");
}
- String maxNodes = XmlHelper.getTagContents(element, EvictionConfiguration.MAX_NODES,
- EvictionConfiguration.ATTR, EvictionConfiguration.NAME);
- if (maxNodes != null && !maxNodes.equals(""))
- {
- setMaxNodes(Integer.parseInt(maxNodes));
- }
- else
+ public String toString()
{
- setMaxNodes(0);
+ StringBuffer str = new StringBuffer();
+ str.append("ElementSizeConfiguration: maxElementsPerNode =");
+ str.append(getMaxElementsPerNode()).append(" maxNodes =").append(getMaxNodes());
+ return str.toString();
}
- String maxElementsPerNode = XmlHelper.getTagContents(element, EvictionConfiguration.MAX_ELEMENTS_PER_NODE,
- EvictionConfiguration.ATTR, EvictionConfiguration.NAME);
- if (maxElementsPerNode == null)
+ @Override
+ public boolean equals(Object obj)
{
- throw new ConfigurationException("ElementSizeConfiguration.parseXMLConfig(): Null maxElementsPerNode element");
- }
- setMaxElementsPerNode(Integer.parseInt(maxElementsPerNode));
-
- if (log.isDebugEnabled())
+ if (this == obj)
+ return true;
+ if (obj instanceof ElementSizeConfiguration && super.equals(obj))
{
- log.debug("parseConfig: name -- " + name + " maxNodes -- "
- + getMaxNodes() + " maxElementsPerNode -- " + getMaxElementsPerNode());
+ return this.maxElementsPerNode == ((ElementSizeConfiguration) obj).maxElementsPerNode;
}
+ return false;
}
- public String toString()
+ @Override
+ public int hashCode()
{
- StringBuffer str = new StringBuffer();
- str.append("ElementSizeConfiguration: maxElementsPerNode =");
- str.append(getMaxElementsPerNode()).append(" maxNodes =").append(getMaxNodes());
- return str.toString();
+ int result = super.hashCode();
+ result = 31 * result + maxElementsPerNode;
+ return result;
}
+
+
}
1.6 +34 -59 JBossCache/src/org/jboss/cache/eviction/FIFOConfiguration.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: FIFOConfiguration.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/eviction/FIFOConfiguration.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- FIFOConfiguration.java 18 Jul 2006 17:50:56 -0000 1.5
+++ FIFOConfiguration.java 27 Oct 2006 19:26:07 -0000 1.6
@@ -6,78 +6,45 @@
*/
package org.jboss.cache.eviction;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.xml.XmlHelper;
import org.jboss.cache.config.ConfigurationException;
-import org.w3c.dom.Element;
/**
- * FIFO Configuration for FIFO Eviction Policy.
- *
- * @author Daniel Huang (dhuang at jboss.org)
- * @version $Revision: 1.5 $
- */
-public class FIFOConfiguration implements EvictionConfiguration
-{
- private static final Log log = LogFactory.getLog(FIFOConfiguration.class);
- private int maxNodes;
-
- /**
- * Get the maximum number of nodes or elements configured for the FIFOPolicy.
- *
- * @return maxNodes
- */
- public int getMaxNodes()
- {
- return maxNodes;
- }
-
- public void setMaxNodes(int maxNodes)
- {
- this.maxNodes = maxNodes;
- }
-
- /**
- * Configure the FIFOPolicy using XML.
+ * Configuration for {@link FIFOPolicy}.
* <p/>
- * This method expects a DOM object in the following format specific to FIFO:
+ * If configured via XML, expects the following:
* <p/>
+ * <pre>
* <region name="abc">
* <attribute name="maxNodes">1000</attribute>
* </region>
- * <p/>
- * FIFO requires a "maxNodes" attribute otherwise a ConfigureException is thrown.
+ * </pre>
+ *
+ * Requires a "maxNodes" attribute otherwise a ConfigurationException is thrown.
*
- * @param element XML DOM element containing the proper FIFO configuration XML.
- * @throws ConfigureException
+ * @author Daniel Huang (dhuang at jboss.org)
+ * @version $Revision: 1.6 $
*/
- public void parseXMLConfig(Element element) throws ConfigurationException
- {
- String name = element.getAttribute(NAME);
-
- if (name == null || name.equals(""))
- {
- throw new ConfigurationException("Name is required for the eviction region");
- }
-
- String maxNodes = XmlHelper.getTagContents(element,
- MAX_NODES, EvictionConfiguration.ATTR, EvictionConfiguration.NAME);
- if (maxNodes != null && !maxNodes.equals(""))
- {
- setMaxNodes(Integer.parseInt(maxNodes));
+public class FIFOConfiguration extends EvictionPolicyConfigBase
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -7229715009546277313L;
- }
- else
+ public FIFOConfiguration()
{
- throw new ConfigurationException("FIFOConfiguration requires maxNodes attribute");
+ setEvictionPolicyClass(FIFOPolicy.class.getName());
+ // We require that maxNodes is set
+ setMaxNodes(-1);
}
- if (log.isDebugEnabled())
+ /**
+ * Requires a positive maxNodes value or ConfigurationException
+ * is thrown.
+ */
+ @Override
+ public void validate() throws ConfigurationException
{
- log.debug("parseConfig: name -- " + name + " maxNodes -- "
- + getMaxNodes());
- }
+ if (getMaxNodes() < 0)
+ throw new ConfigurationException("maxNodes not configured");
}
public String toString()
@@ -86,4 +53,12 @@
ret.append("LFUConfiguration: maxNodes = ").append(getMaxNodes());
return ret.toString();
}
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ return (obj instanceof FIFOConfiguration && super.equals(obj));
+ }
+
+
}
1.1 date: 2006/10/27 19:26:07; author: bstansberry; state: Exp;JBossCache/src/org/jboss/cache/eviction/EvictionPolicyConfigBase.java
Index: EvictionPolicyConfigBase.java
===================================================================
package org.jboss.cache.eviction;
import org.jboss.cache.config.ConfigurationComponent;
import org.jboss.cache.config.ConfigurationException;
import org.jboss.cache.config.Dynamic;
/**
* Base implementation of {@link EvictionPolicyConfig}. Adds properties
* for the most commonly used config elements.
*
* @author <a href="mailto:manik at jboss.org">Manik Surtani</a>
*/
public abstract class EvictionPolicyConfigBase
extends ConfigurationComponent
implements EvictionPolicyConfig
{
/** The serialVersionUID */
private static final long serialVersionUID = 4591691674370188932L;
private String evictionPolicyClass;
@Dynamic
private int maxNodes = 0;
/**
* Can only be instantiated by a subclass.
*
*/
protected EvictionPolicyConfigBase() {}
public String getEvictionPolicyClass()
{
return evictionPolicyClass;
}
public void setEvictionPolicyClass(String evictionPolicyClass)
{
testImmutability("evictionPolicyClass");
this.evictionPolicyClass = evictionPolicyClass;
}
public int getMaxNodes()
{
return maxNodes;
}
public void setMaxNodes(int maxNodes)
{
testImmutability("maxNodes");
this.maxNodes = maxNodes;
}
public void validate() throws ConfigurationException
{
// no-op
}
@Override
public boolean equals(Object obj)
{
if (this == obj)
return true;
if (obj instanceof EvictionPolicyConfigBase)
{
EvictionPolicyConfigBase other = (EvictionPolicyConfigBase) obj;
return this.maxNodes == other.maxNodes
&& safeEquals(this.evictionPolicyClass, other.evictionPolicyClass);
}
return false;
}
@Override
public int hashCode()
{
int result = 17;
result = 31 * result + maxNodes;
result = 31 * result + (evictionPolicyClass == null ? 0 : evictionPolicyClass.hashCode());
return result;
}
}
More information about the jboss-cvs-commits
mailing list