Author: manik.surtani(a)jboss.com
Date: 2008-08-15 06:59:40 -0400 (Fri, 15 Aug 2008)
New Revision: 6562
Added:
core/trunk/src/main/java/org/jboss/cache/config/CloneableConfigurationComponent.java
core/trunk/src/main/java/org/jboss/cache/config/EvictionAlgorithmConfig.java
core/trunk/src/main/java/org/jboss/cache/eviction/DefaultEvictionActionPolicy.java
core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizeAlgorithmConfig.java
core/trunk/src/main/java/org/jboss/cache/eviction/EvictionActionPolicy.java
core/trunk/src/main/java/org/jboss/cache/eviction/EvictionAlgorithmConfigBase.java
core/trunk/src/main/java/org/jboss/cache/eviction/EvictionEvent.java
core/trunk/src/main/java/org/jboss/cache/eviction/EvictionEventType.java
core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationAlgorithmConfig.java
core/trunk/src/main/java/org/jboss/cache/eviction/FIFOAlgorithmConfig.java
core/trunk/src/main/java/org/jboss/cache/eviction/LFUAlgorithmConfig.java
core/trunk/src/main/java/org/jboss/cache/eviction/LRUAlgorithmConfig.java
core/trunk/src/main/java/org/jboss/cache/eviction/MRUAlgorithmConfig.java
core/trunk/src/main/java/org/jboss/cache/eviction/Modernizable.java
core/trunk/src/main/java/org/jboss/cache/eviction/NullEvictionAlgorithmConfig.java
core/trunk/src/main/java/org/jboss/cache/eviction/RemoveOnEvictActionPolicy.java
Removed:
core/trunk/src/main/java/org/jboss/cache/eviction/EvictedEventNode.java
core/trunk/src/main/java/org/jboss/cache/eviction/NodeEventType.java
core/trunk/src/test/java/org/jboss/cache/eviction/DummyEvictionConfiguration.java
core/trunk/src/test/java/org/jboss/cache/eviction/DummyEvictionPolicy.java
core/trunk/src/test/java/org/jboss/cache/interceptors/EvictionInterceptorTest.java
Modified:
core/trunk/src/main/java/org/jboss/cache/Region.java
core/trunk/src/main/java/org/jboss/cache/RegionImpl.java
core/trunk/src/main/java/org/jboss/cache/RegionManager.java
core/trunk/src/main/java/org/jboss/cache/RegionManagerImpl.java
core/trunk/src/main/java/org/jboss/cache/config/ConfigurationComponent.java
core/trunk/src/main/java/org/jboss/cache/config/EvictionConfig.java
core/trunk/src/main/java/org/jboss/cache/config/EvictionPolicyConfig.java
core/trunk/src/main/java/org/jboss/cache/config/EvictionRegionConfig.java
core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigHelper.java
core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser2x.java
core/trunk/src/main/java/org/jboss/cache/config/parsing/element/EvictionElementParser.java
core/trunk/src/main/java/org/jboss/cache/eviction/BaseEvictionAlgorithm.java
core/trunk/src/main/java/org/jboss/cache/eviction/BaseEvictionPolicy.java
core/trunk/src/main/java/org/jboss/cache/eviction/BaseSortedEvictionAlgorithm.java
core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizeAlgorithm.java
core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizeConfiguration.java
core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizePolicy.java
core/trunk/src/main/java/org/jboss/cache/eviction/EvictionAlgorithm.java
core/trunk/src/main/java/org/jboss/cache/eviction/EvictionException.java
core/trunk/src/main/java/org/jboss/cache/eviction/EvictionPolicy.java
core/trunk/src/main/java/org/jboss/cache/eviction/EvictionPolicyConfigBase.java
core/trunk/src/main/java/org/jboss/cache/eviction/EvictionTimerTask.java
core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationAlgorithm.java
core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationConfiguration.java
core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationPolicy.java
core/trunk/src/main/java/org/jboss/cache/eviction/FIFOAlgorithm.java
core/trunk/src/main/java/org/jboss/cache/eviction/FIFOConfiguration.java
core/trunk/src/main/java/org/jboss/cache/eviction/FIFOPolicy.java
core/trunk/src/main/java/org/jboss/cache/eviction/LFUAlgorithm.java
core/trunk/src/main/java/org/jboss/cache/eviction/LFUConfiguration.java
core/trunk/src/main/java/org/jboss/cache/eviction/LFUPolicy.java
core/trunk/src/main/java/org/jboss/cache/eviction/LRUAlgorithm.java
core/trunk/src/main/java/org/jboss/cache/eviction/LRUConfiguration.java
core/trunk/src/main/java/org/jboss/cache/eviction/LRUPolicy.java
core/trunk/src/main/java/org/jboss/cache/eviction/MRUAlgorithm.java
core/trunk/src/main/java/org/jboss/cache/eviction/MRUConfiguration.java
core/trunk/src/main/java/org/jboss/cache/eviction/MRUPolicy.java
core/trunk/src/main/java/org/jboss/cache/eviction/NullEvictionAlgorithm.java
core/trunk/src/main/java/org/jboss/cache/eviction/NullEvictionPolicy.java
core/trunk/src/main/java/org/jboss/cache/eviction/NullEvictionPolicyConfig.java
core/trunk/src/main/java/org/jboss/cache/interceptors/BuddyRegionAwareEvictionInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/EvictionInterceptor.java
core/trunk/src/main/java/org/jboss/cache/statetransfer/LegacyStateTransferIntegrator.java
core/trunk/src/main/java/org/jboss/cache/util/Util.java
core/trunk/src/test/java/org/jboss/cache/api/ResidentNodesTest.java
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationWithCacheLoaderTest.java
core/trunk/src/test/java/org/jboss/cache/buddyreplication/EvictionOfBuddyBackupsTest.java
core/trunk/src/test/java/org/jboss/cache/config/ConfigurationCloningTest.java
core/trunk/src/test/java/org/jboss/cache/config/parsing/EvictionElementParserTest.java
core/trunk/src/test/java/org/jboss/cache/config/parsing/XmlConfigurationParserTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/BaseEvictionAlgorithmTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/ConcurrentEvictionTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizeAlgorithmTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizeConfigurationTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizePolicyTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/EvictionConfigurationTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/ExpirationPolicyTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/FIFOAlgorithmTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/FIFOConfigurationTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/FIFOPolicyTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/LFUAlgorithmTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/LFUConfigurationTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/LFUPolicyTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/LRUAlgorithmTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/LRUConfigurationTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/LRUPolicyTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/MRUAlgorithmTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/MRUConfigurationTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/MRUPolicyTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/NullEvictionConfigTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/NullEvictionPolicyTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/OptimisticEvictionTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/ProgrammaticLRUPolicyTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/RegionManagerTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/RegionTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/ReplicatedLRUPolicyTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/minttl/FIFOMinTTLTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/minttl/LFUMinTTLTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/minttl/LRUMinTTLTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/minttl/MRUMinTTLTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/minttl/MinTTLTestBase.java
core/trunk/src/test/java/org/jboss/cache/factories/UnitTestCacheConfigurationFactory.java
core/trunk/src/test/java/org/jboss/cache/invalidation/TombstoneEvictionTest.java
core/trunk/src/test/java/org/jboss/cache/jmx/deprecated/LegacyConfigurationTest.java
core/trunk/src/test/java/org/jboss/cache/marshall/CacheLoaderMarshallingJDBCTest.java
core/trunk/src/test/java/org/jboss/cache/marshall/CacheLoaderMarshallingTest.java
core/trunk/src/test/java/org/jboss/cache/passivation/PassivationActivationCallbacksTestCase.java
core/trunk/src/test/java/org/jboss/cache/passivation/ReplicatedPassivationIntegrationTest.java
core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransferConcurrencyTest.java
core/trunk/src/test/java/org/jboss/cache/util/internals/EvictionController.java
core/trunk/src/test/resources/unit-test-cache-service.xml
Log:
Changes to eviction interfaces
Modified: core/trunk/src/main/java/org/jboss/cache/Region.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/Region.java 2008-08-14 19:16:15 UTC (rev
6561)
+++ core/trunk/src/main/java/org/jboss/cache/Region.java 2008-08-15 10:59:40 UTC (rev
6562)
@@ -7,11 +7,8 @@
package org.jboss.cache;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.config.EvictionPolicyConfig;
import org.jboss.cache.config.EvictionRegionConfig;
-import org.jboss.cache.eviction.EvictedEventNode;
-import org.jboss.cache.eviction.EvictionPolicy;
-import org.jboss.cache.eviction.LRUPolicy;
+import org.jboss.cache.eviction.EvictionEvent;
/**
* Defines characteristics such as class loading and eviction of {@link
org.jboss.cache.Node}s belonging to a Region in a {@link Cache}.
@@ -19,7 +16,7 @@
* All nodes and child nodes of this Fqn belong to this region.
* <p/>
* If a region is to be recognised as an eviction region (region of type {@link
Type#EVICTION} then
- * it <b>must</b> have an {@link org.jboss.cache.config.EvictionPolicyConfig}
set using {@link #setEvictionPolicy(org.jboss.cache.config.EvictionPolicyConfig)}.
+ * it <b>must</b> have an {@link org.jboss.cache.config.EvictionRegionConfig}
set using {@link #setEvictionRegionConfig(org.jboss.cache.config.EvictionRegionConfig)}.
* <p/>
* Similarly, to be recognised as a marshalling region (region of type {@link
Type#MARSHALLING} then it <b>must</b> have a
* {@link ClassLoader} registered using {@link
#registerContextClassLoader(ClassLoader)}.
@@ -33,7 +30,6 @@
*/
public interface Region extends Comparable<Region>
{
-
/**
* Types of regions.
*/
@@ -114,67 +110,52 @@
ClassLoader getClassLoader();
/**
- * Configures an eviction policy for this region.
- *
- * @param evictionPolicyConfig configuration to set
+ * Processes the eviction queues (primary and recycle queues) associated with this
region. A no-op if this is not an eviction region.
*/
- void setEvictionPolicy(EvictionPolicyConfig evictionPolicyConfig);
+ void processEvictionQueues();
/**
- * Returns an eviction policy configuration.
- *
- * @return an eviction policy configuration
+ * Clears the node event queue used for processing eviction.
*/
- EvictionPolicyConfig getEvictionPolicyConfig();
+ void resetEvictionQueues();
/**
- * Returns an eviction policy.
+ * Configures this region for eviction.
*
- * @return an eviction policy
+ * @param evictionRegionConfig configuration to set
*/
- EvictionPolicy getEvictionPolicy();
+ void setEvictionRegionConfig(EvictionRegionConfig evictionRegionConfig);
/**
- * Returns an eviction region configuration for this region.
- *
- * @return an eviction region configuration
+ * @return the eviction region config, if any, set on the current region.
*/
EvictionRegionConfig getEvictionRegionConfig();
/**
- * Clears the node event queue used for processing eviction.
+ * Registers an eviction event on the region's eviction event queue for later
processing by
+ * {@link #processEvictionQueues()}.
*
- * @see #nodeEventQueueSize()
+ * @param fqn passed in to the constructor of {@link
org.jboss.cache.eviction.EvictionEvent}
+ * @param eventType passed in to the constructor of {@link
org.jboss.cache.eviction.EvictionEvent}
+ * @param elementDifference passed in to the constructor of {@link
org.jboss.cache.eviction.EvictionEvent}
+ * @return an EvictedEventNode that has been created for this queue
*/
- void resetEvictionQueues();
+ EvictionEvent registerEvictionEvent(Fqn fqn, EvictionEvent.Type eventType, int
elementDifference);
/**
- * Returns the size of the node event queue, used by the eviction thread.
+ * An overloaded version of {@link #registerEvictionEvent(Fqn,
org.jboss.cache.eviction.EvictionEvent.Type, int)} which
+ * uses a default elementDifference value.
*
- * @return number of events
+ * @param fqn passed in to the constructor of {@link
org.jboss.cache.eviction.EvictionEvent}
+ * @param eventType passed in to the constructor of {@link
org.jboss.cache.eviction.EvictionEvent}
+ * @return an EvictedEventNode that has been created for this queue
*/
- int nodeEventQueueSize();
+ EvictionEvent registerEvictionEvent(Fqn fqn, EvictionEvent.Type eventType);
/**
- * Returns the most recent {@link org.jboss.cache.eviction.EvictedEventNode} added to
the event queue by
- * {@link #putNodeEvent(EvictedEventNode)}.
- *
- * @return the last {@link org.jboss.cache.eviction.EvictedEventNode}, or null if no
more events exist
- */
- EvictedEventNode takeLastEventNode();
-
- /**
- * Adds an {@link org.jboss.cache.eviction.EvictedEventNode} to the internal queue for
processing
- * by the eviction thread.
- *
- * @param event event to add
- */
- void putNodeEvent(EvictedEventNode event);
-
- /**
* Marks a {@link org.jboss.cache.Node} as currently in use, by adding an event to the
eviction queue.
- * If there is an {@link EvictionPolicy} associated with this region, and
- * it respects this event (e.g., {@link LRUPolicy} does), then the {@link
org.jboss.cache.Node} will not
+ * If there is an {@link org.jboss.cache.config.EvictionRegionConfig} associated with
this region, and
+ * it respects this event (e.g., {@link org.jboss.cache.eviction.LRUAlgorithm} does),
then the {@link org.jboss.cache.Node} will not
* be evicted until {@link #unmarkNodeCurrentlyInUse(Fqn)} is invoked.
* <p/>
* This mechanism can be used to prevent eviction of data that the application
Modified: core/trunk/src/main/java/org/jboss/cache/RegionImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RegionImpl.java 2008-08-14 19:16:15 UTC (rev
6561)
+++ core/trunk/src/main/java/org/jboss/cache/RegionImpl.java 2008-08-15 10:59:40 UTC (rev
6562)
@@ -9,16 +9,15 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.config.EvictionPolicyConfig;
+import org.jboss.cache.config.EvictionAlgorithmConfig;
import org.jboss.cache.config.EvictionRegionConfig;
-import org.jboss.cache.eviction.EvictedEventNode;
-import org.jboss.cache.eviction.EvictionPolicy;
-import org.jboss.cache.eviction.NodeEventType;
+import org.jboss.cache.eviction.EvictionActionPolicy;
+import org.jboss.cache.eviction.EvictionAlgorithm;
+import org.jboss.cache.eviction.EvictionEvent;
import org.jboss.cache.util.Util;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.TimeUnit;
/**
* Default implementation of a {@link Region}
@@ -28,16 +27,17 @@
public class RegionImpl implements Region
{
private static final Log log = LogFactory.getLog(RegionImpl.class);
-
+ private static final boolean trace = log.isTraceEnabled();
private final RegionManager regionManager;
private Fqn fqn;
private Status status;
private ClassLoader classLoader;
- private BlockingQueue<EvictedEventNode> nodeEventQueue = null;
+ private BlockingQueue<EvictionEvent> evictionEventQueue = null;
private int capacityWarnThreshold = 0;
- private EvictionRegionConfig configuration = new EvictionRegionConfig();
- private EvictionPolicy policy;
+ private EvictionRegionConfig evictionRegionConfig;
+ private EvictionAlgorithm evictionAlgorithm;
+
/**
* Constructs a marshalling region from an fqn and region manager.
*/
@@ -51,11 +51,10 @@
/**
* Constructs an eviction region from a policy and configuration, defined by an fqn
and region manager.
*/
- public RegionImpl(EvictionPolicy policy, EvictionRegionConfig config, Fqn fqn,
RegionManager regionManager)
+ public RegionImpl(EvictionRegionConfig config, Fqn fqn, RegionManager regionManager)
{
this(fqn, regionManager);
- this.configuration = config;
- this.policy = policy;
+ this.evictionRegionConfig = config;
createQueue();
}
@@ -105,6 +104,11 @@
return classLoader;
}
+ public void processEvictionQueues()
+ {
+ evictionAlgorithm.process(evictionEventQueue);
+ }
+
public Fqn getFqn()
{
return fqn;
@@ -127,17 +131,19 @@
// -------- eviction stuff -----
+ public BlockingQueue<EvictionEvent> getEvictionEventQueue()
+ {
+ return evictionEventQueue;
+ }
+
public void markNodeCurrentlyInUse(Fqn fqn, long timeout)
{
- EvictedEventNode markUse = new EvictedEventNode(fqn,
NodeEventType.MARK_IN_USE_EVENT);
- markUse.setInUseTimeout(timeout);
- putNodeEvent(markUse);
+ registerEvictionEvent(fqn, EvictionEvent.Type.MARK_IN_USE_EVENT,
0).setInUseTimeout(timeout);
}
public void unmarkNodeCurrentlyInUse(Fqn fqn)
{
- EvictedEventNode markNoUse = new EvictedEventNode(fqn,
NodeEventType.UNMARK_USE_EVENT);
- putNodeEvent(markNoUse);
+ registerEvictionEvent(fqn, EvictionEvent.Type.UNMARK_USE_EVENT, 0);
}
@Override
@@ -147,8 +153,8 @@
"fqn=" + fqn +
"; classloader=" + classLoader +
"; status=" + status +
- "; eviction=" + (getEvictionPolicy() != null) +
- "; timerThreadRegistered=" + (getEvictionPolicy() != null
&& regionManager.getEvictionTimerTask().isRegionRegisteredForProcessing(this)) +
+ "; eviction=" + (evictionAlgorithm != null) +
+ "; timerThreadRegistered=" + (evictionAlgorithm != null &&
regionManager.getEvictionTimerTask().isRegionRegisteredForProcessing(this)) +
'}';
}
@@ -176,105 +182,97 @@
return (fqn != null ? fqn.hashCode() : 0);
}
- public void putNodeEvent(EvictedEventNode event)
+ public void resetEvictionQueues()
{
- try
- {
- if (nodeEventQueue == null) createQueue();// in case the queue does not exist
yet.
- if (nodeEventQueue.size() > capacityWarnThreshold)
- {
- log.warn("putNodeEvent(): eviction node event queue size is at 98%
threshold value of capacity: " + configuration.getEventQueueSize() +
- " Region: " + fqn +
- " You will need to reduce the wakeUpIntervalSeconds
parameter.");
- }
- nodeEventQueue.put(event);
- }
- catch (InterruptedException e)
- {
- log.debug("give up put", e);
- }
+ evictionEventQueue.clear();
}
- public EvictedEventNode takeLastEventNode()
+ public void setEvictionRegionConfig(EvictionRegionConfig evictionRegionConfig)
{
+ this.evictionRegionConfig = evictionRegionConfig;
+ evictionAlgorithm =
createEvictionAlgorithm(evictionRegionConfig.getEvictionAlgorithmConfig(),
evictionRegionConfig.getEvictionActionPolicyClassName());
+ regionManager.getEvictionTimerTask().addRegionToProcess(this);
+ if (evictionEventQueue == null) createQueue();
+ evictionAlgorithm.initialize();
+ }
+
+ public EvictionRegionConfig getEvictionRegionConfig()
+ {
+ return evictionRegionConfig;
+ }
+
+ public EvictionEvent registerEvictionEvent(Fqn fqn, EvictionEvent.Type eventType)
+ {
+ return registerEvictionEvent(fqn, eventType, 0);
+ }
+
+ public EvictionEvent registerEvictionEvent(Fqn fqn, EvictionEvent.Type eventType, int
elementDifference)
+ {
+ if (evictionAlgorithm.canIgnoreEvent(eventType)) return null;
+
+ EvictionEvent event = new EvictionEvent(fqn, eventType, elementDifference);
try
{
- return nodeEventQueue.poll(0, TimeUnit.SECONDS);
+ if (evictionEventQueue == null) createQueue();// in case the queue does not
exist yet.
+ if (evictionEventQueue.size() > capacityWarnThreshold)
+ {
+ if (log.isWarnEnabled())
+ log.warn("putNodeEvent(): eviction node event queue size is at 98%
threshold value of capacity: " + evictionRegionConfig.getEventQueueSize() +
+ " Region: " + fqn +
+ " You will need to reduce the wakeUpIntervalSeconds
parameter.");
+ }
+ evictionEventQueue.put(event);
}
catch (InterruptedException e)
{
+ if (log.isDebugEnabled()) log.debug("Interrupted on adding event",
e);
+ // reinstate interrupt flag
Thread.currentThread().interrupt();
}
- return null;
+ return event;
}
- public int nodeEventQueueSize()
- {
- return nodeEventQueue.size();
- }
-
- public void resetEvictionQueues()
- {
- nodeEventQueue.clear();
- }
-
private void createQueue()
{
- if (nodeEventQueue == null)
+ if (evictionEventQueue == null)
{
- if (configuration == null)
+ if (evictionRegionConfig == null)
{
throw new IllegalArgumentException("null eviction configuration");
}
- int size = configuration.getEventQueueSize();
+ int size = evictionRegionConfig.getEventQueueSize();
capacityWarnThreshold = (98 * size) / 100 - 100;
if (capacityWarnThreshold <= 0)
{
throw new RuntimeException("Capacity warn threshold used in eviction is
smaller than 1.");
}
- nodeEventQueue = new LinkedBlockingQueue<EvictedEventNode>(size);
+ evictionEventQueue = new LinkedBlockingQueue<EvictionEvent>(size);
}
}
- public EvictionRegionConfig getEvictionRegionConfig()
+ private EvictionAlgorithm createEvictionAlgorithm(EvictionAlgorithmConfig algoConfig,
String evictionActionPolicyClass)
{
- return this.configuration;
- }
+ if (algoConfig == null)
+ throw new IllegalArgumentException("Eviction algorithm class must not be
null!");
- public EvictionPolicyConfig getEvictionPolicyConfig()
- {
- return configuration == null ? null : configuration.getEvictionPolicyConfig();
- }
+ if (evictionActionPolicyClass == null)
+ throw new IllegalArgumentException("Eviction action policy class must not
be null!");
- public EvictionPolicy getEvictionPolicy()
- {
- return policy;
- }
-
- public void setEvictionPolicy(EvictionPolicyConfig evictionPolicyConfig)
- {
- configuration.setEvictionPolicyConfig(evictionPolicyConfig);
- policy = createPolicy(evictionPolicyConfig.getEvictionPolicyClass());
- regionManager.getEvictionTimerTask().addRegionToProcess(this);
- if (nodeEventQueue == null) createQueue();
- }
-
- private EvictionPolicy createPolicy(String className)
- {
- if (className == null)
- {
- throw new IllegalArgumentException("null className");
- }
try
{
- if (log.isTraceEnabled()) log.trace("Instantiating " + className);
- EvictionPolicy ep = (EvictionPolicy) Util.loadClass(className).newInstance();
- ep.setCache(regionManager.getCache());
- return ep;
+ if (trace) log.trace("Instantiating " + evictionActionPolicyClass);
+ EvictionActionPolicy actionPolicy = (EvictionActionPolicy)
Util.getInstance(evictionActionPolicyClass);
+ actionPolicy.setCache(regionManager.getCache());
+
+ if (trace) log.trace("Instantiating " +
algoConfig.getEvictionAlgorithmClassName());
+ EvictionAlgorithm algorithm = (EvictionAlgorithm)
Util.getInstance(algoConfig.getEvictionAlgorithmClassName());
+ algorithm.setEvictionActionPolicy(actionPolicy);
+ algorithm.assignToRegion(fqn, regionManager.getCache(), algoConfig,
regionManager.getConfiguration());
+ return algorithm;
}
catch (Exception e)
{
- log.fatal("Unable to instantiate eviction policy class " + className,
e);
+ log.fatal("Unable to instantiate eviction algorithm " +
algoConfig.getEvictionAlgorithmClassName(), e);
throw new IllegalStateException(e);
}
}
@@ -282,14 +280,13 @@
public Region copy(Fqn newRoot)
{
RegionImpl clone;
- clone = new RegionImpl(policy, configuration, Fqn.fromRelativeFqn(newRoot, fqn),
regionManager);
+ clone = new RegionImpl(evictionRegionConfig, Fqn.fromRelativeFqn(newRoot, fqn),
regionManager);
clone.status = status;
// we also need to copy all of the eviction event nodes to the clone's queue
clone.createQueue();
- for (EvictedEventNode een : this.nodeEventQueue)
+ for (EvictionEvent een : this.evictionEventQueue)
{
- EvictedEventNode cloneEEN = een.copy(newRoot);
- clone.putNodeEvent(cloneEEN);
+ clone.registerEvictionEvent(een.getFqn(), een.getEventType(),
een.getElementDifference());
}
return clone;
}
Modified: core/trunk/src/main/java/org/jboss/cache/RegionManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RegionManager.java 2008-08-14 19:16:15 UTC
(rev 6561)
+++ core/trunk/src/main/java/org/jboss/cache/RegionManager.java 2008-08-15 10:59:40 UTC
(rev 6562)
@@ -1,5 +1,6 @@
package org.jboss.cache;
+import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.EvictionConfig;
import org.jboss.cache.eviction.EvictionTimerTask;
@@ -176,4 +177,9 @@
* @return the eviction timer task attached to the region manager
*/
EvictionTimerTask getEvictionTimerTask();
+
+ /**
+ * @return the configuration
+ */
+ Configuration getConfiguration();
}
Modified: core/trunk/src/main/java/org/jboss/cache/RegionManagerImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RegionManagerImpl.java 2008-08-14 19:16:15
UTC (rev 6561)
+++ core/trunk/src/main/java/org/jboss/cache/RegionManagerImpl.java 2008-08-15 10:59:40
UTC (rev 6562)
@@ -8,8 +8,8 @@
import org.jboss.cache.buddyreplication.BuddyManager;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.ConfigurationException;
+import org.jboss.cache.config.EvictionAlgorithmConfig;
import org.jboss.cache.config.EvictionConfig;
-import org.jboss.cache.config.EvictionPolicyConfig;
import org.jboss.cache.config.EvictionRegionConfig;
import org.jboss.cache.eviction.EvictionTimerTask;
import org.jboss.cache.factories.annotations.Destroy;
@@ -92,16 +92,21 @@
@Start
public void start()
{
- log.trace("Starting region manager");
+ if (trace) log.trace("Starting region manager");
isUsingBR = configuration.getBuddyReplicationConfig() != null &&
configuration.getBuddyReplicationConfig().isEnabled();
if (configuration.getEvictionConfig() != null
&& configuration.getEvictionConfig().isValidConfig())
{
+ // start with the default region
+ EvictionRegionConfig defaultRegion =
configuration.getEvictionConfig().getDefaultEvictionRegionConfig();
+ defaultRegion.getEvictionAlgorithmConfig().validate();
+
// validate individual region configs now
for (EvictionRegionConfig erc :
configuration.getEvictionConfig().getEvictionRegionConfigs())
{
- EvictionPolicyConfig epc = erc.getEvictionPolicyConfig();
- if (epc != null) epc.validate();
+ evictionConfig.applyDefaults(erc);
+ EvictionAlgorithmConfig eac = erc.getEvictionAlgorithmConfig();
+ if (eac != null) eac.validate();
}
setEvictionConfig(configuration.getEvictionConfig());
@@ -200,7 +205,7 @@
// mandates that class loaders be registered for marshalling regions.
if (type == ANY
|| (type == MARSHALLING && r.getClassLoader() != null)
- || (type == EVICTION && r.getEvictionPolicyConfig() != null))
+ || (type == EVICTION && r.getEvictionRegionConfig() != null))
{
return r;
}
@@ -235,7 +240,7 @@
// mandates that class loaders be registered for marshalling regions.
if (type == ANY
|| (type == MARSHALLING && r.getClassLoader() != null)
- || (type == EVICTION && r.getEvictionPolicyConfig() != null))
+ || (type == EVICTION && r.getEvictionRegionConfig() != null))
{
nextBestThing = r;
}
@@ -264,7 +269,7 @@
Region r = regionsRegistry.remove(fqn);
if (r == null) return false;
- if (isUsingEvictions() && r.getEvictionPolicy() != null)
+ if (isUsingEvictions() && r.getEvictionRegionConfig() != null)
{
evictionTimerTask.removeRegionToProcess(r);
}
@@ -276,6 +281,11 @@
return evictionTimerTask;
}
+ public Configuration getConfiguration()
+ {
+ return configuration;
+ }
+
public void activate(Fqn fqn) throws RegionNotEmptyException
{
activate(fqn, false);
@@ -600,7 +610,7 @@
case ANY:
return true;
case EVICTION:
- return r.getEvictionPolicy() != null &&
evictionTimerTask.isRegionRegisteredForProcessing(r);
+ return r.getEvictionRegionConfig() != null &&
evictionTimerTask.isRegionRegisteredForProcessing(r);
case MARSHALLING:
return r.isActive() && r.getClassLoader() != null;
}
@@ -671,7 +681,7 @@
// we need to loop thru the regions and only select specific regions to rtn.
for (Region r : regionsRegistry.values())
{
- if ((type == EVICTION && r.getEvictionPolicy() != null &&
evictionTimerTask.isRegionRegisteredForProcessing(r)) ||
+ if ((type == EVICTION && r.getEvictionRegionConfig() != null
&& evictionTimerTask.isRegionRegisteredForProcessing(r)) ||
(type == MARSHALLING && r.isActive() &&
r.getClassLoader() != null))
regions.add(r);
}
@@ -698,24 +708,24 @@
// JBAS-1288
// Try to establish a default region if there isn't one already
- boolean needDefault;
+// boolean needDefault;
List<EvictionRegionConfig> ercs = evictionConfig.getEvictionRegionConfigs();
// Only add a default region if there are no regions. This is
// contrary to the idea that there *must* be a default region, but some
// unit tests fail w/ APPROACH 1, so for now we go with this approach.
- needDefault = ercs.size() == 0;
+// needDefault = ercs.size() == 0;
+ ercs.add(0, evictionConfig.getDefaultEvictionRegionConfig());
+// if (needDefault)
+// {
+// // This may throw ConfigurationException if there is no default
+// // eviction policy class
+// EvictionRegionConfig dflt =
evictionConfig.createDefaultEvictionRegionConfig();
+// ercs.add(0, dflt); // put it first
+// // Need to pass this back into the evictionConfig so it knows
+// // about the new region
+// evictionConfig.setEvictionRegionConfigs(ercs);
+// }
- if (needDefault)
- {
- // This may throw ConfigurationException if there is no default
- // eviction policy class
- EvictionRegionConfig dflt = evictionConfig.createDefaultEvictionRegionConfig();
- ercs.add(0, dflt); // put it first
- // Need to pass this back into the evictionConfig so it knows
- // about the new region
- evictionConfig.setEvictionRegionConfigs(ercs);
- }
-
// create regions for the regions defined in the evictionConfig.
// scan to be sure the _default_ region isn't added twice
boolean setDefault = false;
@@ -724,18 +734,19 @@
Fqn fqn = erc.getRegionFqn();
if (trace) log.trace("Creating eviction region " + fqn);
- if (fqn.equals(DEFAULT_REGION))
+ if (fqn.equals(DEFAULT_REGION) || fqn.isRoot())
{
if (setDefault)
{
throw new ConfigurationException("A default region for evictions has
already been set for this cache");
}
- if (trace) log.trace("Applying settings for " + DEFAULT_REGION +
" to Fqn.ROOT");
+ if (trace) log.trace("Applying settings for default region to
Fqn.ROOT");
fqn = Fqn.ROOT;
setDefault = true;
}
Region r = getRegion(fqn, true);
- r.setEvictionPolicy(erc.getEvictionPolicyConfig());
+ evictionConfig.applyDefaults(erc);
+ r.setEvictionRegionConfig(erc);
}
}
Added:
core/trunk/src/main/java/org/jboss/cache/config/CloneableConfigurationComponent.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/CloneableConfigurationComponent.java
(rev 0)
+++
core/trunk/src/main/java/org/jboss/cache/config/CloneableConfigurationComponent.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -0,0 +1,14 @@
+package org.jboss.cache.config;
+
+import java.io.Serializable;
+
+/**
+ * Interface for all configurable components
+ *
+ * @author Manik Surtani (<a
href="mailto:manik@jboss.org">manik@jboss.org</a>)
+ * @since 3.0
+ */
+public interface CloneableConfigurationComponent extends Serializable, Cloneable
+{
+ CloneableConfigurationComponent clone() throws CloneNotSupportedException;
+}
Modified: core/trunk/src/main/java/org/jboss/cache/config/ConfigurationComponent.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/ConfigurationComponent.java 2008-08-14
19:16:15 UTC (rev 6561)
+++ core/trunk/src/main/java/org/jboss/cache/config/ConfigurationComponent.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -14,7 +14,6 @@
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.factories.annotations.Start;
-import java.io.Serializable;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
@@ -28,7 +27,7 @@
* @version $Revision$
* @see #testImmutability(String)
*/
-public abstract class ConfigurationComponent implements Serializable, Cloneable
+public abstract class ConfigurationComponent implements CloneableConfigurationComponent
{
private static final long serialVersionUID = 4879873994727821938L;
@@ -120,11 +119,6 @@
}
}
- /**
- * Sets a back-reference to the cache associated with this configuration
- *
- * @param cache
- */
public void setCache(CacheSPI cache)
{
this.cache = cache;
@@ -150,7 +144,7 @@
}
@Override
- public ConfigurationComponent clone() throws CloneNotSupportedException
+ public CloneableConfigurationComponent clone() throws CloneNotSupportedException
{
ConfigurationComponent c = (ConfigurationComponent) super.clone();
c.setCache(null);
Added: core/trunk/src/main/java/org/jboss/cache/config/EvictionAlgorithmConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/EvictionAlgorithmConfig.java
(rev 0)
+++
core/trunk/src/main/java/org/jboss/cache/config/EvictionAlgorithmConfig.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -0,0 +1,41 @@
+package org.jboss.cache.config;
+
+/**
+ * An interface used to configure an eviction algorithm. Replaces the deprecated {@link
org.jboss.cache.config.EvictionPolicyConfig}.
+ * <p/>
+ * In it's most basic form, it is implemented by {@link
org.jboss.cache.eviction.EvictionAlgorithmConfigBase}, but
+ * more specific eviction policies may subclass {@link
org.jboss.cache.eviction.EvictionAlgorithmConfigBase} or re-implement
+ * this interface to provide access to more config variables.
+ *
+ * @author Manik Surtani (<a
href="mailto:manik@jboss.org">manik@jboss.org</a>)
+ * @since 3.0
+ */
+public interface EvictionAlgorithmConfig extends CloneableConfigurationComponent
+{
+ /**
+ * Gets the class name of the {@link org.jboss.cache.eviction.EvictionAlgorithm}
implementation
+ * this object will configure.
+ *
+ * @return fully qualified class name
+ */
+ String getEvictionAlgorithmClassName();
+
+ /**
+ * Validate the configuration. Will be called after any configuration
+ * properties are set.
+ *
+ * @throws ConfigurationException if any values for the configuration
+ * properties are invalid
+ */
+ void validate() throws ConfigurationException;
+
+ /**
+ * Resets the values to their defaults.
+ */
+ void reset();
+
+ /**
+ * @return a clone of the EvictionAlgorithmConfig.
+ */
+ EvictionAlgorithmConfig clone() throws CloneNotSupportedException;
+}
Modified: core/trunk/src/main/java/org/jboss/cache/config/EvictionConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/EvictionConfig.java 2008-08-14
19:16:15 UTC (rev 6561)
+++ core/trunk/src/main/java/org/jboss/cache/config/EvictionConfig.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -22,11 +22,11 @@
package org.jboss.cache.config;
import org.jboss.cache.Fqn;
-import org.jboss.cache.RegionManagerImpl;
-import org.jboss.cache.eviction.EvictionPolicy;
+import org.jboss.cache.eviction.DefaultEvictionActionPolicy;
-import java.util.ArrayList;
+import java.util.LinkedList;
import java.util.List;
+import java.util.concurrent.TimeUnit;
public class EvictionConfig extends ConfigurationComponent
{
@@ -35,51 +35,96 @@
*/
private static final long serialVersionUID = -7979639000026975201L;
- public static final int WAKEUP_DEFAULT = 5;
-
+ public static final int WAKEUP_DEFAULT = 5000;
public static final int EVENT_QUEUE_SIZE_DEFAULT = 200000;
+ public static final String EVICTION_ACTION_POLICY_CLASS_DEFAULT =
DefaultEvictionActionPolicy.class.getName();
- private String defaultEvictionPolicyClass;
-
- @Deprecated
- private int wakeupIntervalSeconds = WAKEUP_DEFAULT;
-
/**
* value expressed in millis
*/
@Dynamic
- private long wakeupInterval = WAKEUP_DEFAULT * 1000;
+ private long wakeupInterval = WAKEUP_DEFAULT;
private int defaultEventQueueSize = EVENT_QUEUE_SIZE_DEFAULT;
// Dynamic to support runtime adds/removes of regions
@Dynamic
private List<EvictionRegionConfig> evictionRegionConfigs;
+ private EvictionRegionConfig defaultEvictionRegionConfig;
public EvictionConfig()
{
+ evictionRegionConfigs = new LinkedList<EvictionRegionConfig>();
+ defaultEvictionRegionConfig = new EvictionRegionConfig(Fqn.ROOT);
+ defaultEvictionRegionConfig.setEventQueueSize(EVENT_QUEUE_SIZE_DEFAULT);
+
defaultEvictionRegionConfig.setEvictionActionPolicyClassName(DefaultEvictionActionPolicy.class.getName());
}
- public EvictionConfig(String defaultEvictionClass)
+ /**
+ * @deprecated Use {@link #EvictionConfig(EvictionRegionConfig)} instead.
+ */
+ @Deprecated
+ public EvictionConfig(String defaultEvictionPolicyClass)
{
- setDefaultEvictionPolicyClass(defaultEvictionClass);
+ this();
+ setDefaultEvictionPolicyClass(defaultEvictionPolicyClass);
}
+ public EvictionConfig(EvictionRegionConfig defaultEvictionRegionConfig)
+ {
+ evictionRegionConfigs = new LinkedList<EvictionRegionConfig>();
+ try
+ {
+ this.defaultEvictionRegionConfig = defaultEvictionRegionConfig.clone();
+ }
+ catch (CloneNotSupportedException e)
+ {
+ throw new ConfigurationException(e);
+ }
+ this.defaultEvictionRegionConfig.setEventQueueSize(EVENT_QUEUE_SIZE_DEFAULT);
+ if (this.defaultEvictionRegionConfig.getEvictionActionPolicyClassName() == null)
+
this.defaultEvictionRegionConfig.setEvictionActionPolicyClassName(DefaultEvictionActionPolicy.class.getName());
+ }
+
+ public EvictionConfig(EvictionRegionConfig defaultEvictionRegionConfig, int
wakeupInterval)
+ {
+ this(defaultEvictionRegionConfig);
+ this.wakeupInterval = wakeupInterval;
+ }
+
public boolean isValidConfig()
{
- return (defaultEvictionPolicyClass != null &&
defaultEvictionPolicyClass.length() > 0)
+ return (defaultEvictionRegionConfig != null &&
defaultEvictionRegionConfig.getEvictionActionPolicyClassName() != null &&
defaultEvictionRegionConfig.getEvictionAlgorithmConfig() != null)
|| (evictionRegionConfigs != null && evictionRegionConfigs.size()
> 0);
}
+ public EvictionRegionConfig getDefaultEvictionRegionConfig()
+ {
+ return defaultEvictionRegionConfig;
+ }
+
+ public void setDefaultEvictionRegionConfig(EvictionRegionConfig
defaultEvictionRegionConfig)
+ {
+ this.defaultEvictionRegionConfig = defaultEvictionRegionConfig;
+
this.defaultEvictionRegionConfig.setEventQueueSizeIfUnset(EVENT_QUEUE_SIZE_DEFAULT);
+ }
+
+ /**
+ * @deprecated use {@link #getDefaultEvictionRegionConfig()} instead.
+ */
+ @Deprecated
public String getDefaultEvictionPolicyClass()
{
- return defaultEvictionPolicyClass;
+ throw new ConfigurationException("Please use getDefaultEvictionRegionConfig()
instead.");
}
+ /**
+ * @deprecated use {@link #setDefaultEvictionRegionConfig(EvictionRegionConfig)}
instead.
+ */
+ @Deprecated
public void setDefaultEvictionPolicyClass(String defaultEvictionPolicyClass)
{
- testImmutability("defaultEvictionPolicyClass");
- this.defaultEvictionPolicyClass = defaultEvictionPolicyClass;
+ throw new ConfigurationException("Please use setDefaultEvictionRegionConfig()
instead.");
}
/**
@@ -96,70 +141,33 @@
* @throws ConfigurationException if a
* {@link #setDefaultEvictionPolicyClass(String) a
default eviction policy class}
* has not been set or there is a problem instantiating
the configuration.
+ * @deprecated the default region is now created when this instance is constructed.
Use {@link #getDefaultEvictionRegionConfig()} instead.
*/
+ @Deprecated
public EvictionRegionConfig createDefaultEvictionRegionConfig()
{
- if (defaultEvictionPolicyClass != null)
- {
- try
- {
- Class<?> cpolicy = Class.forName(defaultEvictionPolicyClass);
- EvictionPolicy policy = (EvictionPolicy) cpolicy.newInstance();
- EvictionRegionConfig erc = new EvictionRegionConfig();
- EvictionPolicyConfig epc =
policy.getEvictionConfigurationClass().newInstance();
- erc.setEvictionPolicyConfig(epc);
- erc.setRegionFqn(RegionManagerImpl.DEFAULT_REGION);
- return erc;
- }
- catch (Exception e)
- {
- log.error("Unable to create EvictionRegionConfig for default
region", e);
- throw new ConfigurationException("Unable to create EvictionRegionConfig
for default region", e);
- }
- }
- else
- {
- throw new ConfigurationException("Cannot create EvictionRegionConfig for
default region; no defaultEvictionPolicyClass configured");
- }
+ return getDefaultEvictionRegionConfig();
}
public List<EvictionRegionConfig> getEvictionRegionConfigs()
{
- if (evictionRegionConfigs == null)
- {
- evictionRegionConfigs = new ArrayList<EvictionRegionConfig>(1);
- }
return evictionRegionConfigs;
}
- public int getDefaultEventQueueSize()
+ public void setEvictionRegionConfigs(List<EvictionRegionConfig>
evictionRegionConfigs)
{
- return defaultEventQueueSize;
+ testImmutability("evictionRegionConfigs");
+ this.evictionRegionConfigs = evictionRegionConfigs;
}
- public void setDefaultEventQueueSize(int eventQueueSize)
+ public void addEvictionRegionConfig(EvictionRegionConfig evictionRegionConfig)
{
- this.defaultEventQueueSize = eventQueueSize;
- }
-
- public void setEvictionRegionConfigs(List<EvictionRegionConfig>
evictionRegionConfigs)
- {
testImmutability("evictionRegionConfigs");
-
- // Make sure region configs built by MC have the event queue size
- if (evictionRegionConfigs != null)
- {
- for (EvictionRegionConfig cfg : evictionRegionConfigs)
- {
- cfg.setDefaultEventQueueSize(getDefaultEventQueueSize());
- }
- }
- replaceChildConfigs(this.evictionRegionConfigs, evictionRegionConfigs);
- this.evictionRegionConfigs = evictionRegionConfigs;
+ evictionRegionConfigs.add(evictionRegionConfig);
}
/**
- * value expressed in millis
+ * @return the wake up interval of the eviction thread, in milliseconds.
*/
public long getWakeupInterval()
{
@@ -167,22 +175,35 @@
}
/**
- * value expressed in millis
+ * Set the wake up interval for the eviction thread. 0 or a negative number disables
the eviction thread.
+ *
+ * @param wakeupInterval interval, in milliseconds.
*/
public void setWakeupInterval(long wakeupInterval)
{
- testImmutability("WakeupInterval");
+ testImmutability("wakeupInterval");
this.wakeupInterval = wakeupInterval;
- this.wakeupIntervalSeconds = (int) wakeupInterval / 1000;
}
/**
+ * Set the wake up interval for the eviction thread. 0 or a negative number disables
the eviction thread.
+ *
+ * @param wakeupInterval interval
+ * @param timeUnit for the interval provided
+ */
+ public void setWakeupInterval(long wakeupInterval, TimeUnit timeUnit)
+ {
+ testImmutability("wakeupInterval");
+ this.wakeupInterval = timeUnit.toMillis(wakeupInterval);
+ }
+
+ /**
* @deprecated Use {@link #getWakeupIntervalSeconds()}.
*/
@Deprecated
public int getWakeupIntervalSeconds()
{
- return wakeupIntervalSeconds;
+ return (int) TimeUnit.MILLISECONDS.toSeconds(wakeupInterval);
}
/**
@@ -191,9 +212,7 @@
@Deprecated
public void setWakeupIntervalSeconds(int wakeupIntervalSeconds)
{
- testImmutability("wakeupIntervalSeconds");
- this.wakeupIntervalSeconds = wakeupIntervalSeconds;
- this.wakeupInterval = wakeupIntervalSeconds * 1000;
+ setWakeupInterval(wakeupIntervalSeconds, TimeUnit.SECONDS);
}
public boolean equals(Object o)
@@ -205,9 +224,6 @@
if (defaultEventQueueSize != that.defaultEventQueueSize) return false;
if (wakeupInterval != that.wakeupInterval) return false;
- if (wakeupIntervalSeconds != that.wakeupIntervalSeconds) return false;
- if (defaultEvictionPolicyClass != null ?
!defaultEvictionPolicyClass.equals(that.defaultEvictionPolicyClass) :
that.defaultEvictionPolicyClass != null)
- return false;
if (evictionRegionConfigs != null ?
!evictionRegionConfigs.equals(that.evictionRegionConfigs) : that.evictionRegionConfigs !=
null)
return false;
@@ -217,9 +233,7 @@
public int hashCode()
{
int result;
- result = (defaultEvictionPolicyClass != null ?
defaultEvictionPolicyClass.hashCode() : 0);
- result = 31 * result + wakeupIntervalSeconds;
- result = 31 * result + (int) (wakeupInterval ^ (wakeupInterval >>> 32));
+ result = 31 + (int) (wakeupInterval ^ (wakeupInterval >>> 32));
result = 31 * result + defaultEventQueueSize;
result = 31 * result + (evictionRegionConfigs != null ?
evictionRegionConfigs.hashCode() : 0);
return result;
@@ -231,12 +245,8 @@
EvictionConfig clone = (EvictionConfig) super.clone();
if (evictionRegionConfigs != null)
{
- List<EvictionRegionConfig> ercs = new
ArrayList<EvictionRegionConfig>(evictionRegionConfigs.size());
- for (EvictionRegionConfig erc : evictionRegionConfigs)
- {
- ercs.add(erc.clone());
- }
- clone.setEvictionRegionConfigs(ercs);
+ // needs to be a deep copy
+ for (EvictionRegionConfig erc : evictionRegionConfigs)
clone.addEvictionRegionConfig(erc.clone());
}
return clone;
}
@@ -258,4 +268,24 @@
}
return null;
}
+
+ /**
+ * Applies defaults to a config passed in
+ *
+ * @param config config to apply defaults to
+ */
+ public void applyDefaults(EvictionRegionConfig config)
+ {
+ if (config == null) return; // no op
+ config.setDefaults(defaultEvictionRegionConfig);
+ }
+
+ /**
+ * @deprecated set these attributes on the default eviction region config.
+ */
+ @Deprecated
+ public void setDefaultEventQueueSize(int queueSize)
+ {
+ defaultEvictionRegionConfig.setEventQueueSize(queueSize);
+ }
}
Modified: core/trunk/src/main/java/org/jboss/cache/config/EvictionPolicyConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/EvictionPolicyConfig.java 2008-08-14
19:16:15 UTC (rev 6561)
+++ core/trunk/src/main/java/org/jboss/cache/config/EvictionPolicyConfig.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -17,7 +17,9 @@
* to provide access to more config variables.
*
* @author <a href="mailto:manik@jboss.org">Manik Surtani
(manik(a)jboss.org)</a>
+ * @deprecated see {@link org.jboss.cache.config.EvictionAlgorithmConfig}
*/
+@Deprecated
public interface EvictionPolicyConfig
{
/**
Modified: core/trunk/src/main/java/org/jboss/cache/config/EvictionRegionConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/EvictionRegionConfig.java 2008-08-14
19:16:15 UTC (rev 6561)
+++ core/trunk/src/main/java/org/jboss/cache/config/EvictionRegionConfig.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -22,7 +22,9 @@
package org.jboss.cache.config;
import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.CacheException;
import org.jboss.cache.Fqn;
+import org.jboss.cache.eviction.Modernizable;
import org.jboss.cache.util.Util;
import java.lang.reflect.Method;
@@ -40,38 +42,88 @@
private Fqn regionFqn;
@Dynamic
private Integer eventQueueSize;
- private EvictionPolicyConfig evictionPolicyConfig;
+ private EvictionAlgorithmConfig evictionAlgorithmConfig;
+ @Deprecated
+ private EvictionPolicyConfig deprecatedConfig;
+ private String evictionActionPolicyClassName;
public EvictionRegionConfig()
{
}
+ /**
+ * @deprecated use {@link #EvictionRegionConfig(org.jboss.cache.Fqn,
EvictionAlgorithmConfig)} instead.
+ */
+ @Deprecated
+ @SuppressWarnings("deprecation")
public EvictionRegionConfig(Fqn regionFqn, EvictionPolicyConfig evictionPolicyConfig)
{
this.regionFqn = regionFqn;
- this.evictionPolicyConfig = evictionPolicyConfig;
+ if (evictionPolicyConfig instanceof Modernizable)
+ {
+ this.evictionAlgorithmConfig = ((Modernizable)
evictionPolicyConfig).modernize();
+ deprecatedConfig = evictionPolicyConfig;
+ }
+ else
+ {
+ throw new ConfigurationException("Unable to convert " +
evictionPolicyConfig.getClass().getName() +
+ " to a more modern format, implementing " +
EvictionAlgorithmConfig.class.getSimpleName() + ". Please use " +
+ EvictionAlgorithmConfig.class.getSimpleName() + " which replaces the
deprecated " + EvictionPolicyConfig.class.getSimpleName());
+ }
}
+ public EvictionRegionConfig(Fqn regionFqn, EvictionAlgorithmConfig
evictionAlgorithmConfig)
+ {
+ this.regionFqn = regionFqn;
+ this.evictionAlgorithmConfig = evictionAlgorithmConfig;
+ }
+
+ public EvictionRegionConfig(Fqn fqn)
+ {
+ this.regionFqn = fqn;
+ }
+
+ /**
+ * @deprecated use {@link #getEvictionAlgorithmConfig()} instead.
+ */
+ @Deprecated
public EvictionPolicyConfig getEvictionPolicyConfig()
{
- return evictionPolicyConfig;
+ if (deprecatedConfig != null)
+ return deprecatedConfig;
+ else
+ throw new CacheException("Not supported. Please use " +
EvictionAlgorithmConfig.class.getSimpleName() +
+ " instead of " + EvictionPolicyConfig.class.getSimpleName());
}
- public void setEvictionPolicyConfig(EvictionPolicyConfig config)
+ public EvictionAlgorithmConfig getEvictionAlgorithmConfig()
{
- testImmutability("evictionPolicyConfig");
- if (this.evictionPolicyConfig instanceof ConfigurationComponent)
+ return evictionAlgorithmConfig;
+ }
+
+ /**
+ * @deprecated see {@link #setEvictionAlgorithmConfig(EvictionAlgorithmConfig)}
+ */
+ @Deprecated
+ public void setEvictionPolicyConfig(EvictionPolicyConfig evictionPolicyConfig)
+ {
+ if (evictionPolicyConfig instanceof Modernizable)
{
- removeChildConfig((ConfigurationComponent) this.evictionPolicyConfig);
+ deprecatedConfig = evictionPolicyConfig;
+ setEvictionAlgorithmConfig(((Modernizable) evictionPolicyConfig).modernize());
}
- if (config instanceof ConfigurationComponent)
+ else
{
- addChildConfig((ConfigurationComponent) config);
+ throw new ConfigurationException("Unable to convert " +
evictionPolicyConfig.getClass().getName() +
+ " to a more modern format, implementing " +
EvictionAlgorithmConfig.class.getSimpleName() + ". Please use " +
+ EvictionAlgorithmConfig.class.getSimpleName() + " which replaces the
deprecated " + EvictionPolicyConfig.class.getSimpleName());
}
+ }
- // don't validate here - instead validate when we start things up. See
RegionManager.start()
-
- this.evictionPolicyConfig = config;
+ public void setEvictionAlgorithmConfig(EvictionAlgorithmConfig config)
+ {
+ testImmutability("evictionAlgorithmConfig");
+ this.evictionAlgorithmConfig = config;
}
public Fqn getRegionFqn()
@@ -113,13 +165,15 @@
this.eventQueueSize = queueSize;
}
- public void setDefaultEventQueueSize(int queueSize)
+ public void setDefaults(EvictionRegionConfig defaults)
{
- if (eventQueueSize == null)
- setEventQueueSize(queueSize);
+ // go thru each element that is unset here and copy from "defaults"
+ if (eventQueueSize == null) eventQueueSize = defaults.getEventQueueSize();
+ if (evictionAlgorithmConfig == null) evictionAlgorithmConfig =
defaults.getEvictionAlgorithmConfig();
+ if (evictionActionPolicyClassName == null)
+ evictionActionPolicyClassName = defaults.getEvictionActionPolicyClassName();
}
-
@Override
public boolean equals(Object obj)
{
@@ -130,9 +184,9 @@
{
EvictionRegionConfig other = (EvictionRegionConfig) obj;
boolean equalRegions = Util.safeEquals(this.regionFqn, other.regionFqn);
- boolean equalConfigurations = Util.safeEquals(this.evictionPolicyConfig,
other.evictionPolicyConfig);
+ boolean equalConfigurations = Util.safeEquals(this.evictionAlgorithmConfig,
other.evictionAlgorithmConfig);
boolean equalEventQueuSizes = this.getEventQueueSize() ==
other.getEventQueueSize();
- return equalRegions && equalConfigurations &&
equalConfigurations;
+ return equalRegions && equalConfigurations &&
equalConfigurations && equalEventQueuSizes;
}
return false;
}
@@ -150,36 +204,84 @@
public EvictionRegionConfig clone() throws CloneNotSupportedException
{
EvictionRegionConfig clone = (EvictionRegionConfig) super.clone();
- if (evictionPolicyConfig != null)
+ if (evictionAlgorithmConfig != null)
{
- if (!(evictionPolicyConfig instanceof Cloneable))
+ if (!(evictionAlgorithmConfig instanceof Cloneable))
{
- throw new CloneNotSupportedException(evictionPolicyConfig + " is not
Cloneable");
+ throw new CloneNotSupportedException(evictionAlgorithmConfig + " is not
Cloneable");
}
- if (evictionPolicyConfig instanceof ConfigurationComponent)
+ if (evictionAlgorithmConfig instanceof ConfigurationComponent)
{
- clone.setEvictionPolicyConfig((EvictionPolicyConfig)
((ConfigurationComponent) evictionPolicyConfig).clone());
+ clone.setEvictionAlgorithmConfig((EvictionAlgorithmConfig)
((ConfigurationComponent) evictionAlgorithmConfig).clone());
}
else
{
try
{
- Method cloneMethod =
evictionPolicyConfig.getClass().getDeclaredMethod("clone");
- EvictionPolicyConfig epc = (EvictionPolicyConfig)
cloneMethod.invoke(evictionPolicyConfig);
- clone.setEvictionPolicyConfig(epc);
+ Method cloneMethod =
this.evictionAlgorithmConfig.getClass().getDeclaredMethod("clone");
+ EvictionAlgorithmConfig evictionAlgorithmConfig =
(EvictionAlgorithmConfig) cloneMethod.invoke(this.evictionAlgorithmConfig);
+ clone.setEvictionAlgorithmConfig(evictionAlgorithmConfig);
}
catch (Exception e)
{
- CloneNotSupportedException cnse = new
CloneNotSupportedException("Cannot invoke clone() on " + evictionPolicyConfig);
+ CloneNotSupportedException cnse = new
CloneNotSupportedException("Cannot invoke clone() on " +
evictionAlgorithmConfig);
cnse.initCause(e);
throw cnse;
}
}
}
+ if (deprecatedConfig != null)
+ {
+ if (!(deprecatedConfig instanceof Cloneable))
+ {
+ throw new CloneNotSupportedException(deprecatedConfig + " is not
Cloneable");
+ }
+
+ if (deprecatedConfig instanceof ConfigurationComponent)
+ {
+ clone.setEvictionAlgorithmConfig((EvictionAlgorithmConfig)
((ConfigurationComponent) deprecatedConfig).clone());
+ }
+ else
+ {
+ try
+ {
+ Method cloneMethod =
this.deprecatedConfig.getClass().getDeclaredMethod("clone");
+ EvictionAlgorithmConfig evictionAlgorithmConfig =
(EvictionAlgorithmConfig) cloneMethod.invoke(this.deprecatedConfig);
+ clone.setEvictionAlgorithmConfig(evictionAlgorithmConfig);
+ }
+ catch (Exception e)
+ {
+ CloneNotSupportedException cnse = new
CloneNotSupportedException("Cannot invoke clone() on " + deprecatedConfig);
+ cnse.initCause(e);
+ throw cnse;
+ }
+ }
+ }
+
+ clone.evictionActionPolicyClassName = evictionActionPolicyClassName;
+
return clone;
}
+ public boolean isDefaultRegion()
+ {
+ return regionFqn.isRoot();
+ }
+ public String getEvictionActionPolicyClassName()
+ {
+ return evictionActionPolicyClassName == null ?
EvictionConfig.EVICTION_ACTION_POLICY_CLASS_DEFAULT : evictionActionPolicyClassName;
+ }
+
+ public void setEvictionActionPolicyClassName(String evictionActionPolicyClassName)
+ {
+ this.evictionActionPolicyClassName = evictionActionPolicyClassName;
+ }
+
+ public void setEventQueueSizeIfUnset(int eventQueueSize)
+ {
+ if (this.eventQueueSize == null) this.eventQueueSize = eventQueueSize;
+ }
}
\ No newline at end of file
Modified: core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigHelper.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigHelper.java 2008-08-14
19:16:15 UTC (rev 6561)
+++
core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigHelper.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -22,11 +22,17 @@
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
import java.beans.PropertyEditor;
import java.beans.PropertyEditorManager;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.StringWriter;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
@@ -472,7 +478,9 @@
Class paramTypes[] = m.getParameterTypes();
if (paramTypes.length != 1)
{
- throw new ConfigurationException("Setter " + setter + "
does not contain the expected number of params. Has " + paramTypes.length + "
instead of just 1.");
+ if (log.isTraceEnabled())
+ log.trace("Rejecting setter " + m + " on class "
+ objectClass + " due to incorrect number of parameters");
+ continue; // try another param with the same name.
}
Class parameterType = paramTypes[0];
@@ -499,7 +507,8 @@
}
}
}
- if (!setterFound && failOnMissingSetter) throw new
ConfigurationException("Couldn't find a setter method for parameter " +
propName);
+ if (!setterFound && failOnMissingSetter)
+ throw new ConfigurationException("Couldn't find a setter named
[" + setter + "] which takes a single parameter, for parameter " +
propName);
}
}
@@ -535,4 +544,22 @@
}
return new ParsedAttributes(stringAttribs, xmlAttribs);
}
+
+ public static String toString(Element e)
+ {
+ try
+ {
+ TransformerFactory tfactory = TransformerFactory.newInstance();
+ Transformer xform = tfactory.newTransformer();
+ Source src = new DOMSource(e);
+ java.io.StringWriter writer = new StringWriter();
+ Result result = new javax.xml.transform.stream.StreamResult(writer);
+ xform.transform(src, result);
+ return writer.toString();
+ }
+ catch (Exception ex)
+ {
+ return "Unable to convert to string: " + ex.toString();
+ }
+ }
}
Modified:
core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser2x.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser2x.java 2008-08-14
19:16:15 UTC (rev 6561)
+++
core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser2x.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -19,10 +19,9 @@
import org.jboss.cache.config.EvictionPolicyConfig;
import org.jboss.cache.config.EvictionRegionConfig;
import org.jboss.cache.config.MissingPolicyException;
-import org.jboss.cache.config.parsing.element.EvictionElementParser;
import org.jboss.cache.eviction.EvictionPolicy;
+import org.jboss.cache.util.FileLookup;
import org.jboss.cache.util.Util;
-import org.jboss.cache.util.FileLookup;
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
@@ -383,7 +382,7 @@
eventQueueSize = EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT;
}
- ec.setDefaultEventQueueSize(eventQueueSize);
+ ec.getDefaultEvictionRegionConfig().setEventQueueSize(eventQueueSize);
NodeList list = element.getElementsByTagName(EvictionRegionConfig.REGION);
if (list != null && list.getLength() > 0)
@@ -474,7 +473,8 @@
policy.getEvictionConfigurationClass(), e);
}
- EvictionElementParser.parseEvictionPolicyConfig(element, epc);
+ // TODO FIX this!!!
+// EvictionElementParser.parseEvictionPolicyConfig(element, epc);
erc.setEvictionPolicyConfig(epc);
return erc;
Modified:
core/trunk/src/main/java/org/jboss/cache/config/parsing/element/EvictionElementParser.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/config/parsing/element/EvictionElementParser.java 2008-08-14
19:16:15 UTC (rev 6561)
+++
core/trunk/src/main/java/org/jboss/cache/config/parsing/element/EvictionElementParser.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -1,16 +1,21 @@
package org.jboss.cache.config.parsing.element;
-import org.jboss.cache.RegionManagerImpl;
-import org.jboss.cache.config.*;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.config.ConfigurationException;
+import org.jboss.cache.config.EvictionAlgorithmConfig;
+import org.jboss.cache.config.EvictionConfig;
+import org.jboss.cache.config.EvictionRegionConfig;
+import org.jboss.cache.config.MissingPolicyException;
import org.jboss.cache.config.parsing.ParsedAttributes;
import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.jboss.cache.config.parsing.XmlParserBase;
-import org.jboss.cache.eviction.EvictionPolicy;
+import org.jboss.cache.eviction.EvictionAlgorithm;
import org.jboss.cache.util.Util;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
-import java.util.ArrayList;
+import java.util.LinkedList;
import java.util.List;
/**
@@ -25,8 +30,11 @@
*/
public class EvictionElementParser extends XmlParserBase
{
+ private static final Log log = LogFactory.getLog(EvictionElementParser.class);
+
public EvictionConfig parseEvictionElement(Element evictionElement)
{
+ if (log.isTraceEnabled()) log.trace("Parsing eviction element " +
XmlConfigHelper.toString(evictionElement));
EvictionConfig evictionConfig = new EvictionConfig();
String wakeUpInterval = getAttributeValue(evictionElement,
"wakeUpInterval");
if (existsAttribute(wakeUpInterval))
@@ -35,37 +43,39 @@
}
else
{
- throw new ConfigurationException("Missing mandatory attribute
wakeUpInterval");
+ throw new ConfigurationException("Missing mandatory attribute
wakeUpInterval");
}
- String defaultPolicyClassStr = getAttributeValue(evictionElement,
"defaultPolicyClass");
- if (existsAttribute(defaultPolicyClassStr))
evictionConfig.setDefaultEvictionPolicyClass(defaultPolicyClassStr);
- String defaultEventQueueSize = getAttributeValue(evictionElement,
"defaultEventQueueSize");
- if (existsAttribute(defaultEventQueueSize))
evictionConfig.setDefaultEventQueueSize(getInt(defaultEventQueueSize));
+// String defaultPolicyClassStr = getAttributeValue(evictionElement,
"defaultPolicyClass");
+// if (existsAttribute(defaultPolicyClassStr))
evictionConfig.setDefaultEvictionPolicyClass(defaultPolicyClassStr);
+// String defaultEventQueueSize = getAttributeValue(evictionElement,
"defaultEventQueueSize");
+// if (existsAttribute(defaultEventQueueSize))
evictionConfig.setDefaultEventQueueSize(getInt(defaultEventQueueSize));
- List<EvictionRegionConfig> evictionRegionConfigs = new
ArrayList<EvictionRegionConfig>(3);
- Element rootRegion = getSingleElement("default", evictionElement);
- String defaultPolicyClass = evictionConfig.getDefaultEvictionPolicyClass();
- int defaultEvQueueSize = evictionConfig.getDefaultEventQueueSize();
- if (rootRegion != null)
+ List<EvictionRegionConfig> evictionRegionConfigs = new
LinkedList<EvictionRegionConfig>();
+ Element defaultRegion = getSingleElement("default", evictionElement);
+
+ if (defaultRegion != null)
{
- EvictionRegionConfig erc = getEvictionRegionConfig(rootRegion,
defaultPolicyClass, defaultEvQueueSize);
- erc.setRegionName(RegionManagerImpl.DEFAULT_REGION.toString());
- evictionRegionConfigs.add(erc);
+ EvictionRegionConfig defaultRegionConfig =
getEvictionRegionConfig(defaultRegion, null, true);
+ if (defaultRegionConfig.getEvictionAlgorithmConfig() == null)
+ throw new ConfigurationException("Default eviction region should have an
evictionAlgorithmClass defined.");
+ evictionConfig.setDefaultEvictionRegionConfig(defaultRegionConfig);
}
NodeList regions = evictionElement.getElementsByTagName("region");
for (int i = 0; i < regions.getLength(); i++)
{
Element regionConfig = (Element) regions.item(i);
- EvictionRegionConfig erc = getEvictionRegionConfig(regionConfig,
defaultPolicyClass, defaultEvQueueSize);
+ EvictionRegionConfig erc = getEvictionRegionConfig(regionConfig,
evictionConfig.getDefaultEvictionRegionConfig(), false);
+ evictionConfig.applyDefaults(erc);
evictionRegionConfigs.add(erc);
}
evictionConfig.setEvictionRegionConfigs(evictionRegionConfigs);
return evictionConfig;
}
- private EvictionRegionConfig getEvictionRegionConfig(Element element, String
defaultPolicyClass, int defaultEventQueueSize)
+ @SuppressWarnings("unchecked")
+ private EvictionRegionConfig getEvictionRegionConfig(Element element,
EvictionRegionConfig defaultRegion, boolean isDefault)
{
EvictionRegionConfig erc = new EvictionRegionConfig();
erc.setRegionName(getAttributeValue(element, "name"));
@@ -74,53 +84,99 @@
{
erc.setEventQueueSize(getInt(queueSize));
}
- else
+ else if (defaultRegion == null)
{
- erc.setEventQueueSize(defaultEventQueueSize);
+ erc.setEventQueueSize(EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT);
}
- String policyClass = getAttributeValue(element, "policyClass");
- if (!existsAttribute(policyClass))
+
+ String algorithmClassName = getAttributeValue(element,
"algorithmClass");
+ EvictionAlgorithmConfig eac = null; // every eviction region config needs an
algorithm config.
+
+ if (existsAttribute(algorithmClassName))
{
- if (defaultPolicyClass == null)
+ EvictionAlgorithm algorithm;
+ Class<? extends EvictionAlgorithm> algorithmClass;
+ // try using a 'getInstance()' factory.
+
+ try
{
- throw new MissingPolicyException("There is no Eviction Policy Class
specified on the region or for the entire cache!");
+ algorithmClass = Util.loadClass(algorithmClassName);
}
- else
+ catch (Exception e)
{
- policyClass = defaultPolicyClass;
+ throw new RuntimeException("Unable to load eviction algorithm class
[" + algorithmClassName + "]", e);
}
+
+
+ try
+ {
+ algorithm = Util.getInstance(algorithmClass);
+ }
+ catch (Exception e)
+ {
+ throw new ConfigurationException("Unable to construct eviction algorithm
class [" + algorithmClassName + "]", e);
+ }
+
+ try
+ {
+ eac = Util.getInstance(algorithm.getConfigurationClass());
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Failed to instantiate eviction algorithm
configuration class [" +
+ algorithm.getConfigurationClass() + "]", e);
+ }
}
- EvictionPolicy policy;
- try
+ else
{
- policy = (EvictionPolicy) Util.loadClass(policyClass).newInstance();
+ if (!isDefault)
+ {
+ if (defaultRegion == null || defaultRegion.getEvictionAlgorithmConfig() ==
null)
+ {
+ throw new MissingPolicyException("There is no Eviction Algorithm
Class specified on the region or for the entire cache!");
+ }
+ else
+ {
+ try
+ {
+ eac = defaultRegion.getEvictionAlgorithmConfig().clone();
+ }
+ catch (CloneNotSupportedException e)
+ {
+ throw new ConfigurationException("Unable to clone eviction
algorithm configuration from default", e);
+ }
+ }
+ }
}
- catch (Exception e)
+
+ if (eac != null)
{
- throw new RuntimeException("Eviction class is not properly loaded in
classloader", e);
+ parseEvictionPolicyConfig(element, eac, defaultRegion != null);
+
+ erc.setEvictionAlgorithmConfig(eac);
}
- EvictionPolicyConfig epc;
- try
+ String actionPolicyClass = getAttributeValue(element,
"actionPolicyClass");
+ if (existsAttribute(actionPolicyClass))
{
- epc = policy.getEvictionConfigurationClass().newInstance();
+ erc.setEvictionActionPolicyClassName(actionPolicyClass);
}
- catch (Exception e)
+ else if (defaultRegion == null)
{
- throw new RuntimeException("Failed to instantiate eviction configuration of
class " +
- policy.getEvictionConfigurationClass(), e);
+ // this is the default region. Make sure we set the default
EvictionActionPolicyClass.
+
erc.setEvictionActionPolicyClassName(EvictionConfig.EVICTION_ACTION_POLICY_CLASS_DEFAULT);
}
- parseEvictionPolicyConfig(element, epc);
- erc.setEvictionPolicyConfig(epc);
+
+
return erc;
}
- public static void parseEvictionPolicyConfig(Element element, EvictionPolicyConfig
target)
+ public static void parseEvictionPolicyConfig(Element element, EvictionAlgorithmConfig
target, boolean validate)
{
target.reset();
ParsedAttributes attributes = XmlConfigHelper.extractAttributes(element);
XmlConfigHelper.setValues(target, attributes.stringAttribs, false, true);
XmlConfigHelper.setValues(target, attributes.xmlAttribs, true, true);
- target.validate();
+ if (validate) target.validate();
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/BaseEvictionAlgorithm.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/eviction/BaseEvictionAlgorithm.java 2008-08-14
19:16:15 UTC (rev 6561)
+++
core/trunk/src/main/java/org/jboss/cache/eviction/BaseEvictionAlgorithm.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -8,10 +8,12 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
-import org.jboss.cache.Region;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.Configuration.NodeLockingScheme;
+import org.jboss.cache.config.EvictionAlgorithmConfig;
+import org.jboss.cache.eviction.EvictionEvent.Type;
import org.jboss.cache.lock.TimeoutException;
import java.util.concurrent.BlockingQueue;
@@ -32,33 +34,29 @@
{
private static final Log log = LogFactory.getLog(BaseEvictionAlgorithm.class);
private static final boolean trace = log.isTraceEnabled();
-
+ protected EvictionActionPolicy evictionActionPolicy;
+ protected EvictionAlgorithmConfig evictionAlgorithmConfig;
/**
- * Mapped region.
- */
- protected Region region;
-
- /**
* Contains Fqn instances.
*/
protected BlockingQueue<Fqn> recycleQueue;
-
/**
* Contains NodeEntry instances.
*/
protected EvictionQueue evictionQueue;
-
protected boolean allowTombstones = false;
+ protected Configuration configuration;
+ protected Fqn regionFqn;
+ protected CacheSPI<?, ?> cache;
/**
* This method will create an EvictionQueue implementation and prepare it for use.
*
- * @param region MarshRegion to setup an eviction queue for.
* @return The created EvictionQueue to be used as the eviction queue for this
algorithm.
- * @throws EvictionException
+ * @throws EvictionException if there are problems
* @see EvictionQueue
*/
- protected abstract EvictionQueue setupEvictionQueue(Region region) throws
EvictionException;
+ protected abstract EvictionQueue setupEvictionQueue() throws EvictionException;
/**
* This method will check whether the given node should be evicted or not.
@@ -73,52 +71,64 @@
recycleQueue = new LinkedBlockingQueue<Fqn>(500000);
}
- protected void initialize(Region region) throws EvictionException
+ public void initialize()
{
- if (region == null)
- throw new IllegalArgumentException("region");
- this.region = region;
- evictionQueue = setupEvictionQueue(region);
- log.debug("initialized: " + this);
- // hacky temp solution till we have an ioc fwk to inject configuration elements as
needed
- Configuration c = region.getCacheConfiguration();
- Configuration.CacheMode cm = c != null ? c.getCacheMode() :
Configuration.CacheMode.LOCAL;
- allowTombstones = c != null && c.getNodeLockingScheme() ==
NodeLockingScheme.OPTIMISTIC &&
+ evictionQueue = setupEvictionQueue();
+ if (log.isDebugEnabled()) log.debug("Initialized: " + this);
+ Configuration.CacheMode cm = configuration != null ? configuration.getCacheMode() :
Configuration.CacheMode.LOCAL;
+ allowTombstones = configuration != null &&
configuration.getNodeLockingScheme() == NodeLockingScheme.OPTIMISTIC &&
(cm == Configuration.CacheMode.INVALIDATION_ASYNC || cm ==
Configuration.CacheMode.INVALIDATION_SYNC);
+ }
+ public EvictionActionPolicy getEvictionActionPolicy()
+ {
+ return evictionActionPolicy;
}
+ public void setEvictionActionPolicy(EvictionActionPolicy evictionActionPolicy)
+ {
+ this.evictionActionPolicy = evictionActionPolicy;
+ }
+
+ public EvictionAlgorithmConfig getEvictionAlgorithmConfig()
+ {
+ return evictionAlgorithmConfig;
+ }
+
+ public void assignToRegion(Fqn fqn, CacheSPI<?, ?> cache,
EvictionAlgorithmConfig evictionAlgorithmConfig, Configuration configuration)
+ {
+ this.regionFqn = fqn;
+ this.cache = cache;
+ this.evictionAlgorithmConfig = evictionAlgorithmConfig;
+ this.configuration = configuration;
+ }
+
+ public boolean canIgnoreEvent(Type eventType)
+ {
+ return false; // don't ignore anything!
+ }
+
/**
- * Process the given region.
+ * Process the given eviction event queue. Eviction Processing encompasses the
following:
* <p/>
- * Eviction Processing encompasses the following:
- * <p/>
* - Add/Remove/Visit Nodes
* - Prune according to Eviction Algorithm
* - Empty/Retry the recycle queue of previously evicted but locked (during actual
cache eviction) nodes.
*
- * @param region Cache region to process for eviction.
+ * @param eventQueue queue containing eviction events
* @throws EvictionException
*/
- public void process(Region region) throws EvictionException
+ public void process(BlockingQueue<EvictionEvent> eventQueue) throws
EvictionException
{
- if (this.region == null)
- {
- this.initialize(region);
- }
-
- if (trace)
- {
- log.trace("process(): region: " + region.getFqn());
- }
-
- this.processQueues(region);
+ if (trace) log.trace("process(): region: " + regionFqn);
+ this.processQueues(eventQueue);
this.emptyRecycleQueue();
this.prune();
}
- public void resetEvictionQueue(Region region)
+ public void resetEvictionQueue()
{
+ // a no-op
}
/**
@@ -132,6 +142,19 @@
return this.evictionQueue;
}
+ protected EvictionEvent getNextInQueue(BlockingQueue<EvictionEvent> queue)
+ {
+ try
+ {
+ return queue.poll(0, TimeUnit.SECONDS);
+ }
+ catch (InterruptedException e)
+ {
+ Thread.currentThread().interrupt();
+ }
+ return null;
+ }
+
/**
* Event processing for Evict/Add/Visiting of nodes.
* <p/>
@@ -139,17 +162,15 @@
* - On RemoveEvents, the removed element is removed from the eviction queue.
* - On VisitEvents, the visited node has its eviction statistics updated (idleTime,
numberOfNodeVisists, etc..)
*
- * @param region Cache region to process for eviction.
- * @throws EvictionException
+ * @param queue queue to inspect
+ * @throws EvictionException in the event of problems
*/
- protected void processQueues(Region region) throws EvictionException
+ protected void processQueues(BlockingQueue<EvictionEvent> queue) throws
EvictionException
{
- EvictedEventNode node;
+ EvictionEvent node;
int count = 0;
- while ((node = region.takeLastEventNode()) != null)
+ while ((node = getNextInQueue(queue)) != null)
{
-// Fqn fqn = node.getFqn();
-
count++;
switch (node.getEventType())
{
@@ -179,11 +200,7 @@
}
}
- if (trace)
- {
- log.trace("processed " + count + " node events in region: "
+ region.getFqn());
- }
-
+ if (trace) log.trace("processed " + count + " node events");
}
protected void evict(NodeEntry ne)
@@ -221,15 +238,11 @@
*/
protected boolean evictCacheNode(Fqn fqn)
{
- if (trace)
- {
- log.trace("Attempting to evict cache node with fqn of " + fqn);
- }
+ if (trace) log.trace("Attempting to evict cache node with fqn of " +
fqn);
- EvictionPolicy policy = region.getEvictionPolicy();
try
{
- policy.evict(fqn);
+ evictionActionPolicy.evict(fqn);
}
catch (TimeoutException e)
{
@@ -280,18 +293,18 @@
}
/**
- * Convenience method, which calls {@link #processAddedNodes(EvictedEventNode, int,
boolean)} using values in the
+ * Convenience method, which calls {@link #processAddedNodes(EvictionEvent, int)}
using values in the
* evictedEventNode for number of added elements and the resetElementCount flag.
*
* @param evictedEventNode an evictedEventNode to process
* @throws EvictionException on problems
*/
- protected void processAddedNodes(EvictedEventNode evictedEventNode) throws
EvictionException
+ protected void processAddedNodes(EvictionEvent evictedEventNode) throws
EvictionException
{
processAddedNodes(evictedEventNode, evictedEventNode.getElementDifference());
}
- protected void processAddedNodes(EvictedEventNode evictedEventNode, int
numAddedElements) throws EvictionException
+ protected void processAddedNodes(EvictionEvent evictedEventNode, int numAddedElements)
throws EvictionException
{
Fqn fqn = evictedEventNode.getFqn();
@@ -342,7 +355,7 @@
*
* @throws EvictionException
*/
- protected void processRemovedNodes(EvictedEventNode evictedEventNode) throws
EvictionException
+ protected void processRemovedNodes(EvictionEvent evictedEventNode) throws
EvictionException
{
Fqn fqn = evictedEventNode.getFqn();
@@ -394,7 +407,7 @@
*
* @throws EvictionException
*/
- protected void processVisitedNodes(EvictedEventNode evictedEventNode) throws
EvictionException
+ protected void processVisitedNodes(EvictionEvent evictedEventNode) throws
EvictionException
{
Fqn fqn = evictedEventNode.getFqn();
NodeEntry ne = evictionQueue.getNodeEntry(fqn);
@@ -414,7 +427,7 @@
ne.setModifiedTimeStamp(evictedEventNode.getCreationTimestamp());
}
- protected void processRemovedElement(EvictedEventNode evictedEventNode) throws
EvictionException
+ protected void processRemovedElement(EvictionEvent evictedEventNode) throws
EvictionException
{
Fqn fqn = evictedEventNode.getFqn();
NodeEntry ne = evictionQueue.getNodeEntry(fqn);
@@ -435,7 +448,7 @@
ne.setModifiedTimeStamp(evictedEventNode.getCreationTimestamp());
}
- protected void processAddedElement(EvictedEventNode evictedEventNode) throws
EvictionException
+ protected void processAddedElement(EvictionEvent evictedEventNode) throws
EvictionException
{
Fqn fqn = evictedEventNode.getFqn();
NodeEntry ne = evictionQueue.getNodeEntry(fqn);
@@ -552,7 +565,6 @@
public String toString()
{
return super.toString() +
- " reqion=" + region.getFqn() +
" recycle=" + recycleQueue.size() +
" evict=" + evictionQueue.getNumberOfNodes();
}
@@ -565,9 +577,9 @@
*/
protected boolean isYoungerThanMinimumTimeToLive(NodeEntry entry)
{
- if (region.getEvictionPolicyConfig() instanceof EvictionPolicyConfigBase)
+ if (evictionAlgorithmConfig instanceof EvictionAlgorithmConfigBase)
{
- EvictionPolicyConfigBase cfg = (EvictionPolicyConfigBase)
region.getEvictionPolicyConfig();
+ EvictionAlgorithmConfigBase cfg = (EvictionAlgorithmConfigBase)
evictionAlgorithmConfig;
long minTTL = cfg.getMinTimeToLive();
return minTTL >= 1 && (entry.getModifiedTimeStamp() + minTTL >
System.currentTimeMillis());
}
@@ -577,5 +589,4 @@
return false;
}
}
-
}
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/BaseEvictionPolicy.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/BaseEvictionPolicy.java 2008-08-14
19:16:15 UTC (rev 6561)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/BaseEvictionPolicy.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -9,7 +9,9 @@
* @author Ben Wang 2-2004
* @author Daniel Huang - dhuang(a)jboss.org
* @version $Revision$
+ * @deprecated see {@link org.jboss.cache.eviction.EvictionActionPolicy}
*/
+@Deprecated
public abstract class BaseEvictionPolicy implements EvictionPolicy
{
protected CacheSPI cache_;
@@ -42,7 +44,7 @@
* @see org.jboss.cache.eviction.EvictionPolicy#canIgnoreEvent(org.jboss.cache.Fqn)
*
*/
- public boolean canIgnoreEvent(Fqn fqn, NodeEventType eventType)
+ public boolean canIgnoreEvent(Fqn fqn, EvictionEventType eventType)
{
return false;
}
Modified:
core/trunk/src/main/java/org/jboss/cache/eviction/BaseSortedEvictionAlgorithm.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/eviction/BaseSortedEvictionAlgorithm.java 2008-08-14
19:16:15 UTC (rev 6561)
+++
core/trunk/src/main/java/org/jboss/cache/eviction/BaseSortedEvictionAlgorithm.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -8,9 +8,10 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.Region;
+import java.util.concurrent.BlockingQueue;
+
/**
* An abstract SortedEvictionAlgorithm.
* <p/>
@@ -28,19 +29,13 @@
private static final boolean trace = log.isTraceEnabled();
@Override
- public void process(Region region) throws EvictionException
+ protected void processQueues(BlockingQueue<EvictionEvent> queue) throws
EvictionException
{
- super.process(region);
- }
-
- @Override
- protected void processQueues(Region region) throws EvictionException
- {
boolean evictionNodesModified = false;
- EvictedEventNode node;
+ EvictionEvent node;
int count = 0;
- while ((node = region.takeLastEventNode()) != null)
+ while ((node = getNextInQueue(queue)) != null)
{
count++;
switch (node.getEventType())
Added: core/trunk/src/main/java/org/jboss/cache/eviction/DefaultEvictionActionPolicy.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/DefaultEvictionActionPolicy.java
(rev 0)
+++
core/trunk/src/main/java/org/jboss/cache/eviction/DefaultEvictionActionPolicy.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -0,0 +1,37 @@
+package org.jboss.cache.eviction;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.Cache;
+import org.jboss.cache.Fqn;
+
+/**
+ * Default eviction action policy that calls {@link
org.jboss.cache.Cache#evict(org.jboss.cache.Fqn)} to evict a node.
+ *
+ * @author Manik Surtani (<a
href="mailto:manik@jboss.org">manik@jboss.org</a>)
+ * @since 3.0
+ */
+public class DefaultEvictionActionPolicy implements EvictionActionPolicy
+{
+ Cache<?, ?> cache;
+ private static final Log log = LogFactory.getLog(DefaultEvictionActionPolicy.class);
+
+ public void setCache(Cache<?, ?> cache)
+ {
+ this.cache = cache;
+ }
+
+ public boolean evict(Fqn fqn)
+ {
+ try
+ {
+ cache.evict(fqn);
+ return true;
+ }
+ catch (Exception e)
+ {
+ if (log.isDebugEnabled()) log.debug("Unable to evict " + fqn, e);
+ return false;
+ }
+ }
+}
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizeAlgorithm.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizeAlgorithm.java 2008-08-14
19:16:15 UTC (rev 6561)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizeAlgorithm.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -6,9 +6,8 @@
*/
package org.jboss.cache.eviction;
-import org.jboss.cache.Region;
+import org.jboss.cache.config.EvictionAlgorithmConfig;
-
/**
* @author Daniel Huang
* @version $Revision$
@@ -16,7 +15,7 @@
public class ElementSizeAlgorithm extends BaseSortedEvictionAlgorithm
{
@Override
- protected EvictionQueue setupEvictionQueue(Region region) throws EvictionException
+ protected EvictionQueue setupEvictionQueue() throws EvictionException
{
return new ElementSizeQueue();
}
@@ -27,10 +26,8 @@
// check the minimum time to live and see if we should not evict the node. This
check will
// ensure that, if configured, nodes are kept alive for at least a minimum period
of time.
if (isYoungerThanMinimumTimeToLive(ne)) return false;
-
- ElementSizeConfiguration config = (ElementSizeConfiguration)
region.getEvictionPolicyConfig();
-
int size = this.getEvictionQueue().getNumberOfNodes();
+ ElementSizeAlgorithmConfig config = (ElementSizeAlgorithmConfig)
evictionAlgorithmConfig;
return config.getMaxNodes() != 0 && size > config.getMaxNodes() ||
ne.getNumberOfElements() > config.getMaxElementsPerNode();
}
@@ -43,4 +40,8 @@
((ElementSizeQueue) this.evictionQueue).prune();
}
+ public Class<? extends EvictionAlgorithmConfig> getConfigurationClass()
+ {
+ return ElementSizeAlgorithmConfig.class;
+ }
}
Copied: core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizeAlgorithmConfig.java
(from rev 6544,
core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizeConfiguration.java)
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizeAlgorithmConfig.java
(rev 0)
+++
core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizeAlgorithmConfig.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -0,0 +1,110 @@
+/*
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at
gnu.org.
+ */
+package org.jboss.cache.eviction;
+
+import org.jboss.cache.config.ConfigurationException;
+import org.jboss.cache.config.Dynamic;
+
+/**
+ * Configuration for {@link ElementSizeAlgorithm}.
+ * <p/>
+ * Requires a positive "maxElementsPerNode" value otherwise a
ConfigurationException is thrown.
+ *
+ * @author Manik Surtani
+ * @since 3.0
+ */
+public class ElementSizeAlgorithmConfig extends EvictionAlgorithmConfigBase
+{
+ /**
+ * The serialVersionUID
+ */
+ private static final long serialVersionUID = 2510593544656833758L;
+
+ @Dynamic
+ private int maxElementsPerNode;
+
+ public ElementSizeAlgorithmConfig()
+ {
+ evictionAlgorithmClassName = ElementSizeAlgorithm.class.getName();
+ // Force configuration of maxElementsPerNode
+ setMaxElementsPerNode(-1);
+ }
+
+ public ElementSizeAlgorithmConfig(int maxNodes, int maxElementsPerNode)
+ {
+ this();
+ setMaxNodes(maxNodes);
+ setMaxElementsPerNode(maxElementsPerNode);
+ }
+
+ public int getMaxElementsPerNode()
+ {
+ return maxElementsPerNode;
+ }
+
+ public void setMaxElementsPerNode(int maxElementsPerNode)
+ {
+ testImmutability("maxElementsPerNode");
+ this.maxElementsPerNode = maxElementsPerNode;
+ }
+
+ /**
+ * Requires a positive maxElementsPerNode value or ConfigurationException
+ * is thrown.
+ */
+ @Override
+ public void validate() throws ConfigurationException
+ {
+ if (maxElementsPerNode < 0)
+ {
+ throw new ConfigurationException("maxElementsPerNode must be must be "
+
+ "configured to a value greater than or equal to 0");
+ }
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuilder str = new StringBuilder();
+ str.append("ElementSizeConfiguration: maxElementsPerNode =");
+ str.append(getMaxElementsPerNode()).append(" maxNodes
=").append(getMaxNodes());
+ return str.toString();
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ return true;
+ if (obj instanceof ElementSizeAlgorithmConfig && super.equals(obj))
+ {
+ return this.maxElementsPerNode == ((ElementSizeAlgorithmConfig)
obj).maxElementsPerNode;
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = super.hashCode();
+ result = 31 * result + maxElementsPerNode;
+ return result;
+ }
+
+ @Override
+ public void reset()
+ {
+ super.reset();
+ setMaxElementsPerNode(-1);
+ }
+
+ @Override
+ public ElementSizeAlgorithmConfig clone() throws CloneNotSupportedException
+ {
+ return (ElementSizeAlgorithmConfig) super.clone();
+ }
+}
\ No newline at end of file
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizeConfiguration.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizeConfiguration.java 2008-08-14
19:16:15 UTC (rev 6561)
+++
core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizeConfiguration.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -8,7 +8,10 @@
import org.jboss.cache.config.ConfigurationException;
import org.jboss.cache.config.Dynamic;
+import org.jboss.cache.config.EvictionAlgorithmConfig;
+import java.util.concurrent.TimeUnit;
+
/**
* Configuration for {@link ElementSizePolicy}.
* <p/>
@@ -26,7 +29,9 @@
* @author Daniel Huang
* @author Brian Stansberry
* @version $Revision$
+ * @deprecated see {@link org.jboss.cache.eviction.ElementSizeAlgorithmConfig}
*/
+@Deprecated
public class ElementSizeConfiguration extends EvictionPolicyConfigBase
{
/**
@@ -50,6 +55,16 @@
setEvictionPolicyClass(ElementSizePolicy.class.getName());
}
+ @Override
+ public EvictionAlgorithmConfig modernize()
+ {
+ ElementSizeAlgorithmConfig modernCfg = new ElementSizeAlgorithmConfig();
+ modernCfg.setMaxElementsPerNode(getMaxElementsPerNode());
+ modernCfg.setMaxNodes(getMaxNodes());
+ modernCfg.setMinTimeToLive(getMinTimeToLiveSeconds(), TimeUnit.SECONDS);
+ return modernCfg;
+ }
+
public int getMaxElementsPerNode()
{
return maxElementsPerNode;
@@ -116,6 +131,4 @@
{
return (ElementSizeConfiguration) super.clone();
}
-
-
}
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizePolicy.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizePolicy.java 2008-08-14
19:16:15 UTC (rev 6561)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizePolicy.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -9,7 +9,9 @@
/**
* @author Daniel Huang
* @version $Revison: $
+ * @deprecated see ElementSizeAlgorithm
*/
+@Deprecated
public class ElementSizePolicy extends BaseEvictionPolicy
{
private ElementSizeAlgorithm algorithm;
Deleted: core/trunk/src/main/java/org/jboss/cache/eviction/EvictedEventNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/EvictedEventNode.java 2008-08-14
19:16:15 UTC (rev 6561)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/EvictedEventNode.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -1,102 +0,0 @@
-/*
- * JBoss, the OpenSource J2EE webOS
- *
- * Distributable under LGPL license.
- * See terms of license at
gnu.org.
- */
-package org.jboss.cache.eviction;
-
-import org.jboss.cache.Fqn;
-
-/**
- * Value object used in evicted event node queue.
- *
- * @author Ben Wang 2-2004
- * @author Daniel Huang (dhuang(a)jboss.org)
- * @see org.jboss.cache.Region
- */
-public class EvictedEventNode
-{
- private Fqn fqn;
- private NodeEventType type;
- private int elementDifference;
-
- private long inUseTimeout;
- private long creationTimestamp;
-
- public EvictedEventNode(Fqn fqn, NodeEventType type, int elementDifference)
- {
- this(fqn, type);
- setElementDifference(elementDifference);
- }
-
- public EvictedEventNode(Fqn fqn, NodeEventType event)
- {
- setFqn(fqn);
- setEventType(event);
- creationTimestamp = System.currentTimeMillis();
- }
-
- public long getCreationTimestamp()
- {
- return creationTimestamp;
- }
-
- public long getInUseTimeout()
- {
- return inUseTimeout;
- }
-
- public void setInUseTimeout(long inUseTimeout)
- {
- this.inUseTimeout = inUseTimeout;
- }
-
- public int getElementDifference()
- {
- return elementDifference;
- }
-
- public void setElementDifference(int elementDifference_)
- {
- this.elementDifference = elementDifference_;
- }
-
- public Fqn getFqn()
- {
- return fqn;
- }
-
- public void setFqn(Fqn fqn)
- {
- this.fqn = fqn;
- }
-
- public void setEventType(NodeEventType event)
- {
- type = event;
- }
-
- public NodeEventType getEventType()
- {
- return type;
- }
-
- @Override
- public String toString()
- {
- return "EvictedEventNode[fqn=" + fqn + " event=" + type +
" diff=" + elementDifference + "]";
- }
-
- /**
- * Copies this evicted event node to create a new one with the same values, except
with a new Fqn root.
- *
- * @param newRoot new Fqn root to use
- * @return a new EvictedEventNode instance
- * @see org.jboss.cache.Region#copy(org.jboss.cache.Fqn)
- */
- public EvictedEventNode copy(Fqn newRoot)
- {
- return new EvictedEventNode(Fqn.fromRelativeFqn(newRoot, fqn), type,
elementDifference);
- }
-}
Added: core/trunk/src/main/java/org/jboss/cache/eviction/EvictionActionPolicy.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/EvictionActionPolicy.java
(rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/EvictionActionPolicy.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -0,0 +1,28 @@
+package org.jboss.cache.eviction;
+
+import org.jboss.cache.Cache;
+import org.jboss.cache.Fqn;
+
+/**
+ * Performs an eviction on a given Fqn.
+ *
+ * @author Manik Surtani (<a
href="mailto:manik@jboss.org">manik@jboss.org</a>)
+ * @since 3.0
+ */
+public interface EvictionActionPolicy
+{
+ /**
+ * Sets a reference to the cache.
+ *
+ * @param cache cache
+ */
+ void setCache(Cache<?, ?> cache);
+
+ /**
+ * Performs an eviction on a given node.
+ *
+ * @param fqn fqn to evict
+ * @return true if the eviction was successful, false if not.
+ */
+ boolean evict(Fqn fqn);
+}
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/EvictionAlgorithm.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/EvictionAlgorithm.java 2008-08-14
19:16:15 UTC (rev 6561)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/EvictionAlgorithm.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -1,7 +1,13 @@
package org.jboss.cache.eviction;
-import org.jboss.cache.Region;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.config.EvictionAlgorithmConfig;
+import org.jboss.cache.eviction.EvictionEvent.Type;
+import java.util.concurrent.BlockingQueue;
+
/**
* Interface for all eviction algorithms.
* <p/>
@@ -15,19 +21,17 @@
public interface EvictionAlgorithm
{
/**
- * Entry point for evictin algorithm. This is an api called by the EvictionTimerTask
- * to process the node events in waiting and actual pruning, if necessary.
+ * Entry point for eviction algorithm. Invoking this will cause the algorithm to
process the queue of {@link org.jboss.cache.eviction.EvictionEvent}
+ * passed in.
*
- * @param region MarshRegion that this algorithm will operate on.
+ * @param queue to process
*/
- void process(Region region) throws EvictionException;
+ void process(BlockingQueue<EvictionEvent> queue) throws EvictionException;
/**
- * Reset the whole eviction queue. Queue may needs to be reset due to corrupted state,
for example.
- *
- * @param region MarshRegion that this algorithm will operate on.
+ * Reset the whole eviction queue. The queue may need to be reset due to corrupted
state, for example.
*/
- void resetEvictionQueue(Region region);
+ void resetEvictionQueue();
/**
* Get the EvictionQueue implementation used by this algorithm.
@@ -36,4 +40,41 @@
*/
EvictionQueue getEvictionQueue();
+ /**
+ * Sets the eviction action policy, so the algorithm knows what to do when a node is
to be evicted.
+ *
+ * @param evictionActionPolicy to set
+ */
+ void setEvictionActionPolicy(EvictionActionPolicy evictionActionPolicy);
+
+ /**
+ * Assigns the algorithm instance to a specific region.
+ *
+ * @param fqn of the region to be assigned to
+ * @param cache cache reference
+ * @param evictionAlgorithmConfig configuration for the current algorithm instance.
+ * @param configuration for the entire cache.
+ */
+ void assignToRegion(Fqn fqn, CacheSPI<?, ?> cache, EvictionAlgorithmConfig
evictionAlgorithmConfig, Configuration configuration);
+
+ /**
+ * Tests whether the algorithm would ignore certain event types on certain Fqns.
+ *
+ * @param eventType event type to test for
+ * @return true if the event representing the parameters would be ignored by this
algorithm or not.
+ */
+ boolean canIgnoreEvent(Type eventType);
+
+ /**
+ * Invoked by the region manager when the enclosing region is initialized.
+ */
+ void initialize();
+
+ /**
+ * This is a helper so that the XML parser will be able to select and use the correct
{@link org.jboss.cache.config.EvictionAlgorithmConfig} implementation
+ * class corresponding to this EvictionAlgorithm. E.g., the {@link FIFOAlgorithm}
would return {@link org.jboss.cache.eviction.FIFOAlgorithmConfig}.class.
+ *
+ * @return a class that is used to configure this EvictionAlgorithm.
+ */
+ Class<? extends EvictionAlgorithmConfig> getConfigurationClass();
}
Added: core/trunk/src/main/java/org/jboss/cache/eviction/EvictionAlgorithmConfigBase.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/EvictionAlgorithmConfigBase.java
(rev 0)
+++
core/trunk/src/main/java/org/jboss/cache/eviction/EvictionAlgorithmConfigBase.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -0,0 +1,113 @@
+package org.jboss.cache.eviction;
+
+import org.jboss.cache.config.ConfigurationComponent;
+import org.jboss.cache.config.ConfigurationException;
+import org.jboss.cache.config.Dynamic;
+import org.jboss.cache.config.EvictionAlgorithmConfig;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * A base class used for configuring eviction algorithms.
+ *
+ * @author Manik Surtani (<a
href="mailto:manik@jboss.org">manik@jboss.org</a>)
+ * @since 3.0
+ */
+public abstract class EvictionAlgorithmConfigBase extends ConfigurationComponent
implements EvictionAlgorithmConfig
+{
+ private static final long serialVersionUID = 4591691674370188932L;
+
+ protected String evictionAlgorithmClassName;
+ @Dynamic
+ protected int maxNodes = 0;
+ @Dynamic
+ protected long minTimeToLive;
+
+ /**
+ * Can only be instantiated by a subclass.
+ */
+ protected EvictionAlgorithmConfigBase()
+ {
+ }
+
+ public String getEvictionAlgorithmClassName()
+ {
+ return evictionAlgorithmClassName;
+ }
+
+ public int getMaxNodes()
+ {
+ return maxNodes;
+ }
+
+ public void setMaxNodes(int maxNodes)
+ {
+ testImmutability("maxNodes");
+ this.maxNodes = maxNodes;
+ }
+
+ /**
+ * @return The minimum time to live, in milliseconds.
+ */
+ public long getMinTimeToLive()
+ {
+ return minTimeToLive;
+ }
+
+ /**
+ * @param minTimeToLive time to live, in milliseconds
+ */
+ public void setMinTimeToLive(long minTimeToLive)
+ {
+ testImmutability("minTimeToLive");
+ this.minTimeToLive = minTimeToLive;
+ }
+
+ public void setMinTimeToLive(long time, TimeUnit timeUnit)
+ {
+ testImmutability("minTimeToLive");
+ minTimeToLive = timeUnit.toMillis(time);
+ }
+
+ public void validate() throws ConfigurationException
+ {
+ // no-op
+ }
+
+ public boolean equals(Object o)
+ {
+ if (this == o) return true;
+ if (!(o instanceof EvictionAlgorithmConfigBase)) return false;
+
+ EvictionAlgorithmConfigBase that = (EvictionAlgorithmConfigBase) o;
+
+ if (maxNodes != that.maxNodes) return false;
+ if (minTimeToLive != that.minTimeToLive) return false;
+ if (evictionAlgorithmClassName != null ?
!evictionAlgorithmClassName.equals(that.evictionAlgorithmClassName) :
that.evictionAlgorithmClassName != null)
+ return false;
+
+ return true;
+ }
+
+ public int hashCode()
+ {
+ int result;
+ result = (evictionAlgorithmClassName != null ?
evictionAlgorithmClassName.hashCode() : 0);
+ result = 31 * result + maxNodes;
+ result = (int) (31 * result + minTimeToLive);
+ result = 31 * result + (int) (minTimeToLive ^ (minTimeToLive >>> 32));
+ return result;
+ }
+
+ public void reset()
+ {
+ evictionAlgorithmClassName = null;
+ maxNodes = 0;
+ minTimeToLive = 0;
+ }
+
+ public EvictionAlgorithmConfig clone() throws CloneNotSupportedException
+ {
+ return (EvictionAlgorithmConfig) super.clone();
+ }
+}
Copied: core/trunk/src/main/java/org/jboss/cache/eviction/EvictionEvent.java (from rev
6553, core/trunk/src/main/java/org/jboss/cache/eviction/EvictedEventNode.java)
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/EvictionEvent.java
(rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/EvictionEvent.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -0,0 +1,108 @@
+/*
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at
gnu.org.
+ */
+package org.jboss.cache.eviction;
+
+import org.jboss.cache.Fqn;
+
+/**
+ * An eviction event records activity on nodes in the cache. These are recorded on a
{@link org.jboss.cache.Region} for processing
+ * later by calls to {@link org.jboss.cache.Region#processEvictionQueues()}.
+ * <p/>
+ *
+ * @see org.jboss.cache.Region
+ */
+public class EvictionEvent
+{
+ private Fqn fqn;
+ private Type type;
+ private int elementDifference;
+
+ private long inUseTimeout;
+ private long creationTimestamp;
+
+ public static enum Type
+ {
+ ADD_NODE_EVENT,
+ REMOVE_NODE_EVENT,
+ VISIT_NODE_EVENT,
+ ADD_ELEMENT_EVENT,
+ REMOVE_ELEMENT_EVENT,
+ MARK_IN_USE_EVENT,
+ UNMARK_USE_EVENT
+ }
+
+ public EvictionEvent(Fqn fqn, Type type, int elementDifference)
+ {
+ this.fqn = fqn;
+ this.type = type;
+ this.elementDifference = elementDifference;
+ this.creationTimestamp = System.currentTimeMillis();
+ }
+
+ public long getCreationTimestamp()
+ {
+ return creationTimestamp;
+ }
+
+ public long getInUseTimeout()
+ {
+ return inUseTimeout;
+ }
+
+ public void setInUseTimeout(long inUseTimeout)
+ {
+ this.inUseTimeout = inUseTimeout;
+ }
+
+ public int getElementDifference()
+ {
+ return elementDifference;
+ }
+
+ public void setElementDifference(int elementDifference)
+ {
+ this.elementDifference = elementDifference;
+ }
+
+ public Fqn getFqn()
+ {
+ return fqn;
+ }
+
+ public void setFqn(Fqn fqn)
+ {
+ this.fqn = fqn;
+ }
+
+ public void setEventType(Type event)
+ {
+ type = event;
+ }
+
+ public Type getEventType()
+ {
+ return type;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "EvictedEventNode[fqn=" + fqn + " event=" + type +
" diff=" + elementDifference + "]";
+ }
+
+ /**
+ * Copies this evicted event node to create a new one with the same values, except
with a new Fqn root.
+ *
+ * @param newRoot new Fqn root to use
+ * @return a new EvictedEventNode instance
+ * @see org.jboss.cache.Region#copy(org.jboss.cache.Fqn)
+ */
+ public EvictionEvent copy(Fqn newRoot)
+ {
+ return new EvictionEvent(Fqn.fromRelativeFqn(newRoot, fqn), type,
elementDifference);
+ }
+}
Property changes on: core/trunk/src/main/java/org/jboss/cache/eviction/EvictionEvent.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Added: core/trunk/src/main/java/org/jboss/cache/eviction/EvictionEventType.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/EvictionEventType.java
(rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/EvictionEventType.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -0,0 +1,16 @@
+package org.jboss.cache.eviction;
+
+/**
+ * @deprecated left here for old interfaces. Use {@link
org.jboss.cache.eviction.EvictionEvent.Type} instead.
+ */
+@Deprecated
+public enum EvictionEventType
+{
+ @Deprecated ADD_NODE_EVENT,
+ @Deprecated REMOVE_NODE_EVENT,
+ @Deprecated VISIT_NODE_EVENT,
+ @Deprecated ADD_ELEMENT_EVENT,
+ @Deprecated REMOVE_ELEMENT_EVENT,
+ @Deprecated MARK_IN_USE_EVENT,
+ @Deprecated UNMARK_USE_EVENT
+}
\ No newline at end of file
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/EvictionException.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/EvictionException.java 2008-08-14
19:16:15 UTC (rev 6561)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/EvictionException.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -1,11 +1,13 @@
package org.jboss.cache.eviction;
+import org.jboss.cache.CacheException;
+
/**
* @author Ben Wang, Feb 11, 2004
*/
-public class EvictionException extends Exception
+public class EvictionException extends CacheException
{
-
+
private static final long serialVersionUID = 4006783737166646935L;
public EvictionException()
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/EvictionPolicy.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/EvictionPolicy.java 2008-08-14
19:16:15 UTC (rev 6561)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/EvictionPolicy.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -18,7 +18,9 @@
*
* @author Ben Wang 2-2004
* @author Daniel Huang - dhuang(a)jboss.org - 10/2005
+ * @deprecated please use {@link EvictionActionPolicy} instead.
*/
+@Deprecated
public interface EvictionPolicy
{
/**
@@ -64,7 +66,7 @@
* This method provides a way to optimize the performance of eviction by
* signalling that the node associated with the specified Fqn should not be
* subject to normal eviction processing. It can also be used to filter
- * out certain {@link NodeEventType event types} in which the particular
+ * out certain {@link EvictionEventType event types} in which the particular
* eviction algorithm has no interest.
* </p>
* <p/>
@@ -84,5 +86,5 @@
* @return <code>true</code> to ignore events of this type for this Fqn,
* <code>false</code> to process events normally.
*/
- boolean canIgnoreEvent(Fqn fqn, NodeEventType eventType);
+ boolean canIgnoreEvent(Fqn fqn, EvictionEventType eventType);
}
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/EvictionPolicyConfigBase.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/eviction/EvictionPolicyConfigBase.java 2008-08-14
19:16:15 UTC (rev 6561)
+++
core/trunk/src/main/java/org/jboss/cache/eviction/EvictionPolicyConfigBase.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -3,18 +3,20 @@
import org.jboss.cache.config.ConfigurationComponent;
import org.jboss.cache.config.ConfigurationException;
import org.jboss.cache.config.Dynamic;
+import org.jboss.cache.config.EvictionAlgorithmConfig;
import org.jboss.cache.config.EvictionPolicyConfig;
-import org.jboss.cache.util.Util;
/**
* Base implementation of {@link EvictionPolicyConfig}. Adds properties
* for the most commonly used config elements.
*
* @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
+ * @deprecated See {@link org.jboss.cache.eviction.EvictionAlgorithmConfigBase}.
*/
+@Deprecated
public abstract class EvictionPolicyConfigBase
extends ConfigurationComponent
- implements EvictionPolicyConfig
+ implements EvictionPolicyConfig, Modernizable
{
/**
* The serialVersionUID
@@ -25,15 +27,9 @@
@Dynamic
private int maxNodes = 0;
- @Deprecated
@Dynamic
private int minTimeToLiveSeconds = 0;
-
- /** value expressed in millis */
- @Dynamic
- private long minTimeToLive;
-
/**
* Can only be instantiated by a subclass.
* <p/>
@@ -66,36 +62,14 @@
this.maxNodes = maxNodes;
}
- /** value expressed in millis */
- public long getMinTimeToLive()
- {
- return minTimeToLive;
- }
-
- /** value expressed in millis */
- public void setMinTimeToLive(long minTimeToLive)
- {
- this.minTimeToLive = minTimeToLive;
- this.minTimeToLiveSeconds = (int)(minTimeToLive / 1000);
- }
-
- /**
- * Use {@link #getMinTimeToLive()}
- */
- @Deprecated
public int getMinTimeToLiveSeconds()
{
return this.minTimeToLiveSeconds;
}
- /**
- * Use {@link #setMinTimeToLive(long)}
- */
- @Deprecated
public void setMinTimeToLiveSeconds(int minTimeToLiveSeconds)
{
this.minTimeToLiveSeconds = minTimeToLiveSeconds;
- minTimeToLive = minTimeToLiveSeconds * 1000;
}
public void validate() throws ConfigurationException
@@ -111,7 +85,7 @@
EvictionPolicyConfigBase that = (EvictionPolicyConfigBase) o;
if (maxNodes != that.maxNodes) return false;
- if (minTimeToLive != that.minTimeToLive) return false;
+ if (minTimeToLiveSeconds != that.minTimeToLiveSeconds) return false;
if (evictionPolicyClass != null ?
!evictionPolicyClass.equals(that.evictionPolicyClass) : that.evictionPolicyClass != null)
return false;
@@ -124,7 +98,7 @@
result = (evictionPolicyClass != null ? evictionPolicyClass.hashCode() : 0);
result = 31 * result + maxNodes;
result = 31 * result + minTimeToLiveSeconds;
- result = 31 * result + (int) (minTimeToLive ^ (minTimeToLive >>> 32));
+ result = 31 * result + (minTimeToLiveSeconds ^ (minTimeToLiveSeconds >>>
3));
return result;
}
@@ -133,7 +107,7 @@
setEvictionPolicyClass(null);
setMaxNodes(0);
setMinTimeToLiveSeconds(0);
- setMinTimeToLive(0);
+ setMinTimeToLiveSeconds(0);
setEvictionPolicyClassName();
}
@@ -144,4 +118,16 @@
* called in {@link #reset()}.
*/
abstract protected void setEvictionPolicyClassName();
+
+ /**
+ * A factory method that returns a more modernized {@link
org.jboss.cache.eviction.ExpirationAlgorithmConfig} instance
+ * corresponding to this deprecated configuration element. It is expected that
subclasses of this abstract class
+ * implement this method as needed, copying elements across accordingly.
+ *
+ * @return a new ElementSizeAlgorithmConfig instance with values identical to this
current deprecated config.
+ */
+ public EvictionAlgorithmConfig modernize()
+ {
+ throw new UnsupportedOperationException("Not supported in this implementation
(" + getClass().getName() + ")");
+ }
}
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/EvictionTimerTask.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/EvictionTimerTask.java 2008-08-14
19:16:15 UTC (rev 6561)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/EvictionTimerTask.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -133,13 +133,9 @@
{
synchronized (region)
{
- final EvictionPolicy policy = region.getEvictionPolicy();
- final EvictionAlgorithm algo = policy.getEvictionAlgorithm();
- if (algo == null)
- throw new NullPointerException("algorithm null");
try
{
- algo.process(region);
+ region.processEvictionQueues();
}
catch (EvictionException e)
{
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationAlgorithm.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationAlgorithm.java 2008-08-14
19:16:15 UTC (rev 6561)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationAlgorithm.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -4,11 +4,13 @@
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.NodeSPI;
-import org.jboss.cache.Region;
+import org.jboss.cache.config.EvictionAlgorithmConfig;
+import org.jboss.cache.eviction.EvictionEvent.Type;
import java.util.Iterator;
import java.util.SortedSet;
import java.util.TreeSet;
+import java.util.concurrent.BlockingQueue;
/**
* Eviction algorithm that uses a key in the Node data that indicates the time
@@ -18,19 +20,19 @@
* java.lang.System#currentTimeMillis()}).
* <p/>
* This algorithm also obeys the configuration key {@link
- * ExpirationConfiguration#getMaxNodes()}, and will evict the soonest to
+ * ExpirationAlgorithmConfig#getMaxNodes()}, and will evict the soonest to
* expire entires first to reduce the region size. If there are not enough
* nodes with expiration keys set, a warning is logged.
* <p/>
* If a node in the eviction region does not have an expiration value, then
- * {@link org.jboss.cache.eviction.ExpirationConfiguration#getTimeToLive()} (if set) will
be used.
+ * {@link ExpirationAlgorithmConfig#getTimeToLive()} (if set) will be used.
* The expiration is updated when a node is added or updated.
* <p/>
* If there is no time-to-live set, and a node in the eviction region does not
* have an expiration value, then that node will never be evicted. As
* forgetting to indicate an expiration value is likely a mistake, a warning
* message is logged by this class. This warning, however, can be disabled
- * through {@link ExpirationConfiguration#setWarnNoExpirationKey(boolean)}.
+ * through {@link ExpirationAlgorithmConfig#setWarnNoExpirationKey(boolean)}.
* <p/>
* A node's expiration time can be changed by setting a new value in the node.
* <p/>
@@ -54,22 +56,19 @@
private static final Log log = LogFactory.getLog(ExpirationAlgorithm.class);
private static final boolean trace = log.isTraceEnabled();
- private ExpirationConfiguration config;
+ private ExpirationAlgorithmConfig config;
- private ExpirationPolicy policy;
-
private SortedSet<ExpirationEntry> set;
/**
* Constructs a new algorithm with a policy.
*/
- public ExpirationAlgorithm(ExpirationPolicy policy)
+ public ExpirationAlgorithm()
{
- this.policy = policy;
this.set = new TreeSet<ExpirationEntry>();
}
- private void addEvictionEntry(EvictedEventNode node)
+ private void addEvictionEntry(EvictionEvent node)
{
Fqn fqn = node.getFqn();
addEvictionEntry(fqn);
@@ -80,7 +79,7 @@
Long l = getExpiration(fqn);
if (l == null)
{
- if (config.getWarnNoExpirationKey())
+ if (config.isWarnNoExpirationKey() && log.isWarnEnabled())
log.warn("No expiration key '" + config.getExpirationKeyName()
+ "' for Node: " + fqn);
else if (log.isDebugEnabled())
log.debug("No expiration key for Node: " + fqn);
@@ -102,18 +101,18 @@
@SuppressWarnings("unchecked")
private Long getExpiration(Fqn fqn)
{
- NodeSPI<String, Long> n = policy.getCache().peek(fqn, false);
+ NodeSPI n = cache.peek(fqn, false);
if (n == null)
return null;
- return n.getDirect(config.getExpirationKeyName());
+ return (Long) n.getDirect(config.getExpirationKeyName());
}
@Override
- protected void processQueues(Region region) throws EvictionException
+ protected void processQueues(BlockingQueue<EvictionEvent> queue) throws
EvictionException
{
- EvictedEventNode node;
+ EvictionEvent node;
int count = 0;
- while ((node = region.takeLastEventNode()) != null)
+ while ((node = getNextInQueue(queue)) != null)
{
count++;
switch (node.getEventType())
@@ -139,13 +138,10 @@
}
}
- if (trace)
- {
- log.trace("processed " + count + " node events in region: "
+ region.getFqn());
- }
+ if (trace) log.trace("processed " + count + " node events in region:
" + regionFqn);
}
- private void markInUse(EvictedEventNode node)
+ private void markInUse(EvictionEvent node)
{
long expiration = node.getInUseTimeout() + System.currentTimeMillis();
setExpiration(node.getFqn(), expiration);
@@ -185,7 +181,7 @@
}
@Override
- public void resetEvictionQueue(Region region)
+ public void resetEvictionQueue()
{
for (ExpirationEntry ee : set)
{
@@ -194,10 +190,9 @@
}
@Override
- protected EvictionQueue setupEvictionQueue(Region region) throws EvictionException
+ protected EvictionQueue setupEvictionQueue() throws EvictionException
{
- this.region = region;
- this.config = (ExpirationConfiguration) region.getEvictionPolicyConfig();
+ this.config = (ExpirationAlgorithmConfig) evictionAlgorithmConfig;
return new DummyEvictionQueue();
}
@@ -207,6 +202,17 @@
throw new UnsupportedOperationException();
}
+ @Override
+ public boolean canIgnoreEvent(Type eventType)
+ {
+ return (eventType == EvictionEvent.Type.VISIT_NODE_EVENT);
+ }
+
+ public Class<? extends EvictionAlgorithmConfig> getConfigurationClass()
+ {
+ return ExpirationAlgorithmConfig.class;
+ }
+
/**
* Ordered list of FQN, with the expiration taken from the Map at the time
* of processing.
@@ -345,7 +351,6 @@
{
throw new UnsupportedOperationException();
}
-
}
}
Copied: core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationAlgorithmConfig.java
(from rev 6544,
core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationConfiguration.java)
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationAlgorithmConfig.java
(rev 0)
+++
core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationAlgorithmConfig.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -0,0 +1,123 @@
+package org.jboss.cache.eviction;
+
+import org.jboss.cache.config.Dynamic;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Configuration for indicating the Node key for setting a specific eviction time.
+ */
+public class ExpirationAlgorithmConfig extends EvictionAlgorithmConfigBase
+{
+
+ private static final long serialVersionUID = 47338798734219507L;
+
+ /**
+ * Default key name for indicating expiration time.
+ */
+ public static final String EXPIRATION_KEY = "expiration";
+
+ /**
+ * Node key name used to indicate the expiration of a node.
+ */
+ @Dynamic
+ private String expirationKeyName = EXPIRATION_KEY;
+
+ @Dynamic
+ private boolean warnNoExpirationKey = true;
+
+ @Dynamic
+ private long timeToLive = 0;
+
+ public ExpirationAlgorithmConfig()
+ {
+ evictionAlgorithmClassName = ExpirationAlgorithm.class.getName();
+ }
+
+ /**
+ * Returns the expirationKeyName.
+ * This key should point to a java.lang.Long value in the Node data.
+ */
+ public String getExpirationKeyName()
+ {
+ return expirationKeyName;
+ }
+
+ /**
+ * Sets the expirationKeyName.
+ */
+ public void setExpirationKeyName(String expirationKeyName)
+ {
+ this.expirationKeyName = expirationKeyName;
+ }
+
+ /**
+ * Returns true if the algorithm should warn if a expiration key is missing for a
node.
+ */
+ public boolean isWarnNoExpirationKey()
+ {
+ return warnNoExpirationKey;
+ }
+
+ /**
+ * Sets if the algorithm should warn if a expiration key is missing for a node.
+ */
+ public void setWarnNoExpirationKey(boolean warnNoExpirationKey)
+ {
+ this.warnNoExpirationKey = warnNoExpirationKey;
+ }
+
+ /**
+ * @return time to live, in milliseconds
+ */
+ public long getTimeToLive()
+ {
+ return timeToLive;
+ }
+
+ /**
+ * Sets the time to live
+ *
+ * @param timeToLive value in milliseconds
+ */
+ public void setTimeToLive(long timeToLive)
+ {
+ this.timeToLive = timeToLive;
+ }
+
+ public void setTimeToLive(long timeToLive, TimeUnit timeUnit)
+ {
+ this.timeToLive = timeUnit.toMillis(timeToLive);
+ }
+
+ @Override
+ public ExpirationAlgorithmConfig clone() throws CloneNotSupportedException
+ {
+ return (ExpirationAlgorithmConfig) super.clone();
+ }
+
+ public boolean equals(Object o)
+ {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ if (!super.equals(o)) return false;
+
+ ExpirationAlgorithmConfig that = (ExpirationAlgorithmConfig) o;
+
+ if (timeToLive != that.timeToLive) return false;
+ if (warnNoExpirationKey != that.warnNoExpirationKey) return false;
+ if (expirationKeyName != null ? !expirationKeyName.equals(that.expirationKeyName) :
that.expirationKeyName != null)
+ return false;
+
+ return true;
+ }
+
+ public int hashCode()
+ {
+ int result = super.hashCode();
+ result = 31 * result + (expirationKeyName != null ? expirationKeyName.hashCode() :
0);
+ result = 31 * result + (warnNoExpirationKey ? 1 : 0);
+ result = 31 * result + (int) (timeToLive ^ (timeToLive >>> 32));
+ return result;
+ }
+}
\ No newline at end of file
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationConfiguration.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationConfiguration.java 2008-08-14
19:16:15 UTC (rev 6561)
+++
core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationConfiguration.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -1,10 +1,16 @@
package org.jboss.cache.eviction;
import org.jboss.cache.config.Dynamic;
+import org.jboss.cache.config.EvictionAlgorithmConfig;
+import java.util.concurrent.TimeUnit;
+
/**
* Configuration for indicating the Node key for setting a specific eviction time.
+ *
+ * @deprecated see {@link org.jboss.cache.eviction.ExpirationAlgorithmConfig}
*/
+@Deprecated
public class ExpirationConfiguration extends EvictionPolicyConfigBase
{
@@ -24,19 +30,27 @@
@Dynamic
private boolean warnNoExpirationKey = true;
- @Deprecated
@Dynamic
private int timeToLiveSeconds = 0;
- @Dynamic
- private long timeToLive = 0;
-
@Override
protected void setEvictionPolicyClassName()
{
setEvictionPolicyClass(ExpirationPolicy.class.getName());
}
+ @Override
+ public EvictionAlgorithmConfig modernize()
+ {
+ ExpirationAlgorithmConfig modernCfg = new ExpirationAlgorithmConfig();
+ modernCfg.setExpirationKeyName(getExpirationKeyName());
+ modernCfg.setTimeToLive(getTimeToLiveSeconds(), TimeUnit.SECONDS);
+ modernCfg.setWarnNoExpirationKey(getWarnNoExpirationKey());
+ modernCfg.setMaxNodes(getMaxNodes());
+ modernCfg.setMinTimeToLive(getMinTimeToLiveSeconds(), TimeUnit.SECONDS);
+ return modernCfg;
+ }
+
/**
* Returns the expirationKeyName.
* This key should point to a java.lang.Long value in the Node data.
@@ -70,36 +84,14 @@
this.warnNoExpirationKey = warnNoExpirationKey;
}
- /** value expressed in millis */
- public long getTimeToLive()
- {
- return timeToLive;
- }
-
- /** value expressed in millis */
- public void setTimeToLive(long timeToLive)
- {
- this.timeToLive = timeToLive;
- this.timeToLiveSeconds = (int) (timeToLive * 1000);
- }
-
- /**
- * Use {@link #getTimeToLive()}.
- */
- @Deprecated
public int getTimeToLiveSeconds()
{
return timeToLiveSeconds;
}
- /**
- * use {@link #setTimeToLive(long)}.
- */
- @Deprecated
public void setTimeToLiveSeconds(int timeToLiveSeconds)
{
this.timeToLiveSeconds = timeToLiveSeconds;
- timeToLive = timeToLiveSeconds * 1000;
}
@Override
@@ -107,6 +99,4 @@
{
return (ExpirationConfiguration) super.clone();
}
-
-
}
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationPolicy.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationPolicy.java 2008-08-14
19:16:15 UTC (rev 6561)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationPolicy.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -6,7 +6,9 @@
* Returns the {@link ExpirationAlgorithm} as the policy's algorithm.
*
* @author rosse
+ * @deprecated see ExpirationAlgorithm
*/
+@Deprecated
public class ExpirationPolicy extends BaseEvictionPolicy
{
@@ -14,7 +16,7 @@
public ExpirationPolicy()
{
- algorithm = new ExpirationAlgorithm(this);
+ algorithm = new ExpirationAlgorithm();
}
public EvictionAlgorithm getEvictionAlgorithm()
@@ -31,8 +33,8 @@
* Returns true if it's a visit node event.
*/
@Override
- public boolean canIgnoreEvent(Fqn fqn, NodeEventType eventType)
+ public boolean canIgnoreEvent(Fqn fqn, EvictionEventType eventType)
{
- return (eventType == NodeEventType.VISIT_NODE_EVENT);
+ return (eventType == EvictionEventType.VISIT_NODE_EVENT);
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/FIFOAlgorithm.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/FIFOAlgorithm.java 2008-08-14
19:16:15 UTC (rev 6561)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/FIFOAlgorithm.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -8,7 +8,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.Region;
+import org.jboss.cache.config.EvictionAlgorithmConfig;
/**
* First-in-first-out algorithm used to evict nodes.
@@ -24,7 +24,7 @@
@Override
- protected EvictionQueue setupEvictionQueue(Region region) throws EvictionException
+ protected EvictionQueue setupEvictionQueue() throws EvictionException
{
return new FIFOQueue();
}
@@ -39,7 +39,7 @@
// ensure that, if configured, nodes are kept alive for at least a minimum period
of time.
if (isYoungerThanMinimumTimeToLive(ne)) return false;
- FIFOConfiguration config = (FIFOConfiguration) region.getEvictionPolicyConfig();
+ FIFOAlgorithmConfig config = (FIFOAlgorithmConfig) evictionAlgorithmConfig;
if (trace)
{
log.trace("Deciding whether node in queue " + ne.getFqn() + "
requires eviction.");
@@ -48,5 +48,10 @@
int size = this.getEvictionQueue().getNumberOfNodes();
return config.getMaxNodes() != 0 && size > config.getMaxNodes();
}
+
+ public Class<? extends EvictionAlgorithmConfig> getConfigurationClass()
+ {
+ return FIFOAlgorithmConfig.class;
+ }
}
Copied: core/trunk/src/main/java/org/jboss/cache/eviction/FIFOAlgorithmConfig.java (from
rev 6544, core/trunk/src/main/java/org/jboss/cache/eviction/FIFOConfiguration.java)
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/FIFOAlgorithmConfig.java
(rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/FIFOAlgorithmConfig.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -0,0 +1,79 @@
+/*
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at
gnu.org.
+ */
+package org.jboss.cache.eviction;
+
+import org.jboss.cache.config.ConfigurationException;
+
+/**
+ * Configuration for {@link FIFOAlgorithm}.
+ * <p/>
+ * Requires a "maxNodes" attribute otherwise a ConfigurationException is
thrown.
+ *
+ * @author Manik Surtani
+ * @since 3.0
+ */
+public class FIFOAlgorithmConfig extends EvictionAlgorithmConfigBase
+{
+ /**
+ * The serialVersionUID
+ */
+ private static final long serialVersionUID = -7229715009546277313L;
+
+ public FIFOAlgorithmConfig()
+ {
+ evictionAlgorithmClassName = FIFOAlgorithm.class.getName();
+ // We require that maxNodes is set
+ setMaxNodes(-1);
+ }
+
+ public FIFOAlgorithmConfig(int maxNodes)
+ {
+ evictionAlgorithmClassName = FIFOAlgorithm.class.getName();
+ // We require that maxNodes is set
+ setMaxNodes(maxNodes);
+ }
+
+ /**
+ * Requires a positive maxNodes value or ConfigurationException
+ * is thrown.
+ */
+ @Override
+ public void validate() throws ConfigurationException
+ {
+ if (getMaxNodes() < 0)
+ {
+ throw new ConfigurationException("maxNodes must be must be " +
+ "configured to a value greater than or equal to 0");
+ }
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuilder ret = new StringBuilder();
+ ret.append("FIFOAlgorithmConfig: maxNodes = ").append(getMaxNodes());
+ return ret.toString();
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ return (obj instanceof FIFOAlgorithmConfig && super.equals(obj));
+ }
+
+ @Override
+ public void reset()
+ {
+ setMaxNodes(-1);
+ }
+
+ @Override
+ public FIFOAlgorithmConfig clone() throws CloneNotSupportedException
+ {
+ return (FIFOAlgorithmConfig) super.clone();
+ }
+}
\ No newline at end of file
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/FIFOConfiguration.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/FIFOConfiguration.java 2008-08-14
19:16:15 UTC (rev 6561)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/FIFOConfiguration.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -7,7 +7,10 @@
package org.jboss.cache.eviction;
import org.jboss.cache.config.ConfigurationException;
+import org.jboss.cache.config.EvictionAlgorithmConfig;
+import java.util.concurrent.TimeUnit;
+
/**
* Configuration for {@link FIFOPolicy}.
* <p/>
@@ -23,7 +26,9 @@
*
* @author Daniel Huang (dhuang(a)jboss.org)
* @version $Revision$
+ * @deprecated see {@link org.jboss.cache.eviction.FIFOAlgorithmConfig}
*/
+@Deprecated
public class FIFOConfiguration extends EvictionPolicyConfigBase
{
/**
@@ -38,6 +43,15 @@
setMaxNodes(-1);
}
+ @Override
+ public EvictionAlgorithmConfig modernize()
+ {
+ FIFOAlgorithmConfig modernCfg = new FIFOAlgorithmConfig();
+ modernCfg.setMaxNodes(getMaxNodes());
+ modernCfg.setMinTimeToLive(getMinTimeToLiveSeconds(), TimeUnit.SECONDS);
+ return modernCfg;
+ }
+
/**
* Requires a positive maxNodes value or ConfigurationException
* is thrown.
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/FIFOPolicy.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/FIFOPolicy.java 2008-08-14 19:16:15
UTC (rev 6561)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/FIFOPolicy.java 2008-08-15 10:59:40
UTC (rev 6562)
@@ -13,7 +13,9 @@
* @author Daniel Huang (dhuang(a)jboss.org)
* @author Morten Kvistgaard
* @version $Revision$
+ * @deprecated see FIFOAlgorithm
*/
+@Deprecated
public class FIFOPolicy extends BaseEvictionPolicy
{
private FIFOAlgorithm algorithm;
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/LFUAlgorithm.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/LFUAlgorithm.java 2008-08-14
19:16:15 UTC (rev 6561)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/LFUAlgorithm.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -8,7 +8,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.Region;
+import org.jboss.cache.config.EvictionAlgorithmConfig;
/**
* Least Frequently Used algorithm for cache eviction.
@@ -49,7 +49,7 @@
// ensure that, if configured, nodes are kept alive for at least a minimum period
of time.
if (isYoungerThanMinimumTimeToLive(ne)) return false;
- LFUConfiguration config = (LFUConfiguration) region.getEvictionPolicyConfig();
+ LFUAlgorithmConfig config = (LFUAlgorithmConfig) evictionAlgorithmConfig;
int size = this.getEvictionQueue().getNumberOfNodes();
if (config.getMaxNodes() != 0 && size > config.getMaxNodes())
{
@@ -66,12 +66,11 @@
/**
* Will create a LFUQueue to be used as the underlying eviction queue.
*
- * @param region MarshRegion to create the eviction queue for.
* @return The created LFUQueue.
* @throws EvictionException
*/
@Override
- protected EvictionQueue setupEvictionQueue(Region region) throws EvictionException
+ protected EvictionQueue setupEvictionQueue() throws EvictionException
{
return new LFUQueue();
}
@@ -84,4 +83,9 @@
// clean up the Queue's eviction removals
((LFUQueue) this.evictionQueue).prune();
}
+
+ public Class<? extends EvictionAlgorithmConfig> getConfigurationClass()
+ {
+ return LFUAlgorithmConfig.class;
+ }
}
Copied: core/trunk/src/main/java/org/jboss/cache/eviction/LFUAlgorithmConfig.java (from
rev 6544, core/trunk/src/main/java/org/jboss/cache/eviction/LFUConfiguration.java)
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/LFUAlgorithmConfig.java
(rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/LFUAlgorithmConfig.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -0,0 +1,81 @@
+/*
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at
gnu.org.
+ */
+package org.jboss.cache.eviction;
+
+import org.jboss.cache.config.Dynamic;
+
+/**
+ * Configuration implementation for {@link LFUAlgorithm}.
+ *
+ * @author Manik Surtani
+ * @since 3.0
+ */
+public class LFUAlgorithmConfig extends EvictionAlgorithmConfigBase
+{
+ /**
+ * The serialVersionUID
+ */
+ private static final long serialVersionUID = 1865801530398969179L;
+
+ @Dynamic
+ private int minNodes;
+
+ public LFUAlgorithmConfig()
+ {
+ evictionAlgorithmClassName = LFUAlgorithm.class.getName();
+ }
+
+ public LFUAlgorithmConfig(int maxNodes, int minNodes)
+ {
+ this();
+ setMaxNodes(maxNodes);
+ setMinNodes(minNodes);
+ }
+
+ public int getMinNodes()
+ {
+ return minNodes;
+ }
+
+ public void setMinNodes(int minNodes)
+ {
+ testImmutability("minNodes");
+ this.minNodes = minNodes;
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuilder ret = new StringBuilder();
+ ret.append("LFUAlgorithmConfig: maxNodes =
").append(getMaxNodes()).append(" minNodes = ").append(getMinNodes());
+ return ret.toString();
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj instanceof LFUAlgorithmConfig && super.equals(obj))
+ {
+ return (this.minNodes == ((LFUAlgorithmConfig) obj).minNodes);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = super.hashCode();
+ result = 31 * result + minNodes;
+ return result;
+ }
+
+ @Override
+ public LFUAlgorithmConfig clone() throws CloneNotSupportedException
+ {
+ return (LFUAlgorithmConfig) super.clone();
+ }
+}
\ No newline at end of file
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/LFUConfiguration.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/LFUConfiguration.java 2008-08-14
19:16:15 UTC (rev 6561)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/LFUConfiguration.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -7,7 +7,10 @@
package org.jboss.cache.eviction;
import org.jboss.cache.config.Dynamic;
+import org.jboss.cache.config.EvictionAlgorithmConfig;
+import java.util.concurrent.TimeUnit;
+
/**
* Configuration implementation for {@link LFUPolicy}.
* <p/>
@@ -22,7 +25,9 @@
*
* @author Daniel Huang (dhuang(a)jboss.org)
* @version $Revision$
+ * @deprecated see {@link org.jboss.cache.eviction.LFUAlgorithmConfig}
*/
+@Deprecated
public class LFUConfiguration extends EvictionPolicyConfigBase
{
/**
@@ -51,6 +56,16 @@
}
@Override
+ public EvictionAlgorithmConfig modernize()
+ {
+ LFUAlgorithmConfig modernCfg = new LFUAlgorithmConfig();
+ modernCfg.setMaxNodes(getMaxNodes());
+ modernCfg.setMinTimeToLive(getMinTimeToLiveSeconds(), TimeUnit.SECONDS);
+ modernCfg.setMinNodes(getMinNodes());
+ return modernCfg;
+ }
+
+ @Override
public String toString()
{
StringBuilder ret = new StringBuilder();
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/LFUPolicy.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/LFUPolicy.java 2008-08-14 19:16:15
UTC (rev 6561)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/LFUPolicy.java 2008-08-15 10:59:40
UTC (rev 6562)
@@ -11,7 +11,9 @@
*
* @author Daniel Huang - dhuang(a)jboss.org - 10/2005
* @version $Revision$
+ * @deprecated see LFUAlgorithm
*/
+@Deprecated
public class LFUPolicy extends BaseEvictionPolicy
{
private LFUAlgorithm algorithm;
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/LRUAlgorithm.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/LRUAlgorithm.java 2008-08-14
19:16:15 UTC (rev 6561)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/LRUAlgorithm.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -9,7 +9,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.Region;
+import org.jboss.cache.config.EvictionAlgorithmConfig;
import java.util.Iterator;
@@ -26,7 +26,7 @@
private static final boolean trace = log.isTraceEnabled();
@Override
- protected EvictionQueue setupEvictionQueue(Region region) throws EvictionException
+ protected EvictionQueue setupEvictionQueue() throws EvictionException
{
return new LRUQueue();
}
@@ -38,7 +38,7 @@
// ensure that, if configured, nodes are kept alive for at least a minimum period
of time.
if (isYoungerThanMinimumTimeToLive(entry)) return false;
- LRUConfiguration config = (LRUConfiguration) region.getEvictionPolicyConfig();
+ LRUAlgorithmConfig config = (LRUAlgorithmConfig) evictionAlgorithmConfig;
// no idle or max time limit
if (config.getTimeToLive() == 0 && config.getMaxAge() == 0) return false;
@@ -152,7 +152,7 @@
}
}
- int maxNodes = this.getConfiguration().getMaxNodes();
+ int maxNodes = ((LRUAlgorithmConfig) evictionAlgorithmConfig).getMaxNodes();
if (maxNodes <= 0)
{
return;
@@ -177,9 +177,8 @@
}
}
- protected LRUConfiguration getConfiguration()
+ public Class<? extends EvictionAlgorithmConfig> getConfigurationClass()
{
- return (LRUConfiguration) region.getEvictionPolicyConfig();
+ return LRUAlgorithmConfig.class;
}
-
}
Copied: core/trunk/src/main/java/org/jboss/cache/eviction/LRUAlgorithmConfig.java (from
rev 6544, core/trunk/src/main/java/org/jboss/cache/eviction/LRUConfiguration.java)
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/LRUAlgorithmConfig.java
(rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/LRUAlgorithmConfig.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -0,0 +1,166 @@
+/*
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at
gnu.org.
+ */
+package org.jboss.cache.eviction;
+
+import org.jboss.cache.config.ConfigurationException;
+import org.jboss.cache.config.Dynamic;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Configuration implementation for {@link LRUAlgorithm}.
+ * <p/>
+ *
+ * @author Manik Surtani
+ * @since 3.0
+ */
+public class LRUAlgorithmConfig extends EvictionAlgorithmConfigBase
+{
+ /**
+ * The serialVersionUID
+ */
+ private static final long serialVersionUID = -3426716488271559729L;
+
+ /**
+ * value expressed in millis
+ */
+ @Dynamic
+ private long timeToLive;
+
+ /**
+ * value expressed in millis
+ */
+ @Dynamic
+ private long maxAge;
+
+ public LRUAlgorithmConfig()
+ {
+ evictionAlgorithmClassName = LRUAlgorithm.class.getName();
+ // Force config of ttls
+ setTimeToLive(-1);
+ }
+
+ public LRUAlgorithmConfig(long timeToLive, long maxAge)
+ {
+ this();
+ this.timeToLive = timeToLive;
+ this.maxAge = maxAge;
+ }
+
+ public LRUAlgorithmConfig(int timeToLive, int maxAge, int maxNodes)
+ {
+ this(timeToLive, maxAge);
+ this.maxNodes = maxNodes;
+ }
+
+ /**
+ * @return the time to live, in milliseconds
+ */
+ public long getTimeToLive()
+ {
+ return timeToLive;
+ }
+
+ /**
+ * Sets the time to live
+ *
+ * @param timeToLive the time to live, in milliseconds
+ */
+ public void setTimeToLive(long timeToLive)
+ {
+ testImmutability("timeToLive");
+ this.timeToLive = timeToLive;
+ }
+
+ public void setTimeToLive(long timeToLive, TimeUnit timeUnit)
+ {
+ testImmutability("timeToLive");
+ this.timeToLive = timeUnit.toMillis(timeToLive);
+ }
+
+ /**
+ * @return the max age per element, in milliseconds
+ */
+ public long getMaxAge()
+ {
+ return maxAge;
+ }
+
+ /**
+ * Sets the max age per element
+ *
+ * @param maxAge value in milliseconds
+ */
+ public void setMaxAge(long maxAge)
+ {
+ testImmutability("maxAge");
+ this.maxAge = maxAge;
+ }
+
+ public void setMaxAge(long maxAge, TimeUnit timeUnit)
+ {
+ testImmutability("maxAge");
+ this.maxAge = timeUnit.toMillis(maxAge);
+ }
+
+ /**
+ * Requires a positive timeToLive value or ConfigurationException
+ * is thrown.
+ */
+ @Override
+ public void validate() throws ConfigurationException
+ {
+ if (timeToLive < 0)
+ {
+ throw new ConfigurationException("timeToLive must be " +
+ "configured to a value greater than or equal to 0 for " +
getEvictionAlgorithmClassName());
+ }
+ }
+
+ public String toString()
+ {
+ return "LRUAlgorithmConfig {" +
+ ", timeToLive=" + timeToLive +
+ ", maxAge=" + maxAge +
+ '}';
+ }
+
+ public boolean equals(Object o)
+ {
+ if (this == o) return true;
+ if (!(o instanceof LRUAlgorithmConfig)) return false;
+ if (!super.equals(o)) return false;
+
+ LRUAlgorithmConfig that = (LRUAlgorithmConfig) o;
+
+ if (maxAge != that.maxAge) return false;
+ if (timeToLive != that.timeToLive) return false;
+
+ return true;
+ }
+
+ public int hashCode()
+ {
+ int result = super.hashCode();
+ result = 31 * result + (int) (timeToLive ^ (timeToLive >>> 32));
+ result = 31 * result + (int) (maxAge ^ (maxAge >>> 32));
+ return result;
+ }
+
+ @Override
+ public void reset()
+ {
+ super.reset();
+ setTimeToLive(-1);
+ }
+
+ @Override
+ public LRUAlgorithmConfig clone() throws CloneNotSupportedException
+ {
+ return (LRUAlgorithmConfig) super.clone();
+ }
+}
\ No newline at end of file
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/LRUConfiguration.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/LRUConfiguration.java 2008-08-14
19:16:15 UTC (rev 6561)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/LRUConfiguration.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -8,7 +8,10 @@
import org.jboss.cache.config.ConfigurationException;
import org.jboss.cache.config.Dynamic;
+import org.jboss.cache.config.EvictionAlgorithmConfig;
+import java.util.concurrent.TimeUnit;
+
/**
* Configuration implementation for {@link LRUPolicy}.
* <p/>
@@ -24,7 +27,9 @@
*
* @author Daniel Huang (dhuang(a)jboss.org)
* @version $Revision$
+ * @deprecated see {@link org.jboss.cache.eviction.LRUAlgorithmConfig}
*/
+@Deprecated
public class LRUConfiguration extends EvictionPolicyConfigBase
{
/**
@@ -33,33 +38,26 @@
private static final long serialVersionUID = -3426716488271559729L;
@Dynamic
- @Deprecated
private int timeToLiveSeconds;
@Dynamic
- @Deprecated
private int maxAgeSeconds;
-
- /** value expressed in millis*/
- @Dynamic
- private long timeToLive;
-
- /** value expressed in millis*/
- @Dynamic
- private long maxAge;
-
public LRUConfiguration()
{
super();
// Force config of ttls
- setTimeToLive(-1);
+ setTimeToLiveSeconds(-1);
}
- public LRUConfiguration(long timeToLive, long maxAge)
+ @Override
+ public EvictionAlgorithmConfig modernize()
{
- super();
- setTimeToLive(timeToLive);
- setMaxAge(maxAge);
+ LRUAlgorithmConfig modernCfg = new LRUAlgorithmConfig();
+ modernCfg.setMaxNodes(getMaxNodes());
+ modernCfg.setMinTimeToLive(getMinTimeToLiveSeconds(), TimeUnit.SECONDS);
+ modernCfg.setTimeToLive(getTimeToLiveSeconds(), TimeUnit.SECONDS);
+ modernCfg.setMaxAge(getMaxAgeSeconds(), TimeUnit.SECONDS);
+ return modernCfg;
}
@Override
@@ -68,75 +66,26 @@
setEvictionPolicyClass(LRUPolicy.class.getName());
}
- /** value expressed in millis*/
- public long getTimeToLive()
- {
- return timeToLive;
- }
-
- /** value expressed in millis*/
- public void setTimeToLive(long timeToLive)
- {
- testImmutability("timeToLive");
- this.timeToLive = timeToLive;
- this.timeToLiveSeconds = (int)(timeToLive/1000);
- }
-
- /** value expressed in millis*/
- public long getMaxAge()
- {
- return maxAge;
- }
-
- /** value expressed in millis*/
- public void setMaxAge(long maxAge)
- {
- testImmutability("maxAge");
- this.maxAge = maxAge;
- this.maxAgeSeconds = (int) (maxAge/1000);
- }
-
- /**
- * use {@link #getTimeToLive()}
- * @return
- */
- @Deprecated
public int getTimeToLiveSeconds()
{
return timeToLiveSeconds;
}
- /**
- * Use {@link #setTimeToLive(long)}
- */
- @Deprecated
public void setTimeToLiveSeconds(int timeToLiveSeconds)
{
testImmutability("timeToLiveSeconds");
this.timeToLiveSeconds = timeToLiveSeconds;
- timeToLive = timeToLiveSeconds * 1000;
}
- /**
- * Use {@link #getMaxAge()}
- * @deprecated
- */
- @Deprecated
public int getMaxAgeSeconds()
{
return maxAgeSeconds;
}
- /**
- * Use {@link #getMaxAge()}
- * @param maxAgeSeconds
- */
- @Deprecated
public void setMaxAgeSeconds(int maxAgeSeconds)
{
testImmutability("maxAgeSeconds");
this.maxAgeSeconds = maxAgeSeconds;
- this.maxAge = maxAgeSeconds * 1000;
}
/**
@@ -146,7 +95,7 @@
@Override
public void validate() throws ConfigurationException
{
- if (timeToLive < 0)
+ if (timeToLiveSeconds < 0)
{
throw new ConfigurationException("timeToLive must be " +
"configured to a value greater than or equal to 0 for " +
getEvictionPolicyClass());
@@ -158,8 +107,8 @@
{
return "LRUConfiguration{" +
"timeToLiveSeconds=" + timeToLiveSeconds +
- ", timeToLive=" + timeToLive +
- ", maxAge=" + maxAge +
+ ", timeToLiveSeconds=" + timeToLiveSeconds +
+ ", maxAgeSeconds=" + maxAgeSeconds +
'}';
}
@@ -171,10 +120,10 @@
LRUConfiguration that = (LRUConfiguration) o;
- if (maxAge != that.maxAge) return false;
if (maxAgeSeconds != that.maxAgeSeconds) return false;
- if (timeToLive != that.timeToLive) return false;
+ if (maxAgeSeconds != that.maxAgeSeconds) return false;
if (timeToLiveSeconds != that.timeToLiveSeconds) return false;
+ if (timeToLiveSeconds != that.timeToLiveSeconds) return false;
return true;
}
@@ -184,8 +133,8 @@
int result = super.hashCode();
result = 31 * result + timeToLiveSeconds;
result = 31 * result + maxAgeSeconds;
- result = 31 * result + (int) (timeToLive ^ (timeToLive >>> 32));
- result = 31 * result + (int) (maxAge ^ (maxAge >>> 32));
+ result = 31 * result + (timeToLiveSeconds ^ (timeToLiveSeconds >>> 7));
+ result = 31 * result + (maxAgeSeconds ^ (maxAgeSeconds >>> 7));
return result;
}
@@ -193,7 +142,7 @@
public void reset()
{
super.reset();
- setTimeToLive(-1);
+ setTimeToLiveSeconds(-1);
}
@Override
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/LRUPolicy.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/LRUPolicy.java 2008-08-14 19:16:15
UTC (rev 6561)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/LRUPolicy.java 2008-08-15 10:59:40
UTC (rev 6562)
@@ -17,7 +17,9 @@
* @author Ben Wang 02-2004
* @author Daniel Huang - dhuang(a)jboss.org
* @version $Revision$
+ * @deprecated see LRUAlgorithm
*/
+@Deprecated
public class LRUPolicy extends BaseEvictionPolicy
{
protected RegionManager regionManager_;
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/MRUAlgorithm.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/MRUAlgorithm.java 2008-08-14
19:16:15 UTC (rev 6561)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/MRUAlgorithm.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -6,7 +6,7 @@
*/
package org.jboss.cache.eviction;
-import org.jboss.cache.Region;
+import org.jboss.cache.config.EvictionAlgorithmConfig;
/**
* Most Recently Used Algorithm.
@@ -22,7 +22,7 @@
public class MRUAlgorithm extends BaseEvictionAlgorithm
{
@Override
- protected EvictionQueue setupEvictionQueue(Region region) throws EvictionException
+ protected EvictionQueue setupEvictionQueue() throws EvictionException
{
return new MRUQueue();
}
@@ -34,14 +34,19 @@
// ensure that, if configured, nodes are kept alive for at least a minimum period
of time.
if (isYoungerThanMinimumTimeToLive(ne)) return false;
- MRUConfiguration config = (MRUConfiguration) region.getEvictionPolicyConfig();
+ MRUAlgorithmConfig config = (MRUAlgorithmConfig) evictionAlgorithmConfig;
return evictionQueue.getNumberOfNodes() > config.getMaxNodes();
}
@Override
- protected void processVisitedNodes(EvictedEventNode evictedEventNode) throws
EvictionException
+ protected void processVisitedNodes(EvictionEvent evictedEventNode) throws
EvictionException
{
super.processVisitedNodes(evictedEventNode);
((MRUQueue) evictionQueue).moveToTopOfStack(evictedEventNode.getFqn());
}
+
+ public Class<? extends EvictionAlgorithmConfig> getConfigurationClass()
+ {
+ return MRUAlgorithmConfig.class;
+ }
}
Copied: core/trunk/src/main/java/org/jboss/cache/eviction/MRUAlgorithmConfig.java (from
rev 6552, core/trunk/src/main/java/org/jboss/cache/eviction/MRUConfiguration.java)
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/MRUAlgorithmConfig.java
(rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/MRUAlgorithmConfig.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -0,0 +1,77 @@
+/*
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at
gnu.org.
+ */
+package org.jboss.cache.eviction;
+
+import org.jboss.cache.config.ConfigurationException;
+
+/**
+ * Configuration for {@link MRUAlgorithm}.
+ * <p/>
+ * Requires a "maxNodes" attribute otherwise a ConfigurationException is
thrown.
+ *
+ * @author Manik Surtani
+ * @since 3.0
+ */
+public class MRUAlgorithmConfig extends EvictionAlgorithmConfigBase
+{
+ /**
+ * The serialVersionUID
+ */
+ private static final long serialVersionUID = -8734577898966155218L;
+
+ public MRUAlgorithmConfig()
+ {
+ evictionAlgorithmClassName = MRUAlgorithm.class.getName();
+ // We require that maxNodes is set
+ setMaxNodes(-1);
+ }
+
+ public MRUAlgorithmConfig(int maxNodes)
+ {
+ evictionAlgorithmClassName = MRUAlgorithm.class.getName();
+ setMaxNodes(maxNodes);
+ }
+
+ /**
+ * Requires a positive maxNodes value or ConfigurationException
+ * is thrown.
+ */
+ @Override
+ public void validate() throws ConfigurationException
+ {
+ if (getMaxNodes() < 0)
+ throw new ConfigurationException("maxNodes not configured");
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuilder str = new StringBuilder();
+ str.append("MRUAlgorithmConfig: ").
+ append(" maxNodes =").append(getMaxNodes());
+ return str.toString();
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ return (obj instanceof MRUAlgorithmConfig && super.equals(obj));
+ }
+
+ @Override
+ public void reset()
+ {
+ setMaxNodes(-1);
+ }
+
+ @Override
+ public MRUAlgorithmConfig clone() throws CloneNotSupportedException
+ {
+ return (MRUAlgorithmConfig) super.clone();
+ }
+
+}
\ No newline at end of file
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/MRUConfiguration.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/MRUConfiguration.java 2008-08-14
19:16:15 UTC (rev 6561)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/MRUConfiguration.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -7,7 +7,10 @@
package org.jboss.cache.eviction;
import org.jboss.cache.config.ConfigurationException;
+import org.jboss.cache.config.EvictionAlgorithmConfig;
+import java.util.concurrent.TimeUnit;
+
/**
* Configuration for {@link MRUPolicy}.
* <p/>
@@ -23,7 +26,9 @@
*
* @author Daniel Huang (dhuang(a)jboss.org)
* @version $Revision$
+ * @deprecated see {@link org.jboss.cache.eviction.MRUAlgorithmConfig}
*/
+@Deprecated
public class MRUConfiguration extends EvictionPolicyConfigBase
{
/**
@@ -44,7 +49,16 @@
setEvictionPolicyClass(MRUPolicy.class.getName());
}
+ @Override
+ public EvictionAlgorithmConfig modernize()
+ {
+ MRUAlgorithmConfig modernCfg = new MRUAlgorithmConfig();
+ modernCfg.setMaxNodes(getMaxNodes());
+ modernCfg.setMinTimeToLive(getMinTimeToLiveSeconds(), TimeUnit.SECONDS);
+ return modernCfg;
+ }
+
/**
* Requires a positive maxNodes value or ConfigurationException
* is thrown.
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/MRUPolicy.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/MRUPolicy.java 2008-08-14 19:16:15
UTC (rev 6561)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/MRUPolicy.java 2008-08-15 10:59:40
UTC (rev 6562)
@@ -13,7 +13,9 @@
*
* @author Daniel Huang (dhuang(a)jboss.org)
* @version $Revision$
+ * @deprecated see MRUAlgorithm
*/
+@Deprecated
public class MRUPolicy extends BaseEvictionPolicy
{
private MRUAlgorithm algorithm;
Added: core/trunk/src/main/java/org/jboss/cache/eviction/Modernizable.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/Modernizable.java
(rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/Modernizable.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -0,0 +1,17 @@
+package org.jboss.cache.eviction;
+
+import org.jboss.cache.config.EvictionAlgorithmConfig;
+
+/**
+ * Attached to deprecated eviction configuration elements that know how to map to modern
counterparts. This interface
+ * is itself deprecated and is only used to bridge deprecated configurations.
+ *
+ * @author Manik Surtani (<a
href="mailto:manik@jboss.org">manik@jboss.org</a>)
+ * @since 3.0
+ * @deprecated
+ */
+@Deprecated
+public interface Modernizable
+{
+ EvictionAlgorithmConfig modernize();
+}
Deleted: core/trunk/src/main/java/org/jboss/cache/eviction/NodeEventType.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/NodeEventType.java 2008-08-14
19:16:15 UTC (rev 6561)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/NodeEventType.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -1,40 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.cache.eviction;
-
-/**
- * Enumeration of the valid event types used to create an
- * {@link org.jboss.cache.eviction.EvictedEventNode}.
- *
- * @author <a href="brian.stansberry(a)jboss.com">Brian
Stansberry</a>
- * @version $Revision$
- */
-public enum NodeEventType
-{
- ADD_NODE_EVENT,
- REMOVE_NODE_EVENT,
- VISIT_NODE_EVENT,
- ADD_ELEMENT_EVENT,
- REMOVE_ELEMENT_EVENT,
- MARK_IN_USE_EVENT,
- UNMARK_USE_EVENT
-}
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/NullEvictionAlgorithm.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/eviction/NullEvictionAlgorithm.java 2008-08-14
19:16:15 UTC (rev 6561)
+++
core/trunk/src/main/java/org/jboss/cache/eviction/NullEvictionAlgorithm.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -1,27 +1,40 @@
/**
- *
+ *
*/
package org.jboss.cache.eviction;
-import org.jboss.cache.Region;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.config.EvictionAlgorithmConfig;
+import org.jboss.cache.eviction.EvictionEvent.Type;
+import java.util.concurrent.BlockingQueue;
+
/**
- * Algorithm for {@link NullEvictionPolicy}.
- *
+ * An eviction algorithm that does nothing - a no-op for everything.
+ *
* @author Brian Stansberry
*/
public class NullEvictionAlgorithm implements EvictionAlgorithm
{
- /** Singleton instance of this class. */
- public static final NullEvictionAlgorithm INSTANCE = new NullEvictionAlgorithm();
-
/**
+ * Singleton instance of this class.
+ */
+ private static final NullEvictionAlgorithm INSTANCE = new NullEvictionAlgorithm();
+
+ /**
* Constructs a new NullEvictionAlgorithm.
*/
private NullEvictionAlgorithm()
{
}
+ public static NullEvictionAlgorithm getInstance()
+ {
+ return INSTANCE;
+ }
+
/**
* Returns {@link NullEvictionQueue#INSTANCE}.
*/
@@ -30,16 +43,38 @@
return NullEvictionQueue.INSTANCE;
}
- /** No-op */
- public void process(Region region) throws EvictionException
+ public void setEvictionActionPolicy(EvictionActionPolicy evictionActionPolicy)
{
// no-op
}
- /** No-op */
- public void resetEvictionQueue(Region region)
+ public void assignToRegion(Fqn fqn, CacheSPI<?, ?> cache,
EvictionAlgorithmConfig evictionAlgorithmConfig, Configuration configuration)
{
// no-op
}
+ public void process(BlockingQueue<EvictionEvent> queue) throws
EvictionException
+ {
+ // no-op
+ }
+
+ public void resetEvictionQueue()
+ {
+ // no-op
+ }
+
+ public boolean canIgnoreEvent(Type eventType)
+ {
+ return true; // always ignore everything!
+ }
+
+ public void initialize()
+ {
+ // no-op
+ }
+
+ public Class<? extends EvictionAlgorithmConfig> getConfigurationClass()
+ {
+ return NullEvictionAlgorithmConfig.class;
+ }
}
Copied: core/trunk/src/main/java/org/jboss/cache/eviction/NullEvictionAlgorithmConfig.java
(from rev 6552,
core/trunk/src/main/java/org/jboss/cache/eviction/NullEvictionPolicyConfig.java)
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/NullEvictionAlgorithmConfig.java
(rev 0)
+++
core/trunk/src/main/java/org/jboss/cache/eviction/NullEvictionAlgorithmConfig.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -0,0 +1,45 @@
+/**
+ *
+ */
+package org.jboss.cache.eviction;
+
+import org.jboss.cache.config.ConfigurationComponent;
+import org.jboss.cache.config.ConfigurationException;
+import org.jboss.cache.config.EvictionAlgorithmConfig;
+
+/**
+ * Configuration class for {@link NullEvictionAlgorithm}.
+ *
+ * @author Manik Surtani
+ * @since 3.0
+ */
+public class NullEvictionAlgorithmConfig extends ConfigurationComponent implements
EvictionAlgorithmConfig
+{
+ private static final long serialVersionUID = -6591180473728241737L;
+
+ /**
+ * No-op
+ */
+ public void reset()
+ {
+ // no-op
+ }
+
+ public String getEvictionAlgorithmClassName()
+ {
+ return NullEvictionAlgorithm.class.getName();
+ }
+
+ /**
+ * No-op
+ */
+ public void validate() throws ConfigurationException
+ {
+ // no-op
+ }
+
+ public NullEvictionAlgorithmConfig clone() throws CloneNotSupportedException
+ {
+ return (NullEvictionAlgorithmConfig) super.clone();
+ }
+}
\ No newline at end of file
Property changes on:
core/trunk/src/main/java/org/jboss/cache/eviction/NullEvictionAlgorithmConfig.java
___________________________________________________________________
Name: svn:executable
+ *
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/NullEvictionPolicy.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/NullEvictionPolicy.java 2008-08-14
19:16:15 UTC (rev 6561)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/NullEvictionPolicy.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -18,7 +18,9 @@
* want eviction.
*
* @author Brian Stansberry
+ * @deprecated see NullEvictionAlgorithm
*/
+@Deprecated
public class NullEvictionPolicy implements EvictionPolicy
{
private static final Log log = LogFactory.getLog(NullEvictionPolicy.class);
@@ -28,7 +30,7 @@
/**
* Returns <code>true</code>
*/
- public boolean canIgnoreEvent(Fqn fqn, NodeEventType eventType)
+ public boolean canIgnoreEvent(Fqn fqn, EvictionEventType eventType)
{
return true;
}
@@ -46,7 +48,7 @@
*/
public EvictionAlgorithm getEvictionAlgorithm()
{
- return NullEvictionAlgorithm.INSTANCE;
+ return NullEvictionAlgorithm.getInstance();
}
/**
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/NullEvictionPolicyConfig.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/eviction/NullEvictionPolicyConfig.java 2008-08-14
19:16:15 UTC (rev 6561)
+++
core/trunk/src/main/java/org/jboss/cache/eviction/NullEvictionPolicyConfig.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -5,16 +5,19 @@
import org.jboss.cache.config.ConfigurationComponent;
import org.jboss.cache.config.ConfigurationException;
+import org.jboss.cache.config.EvictionAlgorithmConfig;
import org.jboss.cache.config.EvictionPolicyConfig;
/**
* Configuration class for {@link NullEvictionPolicy}.
*
* @author Brian Stansberry
+ * @deprecated see {@link NullEvictionAlgorithmConfig}
*/
+@Deprecated
public class NullEvictionPolicyConfig
extends ConfigurationComponent
- implements EvictionPolicyConfig
+ implements EvictionPolicyConfig, Modernizable
{
private static final long serialVersionUID = -6591180473728241737L;
@@ -27,6 +30,11 @@
return NullEvictionPolicy.class.getName();
}
+ public EvictionAlgorithmConfig modernize()
+ {
+ return new NullEvictionAlgorithmConfig();
+ }
+
/**
* No-op
*/
@@ -42,5 +50,4 @@
{
// no-op
}
-
}
Added: core/trunk/src/main/java/org/jboss/cache/eviction/RemoveOnEvictActionPolicy.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/RemoveOnEvictActionPolicy.java
(rev 0)
+++
core/trunk/src/main/java/org/jboss/cache/eviction/RemoveOnEvictActionPolicy.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -0,0 +1,36 @@
+package org.jboss.cache.eviction;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.Cache;
+import org.jboss.cache.Fqn;
+
+/**
+ * An eviction action policy that calls {@link
org.jboss.cache.Cache#removeNode(org.jboss.cache.Fqn)} to evict a node.
+ *
+ * @author Manik Surtani (<a
href="mailto:manik@jboss.org">manik@jboss.org</a>)
+ * @since 3.0
+ */
+public class RemoveOnEvictActionPolicy implements EvictionActionPolicy
+{
+ Cache<?, ?> cache;
+ private static final Log log = LogFactory.getLog(DefaultEvictionActionPolicy.class);
+
+ public void setCache(Cache<?, ?> cache)
+ {
+ this.cache = cache;
+ }
+
+ public boolean evict(Fqn fqn)
+ {
+ try
+ {
+ return cache.removeNode(fqn);
+ }
+ catch (Exception e)
+ {
+ if (log.isDebugEnabled()) log.debug("Unable to evict " + fqn, e);
+ return false;
+ }
+ }
+}
\ No newline at end of file
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/BuddyRegionAwareEvictionInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/BuddyRegionAwareEvictionInterceptor.java 2008-08-14
19:16:15 UTC (rev 6561)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/BuddyRegionAwareEvictionInterceptor.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -2,9 +2,8 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
-import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.buddyreplication.BuddyFqnTransformer;
-import org.jboss.cache.eviction.NodeEventType;
+import org.jboss.cache.factories.annotations.Inject;
/**
* A subclass of EvictionInterceptor that is aware of and able to deal with buddy
regions.
@@ -23,9 +22,9 @@
}
@Override
- protected Region getRegion(Fqn fqn, NodeEventType type)
+ protected Region getRegion(Fqn fqn)
{
- Region r = super.getRegion(fqn, type);
+ Region r = super.getRegion(fqn);
if (r != null)
return r;
else if (buddyFqnTransformer.isBackupFqn(fqn))
@@ -41,7 +40,7 @@
//create a new region for this backup
Region newRegion = regionManager.getRegion(Fqn.fromRelativeFqn(backupRoot,
actualRegion.getFqn()), Region.Type.EVICTION, true);
- newRegion.setEvictionPolicy(actualRegion.getEvictionPolicyConfig());
+ newRegion.setEvictionRegionConfig(actualRegion.getEvictionRegionConfig());
return newRegion;
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/EvictionInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/EvictionInterceptor.java 2008-08-14
19:16:15 UTC (rev 6561)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/EvictionInterceptor.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -21,8 +21,8 @@
import org.jboss.cache.commands.write.PutKeyValueCommand;
import org.jboss.cache.commands.write.RemoveKeyCommand;
import org.jboss.cache.commands.write.RemoveNodeCommand;
-import org.jboss.cache.eviction.EvictedEventNode;
-import org.jboss.cache.eviction.NodeEventType;
+import org.jboss.cache.eviction.EvictionEvent;
+import static org.jboss.cache.eviction.EvictionEvent.Type.*;
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.interceptors.base.CommandInterceptor;
import org.jboss.cache.invocation.InvocationContext;
@@ -71,9 +71,9 @@
if (!complete)
{
Region r;
- if (fqn != null && (r = getRegion(fqn, NodeEventType.ADD_NODE_EVENT)) !=
null)
+ if (fqn != null && (r = getRegion(fqn)) != null)
{
- registerEvictionEventToRegionManager(new EvictedEventNode(fqn,
NodeEventType.ADD_NODE_EVENT, 0), r);
+ registerEvictionEventToRegionManager(fqn, ADD_NODE_EVENT, 0, r);
}
}
return retVal;
@@ -90,9 +90,9 @@
{
Object retVal = invokeNextInterceptor(ctx, command);
Region r;
- if (command.getFqn() != null && command.getKey() != null && (r =
getRegion(command.getFqn(), NodeEventType.ADD_ELEMENT_EVENT)) != null)
+ if (command.getFqn() != null && command.getKey() != null && (r =
getRegion(command.getFqn())) != null)
{
- registerEvictionEventToRegionManager(new EvictedEventNode(command.getFqn(),
NodeEventType.ADD_ELEMENT_EVENT, 1), r);
+ registerEvictionEventToRegionManager(command.getFqn(), ADD_ELEMENT_EVENT, 1,
r);
}
return retVal;
}
@@ -103,7 +103,7 @@
Object retVal = invokeNextInterceptor(ctx, command);
Fqn fqn = command.getFqn();
Region r;
- if (fqn != null && (r = getRegion(fqn, NodeEventType.ADD_NODE_EVENT)) !=
null)
+ if (fqn != null && (r = getRegion(fqn)) != null)
{
if (command.getData() == null)
{
@@ -119,8 +119,7 @@
{
size = command.getData().size();
}
- EvictedEventNode event = new EvictedEventNode(fqn,
NodeEventType.ADD_NODE_EVENT, size);
- registerEvictionEventToRegionManager(event, r);
+ registerEvictionEventToRegionManager(fqn, ADD_NODE_EVENT, size, r);
}
}
return retVal;
@@ -142,9 +141,9 @@
{
Fqn fqn = command.getFqn();
Region r;
- if (fqn != null && command.getKey() != null && (r =
getRegion(fqn, NodeEventType.REMOVE_ELEMENT_EVENT)) != null)
+ if (fqn != null && command.getKey() != null && (r =
getRegion(fqn)) != null)
{
- registerEvictionEventToRegionManager(new EvictedEventNode(fqn,
NodeEventType.REMOVE_ELEMENT_EVENT, 1), r);
+ registerEvictionEventToRegionManager(fqn, REMOVE_ELEMENT_EVENT, 1, r);
}
}
return retVal;
@@ -169,9 +168,9 @@
else
{
Region r;
- if (fqn != null && (r = getRegion(fqn, NodeEventType.VISIT_NODE_EVENT))
!= null)
+ if (fqn != null && (r = getRegion(fqn)) != null)
{
- registerEvictionEventToRegionManager(new EvictedEventNode(fqn,
NodeEventType.VISIT_NODE_EVENT), r);
+ registerEvictionEventToRegionManager(fqn, VISIT_NODE_EVENT, 0, r);
}
}
return retVal;
@@ -197,9 +196,9 @@
log.trace("No event added. Element does not exist");
}
}
- else if (fqn != null && command.getKey() != null && (r =
getRegion(fqn, NodeEventType.VISIT_NODE_EVENT)) != null)
+ else if (fqn != null && command.getKey() != null && (r =
getRegion(fqn)) != null)
{
- registerEvictionEventToRegionManager(new EvictedEventNode(fqn,
NodeEventType.VISIT_NODE_EVENT), r);
+ registerEvictionEventToRegionManager(fqn, VISIT_NODE_EVENT, 0, r);
}
return retVal;
}
@@ -209,9 +208,9 @@
{
Object retVal = invokeNextInterceptor(ctx, command);
Region r;
- if (command.getFqn() != null && (r = getRegion(command.getFqn(),
NodeEventType.REMOVE_NODE_EVENT)) != null)
+ if (command.getFqn() != null && (r = getRegion(command.getFqn())) != null)
{
- registerEvictionEventToRegionManager(new EvictedEventNode(command.getFqn(),
NodeEventType.REMOVE_NODE_EVENT), r);
+ registerEvictionEventToRegionManager(command.getFqn(), REMOVE_NODE_EVENT, 0,
r);
}
return retVal;
}
@@ -221,41 +220,25 @@
{
Object retVal = invokeNextInterceptor(ctx, command);
Region r;
- if (command.getFqn() != null && (r = getRegion(command.getFqn(),
NodeEventType.REMOVE_NODE_EVENT)) != null)
+ if (command.getFqn() != null && (r = getRegion(command.getFqn())) != null)
{
- registerEvictionEventToRegionManager(new EvictedEventNode(command.getFqn(),
NodeEventType.REMOVE_NODE_EVENT), r);
+ registerEvictionEventToRegionManager(command.getFqn(), REMOVE_NODE_EVENT, 0,
r);
}
return retVal;
}
- private void registerEvictionEventToRegionManager(EvictedEventNode event, Region
region)
+ private void registerEvictionEventToRegionManager(Fqn fqn, EvictionEvent.Type type,
int elementDifference, Region region)
{
- if (event == null)
- {
- // no node modifications.
- return;
- }
-
//we do not trigger eviction events for resident nodes
- if (dataContainer.isResident(event.getFqn())) return;
+ if (dataContainer.isResident(fqn)) return;
- region.putNodeEvent(event);
+ region.registerEvictionEvent(fqn, type, elementDifference);
- if (trace)
- {
- log.trace("Adding event " + event + " to region at " +
region.getFqn());
- }
-
- if (trace)
- {
- log.trace("Finished updating node");
- }
+ if (trace) log.trace("Registering event " + type + " on node "
+ fqn);
}
- protected Region getRegion(Fqn fqn, NodeEventType type)
+ protected Region getRegion(Fqn fqn)
{
- Region r = regionManager.getRegion(fqn, Region.Type.EVICTION, false);
- if (r != null && r.getEvictionPolicy().canIgnoreEvent(fqn, type)) return
null;
- return r;
+ return regionManager.getRegion(fqn, Region.Type.EVICTION, false);
}
}
Modified:
core/trunk/src/main/java/org/jboss/cache/statetransfer/LegacyStateTransferIntegrator.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/statetransfer/LegacyStateTransferIntegrator.java 2008-08-14
19:16:15 UTC (rev 6561)
+++
core/trunk/src/main/java/org/jboss/cache/statetransfer/LegacyStateTransferIntegrator.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -17,8 +17,7 @@
import org.jboss.cache.Region;
import org.jboss.cache.buddyreplication.BuddyManager;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.eviction.EvictedEventNode;
-import org.jboss.cache.eviction.NodeEventType;
+import org.jboss.cache.eviction.EvictionEvent;
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.factories.annotations.Start;
import org.jboss.cache.invocation.InvocationContext;
@@ -307,10 +306,9 @@
parent.addChild(fqn.getLastElement(), target);
// JBCACHE-913
Region region = cache.getRegion(fqn, false);
- if (region != null && region.getEvictionPolicy() != null)
+ if (region != null && region.getEvictionRegionConfig() != null)
{
- region.putNodeEvent(new EvictedEventNode(fqn,
NodeEventType.ADD_NODE_EVENT,
- attrs == null ? 0 : attrs.size()));
+ region.registerEvictionEvent(fqn, EvictionEvent.Type.ADD_NODE_EVENT, attrs
== null ? 0 : attrs.size());
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/util/Util.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/util/Util.java 2008-08-14 19:16:15 UTC (rev
6561)
+++ core/trunk/src/main/java/org/jboss/cache/util/Util.java 2008-08-15 10:59:40 UTC (rev
6562)
@@ -21,6 +21,7 @@
*/
package org.jboss.cache.util;
+import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
@@ -52,6 +53,32 @@
return cl.loadClass(classname);
}
+ @SuppressWarnings("unchecked")
+ public static <T> T getInstance(Class<T> clazz) throws Exception
+ {
+ // first look for a getInstance() constructor
+ T instance;
+ try
+ {
+ Method factoryMethod = clazz.getMethod("getInstance", new Class[]{});
+ instance = (T) factoryMethod.invoke(null);
+ }
+ catch (Exception e)
+ {
+ // no factory method or factory method failed. Try a constructor.
+ instance = clazz.newInstance();
+ }
+ return instance;
+ }
+
+ @SuppressWarnings("unchecked")
+ public static Object getInstance(String classname) throws Exception
+ {
+ if (classname == null) throw new IllegalArgumentException("Cannot load null
class!");
+ Class clazz = loadClass(classname);
+ return getInstance(clazz);
+ }
+
/**
* Prevent instantiation
*/
@@ -158,5 +185,4 @@
return "Added Entries " + addedEntries + " Removeed Entries
" + removedEntries + " Modified Entries " + modifiedEntries;
}
}
-
}
Modified: core/trunk/src/test/java/org/jboss/cache/api/ResidentNodesTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/ResidentNodesTest.java 2008-08-14
19:16:15 UTC (rev 6561)
+++ core/trunk/src/test/java/org/jboss/cache/api/ResidentNodesTest.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -7,7 +7,7 @@
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.EvictionConfig;
import org.jboss.cache.config.EvictionRegionConfig;
-import org.jboss.cache.eviction.LRUConfiguration;
+import org.jboss.cache.eviction.LRUAlgorithmConfig;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.jboss.cache.util.internals.EvictionController;
import static org.testng.Assert.*;
@@ -53,12 +53,12 @@
EvictionRegionConfig evRegConfig = new EvictionRegionConfig();
evRegConfig.setRegionFqn(Fqn.fromString("/" + TEST_NODES_ROOT));
evRegConfig.setEventQueueSize(100);
- LRUConfiguration lruConfig = new LRUConfiguration();
+ LRUAlgorithmConfig lruConfig = new LRUAlgorithmConfig();
lruConfig.setMaxAge(100000000);
lruConfig.setTimeToLive(100000000);
lruConfig.setMaxNodes(3);
- evRegConfig.setEvictionPolicyConfig(lruConfig);
- evConfig.getEvictionRegionConfigs().add(evRegConfig);
+ evRegConfig.setEvictionAlgorithmConfig(lruConfig);
+ evConfig.addEvictionRegionConfig(evRegConfig);
//end setting up region stuff
}
Modified:
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationWithCacheLoaderTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationWithCacheLoaderTest.java 2008-08-14
19:16:15 UTC (rev 6561)
+++
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationWithCacheLoaderTest.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -13,7 +13,7 @@
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.EvictionConfig;
import org.jboss.cache.config.EvictionRegionConfig;
-import org.jboss.cache.eviction.LRUConfiguration;
+import org.jboss.cache.eviction.LRUAlgorithmConfig;
import org.jboss.cache.loader.CacheLoader;
import org.jboss.cache.util.TestingUtil;
import static org.jboss.cache.util.TestingUtil.dumpCacheContents;
@@ -345,15 +345,13 @@
EvictionConfig ec = new EvictionConfig();
ec.setWakeupInterval(1000);
EvictionRegionConfig erc = new EvictionRegionConfig();
- erc.setRegionName("/_default_");
- LRUConfiguration epc = new LRUConfiguration();
- epc.setMaxAge(2000);
- epc.setTimeToLive(1000);
- epc.setMaxNodes(1);
- erc.setEvictionPolicyConfig(epc);
- List<EvictionRegionConfig> ercs = new
ArrayList<EvictionRegionConfig>();
- ercs.add(erc);
- ec.setEvictionRegionConfigs(ercs);
+ erc.setRegionFqn(Fqn.ROOT);
+ LRUAlgorithmConfig lruAlgorithmConfig = new LRUAlgorithmConfig();
+ lruAlgorithmConfig.setMaxAge(2000);
+ lruAlgorithmConfig.setTimeToLive(1000);
+ lruAlgorithmConfig.setMaxNodes(1);
+ erc.setEvictionAlgorithmConfig(lruAlgorithmConfig);
+ ec.setDefaultEvictionRegionConfig(erc);
cfg.setEvictionConfig(ec);
}
Modified:
core/trunk/src/test/java/org/jboss/cache/buddyreplication/EvictionOfBuddyBackupsTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/buddyreplication/EvictionOfBuddyBackupsTest.java 2008-08-14
19:16:15 UTC (rev 6561)
+++
core/trunk/src/test/java/org/jboss/cache/buddyreplication/EvictionOfBuddyBackupsTest.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -5,15 +5,13 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.config.EvictionConfig;
import org.jboss.cache.config.EvictionRegionConfig;
-import org.jboss.cache.eviction.LRUConfiguration;
-import org.jboss.cache.eviction.NullEvictionPolicy;
+import org.jboss.cache.eviction.LRUAlgorithmConfig;
+import org.jboss.cache.eviction.NullEvictionAlgorithmConfig;
import org.jboss.cache.util.TestingUtil;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
-import java.util.Collections;
-
/**
* Tests the eviction of buddy backup regions
*
@@ -47,13 +45,13 @@
private EvictionConfig getEvictionConfig()
{
EvictionConfig c = new EvictionConfig();
- c.setDefaultEvictionPolicyClass(NullEvictionPolicy.class.getName());
+ EvictionRegionConfig defaultRegion = new EvictionRegionConfig(Fqn.ROOT, new
NullEvictionAlgorithmConfig());
+ c.setDefaultEvictionRegionConfig(defaultRegion);
c.setWakeupInterval(1000);
- LRUConfiguration epc = new LRUConfiguration();
- epc.setMaxAge(1000);
- epc.setTimeToLive(1000);
- EvictionRegionConfig erc = new EvictionRegionConfig(fqn, epc);
- c.setEvictionRegionConfigs(Collections.singletonList(erc));
+
+ LRUAlgorithmConfig lru = new LRUAlgorithmConfig(1000, 1000);
+ EvictionRegionConfig subregion = new EvictionRegionConfig(fqn, lru);
+ c.addEvictionRegionConfig(subregion);
return c;
}
Modified: core/trunk/src/test/java/org/jboss/cache/config/ConfigurationCloningTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/config/ConfigurationCloningTest.java 2008-08-14
19:16:15 UTC (rev 6561)
+++
core/trunk/src/test/java/org/jboss/cache/config/ConfigurationCloningTest.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -24,42 +24,45 @@
/**
* Tests the ability to clone Configuration elements and end up with
* independently modifiable configurations.
- *
+ *
* @author Brian Stansberry
*/
@Test(groups = {"functional"})
public class ConfigurationCloningTest
{
- /** A file that includes every configuration element I could think of */
+ /**
+ * A file that includes every configuration element I could think of
+ */
public static final String DEFAULT_CONFIGURATION_FILE =
"configs/clonable-config.xml";
-
+
private static final Log log = LogFactory.getLog(ConfigurationCloningTest.class);
-
+
public void testClone() throws Exception
{
XmlConfigurationParser parser = new XmlConfigurationParser();
Configuration c = parser.parseFile(DEFAULT_CONFIGURATION_FILE);
-
- try {
- Configuration clone = c.clone();
-
+
+ try
+ {
+ Configuration clone = c.clone();
+
// Test a few simple properties
- assertEquals(NodeLockingScheme.OPTIMISTIC, clone.getNodeLockingScheme());
+ assertEquals(NodeLockingScheme.OPTIMISTIC, clone.getNodeLockingScheme());
assertEquals(CacheMode.REPL_SYNC, clone.getCacheMode());
- assertEquals("CloneCluster", clone.getClusterName());
- assertEquals(c.getClusterConfig(), clone.getClusterConfig());
+ assertEquals("CloneCluster", clone.getClusterName());
+ assertEquals(c.getClusterConfig(), clone.getClusterConfig());
assertEquals(3, clone.getStateRetrievalTimeout());
-
+
// Eviction
EvictionConfig ec1 = c.getEvictionConfig();
EvictionConfig ec2 = clone.getEvictionConfig();
-
+
assertFalse(ec1 == ec2);
-
- assertEquals(4, ec2.getDefaultEventQueueSize());
+
+ assertEquals(4, ec2.getDefaultEvictionRegionConfig().getEventQueueSize());
assertEquals(45000, ec2.getWakeupInterval());
assertEquals(LRUPolicy.class.getName(), ec2.getDefaultEvictionPolicyClass());
-
+
List<EvictionRegionConfig> ercs1 = ec1.getEvictionRegionConfigs();
List<EvictionRegionConfig> ercs2 = ec2.getEvictionRegionConfigs();
assertEquals(ercs1.size(), ercs2.size());
@@ -67,16 +70,16 @@
{
compareEvictionRegionConfigs(ercs1.get(i), ercs2.get(i));
}
-
+
// Cache loading
CacheLoaderConfig clc1 = c.getCacheLoaderConfig();
CacheLoaderConfig clc2 = clone.getCacheLoaderConfig();
-
+
assertFalse(clc1 == clc2);
-
+
assertFalse(clc2.isPassivation());
assertTrue(clc2.isShared());
-
+
List<IndividualCacheLoaderConfig> clcs1 =
clc1.getIndividualCacheLoaderConfigs();
List<IndividualCacheLoaderConfig> clcs2 =
clc2.getIndividualCacheLoaderConfigs();
assertEquals(clcs1.size(), clcs2.size());
@@ -84,12 +87,12 @@
{
compareCacheLoaderConfigs(clcs1.get(i), clcs2.get(i));
}
-
+
RuntimeConfig rc1 = c.getRuntimeConfig();
RuntimeConfig rc2 = clone.getRuntimeConfig();
assertFalse(rc1 == rc2);
assertEquals(rc1, rc2);
-
+
}
catch (CloneNotSupportedException e)
{
@@ -99,31 +102,31 @@
}
private void compareEvictionRegionConfigs(EvictionRegionConfig erc1,
- EvictionRegionConfig erc2)
+ EvictionRegionConfig erc2)
{
assertEquals(erc1.getRegionName(), erc2.getRegionName());
assertEquals(erc1.getRegionFqn(), erc2.getRegionFqn());
assertEquals(erc1.getEventQueueSize(), erc2.getEventQueueSize());
-
+
EvictionPolicyConfig epc1 = erc1.getEvictionPolicyConfig();
EvictionPolicyConfig epc2 = erc2.getEvictionPolicyConfig();
-
+
assertFalse(epc1 == epc2);
assertEquals(epc1, epc2);
}
private void compareCacheLoaderConfigs(IndividualCacheLoaderConfig clc1,
- IndividualCacheLoaderConfig clc2)
+ IndividualCacheLoaderConfig clc2)
{
assertFalse(clc1 == clc2);
assertEquals(clc1, clc2);
-
- Properties p1 = clc1.getProperties();
+
+ Properties p1 = clc1.getProperties();
Properties p2 = clc2.getProperties();
assertFalse(p1 == p2);
assertEquals(p1, p2);
-
- SingletonStoreConfig ssc1 = clc1.getSingletonStoreConfig();
+
+ SingletonStoreConfig ssc1 = clc1.getSingletonStoreConfig();
SingletonStoreConfig ssc2 = clc2.getSingletonStoreConfig();
assertFalse(ssc1 == ssc2);
assertEquals(ssc1, ssc2);
Modified:
core/trunk/src/test/java/org/jboss/cache/config/parsing/EvictionElementParserTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/config/parsing/EvictionElementParserTest.java 2008-08-14
19:16:15 UTC (rev 6561)
+++
core/trunk/src/test/java/org/jboss/cache/config/parsing/EvictionElementParserTest.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -1,14 +1,18 @@
package org.jboss.cache.config.parsing;
import org.jboss.cache.Fqn;
-import org.jboss.cache.RegionManagerImpl;
import org.jboss.cache.config.ConfigurationException;
import org.jboss.cache.config.EvictionConfig;
import org.jboss.cache.config.EvictionRegionConfig;
import org.jboss.cache.config.MissingPolicyException;
import org.jboss.cache.config.parsing.element.EvictionElementParser;
-import org.jboss.cache.eviction.LRUConfiguration;
-import org.jboss.cache.eviction.MRUConfiguration;
+import org.jboss.cache.eviction.DefaultEvictionActionPolicy;
+import org.jboss.cache.eviction.LFUAlgorithmConfig;
+import org.jboss.cache.eviction.LRUAlgorithmConfig;
+import org.jboss.cache.eviction.MRUAlgorithmConfig;
+import org.jboss.cache.eviction.NullEvictionAlgorithm;
+import org.jboss.cache.eviction.NullEvictionAlgorithmConfig;
+import org.jboss.cache.eviction.RemoveOnEvictActionPolicy;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
@@ -30,20 +34,21 @@
{
String xml =
" <eviction wakeUpInterval=\"5\">\n" +
- " <defaults
policyClass=\"org.jboss.cache.eviction.MRUPolicy\"/>\n" +
- " <region name=\"/org/jboss/xyz\"
policyClass=\"org.jboss.cache.eviction.MRUPolicy\"
eventQueueSize=\"21\">\n" +
+ " <default
algorithmClass=\"org.jboss.cache.eviction.MRUAlgorithm\"/>\n" +
+ " <region name=\"/org/jboss/xyz\"
eventQueueSize=\"21\">\n" +
" <attribute
name=\"maxNodes\">2103</attribute>\n" +
" <attribute
name=\"minTimeToLive\">22</attribute>\n" +
" </region>\n" +
" </eviction>";
EvictionConfig evictionConfig = getEvictionConfig(xml);
- assert evictionConfig.getDefaultEventQueueSize() ==
EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT;
+ assert evictionConfig.getDefaultEvictionRegionConfig().getEventQueueSize() ==
EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT;
+ assert
evictionConfig.getDefaultEvictionRegionConfig().getEvictionActionPolicyClassName().equals(DefaultEvictionActionPolicy.class.getName());
}
/**
- * test an happy flow.
+ * test unnecessary attributes
*/
- public void testNormalConfig()
+ public void testUnnecessaryAttributes()
{
String xml =
" <eviction wakeUpInterval=\"5\"
defaultPolicyClass=\"org.jboss.cache.eviction.MRUPolicy\"
defaultEventQueueSize=\"123456\">\n" +
@@ -51,11 +56,35 @@
" <attribute
name=\"maxNodes\">6</attribute>\n" +
" <attribute
name=\"minTimeToLive\">7</attribute>\n" +
" </default>\n" +
+ " </eviction>";
+ try
+ {
+ EvictionConfig config = getEvictionConfig(xml);
+ assert false : "Should throw ConfigurationException!";
+ }
+ catch (ConfigurationException good)
+ {
+ // expected
+ }
+ }
+
+
+ /**
+ * test an happy flow.
+ */
+ public void testNormalConfig()
+ {
+ String xml =
+ " <eviction wakeUpInterval=\"5\">\n" +
+ " <default
algorithmClass=\"org.jboss.cache.eviction.MRUAlgorithm\"
eventQueueSize=\"123456\">\n" +
+ " <attribute
name=\"maxNodes\">6</attribute>\n" +
+ " <attribute
name=\"minTimeToLive\">7</attribute>\n" +
+ " </default>\n" +
" <region name=\"/org/jboss/data\">\n"
+
" <attribute
name=\"minTimeToLive\">1002</attribute>\n" +
" <attribute
name=\"maxNodes\">2021</attribute>\n" +
" </region>\n" +
- " <region name=\"/org/jboss/xyz\"
policyClass=\"org.jboss.cache.eviction.LRUPolicy\"
eventQueueSize=\"21\">\n" +
+ " <region name=\"/org/jboss/xyz\"
algorithmClass=\"org.jboss.cache.eviction.LRUAlgorithm\"
eventQueueSize=\"21\">\n" +
" <attribute
name=\"maxNodes\">2103</attribute>\n" +
" <attribute
name=\"timeToLive\">22</attribute>\n" +
" </region>\n" +
@@ -63,39 +92,41 @@
EvictionConfig config = getEvictionConfig(xml);
//tests the defaults
assert config.getWakeupInterval() == 5;
- assert
config.getDefaultEvictionPolicyClass().equals("org.jboss.cache.eviction.MRUPolicy");
- assert config.getDefaultEventQueueSize() == 123456;
- assert config.getEvictionRegionConfigs().size() == 3;
+ assert config.getDefaultEvictionRegionConfig().getEvictionAlgorithmConfig()
instanceof MRUAlgorithmConfig;
+ assert config.getDefaultEvictionRegionConfig().getEventQueueSize() == 123456;
+ assert config.getEvictionRegionConfigs().size() == 2;
//test first region config
- EvictionRegionConfig erConfig1 = config.getEvictionRegionConfigs().get(0);
+ EvictionRegionConfig erConfig1 = config.getDefaultEvictionRegionConfig();
erConfig1.getRegionFqn().equals(Fqn.ROOT);
- MRUConfiguration defaultPolicyonfig = (MRUConfiguration)
erConfig1.getEvictionPolicyConfig();
- assert defaultPolicyonfig.getMaxNodes() == 6;
- assert defaultPolicyonfig.getMinTimeToLive() == 7;
+ MRUAlgorithmConfig defaultPolicyConfig = (MRUAlgorithmConfig)
erConfig1.getEvictionAlgorithmConfig();
+ assert defaultPolicyConfig.getMaxNodes() == 6;
+ assert defaultPolicyConfig.getMinTimeToLive() == 7;
//test second region config
- EvictionRegionConfig erConfig2 = config.getEvictionRegionConfigs().get(1);
- assert erConfig2.getEventQueueSize() == 123456;
+ EvictionRegionConfig erConfig2 = config.getEvictionRegionConfigs().get(0);
+ assert erConfig2.getEventQueueSize() == 123456 : "Got " +
erConfig2.getEventQueueSize();
assert
erConfig2.getRegionFqn().equals(Fqn.fromString("/org/jboss/data"));
- MRUConfiguration mruConfiguration = (MRUConfiguration)
erConfig2.getEvictionPolicyConfig();
+ MRUAlgorithmConfig mruConfiguration = (MRUAlgorithmConfig)
erConfig2.getEvictionAlgorithmConfig();
assert mruConfiguration.getMinTimeToLive() == 1002;
assert mruConfiguration.getMaxNodes() == 2021;
//test 3rd region config
- EvictionRegionConfig erConfig3 = config.getEvictionRegionConfigs().get(2);
+ EvictionRegionConfig erConfig3 = config.getEvictionRegionConfigs().get(1);
assert erConfig3.getEventQueueSize() == 21;
assert
erConfig3.getRegionFqn().equals(Fqn.fromString("/org/jboss/xyz"));
- LRUConfiguration lruConfiguration = (LRUConfiguration)
erConfig3.getEvictionPolicyConfig();
+ LRUAlgorithmConfig lruConfiguration = (LRUAlgorithmConfig)
erConfig3.getEvictionAlgorithmConfig();
assert lruConfiguration.getTimeToLive() == 22;
assert lruConfiguration.getMaxNodes() == 2103;
+
+ assert
config.getDefaultEvictionRegionConfig().getEvictionActionPolicyClassName().equals(DefaultEvictionActionPolicy.class.getName());
}
public void testLruConfig()
{
String xml =
- " <eviction wakeUpInterval=\"45000\"
defaultPolicyClass=\"org.jboss.cache.eviction.LRUPolicy\"
defaultEventQueueSize=\"4\">\n" +
- " <default>\n" +
+ " <eviction wakeUpInterval=\"45000\">\n" +
+ " <default
algorithmClass=\"org.jboss.cache.eviction.LRUAlgorithm\"
eventQueueSize=\"4\">\n" +
" <attribute
name=\"maxNodes\">5000</attribute>\n" +
" <attribute
name=\"timeToLive\">1000000</attribute>\n" +
" <attribute
name=\"maxAge\">15000</attribute>\n" +
@@ -114,10 +145,11 @@
" </region>\n" +
" </eviction>";
EvictionConfig evConfig = getEvictionConfig(xml);
- EvictionRegionConfig evictionRegionConfig =
evConfig.getEvictionRegionConfigs().get(0);
- assert
evictionRegionConfig.getRegionName().equals(RegionManagerImpl.DEFAULT_REGION.toString());
- assert
evictionRegionConfig.getRegionName().equals(RegionManagerImpl.DEFAULT_REGION.toString());
- assert ((LRUConfiguration)
evictionRegionConfig.getEvictionPolicyConfig()).getTimeToLive() == 1000000;
+ EvictionRegionConfig evictionRegionConfig =
evConfig.getDefaultEvictionRegionConfig();
+ assert evictionRegionConfig.getRegionName().equals(Fqn.ROOT.toString()) : "Was
" + evictionRegionConfig.getRegionName();
+ assert ((LRUAlgorithmConfig)
evictionRegionConfig.getEvictionAlgorithmConfig()).getTimeToLive() == 1000000;
+
+ assert
evConfig.getDefaultEvictionRegionConfig().getEvictionActionPolicyClassName().equals(DefaultEvictionActionPolicy.class.getName());
}
/**
@@ -126,8 +158,8 @@
public void testMissingWakeUpInterval() throws Exception
{
String xml =
- " <eviction
defaultPolicyClass=\"org.jboss.cache.eviction.LRUPolicy\"
defaultEventQueueSize=\"200000\">\n" +
- " <default>\n" +
+ " <eviction>\n" +
+ " <default
algorithmClass=\"org.jboss.cache.eviction.LRUAlgorithm\"
eventQueueSize=\"200000\">\n" +
" <attribute
name=\"maxNodes\">5000</attribute>\n" +
" <attribute
name=\"timeToLive\">1000</attribute>\n" +
" </default>\n" +
@@ -153,8 +185,8 @@
public void testMissingPolicyOnRegion()
{
String xml =
- " <eviction defaultEventQueueSize=\"200000\"
wakeUpInterval=\"5000\">\n" +
- " <region name=\"/org/jboss/data\">\n"
+
+ " <eviction wakeUpInterval=\"5000\">\n" +
+ " <region name=\"/org/jboss/data\"
eventQueueSize=\"5\">\n" +
" <attribute
name=\"timeToLive\">1002</attribute>\n" +
" </region>\n" +
" </eviction>";
@@ -169,6 +201,22 @@
}
}
+ /**
+ * Same as above, except no queue size is specified. SHould NOT fail.
+ */
+ public void testMissingQueueSizeOnRegion()
+ {
+ String xml =
+ " <eviction wakeUpInterval=\"5000\">\n" +
+ " <region name=\"/org/jboss/data\"
algorithmClass=\"org.jboss.cache.eviction.LRUAlgorithm\">\n" +
+ " <attribute
name=\"timeToLive\">1002</attribute>\n" +
+ " </region>\n" +
+ " </eviction>";
+ EvictionConfig ec = getEvictionConfig(xml);
+ assert ec.getEvictionRegionConfigs().get(0).getEventQueueSize() ==
EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT;
+ }
+
+
private EvictionConfig getEvictionConfig(String xml)
{
Element el;
@@ -191,7 +239,7 @@
" <attribute
name=\"maxNodes\">5000</attribute>\n" +
" <attribute
name=\"timeToLive\">1000</attribute>\n" +
" </default>\n" +
- " <region name=\"/org/jboss/data\"
policyClass=\"org.jboss.cache.eviction.LFUPolicy\">\n" +
+ " <region name=\"/org/jboss/data\"
algorithmClass=\"org.jboss.cache.eviction.LFUAlgorithm\">\n" +
" <attribute
name=\"maxNodes\">5000</attribute>\n" +
" <attribute
name=\"minNodes\">1000</attribute>\n" +
" </region>\n" +
@@ -199,11 +247,49 @@
try
{
getEvictionConfig(xml);
- assert false : " excewption expectecd as root does not have a eviction
policy defined";
+ assert false : " exception expected as default element does not have a
eviction policy defined";
}
catch (MissingPolicyException e)
{
//expected
}
}
+
+ public void testDifferentEvictionActionPolicyClasses() throws Exception
+ {
+ String xml =
+ " <eviction wakeUpInterval=\"5000\">\n" +
+ " <default algorithmClass=\"" +
NullEvictionAlgorithm.class.getName() + "\" actionPolicyClass=\"" +
RemoveOnEvictActionPolicy.class.getName() + "\">\n" +
+ " </default>\n" +
+ " <region name=\"/one\"
algorithmClass=\"org.jboss.cache.eviction.LFUAlgorithm\">\n" +
+ " <attribute
name=\"maxNodes\">5000</attribute>\n" +
+ " <attribute
name=\"minNodes\">1000</attribute>\n" +
+ " </region>\n" +
+ " <region name=\"/two\"
actionPolicyClass=\"" + DefaultEvictionActionPolicy.class.getName() +
"\">\n" +
+ " </region>\n" +
+ " </eviction>";
+ EvictionConfig config = getEvictionConfig(xml);
+
+ // default region
+ assert config.getDefaultEvictionRegionConfig().getEvictionAlgorithmConfig()
instanceof NullEvictionAlgorithmConfig;
+ assert
config.getDefaultEvictionRegionConfig().getEvictionActionPolicyClassName().equals(RemoveOnEvictActionPolicy.class.getName());
+
+ // region /one
+ assert findRegionConfig(config, "/one").getEvictionAlgorithmConfig()
instanceof LFUAlgorithmConfig;
+ assert findRegionConfig(config,
"/one").getEvictionActionPolicyClassName().equals(RemoveOnEvictActionPolicy.class.getName());
+
+ // region /two
+ assert findRegionConfig(config, "/two").getEvictionAlgorithmConfig()
instanceof NullEvictionAlgorithmConfig;
+ assert findRegionConfig(config,
"/two").getEvictionActionPolicyClassName().equals(DefaultEvictionActionPolicy.class.getName());
+ }
+
+ private EvictionRegionConfig findRegionConfig(EvictionConfig evictionConfig, String
fqn)
+ {
+ for (EvictionRegionConfig erc : evictionConfig.getEvictionRegionConfigs())
+ {
+ if (erc.getRegionFqn().equals(Fqn.fromString(fqn))) return erc;
+ }
+
+ return null;
+ }
}
Modified:
core/trunk/src/test/java/org/jboss/cache/config/parsing/XmlConfigurationParserTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/config/parsing/XmlConfigurationParserTest.java 2008-08-14
19:16:15 UTC (rev 6561)
+++
core/trunk/src/test/java/org/jboss/cache/config/parsing/XmlConfigurationParserTest.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -9,8 +9,8 @@
import org.jboss.cache.config.OldFileFormatException;
import org.jboss.cache.config.parsing.custominterceptors.AaaCustomInterceptor;
import org.jboss.cache.config.parsing.custominterceptors.BbbCustomInterceptor;
-import org.jboss.cache.eviction.LRUConfiguration;
-import org.jboss.cache.eviction.MRUConfiguration;
+import org.jboss.cache.eviction.LRUAlgorithmConfig;
+import org.jboss.cache.eviction.MRUAlgorithmConfig;
import org.jboss.cache.lock.IsolationLevel;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -202,7 +202,7 @@
{
EvictionConfig evictionConfig = config.getEvictionConfig();
assert
"org.jboss.cache.eviction.LRUPolicy".equals(evictionConfig.getDefaultEvictionPolicyClass());
- assert 200000 == evictionConfig.getDefaultEventQueueSize();
+ assert 200000 ==
evictionConfig.getDefaultEvictionRegionConfig().getEventQueueSize();
assert 5 == evictionConfig.getWakeupInterval();
List<EvictionRegionConfig> regionConfigs =
evictionConfig.getEvictionRegionConfigs();
@@ -210,20 +210,20 @@
EvictionRegionConfig first = regionConfigs.get(0);
assert first.getRegionName().equals("/_default_");
- assert first.getEvictionPolicyConfig() instanceof LRUConfiguration;
- LRUConfiguration firstConfiguration = (LRUConfiguration)
first.getEvictionPolicyConfig();
+ assert first.getEvictionAlgorithmConfig() instanceof LRUAlgorithmConfig;
+ LRUAlgorithmConfig firstConfiguration = (LRUAlgorithmConfig)
first.getEvictionAlgorithmConfig();
assert firstConfiguration.getMaxAge() <= 0;
assert firstConfiguration.getTimeToLive() == 1000;
assert firstConfiguration.getMaxNodes() == 5000;
EvictionRegionConfig second = regionConfigs.get(1);
- LRUConfiguration secondConfiguration = (LRUConfiguration)
second.getEvictionPolicyConfig();
+ LRUAlgorithmConfig secondConfiguration = (LRUAlgorithmConfig)
second.getEvictionAlgorithmConfig();
assert secondConfiguration.getMaxAge() == 0;
assert secondConfiguration.getTimeToLive() == 1002;
assert secondConfiguration.getMaxNodes() == 0;
EvictionRegionConfig third = regionConfigs.get(2);
- MRUConfiguration thirdConfiguration = (MRUConfiguration)
third.getEvictionPolicyConfig();
+ MRUAlgorithmConfig thirdConfiguration = (MRUAlgorithmConfig)
third.getEvictionAlgorithmConfig();
assert thirdConfiguration.getMaxNodes() == 2103;
assert thirdConfiguration.getMinTimeToLive() == 22;
assert third.getEventQueueSize() == 21;
Modified:
core/trunk/src/test/java/org/jboss/cache/eviction/BaseEvictionAlgorithmTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/eviction/BaseEvictionAlgorithmTest.java 2008-08-14
19:16:15 UTC (rev 6561)
+++
core/trunk/src/test/java/org/jboss/cache/eviction/BaseEvictionAlgorithmTest.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -23,14 +23,16 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
+import org.jboss.cache.RegionImpl;
import org.jboss.cache.RegionManager;
import org.jboss.cache.RegionManagerImpl;
import org.jboss.cache.RegionRegistry;
+import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.ConfigurationException;
-import org.jboss.cache.config.EvictionPolicyConfig;
+import org.jboss.cache.config.EvictionAlgorithmConfig;
+import org.jboss.cache.config.EvictionRegionConfig;
import static org.testng.AssertJUnit.fail;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -59,7 +61,7 @@
public void setUp() throws Exception
{
RegionManagerImpl rmi = new RegionManagerImpl();
- rmi.injectDependencies(null, null, null, null, null, new RegionRegistry());
+ rmi.injectDependencies(null, new Configuration(), null, null, null, new
RegionRegistry());
regionManager = rmi;
}
@@ -71,16 +73,16 @@
BaseEvictionAlgorithm algorithm = new MockEvictionAlgorithm(recycleQueueCapacity);
Region region = regionManager.getRegion("/a/b/c", true);
- region.setEvictionPolicy(new MockEvictionPolicyConfig());
+ region.setEvictionRegionConfig(new EvictionRegionConfig(region.getFqn(), new
MockEvictionAlgorithmConfig()));
for (int i = 0; i < (recycleQueueCapacity + 1); i++)
{
Fqn fqn = Fqn.fromString("/a/b/c/" + Integer.toString(i + 1));
- region.putNodeEvent(new EvictedEventNode(fqn, NodeEventType.ADD_NODE_EVENT));
+ region.registerEvictionEvent(fqn, EvictionEvent.Type.ADD_NODE_EVENT);
}
ExecutorService executor = Executors.newSingleThreadExecutor();
- Future<Void> future = executor.submit(new ProcessEvictionRegion(region,
algorithm));
+ Future<Void> future = executor.submit(new ProcessEvictionRegion((RegionImpl)
region, algorithm));
try
{
@@ -103,13 +105,21 @@
public static class MockEvictionAlgorithm extends BaseEvictionAlgorithm
{
- public MockEvictionAlgorithm(int recycleQueueCapacity)
+ private static MockEvictionAlgorithm singleton;
+
+ private MockEvictionAlgorithm(int recycleQueueCapacity)
{
recycleQueue = new LinkedBlockingQueue<Fqn>(recycleQueueCapacity);
+ singleton = this;
}
+ public static MockEvictionAlgorithm getInstance()
+ {
+ return singleton;
+ }
+
@Override
- protected EvictionQueue setupEvictionQueue(Region region) throws EvictionException
+ protected EvictionQueue setupEvictionQueue() throws EvictionException
{
return new LRUQueue();
}
@@ -121,60 +131,42 @@
return true;
}
- }
-
- public static class MockEvictionPolicy extends BaseEvictionPolicy
- {
-
- @Override
- public void evict(Fqn fqn) throws Exception
+ public Class<? extends EvictionAlgorithmConfig> getConfigurationClass()
{
- throw new Exception("Unable to evict");
- }
-
- @Override
- public void setCache(CacheSPI cache)
- {
- /* no op */
- }
-
- public EvictionAlgorithm getEvictionAlgorithm()
- {
return null;
}
-
- public Class<? extends EvictionPolicyConfig> getEvictionConfigurationClass()
- {
- return MockEvictionPolicyConfig.class;
- }
}
- public static class MockEvictionPolicyConfig implements EvictionPolicyConfig
+ public static class MockEvictionAlgorithmConfig implements EvictionAlgorithmConfig
{
-
- public String getEvictionPolicyClass()
+ public void reset()
{
- return MockEvictionPolicy.class.getName();
+ /* no op */
}
- public void reset()
+ public String getEvictionAlgorithmClassName()
{
- /* no op */
+ return MockEvictionAlgorithm.class.getName();
}
public void validate() throws ConfigurationException
{
/* no op */
}
+
+ public EvictionAlgorithmConfig clone() throws CloneNotSupportedException
+ {
+ return (EvictionAlgorithmConfig) super.clone();
+ }
}
public class ProcessEvictionRegion implements Callable<Void>
{
- private Region region;
+ private RegionImpl region;
private EvictionAlgorithm algorithm;
- public ProcessEvictionRegion(Region region, EvictionAlgorithm algorithm)
+ public ProcessEvictionRegion(RegionImpl region, EvictionAlgorithm algorithm)
{
this.region = region;
this.algorithm = algorithm;
@@ -184,7 +176,7 @@
{
try
{
- algorithm.process(region);
+ algorithm.process(region.getEvictionEventQueue());
}
catch (EvictionException e)
{
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/ConcurrentEvictionTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/eviction/ConcurrentEvictionTest.java 2008-08-14
19:16:15 UTC (rev 6561)
+++
core/trunk/src/test/java/org/jboss/cache/eviction/ConcurrentEvictionTest.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -16,6 +16,7 @@
import org.jboss.cache.config.EvictionConfig;
import org.jboss.cache.config.EvictionRegionConfig;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
+import org.jboss.cache.transaction.DummyTransactionManagerLookup;
import org.jboss.cache.util.TestingUtil;
import static org.testng.AssertJUnit.assertNotNull;
import static org.testng.AssertJUnit.fail;
@@ -24,8 +25,6 @@
import org.testng.annotations.Test;
import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
import java.util.Properties;
/**
@@ -37,8 +36,8 @@
@Test(groups = {"functional"})
public class ConcurrentEvictionTest
{
- private Cache<Integer, String> cache_;
- private long wakeupIntervalMillis_ = 0;
+ private Cache<Integer, String> cache;
+ private long wakeupIntervalMillis = 0;
private String tmpDir = System.getProperty("java.io.tmpdir",
"/tmp");
private String cacheLoaderDir = "/JBossCacheFileCacheLoader";
@@ -46,10 +45,10 @@
public void setUp() throws Exception
{
initCaches();
- wakeupIntervalMillis_ =
cache_.getConfiguration().getEvictionConfig().getWakeupInterval();
- if (wakeupIntervalMillis_ < 0)
+ wakeupIntervalMillis =
cache.getConfiguration().getEvictionConfig().getWakeupInterval();
+ if (wakeupIntervalMillis < 0)
{
- fail("testEviction(): eviction thread wake up interval is illegal " +
wakeupIntervalMillis_);
+ fail("testEviction(): eviction thread wake up interval is illegal " +
wakeupIntervalMillis);
}
}
@@ -61,8 +60,8 @@
Configuration conf =
UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL,
true);
conf.setEvictionConfig(buildEvictionConfig());
conf.setCacheLoaderConfig(buildCacheLoaderConfig());
-
conf.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
- cache_ = factory.createCache(conf, true);// read in generic local xml
+
conf.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+ cache = factory.createCache(conf, true);// read in generic local xml
}
private CacheLoaderConfig buildCacheLoaderConfig()
@@ -86,23 +85,19 @@
private EvictionConfig buildEvictionConfig()
{
- EvictionConfig ec = new
EvictionConfig("org.jboss.cache.eviction.LRUPolicy");
- ec.setDefaultEvictionPolicyClass("org.jboss.cache.eviction.LRUPolicy");
- ec.setWakeupInterval(5000);
-
- EvictionRegionConfig erc =
UnitTestCacheConfigurationFactory.buildLruEvictionRegionConfig("_default_",
5000, 1000000);
- List<EvictionRegionConfig> erConfigs = new
ArrayList<EvictionRegionConfig>();
- erConfigs.add(erc);
- ec.setEvictionRegionConfigs(erConfigs);
- return ec;
+ return new EvictionConfig(
+ new EvictionRegionConfig(
+ Fqn.ROOT,
+ new LRUAlgorithmConfig(1000000, 5000)
+ ),
+ 5000);
}
@AfterMethod(alwaysRun = true)
public void tearDown() throws Exception
{
TestingUtil.recursiveFileRemove(tmpDir + cacheLoaderDir);
- cache_.stop();
- cache_ = null;
+ TestingUtil.killCaches(cache);
}
public void testConcurrentEviction() throws Exception
@@ -113,11 +108,11 @@
// region's maxNodes so we know eviction will kick in
for (int i = 0; i < 1000; i++)
{
- cache_.put(Fqn.fromRelativeElements(base, i / 100), i, "value");
+ cache.put(Fqn.fromRelativeElements(base, i / 100), i, "value");
}
// Loop for long enough to have 5 runs of the eviction thread
- long loopDone = System.currentTimeMillis() + (5 * wakeupIntervalMillis_);
+ long loopDone = System.currentTimeMillis() + (5 * wakeupIntervalMillis);
while (System.currentTimeMillis() < loopDone)
{
// If any get returns null, that's a failure
@@ -126,7 +121,7 @@
Fqn fqn = Fqn.fromRelativeElements(base, i / 100);
Integer key = i;
assertNotNull("found value under Fqn " + fqn + " and key
" + key,
- cache_.get(fqn, key));
+ cache.get(fqn, key));
}
}
}
Deleted:
core/trunk/src/test/java/org/jboss/cache/eviction/DummyEvictionConfiguration.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/eviction/DummyEvictionConfiguration.java 2008-08-14
19:16:15 UTC (rev 6561)
+++
core/trunk/src/test/java/org/jboss/cache/eviction/DummyEvictionConfiguration.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -1,41 +0,0 @@
-/*
- * JBoss, the OpenSource J2EE webOS
- *
- * Distributable under LGPL license.
- * See terms of license at
gnu.org.
- */
-package org.jboss.cache.eviction;
-
-import org.jboss.cache.config.ConfigurationException;
-import org.jboss.cache.config.EvictionPolicyConfig;
-
-
-/**
- * @author Daniel Huang (dhuang(a)jboss.org)
- * @version $Revision$
- */
-public class DummyEvictionConfiguration implements EvictionPolicyConfig, Cloneable
-{
- public String getEvictionPolicyClass()
- {
- return DummyEvictionPolicy.class.getName();
- }
-
- public void validate() throws ConfigurationException
- {
- // no-op
- }
-
- public void reset()
- {
- // no-op
- }
-
- @Override
- public DummyEvictionConfiguration clone() throws CloneNotSupportedException
- {
- return (DummyEvictionConfiguration) super.clone();
- }
-
-
-}
Deleted: core/trunk/src/test/java/org/jboss/cache/eviction/DummyEvictionPolicy.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/DummyEvictionPolicy.java 2008-08-14
19:16:15 UTC (rev 6561)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/DummyEvictionPolicy.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -1,40 +0,0 @@
-package org.jboss.cache.eviction;
-
-import org.jboss.cache.CacheSPI;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.config.EvictionPolicyConfig;
-
-/**
- * @author Ben Feb 13, 2004
- */
-public class DummyEvictionPolicy extends BaseEvictionPolicy
-{
- public void evict(Fqn fqn) throws Exception
- {
- // no-op
-// throw new RuntimeException("Testing only");
- }
-
- public int getWakeupIntervalSeconds()
- {
- return 0; //To change body of implemented methods use File | Settings | File
Templates.
- }
-
- public void setCache(CacheSPI cache)
- {
- // no op
- }
-
- public EvictionAlgorithm getEvictionAlgorithm()
- {
- // no op
- return null;
- }
-
- public Class<? extends EvictionPolicyConfig> getEvictionConfigurationClass()
- {
- return null;
- }
-
-
-}
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizeAlgorithmTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizeAlgorithmTest.java 2008-08-14
19:16:15 UTC (rev 6561)
+++
core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizeAlgorithmTest.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -1,16 +1,12 @@
-/*
- * JBoss, the OpenSource J2EE webOS
- *
- * Distributable under LGPL license.
- * See terms of license at
gnu.org.
- */
package org.jboss.cache.eviction;
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
+import org.jboss.cache.RegionImpl;
import org.jboss.cache.RegionManager;
import org.jboss.cache.RegionManagerImpl;
import org.jboss.cache.RegionRegistry;
+import org.jboss.cache.config.EvictionRegionConfig;
import static org.testng.AssertJUnit.assertEquals;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -33,34 +29,35 @@
algo = new ElementSizeAlgorithm();
regionManager = new RegionManagerImpl();
((RegionManagerImpl) regionManager).injectDependencies(null, null, null, null,
null, new RegionRegistry());
- ElementSizeConfiguration config = new ElementSizeConfiguration();
+ ElementSizeAlgorithmConfig config = new ElementSizeAlgorithmConfig();
// We have to setCache maxElementsPerNode!!
config.setMaxElementsPerNode(0);
- config.setEvictionPolicyClass(DummyEvictionPolicy.class.getName());
- regionManager.getRegion("/a/b", true).setEvictionPolicy(config);
+// config.setEvictionPolicyClass(DummyEvictionPolicy.class.getName());
+ Region r = regionManager.getRegion("/a/b", true);
+ r.setEvictionRegionConfig(new EvictionRegionConfig(r.getFqn(), config));
}
public void testMaxElements() throws Exception
{
- Region region = regionManager.getRegion("/a/b", true);
- ElementSizeConfiguration config = (ElementSizeConfiguration)
region.getEvictionPolicyConfig();
+ RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
+ ElementSizeAlgorithmConfig config = (ElementSizeAlgorithmConfig)
region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
config.setMaxNodes(10);
config.setMaxElementsPerNode(6);
for (int i = 0; i < 10; i++)
{
Fqn fqn = Fqn.fromString("/a/b/" + Integer.toString(i));
- region.putNodeEvent(new EvictedEventNode(fqn, NodeEventType.ADD_NODE_EVENT));
+ region.registerEvictionEvent(fqn, EvictionEvent.Type.ADD_NODE_EVENT);
if (i % 2 == 0)
{
for (int k = 0; k < i; k++)
{
- region.putNodeEvent(new EvictedEventNode(fqn,
NodeEventType.ADD_ELEMENT_EVENT));
+ region.registerEvictionEvent(fqn, EvictionEvent.Type.ADD_ELEMENT_EVENT);
}
}
}
- algo.process(region);
+ algo.process(region.getEvictionEventQueue());
ElementSizeQueue queue = (ElementSizeQueue) algo.evictionQueue;
assertEquals(9, algo.getEvictionQueue().getNumberOfNodes());
@@ -86,34 +83,34 @@
for (int i = 0; i < 7; i++)
{
- region.putNodeEvent(new EvictedEventNode(Fqn.fromString("/a/b/9"),
NodeEventType.ADD_ELEMENT_EVENT));
- region.putNodeEvent(new EvictedEventNode(Fqn.fromString("/a/b/7"),
NodeEventType.ADD_ELEMENT_EVENT));
+ region.registerEvictionEvent(Fqn.fromString("/a/b/9"),
EvictionEvent.Type.ADD_ELEMENT_EVENT);
+ region.registerEvictionEvent(Fqn.fromString("/a/b/7"),
EvictionEvent.Type.ADD_ELEMENT_EVENT);
}
- algo.process(region);
+ algo.process(region.getEvictionEventQueue());
assertEquals(7, queue.getNumberOfNodes());
}
public void testMaxNodesAndMaxElements() throws Exception
{
- Region region = regionManager.getRegion("/a/b", true);
- ElementSizeConfiguration config = (ElementSizeConfiguration)
region.getEvictionPolicyConfig();
+ RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
+ ElementSizeAlgorithmConfig config = (ElementSizeAlgorithmConfig)
region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
config.setMaxNodes(10);
config.setMaxElementsPerNode(100);
for (int i = 0; i < 20; i++)
{
Fqn fqn = Fqn.fromString("/a/b/" + Integer.toString(i));
- region.putNodeEvent(new EvictedEventNode(fqn, NodeEventType.ADD_NODE_EVENT));
+ region.registerEvictionEvent(fqn, EvictionEvent.Type.ADD_NODE_EVENT);
for (int k = 0; k < i; k++)
{
- region.putNodeEvent(new EvictedEventNode(fqn,
NodeEventType.ADD_ELEMENT_EVENT));
+ region.registerEvictionEvent(fqn, EvictionEvent.Type.ADD_ELEMENT_EVENT);
}
}
- algo.process(region);
+ algo.process(region.getEvictionEventQueue());
ElementSizeQueue queue = (ElementSizeQueue) algo.evictionQueue;
assertEquals(10, algo.getEvictionQueue().getNumberOfNodes());
Modified:
core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizeConfigurationTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizeConfigurationTest.java 2008-08-14
19:16:15 UTC (rev 6561)
+++
core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizeConfigurationTest.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -6,32 +6,30 @@
*/
package org.jboss.cache.eviction;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertTrue;
-import static org.testng.AssertJUnit.fail;
-
import org.jboss.cache.config.ConfigurationException;
-import org.jboss.cache.config.parsing.element.EvictionElementParser;
import org.jboss.cache.config.parsing.XmlConfigHelper;
+import org.jboss.cache.config.parsing.element.EvictionElementParser;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
+
/**
* @author Daniel Huang
* @version $Revision$
*/
-@Test(groups = {"functional"})
+@Test(groups = "unit", sequential = false)
public class ElementSizeConfigurationTest
{
public void testXMLParse1() throws Exception
{
- ElementSizeConfiguration config = new ElementSizeConfiguration();
+ ElementSizeAlgorithmConfig config = new ElementSizeAlgorithmConfig();
String xml = "<region name=\"abc\">" +
- "<attribute
name=\"maxNodes\">1000</attribute>" +
- "<attribute
name=\"maxElementsPerNode\">100</attribute>" +
- "</region>";
+ "<attribute
name=\"maxNodes\">1000</attribute>" +
+ "<attribute
name=\"maxElementsPerNode\">100</attribute>" +
+ "</region>";
Element element = XmlConfigHelper.stringToElement(xml);
- EvictionElementParser.parseEvictionPolicyConfig(element, config);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config, true);
assertEquals(100, config.getMaxElementsPerNode());
assertEquals(1000, config.getMaxNodes());
@@ -40,15 +38,15 @@
public void testXMLParse2() throws Exception
{
- ElementSizeConfiguration config = new ElementSizeConfiguration();
+ ElementSizeAlgorithmConfig config = new ElementSizeAlgorithmConfig();
String xml = "<region name=\"abc\">" +
- "<attribute
name=\"maxNodes\">1000</attribute>" +
- "</region>";
+ "<attribute
name=\"maxNodes\">1000</attribute>" +
+ "</region>";
Element element = XmlConfigHelper.stringToElement(xml);
try
{
- EvictionElementParser.parseEvictionPolicyConfig(element, config);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config, true);
}
catch (ConfigurationException ce)
{
@@ -62,14 +60,14 @@
public void testXMLParse3() throws Exception
{
- ElementSizeConfiguration config = new ElementSizeConfiguration();
+ ElementSizeAlgorithmConfig config = new ElementSizeAlgorithmConfig();
String xml = "<region name=\"abc\">" +
- "<attribute
name=\"maxElementsPerNode\">100</attribute>" +
- "</region>";
+ "<attribute
name=\"maxElementsPerNode\">100</attribute>" +
+ "</region>";
Element element = XmlConfigHelper.stringToElement(xml);
- EvictionElementParser.parseEvictionPolicyConfig(element, config);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config, true);
assertEquals(100, config.getMaxElementsPerNode());
assertEquals(0, config.getMaxNodes());
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizePolicyTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizePolicyTest.java 2008-08-14
19:16:15 UTC (rev 6561)
+++
core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizePolicyTest.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -16,14 +16,12 @@
import org.jboss.cache.config.EvictionRegionConfig;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.jboss.cache.lock.IsolationLevel;
+import org.jboss.cache.transaction.DummyTransactionManagerLookup;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import java.util.ArrayList;
-import java.util.List;
-
/**
* @author Daniel Huang
* @version $Revison: $
@@ -56,36 +54,18 @@
void initCaches() throws Exception
{
Configuration conf =
UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL,
true);
- EvictionConfig evConfig = conf.getEvictionConfig();
-
evConfig.setDefaultEvictionPolicyClass("org.jboss.cache.eviction.ElementSizePolicy");
- evConfig.setWakeupInterval(3000);
+ EvictionConfig evConfig = new EvictionConfig(new EvictionRegionConfig(Fqn.ROOT, new
ElementSizeAlgorithmConfig(5000, 100)), 3000);
evConfig.setDefaultEventQueueSize(200000);
-
- List<EvictionRegionConfig> regionConfigs = new
ArrayList<EvictionRegionConfig>();
- regionConfigs.add(createEvictionRegionConfig("_default_", 5000, 100));
- regionConfigs.add(createEvictionRegionConfig("/org/jboss/data", 10,
20));
- regionConfigs.add(createEvictionRegionConfig("/org/jboss/test/data", -1,
5));
- regionConfigs.add(createEvictionRegionConfig("/test/", 5000, 1));
-
- evConfig.setEvictionRegionConfigs(regionConfigs);
-
+ evConfig.addEvictionRegionConfig(new
EvictionRegionConfig(Fqn.fromString("/org/jboss/data"), new
ElementSizeAlgorithmConfig(10, 20)));
+ evConfig.addEvictionRegionConfig(new
EvictionRegionConfig(Fqn.fromString("/org/jboss/test/data"), new
ElementSizeAlgorithmConfig(-1, 5)));
+ evConfig.addEvictionRegionConfig(new
EvictionRegionConfig(Fqn.fromString("/test/"), new
ElementSizeAlgorithmConfig(5000, 1)));
+ conf.setEvictionConfig(evConfig);
cache = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object,
Object>().createCache(conf, false);
-
cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
+
cache.getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
cache.getConfiguration().setIsolationLevel(IsolationLevel.SERIALIZABLE);
cache.start();
}
- private EvictionRegionConfig createEvictionRegionConfig(String regionName, int
maxNodes, int maxElementsPerNode)
- {
- EvictionRegionConfig ercDefault = new EvictionRegionConfig();
- ercDefault.setRegionName(regionName);
- ElementSizeConfiguration esConfig = new ElementSizeConfiguration();
- if (maxNodes >= 0) esConfig.setMaxNodes(maxNodes);
- if (maxElementsPerNode >= 0)
esConfig.setMaxElementsPerNode(maxElementsPerNode);
- ercDefault.setEvictionPolicyConfig(esConfig);
- return ercDefault;
- }
-
@AfterMethod(alwaysRun = true)
public void tearDown() throws Exception
{
Modified:
core/trunk/src/test/java/org/jboss/cache/eviction/EvictionConfigurationTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/eviction/EvictionConfigurationTest.java 2008-08-14
19:16:15 UTC (rev 6561)
+++
core/trunk/src/test/java/org/jboss/cache/eviction/EvictionConfigurationTest.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -11,8 +11,9 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
import org.jboss.cache.RegionManager;
-import org.jboss.cache.config.EvictionPolicyConfig;
+import org.jboss.cache.config.EvictionRegionConfig;
import org.jboss.cache.lock.IsolationLevel;
+import org.jboss.cache.util.TestingUtil;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertTrue;
import org.testng.annotations.Test;
@@ -23,166 +24,163 @@
* @author Daniel Huang (dhuang(a)jboss.org)
* @version $Revision$
*/
-@Test(groups = {"functional"})
+@Test(groups = "unit", sequential = false)
public class EvictionConfigurationTest
{
- CacheSPI<Object, Object> cache;
- RegionManager regionManager;
-
public void testPolicyPerRegion() throws Exception
{
- this.setupCache("configs/policyPerRegion-eviction.xml");
- assertEquals(5000,
cache.getConfiguration().getEvictionConfig().getWakeupInterval());
+ CacheSPI<Object, Object> cache = null;
+ RegionManager regionManager = null;
+ try
+ {
+ cache = setupCache("configs/policyPerRegion-eviction.xml");
+ regionManager = cache.getRegionManager();
+ assertEquals(5000,
cache.getConfiguration().getEvictionConfig().getWakeupInterval());
- Region region = regionManager.getRegion("/org/jboss/data", true);
- EvictionPolicy policy = region.getEvictionPolicy();
- EvictionPolicyConfig configuration = region.getEvictionPolicyConfig();
- assertEquals(Fqn.fromString("/org/jboss/data"), region.getFqn());
- assertTrue(policy instanceof LFUPolicy);
- assertTrue(configuration instanceof LFUConfiguration);
- assertEquals(5000, ((LFUConfiguration) configuration).getMaxNodes());
- assertEquals(1000, ((LFUConfiguration) configuration).getMinNodes());
+ Region region = regionManager.getRegion("/org/jboss/data", true);
+ EvictionRegionConfig evictionRegionConfig = region.getEvictionRegionConfig();
+ assertEquals(Fqn.fromString("/org/jboss/data"), region.getFqn());
+ assertTrue(evictionRegionConfig.getEvictionAlgorithmConfig() instanceof
LFUAlgorithmConfig);
+ assertEquals(5000, ((LFUAlgorithmConfig)
evictionRegionConfig.getEvictionAlgorithmConfig()).getMaxNodes());
+ assertEquals(1000, ((LFUAlgorithmConfig)
evictionRegionConfig.getEvictionAlgorithmConfig()).getMinNodes());
- region = regionManager.getRegion("/org/jboss/test/data", true);
- policy = region.getEvictionPolicy();
- configuration = region.getEvictionPolicyConfig();
- assertEquals(Fqn.fromString("/org/jboss/test/data"), region.getFqn());
- assertTrue(policy instanceof FIFOPolicy);
- assertTrue(configuration instanceof FIFOConfiguration);
- assertEquals(5, ((FIFOConfiguration) configuration).getMaxNodes());
+ region = regionManager.getRegion("/org/jboss/test/data", true);
+ evictionRegionConfig = region.getEvictionRegionConfig();
+ assertEquals(Fqn.fromString("/org/jboss/test/data"),
region.getFqn());
+ assertTrue(evictionRegionConfig.getEvictionAlgorithmConfig() instanceof
FIFOAlgorithmConfig);
+ assertEquals(5, ((FIFOAlgorithmConfig)
evictionRegionConfig.getEvictionAlgorithmConfig()).getMaxNodes());
- region = regionManager.getRegion("/test", true);
- policy = region.getEvictionPolicy();
- configuration = region.getEvictionPolicyConfig();
- assertEquals(Fqn.fromString("/test"), region.getFqn());
- assertTrue(policy instanceof MRUPolicy);
- assertTrue(configuration instanceof MRUConfiguration);
- assertEquals(10000, ((MRUConfiguration) configuration).getMaxNodes());
+ region = regionManager.getRegion("/test", true);
+ evictionRegionConfig = region.getEvictionRegionConfig();
+ assertEquals(Fqn.fromString("/test"), region.getFqn());
+ assertTrue(evictionRegionConfig.getEvictionAlgorithmConfig() instanceof
MRUAlgorithmConfig);
+ assertEquals(10000, ((MRUAlgorithmConfig)
evictionRegionConfig.getEvictionAlgorithmConfig()).getMaxNodes());
- region = regionManager.getRegion("/maxAgeTest", true);
- policy = region.getEvictionPolicy();
- configuration = region.getEvictionPolicyConfig();
- assertEquals(Fqn.fromString("/maxAgeTest"), region.getFqn());
- assertTrue(policy instanceof LRUPolicy);
- assertTrue(configuration instanceof LRUConfiguration);
- assertEquals(10000, ((LRUConfiguration) configuration).getMaxNodes());
- assertEquals(8000, ((LRUConfiguration) configuration).getTimeToLive());
- assertEquals(10000, ((LRUConfiguration) configuration).getMaxAge());
+ region = regionManager.getRegion("/maxAgeTest", true);
+ evictionRegionConfig = region.getEvictionRegionConfig();
+ assertEquals(Fqn.fromString("/maxAgeTest"), region.getFqn());
+ assertTrue(evictionRegionConfig.getEvictionAlgorithmConfig() instanceof
LRUAlgorithmConfig);
+ assertEquals(10000, ((LRUAlgorithmConfig)
evictionRegionConfig.getEvictionAlgorithmConfig()).getMaxNodes());
+ assertEquals(8000, ((LRUAlgorithmConfig)
evictionRegionConfig.getEvictionAlgorithmConfig()).getTimeToLive());
+ assertEquals(10000, ((LRUAlgorithmConfig)
evictionRegionConfig.getEvictionAlgorithmConfig()).getMaxAge());
- // test the default region. use a region name that isn't defined explicitly in
conf file.
- region = regionManager.getRegion("/a/b/c", false);
- policy = region.getEvictionPolicy();
- configuration = region.getEvictionPolicyConfig();
- assertEquals(Fqn.ROOT, region.getFqn());
- assertTrue(policy instanceof LRUPolicy);
- assertTrue(configuration instanceof LRUConfiguration);
- assertEquals(5000, ((LRUConfiguration) configuration).getMaxNodes());
- assertEquals(1000000, ((LRUConfiguration) configuration).getTimeToLive());
- assertEquals(0, ((LRUConfiguration) configuration).getMaxAge());
+ // test the default region. use a region name that isn't defined explicitly
in conf file.
+ region = regionManager.getRegion("/a/b/c", false);
+ evictionRegionConfig = region.getEvictionRegionConfig();
+ assertEquals(Fqn.ROOT, region.getFqn());
+ assertTrue(evictionRegionConfig.getEvictionAlgorithmConfig() instanceof
LRUAlgorithmConfig);
+ assertEquals(5000, ((LRUAlgorithmConfig)
evictionRegionConfig.getEvictionAlgorithmConfig()).getMaxNodes());
+ assertEquals(1000000, ((LRUAlgorithmConfig)
evictionRegionConfig.getEvictionAlgorithmConfig()).getTimeToLive());
+ assertEquals(0, ((LRUAlgorithmConfig)
evictionRegionConfig.getEvictionAlgorithmConfig()).getMaxAge());
- cache.stop();
+ }
+ finally
+ {
+ TestingUtil.killCaches(cache);
+ }
}
public void testMixedPolicies() throws Exception
{
- this.setupCache("configs/mixedPolicy-eviction.xml");
- assertEquals(5000,
cache.getConfiguration().getEvictionConfig().getWakeupInterval());
+ CacheSPI<Object, Object> cache = null;
+ RegionManager regionManager = null;
- Region region = regionManager.getRegion("/org/jboss/data", true);
- EvictionPolicy policy = region.getEvictionPolicy();
- EvictionPolicyConfig configuration = region.getEvictionPolicyConfig();
- assertEquals(Fqn.fromString("/org/jboss/data/"), region.getFqn());
- assertTrue(policy instanceof FIFOPolicy);
- assertTrue(configuration instanceof FIFOConfiguration);
- assertEquals(5000, ((FIFOConfiguration) configuration).getMaxNodes());
+ try
+ {
+ cache = setupCache("configs/mixedPolicy-eviction.xml");
+ regionManager = cache.getRegionManager();
+ assertEquals(5000,
cache.getConfiguration().getEvictionConfig().getWakeupInterval());
- region = regionManager.getRegion("/test", true);
- policy = region.getEvictionPolicy();
- configuration = region.getEvictionPolicyConfig();
- assertEquals(Fqn.fromString("/test/"), region.getFqn());
- assertTrue(policy instanceof MRUPolicy);
- assertTrue(configuration instanceof MRUConfiguration);
- assertEquals(10000, ((MRUConfiguration) configuration).getMaxNodes());
+ Region region = regionManager.getRegion("/org/jboss/data", true);
+ EvictionRegionConfig evictionRegionConfig = region.getEvictionRegionConfig();
+ assertEquals(Fqn.fromString("/org/jboss/data/"), region.getFqn());
+ assertTrue(evictionRegionConfig.getEvictionAlgorithmConfig() instanceof
FIFOAlgorithmConfig);
+ assertEquals(5000, ((FIFOAlgorithmConfig)
evictionRegionConfig.getEvictionAlgorithmConfig()).getMaxNodes());
- // test the default region. use a region name that isn't defined explicitly in
conf file.
- region = regionManager.getRegion("/a/b/c", false);
- policy = region.getEvictionPolicy();
- configuration = region.getEvictionPolicyConfig();
- assertEquals(Fqn.ROOT, region.getFqn());
- assertTrue(policy instanceof LRUPolicy);
- assertTrue(configuration instanceof LRUConfiguration);
- assertEquals(5000, ((LRUConfiguration) configuration).getMaxNodes());
- assertEquals(1000000, ((LRUConfiguration) configuration).getTimeToLive());
- assertEquals(0, ((LRUConfiguration) configuration).getMaxAge());
+ region = regionManager.getRegion("/test", true);
+ evictionRegionConfig = region.getEvictionRegionConfig();
+ assertEquals(Fqn.fromString("/test/"), region.getFqn());
+ assertTrue(evictionRegionConfig.getEvictionAlgorithmConfig() instanceof
MRUAlgorithmConfig);
+ assertEquals(10000, ((MRUAlgorithmConfig)
evictionRegionConfig.getEvictionAlgorithmConfig()).getMaxNodes());
- region = regionManager.getRegion("/maxAgeTest", false);
- policy = region.getEvictionPolicy();
- configuration = region.getEvictionPolicyConfig();
- assertEquals(Fqn.fromString("/maxAgeTest/"), region.getFqn());
- assertTrue(policy instanceof LRUPolicy);
- assertTrue(configuration instanceof LRUConfiguration);
- assertEquals(10000, ((LRUConfiguration) configuration).getMaxNodes());
- assertEquals(8000, ((LRUConfiguration) configuration).getTimeToLive());
- assertEquals(10000, ((LRUConfiguration) configuration).getMaxAge());
+ // test the default region. use a region name that isn't defined explicitly
in conf file.
+ region = regionManager.getRegion("/a/b/c", false);
+ evictionRegionConfig = region.getEvictionRegionConfig();
+ assertEquals(Fqn.ROOT, region.getFqn());
+ assertTrue(evictionRegionConfig.getEvictionAlgorithmConfig() instanceof
LRUAlgorithmConfig);
+ assertEquals(5000, ((LRUAlgorithmConfig)
evictionRegionConfig.getEvictionAlgorithmConfig()).getMaxNodes());
+ assertEquals(1000000, ((LRUAlgorithmConfig)
evictionRegionConfig.getEvictionAlgorithmConfig()).getTimeToLive());
+ assertEquals(0, ((LRUAlgorithmConfig)
evictionRegionConfig.getEvictionAlgorithmConfig()).getMaxAge());
- cache.stop();
+ region = regionManager.getRegion("/maxAgeTest", false);
+ evictionRegionConfig = region.getEvictionRegionConfig();
+ assertEquals(Fqn.fromString("/maxAgeTest/"), region.getFqn());
+ assertTrue(evictionRegionConfig.getEvictionAlgorithmConfig() instanceof
LRUAlgorithmConfig);
+ assertEquals(10000, ((LRUAlgorithmConfig)
evictionRegionConfig.getEvictionAlgorithmConfig()).getMaxNodes());
+ assertEquals(8000, ((LRUAlgorithmConfig)
evictionRegionConfig.getEvictionAlgorithmConfig()).getTimeToLive());
+ assertEquals(10000, ((LRUAlgorithmConfig)
evictionRegionConfig.getEvictionAlgorithmConfig()).getMaxAge());
+
+ }
+ finally
+ {
+ TestingUtil.killCaches(cache);
+ }
}
public void testLegacyPolicyConfiguration() throws Exception
{
- this.setupCache("configs/local-lru-eviction.xml");
- assertEquals(5000,
cache.getConfiguration().getEvictionConfig().getWakeupInterval());
+ CacheSPI<Object, Object> cache = null;
+ RegionManager regionManager = null;
- Region region = regionManager.getRegion("/org/jboss/data", false);
- EvictionPolicy policy = region.getEvictionPolicy();
- EvictionPolicyConfig configuration = region.getEvictionPolicyConfig();
- assertEquals(Fqn.fromString("/org/jboss/data/"), region.getFqn());
- assertTrue(policy instanceof LRUPolicy);
- assertTrue(configuration instanceof LRUConfiguration);
- assertEquals(5000, ((LRUConfiguration) configuration).getMaxNodes());
- assertEquals(1000000, ((LRUConfiguration) configuration).getTimeToLive());
+ try
+ {
+ cache = setupCache("configs/local-lru-eviction.xml");
+ regionManager = cache.getRegionManager();
+ assertEquals(5000,
cache.getConfiguration().getEvictionConfig().getWakeupInterval());
- region = regionManager.getRegion("/org/jboss/test/data", false);
- policy = region.getEvictionPolicy();
- configuration = region.getEvictionPolicyConfig();
- assertEquals(Fqn.fromString("/org/jboss/test/data/"), region.getFqn());
- assertTrue(policy instanceof LRUPolicy);
- assertTrue(configuration instanceof LRUConfiguration);
- assertEquals(5, ((LRUConfiguration) configuration).getMaxNodes());
- assertEquals(4000, ((LRUConfiguration) configuration).getTimeToLive());
+ Region region = regionManager.getRegion("/org/jboss/data", false);
+ EvictionRegionConfig evictionRegionConfig = region.getEvictionRegionConfig();
+ assertEquals(Fqn.fromString("/org/jboss/data/"), region.getFqn());
+ assertTrue(evictionRegionConfig.getEvictionAlgorithmConfig() instanceof
LRUAlgorithmConfig);
+ assertEquals(5000, ((LRUAlgorithmConfig)
evictionRegionConfig.getEvictionAlgorithmConfig()).getMaxNodes());
+ assertEquals(1000000, ((LRUAlgorithmConfig)
evictionRegionConfig.getEvictionAlgorithmConfig()).getTimeToLive());
- region = regionManager.getRegion("/test", true);
- policy = region.getEvictionPolicy();
- configuration = region.getEvictionPolicyConfig();
- assertEquals(Fqn.fromString("/test/"), region.getFqn());
- assertTrue(policy instanceof LRUPolicy);
- assertTrue(configuration instanceof LRUConfiguration);
- assertEquals(10000, ((LRUConfiguration) configuration).getMaxNodes());
- assertEquals(4000, ((LRUConfiguration) configuration).getTimeToLive());
+ region = regionManager.getRegion("/org/jboss/test/data", false);
+ evictionRegionConfig = region.getEvictionRegionConfig();
+ assertEquals(Fqn.fromString("/org/jboss/test/data/"),
region.getFqn());
+ assertTrue(evictionRegionConfig.getEvictionAlgorithmConfig() instanceof
LRUAlgorithmConfig);
+ assertEquals(5, ((LRUAlgorithmConfig)
evictionRegionConfig.getEvictionAlgorithmConfig()).getMaxNodes());
+ assertEquals(4000, ((LRUAlgorithmConfig)
evictionRegionConfig.getEvictionAlgorithmConfig()).getTimeToLive());
- region = regionManager.getRegion("/maxAgeTest", true);
- policy = region.getEvictionPolicy();
- configuration = region.getEvictionPolicyConfig();
- assertEquals(Fqn.fromString("/maxAgeTest/"), region.getFqn());
- assertTrue(policy instanceof LRUPolicy);
- assertTrue(configuration instanceof LRUConfiguration);
- assertEquals(10000, ((LRUConfiguration) configuration).getMaxNodes());
- assertEquals(8000, ((LRUConfiguration) configuration).getTimeToLive());
- assertEquals(10000, ((LRUConfiguration) configuration).getMaxAge());
+ region = regionManager.getRegion("/test", true);
+ evictionRegionConfig = region.getEvictionRegionConfig();
+ assertEquals(Fqn.fromString("/test/"), region.getFqn());
+ assertTrue(evictionRegionConfig.getEvictionAlgorithmConfig() instanceof
LRUAlgorithmConfig);
+ assertEquals(10000, ((LRUAlgorithmConfig)
evictionRegionConfig.getEvictionAlgorithmConfig()).getMaxNodes());
+ assertEquals(4000, ((LRUAlgorithmConfig)
evictionRegionConfig.getEvictionAlgorithmConfig()).getTimeToLive());
- // test the default region. use a region name that isn't defined explicitly in
conf file.
- region = regionManager.getRegion("/a/b/c", false);
- policy = region.getEvictionPolicy();
- configuration = region.getEvictionPolicyConfig();
- assertEquals(Fqn.ROOT, region.getFqn());
- assertTrue(policy instanceof LRUPolicy);
- assertTrue(configuration instanceof LRUConfiguration);
- assertEquals(5000, ((LRUConfiguration) configuration).getMaxNodes());
- assertEquals(1000000, ((LRUConfiguration) configuration).getTimeToLive());
- assertEquals(0, ((LRUConfiguration) configuration).getMaxAge());
+ region = regionManager.getRegion("/maxAgeTest", true);
+ evictionRegionConfig = region.getEvictionRegionConfig();
+ assertEquals(Fqn.fromString("/maxAgeTest/"), region.getFqn());
+ assertTrue(evictionRegionConfig.getEvictionAlgorithmConfig() instanceof
LRUAlgorithmConfig);
+ assertEquals(10000, ((LRUAlgorithmConfig)
evictionRegionConfig.getEvictionAlgorithmConfig()).getMaxNodes());
+ assertEquals(8000, ((LRUAlgorithmConfig)
evictionRegionConfig.getEvictionAlgorithmConfig()).getTimeToLive());
+ assertEquals(10000, ((LRUAlgorithmConfig)
evictionRegionConfig.getEvictionAlgorithmConfig()).getMaxAge());
- cache.stop();
+ // test the default region. use a region name that isn't defined explicitly
in conf file.
+ region = regionManager.getRegion("/a/b/c", false);
+ evictionRegionConfig = region.getEvictionRegionConfig();
+ assertEquals(Fqn.ROOT, region.getFqn());
+ assertTrue(evictionRegionConfig.getEvictionAlgorithmConfig() instanceof
LRUAlgorithmConfig);
+ assertEquals(5000, ((LRUAlgorithmConfig)
evictionRegionConfig.getEvictionAlgorithmConfig()).getMaxNodes());
+ assertEquals(1000000, ((LRUAlgorithmConfig)
evictionRegionConfig.getEvictionAlgorithmConfig()).getTimeToLive());
+ assertEquals(0, ((LRUAlgorithmConfig)
evictionRegionConfig.getEvictionAlgorithmConfig()).getMaxAge());
+ }
+ finally
+ {
+ TestingUtil.killCaches(cache);
+ }
}
public void testTwoCacheInstanceConfiguration() throws Exception
@@ -193,17 +191,27 @@
public void testNoEviction() throws Exception
{
- cache = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object,
Object>().createCache();
- regionManager = cache.getRegionManager();
- assertEquals(0, regionManager.getAllRegions(Region.Type.ANY).size());
+ CacheSPI<Object, Object> cache = null;
+ RegionManager regionManager = null;
+
+ try
+ {
+ cache = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object,
Object>().createCache();
+ regionManager = cache.getRegionManager();
+ assertEquals(0, regionManager.getAllRegions(Region.Type.ANY).size());
+ }
+ finally
+ {
+ TestingUtil.killCaches(cache);
+ }
}
- private void setupCache(String configurationName)
+ private CacheSPI<Object, Object> setupCache(String configurationName)
{
- cache = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object,
Object>().createCache(configurationName, false);
+ CacheSPI<Object, Object> cache = (CacheSPI<Object, Object>) new
DefaultCacheFactory<Object, Object>().createCache(configurationName, false);
cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
cache.getConfiguration().setIsolationLevel(IsolationLevel.SERIALIZABLE);
cache.start();
- regionManager = cache.getRegionManager();
+ return cache;
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/ExpirationPolicyTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/ExpirationPolicyTest.java 2008-08-14
19:16:15 UTC (rev 6561)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/ExpirationPolicyTest.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -14,7 +14,7 @@
import org.jboss.cache.Region;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.EvictionConfig;
-import org.jboss.cache.config.EvictionPolicyConfig;
+import org.jboss.cache.config.EvictionRegionConfig;
import org.jboss.cache.util.TestingUtil;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
@@ -22,7 +22,7 @@
import org.testng.annotations.Test;
/**
- * Unit tests for {@link ExpirationPolicy}.
+ * Unit tests for {@link org.jboss.cache.eviction.ExpirationAlgorithm}.
*
* @author Elias Ross
* @version $Revision$
@@ -46,7 +46,9 @@
public void setUp() throws Exception
{
Configuration conf = new Configuration();
- EvictionConfig econf = new EvictionConfig(ExpirationPolicy.class.getName());
+ ExpirationAlgorithmConfig eAC = new ExpirationAlgorithmConfig();
+ EvictionRegionConfig eRC = new EvictionRegionConfig(Fqn.ROOT, eAC);
+ EvictionConfig econf = new EvictionConfig(eRC);
econf.setWakeupInterval(1000);
conf.setEvictionConfig(econf);
cache = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object,
Object>().createCache(conf, false);
@@ -64,9 +66,9 @@
public void testEviction() throws Exception
{
- cache.put(fqn1, ExpirationConfiguration.EXPIRATION_KEY, future);
- cache.put(fqn2, ExpirationConfiguration.EXPIRATION_KEY, past);
- cache.put(fqn3, ExpirationConfiguration.EXPIRATION_KEY, future);
+ cache.put(fqn1, ExpirationAlgorithmConfig.EXPIRATION_KEY, future);
+ cache.put(fqn2, ExpirationAlgorithmConfig.EXPIRATION_KEY, past);
+ cache.put(fqn3, ExpirationAlgorithmConfig.EXPIRATION_KEY, future);
cache.put(fqn4, "foo", "bar");
TestingUtil.sleepThread(2000);
assertNotNull(cache.getNode(fqn1));
@@ -83,10 +85,10 @@
public void testUpdate() throws Exception
{
log.info("update 1 from future to past");
- cache.put(fqn1, ExpirationConfiguration.EXPIRATION_KEY, future);
+ cache.put(fqn1, ExpirationAlgorithmConfig.EXPIRATION_KEY, future);
assertNotNull(cache.getNode(fqn1));
TestingUtil.sleepThread(1500);
- cache.put(fqn1, ExpirationConfiguration.EXPIRATION_KEY, past);
+ cache.put(fqn1, ExpirationAlgorithmConfig.EXPIRATION_KEY, past);
TestingUtil.sleepThread(1500);
assertNull(cache.getNode(fqn1));
cache.removeNode(Fqn.ROOT);
@@ -97,10 +99,10 @@
{
log.info("update 1 from future to past");
Long future2 = future + 2000;
- cache.put(fqn1, ExpirationConfiguration.EXPIRATION_KEY, future);
+ cache.put(fqn1, ExpirationAlgorithmConfig.EXPIRATION_KEY, future);
TestingUtil.sleepThread(2000);
assertNotNull(cache.getNode(fqn1));
- cache.put(fqn1, ExpirationConfiguration.EXPIRATION_KEY, future2);
+ cache.put(fqn1, ExpirationAlgorithmConfig.EXPIRATION_KEY, future2);
TestingUtil.sleepThread(3000);
assertNotNull(cache.getNode(fqn1));
TestingUtil.sleepThread(3000);
@@ -111,14 +113,14 @@
public void testMaxNodes() throws Exception
{
log.info("set max nodes to 2, expire soonest to expire first");
- EvictionPolicyConfig epc =
cache.getRegionManager().getAllRegions(Region.Type.EVICTION).get(0).getEvictionPolicyConfig();
- ExpirationConfiguration ec = (ExpirationConfiguration) epc;
+ EvictionRegionConfig regionConfig =
cache.getRegionManager().getAllRegions(Region.Type.EVICTION).get(0).getEvictionRegionConfig();
+ ExpirationAlgorithmConfig ec = (ExpirationAlgorithmConfig)
regionConfig.getEvictionAlgorithmConfig();
ec.setMaxNodes(2);
Long future2 = future + 500;
- cache.put(fqn1, ExpirationConfiguration.EXPIRATION_KEY, future2);
- cache.put(fqn2, ExpirationConfiguration.EXPIRATION_KEY, future2);
- cache.put(fqn3, ExpirationConfiguration.EXPIRATION_KEY, future);
- cache.put(fqn4, ExpirationConfiguration.EXPIRATION_KEY, past);
+ cache.put(fqn1, ExpirationAlgorithmConfig.EXPIRATION_KEY, future2);
+ cache.put(fqn2, ExpirationAlgorithmConfig.EXPIRATION_KEY, future2);
+ cache.put(fqn3, ExpirationAlgorithmConfig.EXPIRATION_KEY, future);
+ cache.put(fqn4, ExpirationAlgorithmConfig.EXPIRATION_KEY, past);
assertEquals(5, cache.getNumberOfNodes());
Thread.sleep(2000);
assertNotNull(cache.getNode(fqn1));
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/FIFOAlgorithmTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/FIFOAlgorithmTest.java 2008-08-14
19:16:15 UTC (rev 6561)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/FIFOAlgorithmTest.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -8,9 +8,11 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
+import org.jboss.cache.RegionImpl;
import org.jboss.cache.RegionManager;
import org.jboss.cache.RegionManagerImpl;
import org.jboss.cache.RegionRegistry;
+import org.jboss.cache.config.EvictionRegionConfig;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertTrue;
import org.testng.annotations.BeforeMethod;
@@ -35,28 +37,29 @@
public void setUp() throws Exception
{
algo = new FIFOAlgorithm();
- FIFOConfiguration config = new FIFOConfiguration();
+ FIFOAlgorithmConfig config = new FIFOAlgorithmConfig();
// We have to setCache maxNodes!!
config.setMaxNodes(0);
regionManager = new RegionManagerImpl();
((RegionManagerImpl) regionManager).injectDependencies(null, null, null, null,
null, new RegionRegistry());
- config.setEvictionPolicyClass(DummyEvictionPolicy.class.getName());
- regionManager.getRegion("/a/b", true).setEvictionPolicy(config);
+// config.setEvictionPolicyClass(DummyEvictionPolicy.class.getName());
+ Region r = regionManager.getRegion("/a/b", true);
+ r.setEvictionRegionConfig(new EvictionRegionConfig(r.getFqn(), config));
}
public void testMaxNodes1() throws Exception
{
- Region region = regionManager.getRegion("/a/b", true);
- FIFOConfiguration config = (FIFOConfiguration) region.getEvictionPolicyConfig();
+ RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
+ FIFOAlgorithmConfig config = (FIFOAlgorithmConfig)
region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
config.setMaxNodes(5);
for (int i = 0; i < 8; i++)
{
Fqn fqn = Fqn.fromString("/a/b/" + Integer.toString(i));
- region.putNodeEvent(new EvictedEventNode(fqn, NodeEventType.ADD_NODE_EVENT));
+ region.registerEvictionEvent(fqn, EvictionEvent.Type.ADD_NODE_EVENT);
}
- algo.process(region);
+ algo.process(region.getEvictionEventQueue());
FIFOQueue queue = (FIFOQueue) algo.evictionQueue;
assertEquals(5, algo.getEvictionQueue().getNumberOfNodes());
@@ -75,15 +78,15 @@
for (int i = 3; i < 8; i++)
{
Fqn fqn = Fqn.fromString("/a/b/" + Integer.toString(i));
- region.putNodeEvent(new EvictedEventNode(fqn, NodeEventType.VISIT_NODE_EVENT));
+ region.registerEvictionEvent(fqn, EvictionEvent.Type.VISIT_NODE_EVENT);
}
for (int i = 3; i < 5; i++)
{
Fqn fqn = Fqn.fromString("/a/b/" + Integer.toString(i));
- region.putNodeEvent(new EvictedEventNode(fqn, NodeEventType.VISIT_NODE_EVENT));
+ region.registerEvictionEvent(fqn, EvictionEvent.Type.VISIT_NODE_EVENT);
}
- algo.process(region);
+ algo.process(region.getEvictionEventQueue());
assertEquals(5, algo.getEvictionQueue().getNumberOfNodes());
@@ -100,17 +103,17 @@
public void testMaxNodes2() throws Exception
{
- Region region = regionManager.getRegion("/a/b", true);
- FIFOConfiguration config = (FIFOConfiguration) region.getEvictionPolicyConfig();
+ RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
+ FIFOAlgorithmConfig config = (FIFOAlgorithmConfig)
region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
config.setMaxNodes(50000);
for (int i = 0; i < 50000; i++)
{
Fqn fqn = Fqn.fromString("/a/b/" + Integer.toString(i));
- region.putNodeEvent(new EvictedEventNode(fqn, NodeEventType.ADD_NODE_EVENT));
+ region.registerEvictionEvent(fqn, EvictionEvent.Type.ADD_NODE_EVENT);
}
- algo.process(region);
+ algo.process(region.getEvictionEventQueue());
FIFOQueue queue = (FIFOQueue) algo.evictionQueue;
assertEquals(50000, algo.getEvictionQueue().getNumberOfNodes());
@@ -126,10 +129,10 @@
for (int i = 50000; i < 60000; i++)
{
Fqn fqn = Fqn.fromString("/a/b/" + Integer.toString(i));
- region.putNodeEvent(new EvictedEventNode(fqn, NodeEventType.ADD_NODE_EVENT));
+ region.registerEvictionEvent(fqn, EvictionEvent.Type.ADD_NODE_EVENT);
}
- algo.process(region);
+ algo.process(region.getEvictionEventQueue());
it = queue.iterate();
index = 10000;
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/FIFOConfigurationTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/eviction/FIFOConfigurationTest.java 2008-08-14
19:16:15 UTC (rev 6561)
+++
core/trunk/src/test/java/org/jboss/cache/eviction/FIFOConfigurationTest.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -6,13 +6,10 @@
*/
package org.jboss.cache.eviction;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertTrue;
-import static org.testng.AssertJUnit.fail;
-
import org.jboss.cache.config.ConfigurationException;
-import org.jboss.cache.config.parsing.element.EvictionElementParser;
import org.jboss.cache.config.parsing.XmlConfigHelper;
+import org.jboss.cache.config.parsing.element.EvictionElementParser;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
@@ -22,20 +19,19 @@
* @author Daniel Huang (dhuang(a)jboss.org)
* @version $Revision$
*/
-@Test(groups = {"functional"})
+@Test(groups = "unit", sequential = false)
public class FIFOConfigurationTest
{
-
public void testXMLParse() throws Exception
{
- FIFOConfiguration config = new FIFOConfiguration();
+ FIFOAlgorithmConfig config = new FIFOAlgorithmConfig();
String xml = "<region name=\"abc\">" +
"<attribute
name=\"maxNodes\">1000</attribute>" +
"</region>";
Element element = XmlConfigHelper.stringToElement(xml);
- EvictionElementParser.parseEvictionPolicyConfig(element, config);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config, true);
assertEquals(1000, config.getMaxNodes());
@@ -43,7 +39,7 @@
public void testXMLParse2() throws Exception
{
- FIFOConfiguration config = new FIFOConfiguration();
+ FIFOAlgorithmConfig config = new FIFOAlgorithmConfig();
String xml = "<region name=\"abc\">" +
"</region>";
@@ -51,7 +47,7 @@
try
{
- EvictionElementParser.parseEvictionPolicyConfig(element, config);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config, true);
}
catch (ConfigurationException ce)
{
@@ -63,7 +59,7 @@
public void testXMLParse3() throws Exception
{
- FIFOConfiguration config = new FIFOConfiguration();
+ FIFOAlgorithmConfig config = new FIFOAlgorithmConfig();
String xml = "<region>" +
"<attribute
name=\"maxNodes\">1000</attribute>" +
"</region>";
@@ -72,7 +68,7 @@
try
{
- EvictionElementParser.parseEvictionPolicyConfig(element, config);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config, true);
}
catch (ConfigurationException ce)
{
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/FIFOPolicyTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/FIFOPolicyTest.java 2008-08-14
19:16:15 UTC (rev 6561)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/FIFOPolicyTest.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -14,6 +14,7 @@
import org.jboss.cache.config.EvictionRegionConfig;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.jboss.cache.lock.IsolationLevel;
+import org.jboss.cache.transaction.DummyTransactionManagerLookup;
import org.jboss.cache.util.TestingUtil;
import org.jboss.cache.util.internals.EvictionController;
import static org.testng.AssertJUnit.*;
@@ -21,9 +22,6 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import java.util.ArrayList;
-import java.util.List;
-
/**
* Unit tests for FIFOPolicy.
*
@@ -58,31 +56,15 @@
void initCaches() throws Exception
{
Configuration config =
UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL,
true);
- EvictionConfig evConfig = config.getEvictionConfig();
- evConfig.setWakeupInterval(3000);
+ EvictionConfig evConfig = new EvictionConfig(new EvictionRegionConfig(Fqn.ROOT, new
FIFOAlgorithmConfig(5000)), 3000);
evConfig.setDefaultEventQueueSize(20000);
-
evConfig.setDefaultEvictionPolicyClass("org.jboss.cache.eviction.FIFOPolicy");
- List<EvictionRegionConfig> erConfigs = new
ArrayList<EvictionRegionConfig>();
- erConfigs.add(createEvictionRegionConfig("/_default_", 5000));
- erConfigs.add(createEvictionRegionConfig("/org/jboss/test/data", 5));
- evConfig.setEvictionRegionConfigs(erConfigs);
-
config.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
+ evConfig.addEvictionRegionConfig(new
EvictionRegionConfig(Fqn.fromString("/org/jboss/test/data"), new
FIFOAlgorithmConfig(5)));
+ config.setEvictionConfig(evConfig);
+
config.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
config.setIsolationLevel(IsolationLevel.SERIALIZABLE);
cache = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object,
Object>().createCache(config, true);// read in generic local xml
}
-
- private EvictionRegionConfig createEvictionRegionConfig(String regionName, int
maxNodes)
- {
- EvictionRegionConfig ercDefault = new EvictionRegionConfig();
- ercDefault.setRegionName(regionName);
- FIFOConfiguration esConfig = new FIFOConfiguration();
- if (maxNodes >= 0) esConfig.setMaxNodes(maxNodes);
- ercDefault.setEvictionPolicyConfig(esConfig);
- return ercDefault;
- }
-
-
@AfterMethod(alwaysRun = true)
public void tearDown() throws Exception
{
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/LFUAlgorithmTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/LFUAlgorithmTest.java 2008-08-14
19:16:15 UTC (rev 6561)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/LFUAlgorithmTest.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -7,10 +7,12 @@
package org.jboss.cache.eviction;
import org.jboss.cache.Fqn;
-import org.jboss.cache.Region;
+import org.jboss.cache.RegionImpl;
import org.jboss.cache.RegionManager;
import org.jboss.cache.RegionManagerImpl;
import org.jboss.cache.RegionRegistry;
+import org.jboss.cache.config.EvictionRegionConfig;
+import static org.jboss.cache.eviction.EvictionEvent.Type.*;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -33,11 +35,10 @@
public void setUp() throws Exception
{
algo = new LFUAlgorithm();
- LFUConfiguration config = new LFUConfiguration();
+ LFUAlgorithmConfig config = new LFUAlgorithmConfig();
regionManager = new RegionManagerImpl();
((RegionManagerImpl) regionManager).injectDependencies(null, null, null, null,
null, new RegionRegistry());
- config.setEvictionPolicyClass(DummyEvictionPolicy.class.getName());
- regionManager.getRegion("/a/b", true).setEvictionPolicy(config);
+ regionManager.getRegion("/a/b", true).setEvictionRegionConfig(new
EvictionRegionConfig(Fqn.fromString("/a/b"), config));
// doesn't this need a cache?!?? :-/
}
@@ -45,16 +46,16 @@
{
Fqn fqn1 = Fqn.fromString("/a/b/c");
Fqn fqn2 = Fqn.fromString("/a/b/d");
- Region region = regionManager.getRegion("/a/b", true);
- LFUConfiguration config = new LFUConfiguration();
+ RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
+ LFUAlgorithmConfig config = new LFUAlgorithmConfig();
config.setMaxNodes(0);
config.setMinNodes(20);
- region.setEvictionPolicy(config);
- region.putNodeEvent(new EvictedEventNode(fqn1, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
+ region.setEvictionRegionConfig(new EvictionRegionConfig(region.getFqn(), config));
+ region.registerEvictionEvent(fqn1, ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn2, ADD_NODE_EVENT);
try
{
- algo.process(region);
+ algo.process(region.getEvictionEventQueue());
}
catch (EvictionException e)
{
@@ -70,17 +71,17 @@
Fqn fqn1 = Fqn.fromString("/a/b/c");
Fqn fqn2 = Fqn.fromString("/a/b/d");
Fqn fqn3 = Fqn.fromString("/a/b/e");
- Region region = regionManager.getRegion("/a/b", true);
- LFUConfiguration config = new LFUConfiguration();
+ RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
+ LFUAlgorithmConfig config = new LFUAlgorithmConfig();
config.setMaxNodes(1);
config.setMinNodes(20);
- region.setEvictionPolicy(config);
- region.putNodeEvent(new EvictedEventNode(fqn1, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
+ region.setEvictionRegionConfig(new EvictionRegionConfig(region.getFqn(), config));
+ region.registerEvictionEvent(fqn1, ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn2, ADD_NODE_EVENT);
try
{
- algo.process(region);
+ algo.process(region.getEvictionEventQueue());
}
catch (EvictionException e)
{
@@ -89,13 +90,13 @@
}
assertEquals("Queue size should be ", 1,
algo.getEvictionQueue().getNumberOfNodes());
- region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn3, NodeEventType.ADD_NODE_EVENT));
+ region.registerEvictionEvent(fqn2, ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn3, ADD_NODE_EVENT);
try
{
- algo.process(region);
+ algo.process(region.getEvictionEventQueue());
}
catch (EvictionException e)
{
@@ -105,35 +106,6 @@
assertEquals("Queue size should be ", 1,
algo.getEvictionQueue().getNumberOfNodes());
}
- // What's this doing here? This should be a stress test, not a functional test.
There are no assertions, for
- // example. :S - Manik, Nov 06
-
- // public void testMaxNode3() throws Exception
- // {
- // Region region = regionManager.getRegion("/a/b", true);
- // LFUConfiguration config = new LFUConfiguration();
- //
- // config.setMaxNodes(15000);
- // config.setMinNodes(15000);
- //
- // region.setEvictionPolicy(config);
- // for (int i = 0; i < 20000; i++)
- // {
- // Fqn fqn = Fqn.fromString("/a/b/" + Integer.toString(i));
- // region.putNodeEvent(new EvictedEventNode(fqn,
NodeEventType.ADD_NODE_EVENT));
- //
- // if ((i % 2) == 0)
- // {
- // region.putNodeEvent(new EvictedEventNode(fqn,
NodeEventType.VISIT_NODE_EVENT));
- // }
- // }
- //
- // algo.invokeRemote(region);
- //// LFUQueue queue = (LFUQueue) algo.evictionQueue;
- //// Iterator it = queue.iterate();
- //
- // }
-
public void testMinNode1() throws Exception
{
Fqn fqn1 = Fqn.fromString("/a/b/c");
@@ -141,18 +113,18 @@
Fqn fqn3 = Fqn.fromString("/a/b/c/d/e");
Fqn fqn4 = Fqn.fromString("/a/b/c/d/e/f");
- Region region = regionManager.getRegion("/a/b", true);
- LFUConfiguration config = (LFUConfiguration) region.getEvictionPolicyConfig();
+ RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
+ LFUAlgorithmConfig config = (LFUAlgorithmConfig)
region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
config.setMaxNodes(0);
config.setMinNodes(2);
- region.putNodeEvent(new EvictedEventNode(fqn1, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn3, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn4, NodeEventType.ADD_NODE_EVENT));
+ region.registerEvictionEvent(fqn1, ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn2, ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn3, ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn4, ADD_NODE_EVENT);
- algo.process(region);
+ algo.process(region.getEvictionEventQueue());
assertEquals("Queue size should be ", 2,
algo.getEvictionQueue().getNumberOfNodes());
}
@@ -162,16 +134,16 @@
Fqn fqn1 = Fqn.fromString("/a/b/c");
Fqn fqn2 = Fqn.fromString("/a/b/d");
- Region region = regionManager.getRegion("/a/b", true);
- LFUConfiguration config = (LFUConfiguration) region.getEvictionPolicyConfig();
+ RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
+ LFUAlgorithmConfig config = (LFUAlgorithmConfig)
region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
config.setMaxNodes(0);
config.setMinNodes(0);
- region.putNodeEvent(new EvictedEventNode(fqn1, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
+ region.registerEvictionEvent(fqn1, ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn2, ADD_NODE_EVENT);
- algo.process(region);
+ algo.process(region.getEvictionEventQueue());
assertEquals("Queue size should be ", 0,
algo.getEvictionQueue().getNumberOfNodes());
}
@@ -190,23 +162,23 @@
Fqn fqn10 = Fqn.fromString("/a/b/c/d/e/f/g/h/i/j/k/l/m");
- Region region = regionManager.getRegion("/a/b", true);
- LFUConfiguration config = (LFUConfiguration) region.getEvictionPolicyConfig();
+ RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
+ LFUAlgorithmConfig config = (LFUAlgorithmConfig)
region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
config.setMaxNodes(0);
config.setMinNodes(100);
- region.putNodeEvent(new EvictedEventNode(fqn1, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn3, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn4, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn5, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn6, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn7, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn8, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn9, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn10, NodeEventType.ADD_NODE_EVENT));
+ region.registerEvictionEvent(fqn1, ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn2, ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn3, ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn4, ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn5, ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn6, ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn7, ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn8, ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn9, ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn10, ADD_NODE_EVENT);
- algo.process(region);
+ algo.process(region.getEvictionEventQueue());
LFUQueue queue = (LFUQueue) algo.evictionQueue;
assertEquals(10, algo.getEvictionQueue().getNumberOfNodes());
Iterator it = queue.iterate();
@@ -219,31 +191,31 @@
}
// fqn1 visited 4 additional times.
- region.putNodeEvent(new EvictedEventNode(fqn1, NodeEventType.VISIT_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn1, NodeEventType.VISIT_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn1, NodeEventType.VISIT_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn1, NodeEventType.VISIT_NODE_EVENT));
+ region.registerEvictionEvent(fqn1, VISIT_NODE_EVENT);
+ region.registerEvictionEvent(fqn1, VISIT_NODE_EVENT);
+ region.registerEvictionEvent(fqn1, VISIT_NODE_EVENT);
+ region.registerEvictionEvent(fqn1, VISIT_NODE_EVENT);
// fqn2 visited 3 additional times.
- region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.VISIT_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.VISIT_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.VISIT_NODE_EVENT));
+ region.registerEvictionEvent(fqn2, VISIT_NODE_EVENT);
+ region.registerEvictionEvent(fqn2, VISIT_NODE_EVENT);
+ region.registerEvictionEvent(fqn2, VISIT_NODE_EVENT);
// fqn3 visited 1 additional time.
- region.putNodeEvent(new EvictedEventNode(fqn3, NodeEventType.VISIT_NODE_EVENT));
+ region.registerEvictionEvent(fqn3, VISIT_NODE_EVENT);
// fqn4 visited 2 additional times.
- region.putNodeEvent(new EvictedEventNode(fqn4, NodeEventType.VISIT_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn4, NodeEventType.VISIT_NODE_EVENT));
+ region.registerEvictionEvent(fqn4, VISIT_NODE_EVENT);
+ region.registerEvictionEvent(fqn4, VISIT_NODE_EVENT);
// fqn9 visited 1 additional time.
- region.putNodeEvent(new EvictedEventNode(fqn9, NodeEventType.VISIT_NODE_EVENT));
+ region.registerEvictionEvent(fqn9, VISIT_NODE_EVENT);
// fqn10 visited 2 additional times.
- region.putNodeEvent(new EvictedEventNode(fqn10, NodeEventType.VISIT_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn10, NodeEventType.VISIT_NODE_EVENT));
+ region.registerEvictionEvent(fqn10, VISIT_NODE_EVENT);
+ region.registerEvictionEvent(fqn10, VISIT_NODE_EVENT);
- algo.process(region);
+ algo.process(region.getEvictionEventQueue());
System.out.println();
System.out.println();
@@ -282,10 +254,10 @@
Fqn fqn11 = Fqn.fromString("/a");
Fqn fqn12 = Fqn.fromString("/a/b");
- region.putNodeEvent(new EvictedEventNode(fqn11, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn12, NodeEventType.ADD_NODE_EVENT));
+ region.registerEvictionEvent(fqn11, ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn12, ADD_NODE_EVENT);
- algo.process(region);
+ algo.process(region.getEvictionEventQueue());
System.out.println();
System.out.println();
@@ -320,12 +292,12 @@
assertEquals(12, algo.getEvictionQueue().getNumberOfNodes());
- region.putNodeEvent(new EvictedEventNode(fqn1, NodeEventType.REMOVE_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn11, NodeEventType.REMOVE_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn12, NodeEventType.REMOVE_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn10, NodeEventType.REMOVE_NODE_EVENT));
+ region.registerEvictionEvent(fqn1, REMOVE_NODE_EVENT);
+ region.registerEvictionEvent(fqn11, REMOVE_NODE_EVENT);
+ region.registerEvictionEvent(fqn12, REMOVE_NODE_EVENT);
+ region.registerEvictionEvent(fqn10, REMOVE_NODE_EVENT);
- algo.process(region);
+ algo.process(region.getEvictionEventQueue());
System.out.println();
System.out.println();
@@ -357,22 +329,22 @@
assertEquals(8, algo.getEvictionQueue().getNumberOfNodes());
//test add/visit/remove combination
- region.putNodeEvent(new EvictedEventNode(fqn11, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn11, NodeEventType.VISIT_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn11, NodeEventType.VISIT_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn11, NodeEventType.VISIT_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn11, NodeEventType.VISIT_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn11, NodeEventType.VISIT_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn4, NodeEventType.VISIT_NODE_EVENT));
+ region.registerEvictionEvent(fqn11, ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn11, VISIT_NODE_EVENT);
+ region.registerEvictionEvent(fqn11, VISIT_NODE_EVENT);
+ region.registerEvictionEvent(fqn11, VISIT_NODE_EVENT);
+ region.registerEvictionEvent(fqn11, VISIT_NODE_EVENT);
+ region.registerEvictionEvent(fqn11, VISIT_NODE_EVENT);
+ region.registerEvictionEvent(fqn4, VISIT_NODE_EVENT);
// purposefully revisit a node that has been removed. assert that it is readded.
- region.putNodeEvent(new EvictedEventNode(fqn1, NodeEventType.VISIT_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn1, NodeEventType.VISIT_NODE_EVENT));
+ region.registerEvictionEvent(fqn1, VISIT_NODE_EVENT);
+ region.registerEvictionEvent(fqn1, VISIT_NODE_EVENT);
- region.putNodeEvent(new EvictedEventNode(fqn3, NodeEventType.REMOVE_NODE_EVENT));
+ region.registerEvictionEvent(fqn3, REMOVE_NODE_EVENT);
- algo.process(region);
+ algo.process(region.getEvictionEventQueue());
System.out.println();
System.out.println();
@@ -405,18 +377,18 @@
public void testEvictionQueueSortOrder2() throws Exception
{
- Region region = regionManager.getRegion("/a/b", true);
- LFUConfiguration config = (LFUConfiguration) region.getEvictionPolicyConfig();
+ RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
+ EvictionRegionConfig config = region.getEvictionRegionConfig();
- config.setMaxNodes(0);
- config.setMinNodes(10000);
+ ((LFUAlgorithmConfig) config.getEvictionAlgorithmConfig()).setMaxNodes(0);
+ ((LFUAlgorithmConfig) config.getEvictionAlgorithmConfig()).setMinNodes(10000);
for (int i = 0; i < 10000; i++)
{
Fqn fqn = Fqn.fromString("/a/b/" + Integer.toString(i));
- region.putNodeEvent(new EvictedEventNode(fqn, NodeEventType.ADD_NODE_EVENT));
+ region.registerEvictionEvent(fqn, ADD_NODE_EVENT);
}
- algo.process(region);
+ algo.process(region.getEvictionEventQueue());
LFUQueue queue = (LFUQueue) algo.evictionQueue;
Iterator it = queue.iterate();
@@ -433,11 +405,11 @@
if ((i % 2) == 0)
{
Fqn fqn = Fqn.fromString("/a/b/" + Integer.toString(i));
- region.putNodeEvent(new EvictedEventNode(fqn,
NodeEventType.VISIT_NODE_EVENT));
+ region.registerEvictionEvent(fqn, VISIT_NODE_EVENT);
}
}
- algo.process(region);
+ algo.process(region.getEvictionEventQueue());
it = queue.iterate();
int count = 0;
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/LFUConfigurationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/LFUConfigurationTest.java 2008-08-14
19:16:15 UTC (rev 6561)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/LFUConfigurationTest.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -6,10 +6,9 @@
*/
package org.jboss.cache.eviction;
-import static org.testng.AssertJUnit.assertEquals;
-
-import org.jboss.cache.config.parsing.element.EvictionElementParser;
import org.jboss.cache.config.parsing.XmlConfigHelper;
+import org.jboss.cache.config.parsing.element.EvictionElementParser;
+import static org.testng.AssertJUnit.assertEquals;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
@@ -19,22 +18,22 @@
* @author Daniel Huang (dhuang(a)jboss.org)
* @version $Revision$
*/
-@Test(groups = {"functional"})
+@Test(groups = "unit", sequential = false)
public class LFUConfigurationTest
{
public void testXMLParsing() throws Exception
{
- LFUConfiguration config = new LFUConfiguration();
+ LFUAlgorithmConfig config = new LFUAlgorithmConfig();
String xml =
"<region name=\"abc\">" +
- "<attribute name=\"minNodes\">10</attribute>"
+
- "<attribute name=\"maxNodes\">20</attribute>"
+
- "</region>";
+ "<attribute
name=\"minNodes\">10</attribute>" +
+ "<attribute
name=\"maxNodes\">20</attribute>" +
+ "</region>";
Element element = XmlConfigHelper.stringToElement(xml);
- EvictionElementParser.parseEvictionPolicyConfig(element, config);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config, true);
assertEquals(10, config.getMinNodes());
assertEquals(20, config.getMaxNodes());
@@ -42,14 +41,14 @@
public void testXMLParsing2() throws Exception
{
- LFUConfiguration config = new LFUConfiguration();
+ LFUAlgorithmConfig config = new LFUAlgorithmConfig();
String xml =
"<region name=\"abc\">" +
- "<attribute name=\"minNodes\">10</attribute>"
+
- "</region>";
+ "<attribute
name=\"minNodes\">10</attribute>" +
+ "</region>";
Element element = XmlConfigHelper.stringToElement(xml);
- EvictionElementParser.parseEvictionPolicyConfig(element, config);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config, true);
assertEquals(10, config.getMinNodes());
assertEquals(0, config.getMaxNodes());
@@ -57,14 +56,14 @@
public void testXMLParsing3() throws Exception
{
- LFUConfiguration config = new LFUConfiguration();
+ LFUAlgorithmConfig config = new LFUAlgorithmConfig();
String xml =
"<region name=\"abc\">" +
- "<attribute name=\"maxNodes\">20</attribute>"
+
- "</region>";
+ "<attribute
name=\"maxNodes\">20</attribute>" +
+ "</region>";
Element element = XmlConfigHelper.stringToElement(xml);
- EvictionElementParser.parseEvictionPolicyConfig(element, config);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config, true);
assertEquals(0, config.getMinNodes());
assertEquals(20, config.getMaxNodes());
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/LFUPolicyTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/LFUPolicyTest.java 2008-08-14
19:16:15 UTC (rev 6561)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/LFUPolicyTest.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -20,9 +20,6 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import java.util.ArrayList;
-import java.util.List;
-
/**
* Unit tests for LFU Policy.
*
@@ -57,31 +54,16 @@
void initCaches() throws Exception
{
Configuration config =
UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL,
true);
- EvictionConfig evConfig = config.getEvictionConfig();
- evConfig.setWakeupInterval(3000);
+ EvictionConfig evConfig = new EvictionConfig(new EvictionRegionConfig(Fqn.ROOT, new
LFUAlgorithmConfig(500, 10)), 3000);
evConfig.setDefaultEventQueueSize(200000);
- List<EvictionRegionConfig> erConfigs = new
ArrayList<EvictionRegionConfig>();
- erConfigs.add(createEvictionRegionConfig("/_default_", 500, 10));
- erConfigs.add(createEvictionRegionConfig("/org/jboss/data", 5000,
4000));
- erConfigs.add(createEvictionRegionConfig("/org/jboss/test/data", -1,
5));
- evConfig.setEvictionRegionConfigs(erConfigs);
+ evConfig.addEvictionRegionConfig(new
EvictionRegionConfig(Fqn.fromString("/org/jboss/data"), new
LFUAlgorithmConfig(5000, 4000)));
+ evConfig.addEvictionRegionConfig(new
EvictionRegionConfig(Fqn.fromString("/org/jboss/test/data"), new
LFUAlgorithmConfig(-1, 5)));
+ config.setEvictionConfig(evConfig);
config.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
config.setIsolationLevel(IsolationLevel.SERIALIZABLE);
cache = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object,
Object>().createCache(config, true);
}
- private EvictionRegionConfig createEvictionRegionConfig(String regionName, int
maxNodes, int minNodes)
- {
- EvictionRegionConfig ercDefault = new EvictionRegionConfig();
- ercDefault.setRegionName(regionName);
- LFUConfiguration esConfig = new LFUConfiguration();
- if (maxNodes >= 0) esConfig.setMaxNodes(maxNodes);
- if (minNodes >= 0) esConfig.setMinNodes(minNodes);
- ercDefault.setEvictionPolicyConfig(esConfig);
- esConfig.setEvictionPolicyClassName();
- return ercDefault;
- }
-
@AfterMethod(alwaysRun = true)
public void tearDown() throws Exception
{
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/LRUAlgorithmTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/LRUAlgorithmTest.java 2008-08-14
19:16:15 UTC (rev 6561)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/LRUAlgorithmTest.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -4,9 +4,11 @@
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
+import org.jboss.cache.RegionImpl;
import org.jboss.cache.RegionManager;
import org.jboss.cache.RegionManagerImpl;
import org.jboss.cache.RegionRegistry;
+import org.jboss.cache.config.EvictionRegionConfig;
import org.jboss.cache.util.TestingUtil;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertTrue;
@@ -24,21 +26,22 @@
{
RegionManager regionManager;
LRUAlgorithm algorithm;
- LRUConfiguration config;
+ LRUAlgorithmConfig config;
Log log = LogFactory.getLog(LRUAlgorithm.class);
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
algorithm = new LRUAlgorithm();
- config = new LRUConfiguration();
- config.setEvictionPolicyClass(DummyEvictionPolicy.class.getName());
+ config = new LRUAlgorithmConfig();
+// config.setEvictionPolicyClass(DummyEvictionPolicy.class.getName());
// We have to setCache timeToLiveSeconds!!
config.setTimeToLive(0);
regionManager = new RegionManagerImpl();
((RegionManagerImpl) regionManager).injectDependencies(null, null, null, null,
null, new RegionRegistry());
- regionManager.getRegion("/a/b", true).setEvictionPolicy(config);
+ Region r = regionManager.getRegion("/a/b", true);
+ r.setEvictionRegionConfig(new EvictionRegionConfig(r.getFqn(), config));
}
/**
@@ -49,20 +52,20 @@
Fqn fqn1 = Fqn.fromString("/a/b/c");
Fqn fqn2 = Fqn.fromString("/a/b/d");
Fqn fqn3 = Fqn.fromString("/a/b/e");
- Region region = regionManager.getRegion("/a/b", true);
- LRUConfiguration config = (LRUConfiguration) region.getEvictionPolicyConfig();
+ RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
+ LRUAlgorithmConfig config = (LRUAlgorithmConfig)
region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
config.setMaxNodes(1);
- region.putNodeEvent(new EvictedEventNode(fqn1, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
+ region.registerEvictionEvent(fqn1, EvictionEvent.Type.ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn2, EvictionEvent.Type.ADD_NODE_EVENT);
- algorithm.process(region);
+ algorithm.process(region.getEvictionEventQueue());
assertEquals("Queue size should be ", 1,
algorithm.getEvictionQueue().getNumberOfNodes());
- region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn3, NodeEventType.ADD_NODE_EVENT));
+ region.registerEvictionEvent(fqn2, EvictionEvent.Type.ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn3, EvictionEvent.Type.ADD_NODE_EVENT);
- algorithm.process(region);
+ algorithm.process(region.getEvictionEventQueue());
assertEquals("Queue size should be ", 1,
algorithm.getEvictionQueue().getNumberOfNodes());
}
@@ -75,13 +78,13 @@
{
Fqn fqn1 = Fqn.fromString("/a/b/c");
Fqn fqn2 = Fqn.fromString("/a/b/d");
- Region region = regionManager.getRegion("/a/b", true);
- LRUConfiguration config = (LRUConfiguration) region.getEvictionPolicyConfig();
+ RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
+ LRUAlgorithmConfig config = (LRUAlgorithmConfig)
region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
config.setMaxNodes(0);
- region.putNodeEvent(new EvictedEventNode(fqn1, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
+ region.registerEvictionEvent(fqn1, EvictionEvent.Type.ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn2, EvictionEvent.Type.ADD_NODE_EVENT);
- algorithm.process(region);
+ algorithm.process(region.getEvictionEventQueue());
assertEquals("Queue size should be ", 2,
algorithm.getEvictionQueue().getNumberOfNodes());
}
@@ -94,21 +97,21 @@
Fqn fqn1 = Fqn.fromString("/a/b/c");
Fqn fqn2 = Fqn.fromString("/a/b/d");
Fqn fqn3 = Fqn.fromString("/a/b/e");
- Region region = regionManager.getRegion("/a/b", true);
- LRUConfiguration config = (LRUConfiguration) region.getEvictionPolicyConfig();
+ RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
+ LRUAlgorithmConfig config = (LRUAlgorithmConfig)
region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
config.setMaxNodes(1);
- region.putNodeEvent(new EvictedEventNode(fqn1, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
+ region.registerEvictionEvent(fqn1, EvictionEvent.Type.ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn2, EvictionEvent.Type.ADD_NODE_EVENT);
- algorithm.process(region);
+ algorithm.process(region.getEvictionEventQueue());
assertEquals("Queue size should be ", 1,
algorithm.getEvictionQueue().getNumberOfNodes());
- region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn3, NodeEventType.ADD_NODE_EVENT));
+ region.registerEvictionEvent(fqn2, EvictionEvent.Type.ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn3, EvictionEvent.Type.ADD_NODE_EVENT);
- algorithm.process(region);
+ algorithm.process(region.getEvictionEventQueue());
assertEquals("Queue size should be ", 1,
algorithm.getEvictionQueue().getNumberOfNodes());
}
@@ -120,16 +123,16 @@
{
Fqn fqn1 = Fqn.fromString("/a/b/c");
Fqn fqn2 = Fqn.fromString("/a/b/d");
- Region region = regionManager.getRegion("/a/b", true);
- LRUConfiguration config = (LRUConfiguration) region.getEvictionPolicyConfig();
+ RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
+ LRUAlgorithmConfig config = (LRUAlgorithmConfig)
region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
config.setMaxNodes(0);
config.setTimeToLive(0);
- region.putNodeEvent(new EvictedEventNode(fqn1, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
+ region.registerEvictionEvent(fqn1, EvictionEvent.Type.ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn2, EvictionEvent.Type.ADD_NODE_EVENT);
TestingUtil.sleepThread(500);
- algorithm.process(region);
+ algorithm.process(region.getEvictionEventQueue());
assertEquals("Queue size should be ", 2,
algorithm.getEvictionQueue().getNumberOfNodes());
}
@@ -142,20 +145,20 @@
Fqn fqn1 = Fqn.fromString("/a/b/c");
Fqn fqn2 = Fqn.fromString("/a/b/d");
Fqn fqn3 = Fqn.fromString("/a/b/e");
- Region region = regionManager.getRegion("/a/b", true);
- LRUConfiguration config = (LRUConfiguration) region.getEvictionPolicyConfig();
+ RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
+ LRUAlgorithmConfig config = (LRUAlgorithmConfig)
region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
config.setMaxNodes(0);
config.setTimeToLive(1000);
- region.putNodeEvent(new EvictedEventNode(fqn1, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn3, NodeEventType.ADD_NODE_EVENT));
+ region.registerEvictionEvent(fqn1, EvictionEvent.Type.ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn2, EvictionEvent.Type.ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn3, EvictionEvent.Type.ADD_NODE_EVENT);
- algorithm.process(region);
+ algorithm.process(region.getEvictionEventQueue());
assertEquals("Queue size #1: ", 3,
algorithm.getEvictionQueue().getNumberOfNodes());
TestingUtil.sleepThread(1100);
- algorithm.process(region);
+ algorithm.process(region.getEvictionEventQueue());
assertEquals("Queue size #2: ", 0,
algorithm.getEvictionQueue().getNumberOfNodes());
}
@@ -168,21 +171,21 @@
Fqn fqn1 = Fqn.fromString("/a/b/c");
Fqn fqn2 = Fqn.fromString("/a/b/d");
Fqn fqn3 = Fqn.fromString("/a/b/e");
- Region region = regionManager.getRegion("/a/b", true);
- LRUConfiguration config = (LRUConfiguration) region.getEvictionPolicyConfig();
+ RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
+ LRUAlgorithmConfig config = (LRUAlgorithmConfig)
region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
config.setMaxNodes(0);
config.setTimeToLive(1000);
- region.putNodeEvent(new EvictedEventNode(fqn1, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn3, NodeEventType.ADD_NODE_EVENT));
+ region.registerEvictionEvent(fqn1, EvictionEvent.Type.ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn2, EvictionEvent.Type.ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn3, EvictionEvent.Type.ADD_NODE_EVENT);
- algorithm.process(region);
+ algorithm.process(region.getEvictionEventQueue());
assertEquals("Queue size #1: ", 3,
algorithm.getEvictionQueue().getNumberOfNodes());
TestingUtil.sleepThread(1100);
- region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.VISIT_NODE_EVENT));
+ region.registerEvictionEvent(fqn2, EvictionEvent.Type.VISIT_NODE_EVENT);
- algorithm.process(region);
+ algorithm.process(region.getEvictionEventQueue());
assertEquals("Queue size #2: ", 1,
algorithm.getEvictionQueue().getNumberOfNodes());
}
@@ -196,19 +199,19 @@
Fqn fqn1 = Fqn.fromString("/a/b/c");
Fqn fqn2 = Fqn.fromString("/a/b/d");
Fqn fqn3 = Fqn.fromString("/a/b/e");
- Region region = regionManager.getRegion("/a/b", true);
- LRUConfiguration config = (LRUConfiguration) region.getEvictionPolicyConfig();
+ RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
+ LRUAlgorithmConfig config = (LRUAlgorithmConfig)
region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
config.setMaxNodes(0);
config.setTimeToLive(0);
config.setMaxAge(1000);
- region.putNodeEvent(new EvictedEventNode(fqn1, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn3, NodeEventType.ADD_NODE_EVENT));
+ region.registerEvictionEvent(fqn1, EvictionEvent.Type.ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn2, EvictionEvent.Type.ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn3, EvictionEvent.Type.ADD_NODE_EVENT);
- algorithm.process(region);
+ algorithm.process(region.getEvictionEventQueue());
assertEquals("Queue size #1: ", 3,
algorithm.getEvictionQueue().getNumberOfNodes());
TestingUtil.sleepThread(1100);
- algorithm.process(region);
+ algorithm.process(region.getEvictionEventQueue());
assertEquals("Queue size #2: ", 0,
algorithm.getEvictionQueue().getNumberOfNodes());
}
@@ -222,23 +225,23 @@
Fqn fqn1 = Fqn.fromString("/a/b/c");
Fqn fqn2 = Fqn.fromString("/a/b/d");
Fqn fqn3 = Fqn.fromString("/a/b/e");
- Region region = regionManager.getRegion("/a/b", true);
- LRUConfiguration config = (LRUConfiguration) region.getEvictionPolicyConfig();
+ RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
+ LRUAlgorithmConfig config = (LRUAlgorithmConfig)
region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
config.setMaxNodes(0);
config.setTimeToLive(0);
config.setMaxAge(1000);
- region.putNodeEvent(new EvictedEventNode(fqn1, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn3, NodeEventType.ADD_NODE_EVENT));
+ region.registerEvictionEvent(fqn1, EvictionEvent.Type.ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn2, EvictionEvent.Type.ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn3, EvictionEvent.Type.ADD_NODE_EVENT);
- algorithm.process(region);
+ algorithm.process(region.getEvictionEventQueue());
assertEquals("Queue size #1: ", 3,
algorithm.getEvictionQueue().getNumberOfNodes());
TestingUtil.sleepThread(500);
- algorithm.process(region);
+ algorithm.process(region.getEvictionEventQueue());
assertEquals("Queue size #2: ", 3,
algorithm.getEvictionQueue().getNumberOfNodes());
TestingUtil.sleepThread(600);
- algorithm.process(region);
+ algorithm.process(region.getEvictionEventQueue());
assertEquals("Queue size #3: ", 0,
algorithm.getEvictionQueue().getNumberOfNodes());
}
@@ -251,18 +254,18 @@
Fqn fqn2 = Fqn.fromString("/a/b/d");
Fqn fqn3 = Fqn.fromString("/a/b/e");
Fqn fqn4 = Fqn.fromString("/a/b/f");
- Region region = regionManager.getRegion("/a/b", true);
- LRUConfiguration config = (LRUConfiguration) region.getEvictionPolicyConfig();
+ RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
+ LRUAlgorithmConfig config = (LRUAlgorithmConfig)
region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
// Should have a maximum of 2 nodes.
config.setMaxNodes(2);
config.setTimeToLive(1000);
config.setMaxAge(3000);
- region.putNodeEvent(new EvictedEventNode(fqn1, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn4, NodeEventType.ADD_NODE_EVENT));
+ region.registerEvictionEvent(fqn1, EvictionEvent.Type.ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn2, EvictionEvent.Type.ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn4, EvictionEvent.Type.ADD_NODE_EVENT);
- algorithm.process(region);
+ algorithm.process(region.getEvictionEventQueue());
EvictionQueue eq = algorithm.getEvictionQueue();
int numNodesInQueue = eq.getNumberOfNodes();
@@ -271,9 +274,9 @@
// make sure all nodes now expire
TestingUtil.sleepThread(1100);
- region.putNodeEvent(new EvictedEventNode(fqn3, NodeEventType.ADD_NODE_EVENT));
+ region.registerEvictionEvent(fqn3, EvictionEvent.Type.ADD_NODE_EVENT);
- algorithm.process(region);
+ algorithm.process(region.getEvictionEventQueue());
numNodesInQueue = eq.getNumberOfNodes();
assert 1 == numNodesInQueue : "Queue size #2: expected 1 but was " +
numNodesInQueue;
@@ -281,9 +284,9 @@
TestingUtil.sleepThread(3100);
// visit the node now to prevent the idle time from doing the pruning - node still
gets pruned but by
// max age.
- region.putNodeEvent(new EvictedEventNode(fqn3, NodeEventType.VISIT_NODE_EVENT));
+ region.registerEvictionEvent(fqn3, EvictionEvent.Type.VISIT_NODE_EVENT);
- algorithm.process(region);
+ algorithm.process(region.getEvictionEventQueue());
numNodesInQueue = eq.getNumberOfNodes();
assert 0 == numNodesInQueue : "Queue size #3: expected 0 but was " +
numNodesInQueue;
@@ -297,17 +300,17 @@
Fqn fqn1 = Fqn.fromString("/a/b/c");
Fqn fqn2 = Fqn.fromString("/a/b/d");
Fqn fqn3 = Fqn.fromString("/a/b/e");
- Region region = regionManager.getRegion("/a/b", true);
- LRUConfiguration config = (LRUConfiguration) region.getEvictionPolicyConfig();
+ RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
+ LRUAlgorithmConfig config = (LRUAlgorithmConfig)
region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
config.setMaxNodes(2);
config.setTimeToLive(1000);
config.setMaxAge(3000);
- region.putNodeEvent(new EvictedEventNode(fqn1, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.REMOVE_NODE_EVENT));
+ region.registerEvictionEvent(fqn1, EvictionEvent.Type.ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn2, EvictionEvent.Type.ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn2, EvictionEvent.Type.REMOVE_NODE_EVENT);
- algorithm.process(region);
+ algorithm.process(region.getEvictionEventQueue());
EvictionQueue eq = algorithm.getEvictionQueue();
int numNodesInQueue = eq.getNumberOfNodes();
@@ -315,17 +318,17 @@
// make sure existing events all time out
TestingUtil.sleepThread(1100);
- region.putNodeEvent(new EvictedEventNode(fqn3, NodeEventType.ADD_NODE_EVENT));
+ region.registerEvictionEvent(fqn3, EvictionEvent.Type.ADD_NODE_EVENT);
- algorithm.process(region);
+ algorithm.process(region.getEvictionEventQueue());
numNodesInQueue = eq.getNumberOfNodes();
assert 1 == numNodesInQueue : "Queue size #2: expected 1 but was " +
numNodesInQueue;
TestingUtil.sleepThread(3100);
- region.putNodeEvent(new EvictedEventNode(fqn3, NodeEventType.VISIT_NODE_EVENT));
+ region.registerEvictionEvent(fqn3, EvictionEvent.Type.VISIT_NODE_EVENT);
- algorithm.process(region);
+ algorithm.process(region.getEvictionEventQueue());
numNodesInQueue = eq.getNumberOfNodes();
assert 0 == numNodesInQueue : "Queue size #3: expected 0 but was " +
numNodesInQueue;
@@ -333,8 +336,8 @@
public void testEvictionSortOrder() throws EvictionException
{
- Region region = regionManager.getRegion("/a/b", true);
- LRUConfiguration config = (LRUConfiguration) region.getEvictionPolicyConfig();
+ RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
+ LRUAlgorithmConfig config = (LRUAlgorithmConfig)
region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
config.setMaxAge(1000000);
config.setMaxNodes(0);
@@ -343,21 +346,21 @@
for (int i = 0; i < 100; i++)
{
Fqn fqn = Fqn.fromString("/a/b/" + Integer.toString(i));
- region.putNodeEvent(new EvictedEventNode(fqn, NodeEventType.ADD_NODE_EVENT));
+ region.registerEvictionEvent(fqn, EvictionEvent.Type.ADD_NODE_EVENT);
}
- algorithm.process(region);
+ algorithm.process(region.getEvictionEventQueue());
for (int i = 0; i < 100; i++)
{
Fqn fqn = Fqn.fromString("/a/b/" + Integer.toString(i));
if (i % 2 == 0)
{
- region.putNodeEvent(new EvictedEventNode(fqn,
NodeEventType.VISIT_NODE_EVENT));
+ region.registerEvictionEvent(fqn, EvictionEvent.Type.VISIT_NODE_EVENT);
}
}
- algorithm.process(region);
+ algorithm.process(region.getEvictionEventQueue());
LRUQueue queue = (LRUQueue) algorithm.getEvictionQueue();
@@ -380,10 +383,10 @@
for (int i = 0; i < 100; i++)
{
Fqn fqn = Fqn.fromString("/a/b/" + Integer.toString(i));
- region.putNodeEvent(new EvictedEventNode(fqn, NodeEventType.ADD_NODE_EVENT));
+ region.registerEvictionEvent(fqn, EvictionEvent.Type.ADD_NODE_EVENT);
}
- algorithm.process(region);
+ algorithm.process(region.getEvictionEventQueue());
long lastCreateTimestamp = 0;
while ((ne = queue.getFirstMaxAgeNodeEntry()) != null)
{
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/LRUConfigurationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/LRUConfigurationTest.java 2008-08-14
19:16:15 UTC (rev 6561)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/LRUConfigurationTest.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -6,12 +6,11 @@
*/
package org.jboss.cache.eviction;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertTrue;
-
import org.jboss.cache.config.ConfigurationException;
-import org.jboss.cache.config.parsing.element.EvictionElementParser;
import org.jboss.cache.config.parsing.XmlConfigHelper;
+import org.jboss.cache.config.parsing.element.EvictionElementParser;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertTrue;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
@@ -21,13 +20,13 @@
* @author Daniel Huang (dhuang(a)jboss.org)
* @version $Revision$
*/
-@Test(groups = {"functional"})
+@Test(groups = "unit", sequential = false)
public class LRUConfigurationTest
{
public void testXMLParsing() throws Exception
{
- LRUConfiguration config = new LRUConfiguration();
+ LRUAlgorithmConfig config = new LRUAlgorithmConfig();
String xml =
"<region name=\"/org/jboss/data\">\n" +
"<attribute
name=\"maxNodes\">5000</attribute>\n" +
@@ -36,7 +35,7 @@
Element element = XmlConfigHelper.stringToElement(xml);
- EvictionElementParser.parseEvictionPolicyConfig(element, config);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config, true);
assertEquals(5000, config.getMaxNodes());
assertEquals(1000000, config.getTimeToLive());
@@ -44,7 +43,7 @@
public void testXMLParsing2() throws Exception
{
- LRUConfiguration config = new LRUConfiguration();
+ LRUAlgorithmConfig config = new LRUAlgorithmConfig();
String xml = "<region name=\"/maxAgeTest/\">\n" +
"<attribute
name=\"maxNodes\">10000</attribute>\n" +
"<attribute
name=\"timeToLiveSeconds\">8</attribute>\n" +
@@ -52,7 +51,7 @@
"</region>";
Element element = XmlConfigHelper.stringToElement(xml);
- EvictionElementParser.parseEvictionPolicyConfig(element, config);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config, true);
assertEquals(10000, config.getMaxNodes());
assertEquals(8000, config.getTimeToLive());
@@ -61,7 +60,7 @@
public void testXMLParsing3() throws Exception
{
- LRUConfiguration config = new LRUConfiguration();
+ LRUAlgorithmConfig config = new LRUAlgorithmConfig();
String xml = "<region name=\"/maxAgeTest/\">\n" +
"<attribute
name=\"maxNodes\">10000</attribute>\n" +
"<attribute
name=\"maxAgeSeconds\">10</attribute>\n" +
@@ -70,7 +69,7 @@
boolean caught = false;
try
{
- EvictionElementParser.parseEvictionPolicyConfig(element, config);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config, true);
}
catch (ConfigurationException ce)
{
@@ -85,7 +84,7 @@
element = XmlConfigHelper.stringToElement(xml);
- EvictionElementParser.parseEvictionPolicyConfig(element, config);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config, true);
assertEquals(0, config.getMaxNodes());
}
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/LRUPolicyTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/LRUPolicyTest.java 2008-08-14
19:16:15 UTC (rev 6561)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/LRUPolicyTest.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -47,8 +47,8 @@
EvictionConfig evConfig = conf.getEvictionConfig();
evConfig.setWakeupInterval(1000);
List<EvictionRegionConfig> regionConfigs = new
ArrayList<EvictionRegionConfig>();
-
regionConfigs.add(UnitTestCacheConfigurationFactory.buildLruEvictionRegionConfig("/org/jboss/test/data",
5, dataRegionTTLMillis));
-
regionConfigs.add(UnitTestCacheConfigurationFactory.buildLruEvictionRegionConfig("/test",
10000, testRegionTTLMillis));
+ regionConfigs.add(new
EvictionRegionConfig(Fqn.fromString("/org/jboss/test/data"), new
LRUAlgorithmConfig(dataRegionTTLMillis, 5)));
+ regionConfigs.add(new EvictionRegionConfig(Fqn.fromString("/test"), new
LRUAlgorithmConfig(testRegionTTLMillis, 10000)));
evConfig.setEvictionRegionConfigs(regionConfigs);
conf.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
conf.setIsolationLevel(IsolationLevel.SERIALIZABLE);
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/MRUAlgorithmTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/MRUAlgorithmTest.java 2008-08-14
19:16:15 UTC (rev 6561)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/MRUAlgorithmTest.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -8,9 +8,11 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
+import org.jboss.cache.RegionImpl;
import org.jboss.cache.RegionManager;
import org.jboss.cache.RegionManagerImpl;
import org.jboss.cache.RegionRegistry;
+import org.jboss.cache.config.EvictionRegionConfig;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -31,13 +33,14 @@
public void setUp() throws Exception
{
algorithm = new MRUAlgorithm();
- MRUConfiguration config = new MRUConfiguration();
- // We have to setCache maxNodes!!
+ MRUAlgorithmConfig config = new MRUAlgorithmConfig();
+ // We have to set maxNodes explicitly!!
config.setMaxNodes(0);
- config.setEvictionPolicyClass(DummyEvictionPolicy.class.getName());
+// config.setEvictionPolicyClass(DummyEvictionPolicy.class.getName());
regionManager = new RegionManagerImpl();
((RegionManagerImpl) regionManager).injectDependencies(null, null, null, null,
null, new RegionRegistry());
- regionManager.getRegion("/a/b", true).setEvictionPolicy(config);
+ Region r = regionManager.getRegion("/a/b", true);
+ r.setEvictionRegionConfig(new EvictionRegionConfig(r.getFqn(), config));
}
public void testMaxNodes() throws Exception
@@ -45,13 +48,13 @@
Fqn fqn1 = Fqn.fromString("/a/b/c");
Fqn fqn2 = Fqn.fromString("/a/b/d");
Fqn fqn3 = Fqn.fromString("/a/b/e");
- Region region = regionManager.getRegion("/a/b", true);
- MRUConfiguration config = (MRUConfiguration) region.getEvictionPolicyConfig();
+ RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
+ MRUAlgorithmConfig config = (MRUAlgorithmConfig)
region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
config.setMaxNodes(1);
- region.putNodeEvent(new EvictedEventNode(fqn1, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn3, NodeEventType.ADD_NODE_EVENT));
- algorithm.process(region);
+ region.registerEvictionEvent(fqn1, EvictionEvent.Type.ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn2, EvictionEvent.Type.ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn3, EvictionEvent.Type.ADD_NODE_EVENT);
+ algorithm.process(region.getEvictionEventQueue());
assertEquals(1, algorithm.getEvictionQueue().getNumberOfNodes());
@@ -59,10 +62,10 @@
for (int i = 0; i < 150; i++)
{
Fqn fqn = Fqn.fromString("/a/b/c/" + Integer.toString(i));
- region.putNodeEvent(new EvictedEventNode(fqn, NodeEventType.ADD_NODE_EVENT));
+ region.registerEvictionEvent(fqn, EvictionEvent.Type.ADD_NODE_EVENT);
}
- algorithm.process(region);
+ algorithm.process(region.getEvictionEventQueue());
assertEquals(100, algorithm.getEvictionQueue().getNumberOfNodes());
}
@@ -79,32 +82,32 @@
Fqn fqn8 = Fqn.fromString("/a/b/j");
Fqn fqn9 = Fqn.fromString("/a/b/k");
Fqn fqn10 = Fqn.fromString("/a/b/l");
- Region region = regionManager.getRegion("/a/b", true);
- MRUConfiguration config = (MRUConfiguration) region.getEvictionPolicyConfig();
+ RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
+ MRUAlgorithmConfig config = (MRUAlgorithmConfig)
region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
config.setMaxNodes(8);
- region.putNodeEvent(new EvictedEventNode(fqn1, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn3, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn4, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn5, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn6, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn7, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn8, NodeEventType.ADD_NODE_EVENT));
+ region.registerEvictionEvent(fqn1, EvictionEvent.Type.ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn2, EvictionEvent.Type.ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn3, EvictionEvent.Type.ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn4, EvictionEvent.Type.ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn5, EvictionEvent.Type.ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn6, EvictionEvent.Type.ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn7, EvictionEvent.Type.ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn8, EvictionEvent.Type.ADD_NODE_EVENT);
- algorithm.process(region);
+ algorithm.process(region.getEvictionEventQueue());
assertEquals(8, algorithm.getEvictionQueue().getNumberOfNodes());
- region.putNodeEvent(new EvictedEventNode(fqn9, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn10, NodeEventType.ADD_NODE_EVENT));
+ region.registerEvictionEvent(fqn9, EvictionEvent.Type.ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn10, EvictionEvent.Type.ADD_NODE_EVENT);
Thread.sleep(5000);
assertEquals(8, algorithm.getEvictionQueue().getNumberOfNodes());
- region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn4, NodeEventType.ADD_NODE_EVENT));
+ region.registerEvictionEvent(fqn2, EvictionEvent.Type.ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn4, EvictionEvent.Type.ADD_NODE_EVENT);
- algorithm.process(region);
+ algorithm.process(region.getEvictionEventQueue());
assertEquals(8, algorithm.getEvictionQueue().getNumberOfNodes());
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/MRUConfigurationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/MRUConfigurationTest.java 2008-08-14
19:16:15 UTC (rev 6561)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/MRUConfigurationTest.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -6,12 +6,11 @@
*/
package org.jboss.cache.eviction;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertTrue;
-
import org.jboss.cache.config.ConfigurationException;
-import org.jboss.cache.config.parsing.element.EvictionElementParser;
import org.jboss.cache.config.parsing.XmlConfigHelper;
+import org.jboss.cache.config.parsing.element.EvictionElementParser;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertTrue;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
@@ -22,15 +21,15 @@
* @author Daniel Huang (dhuang(a)jboss.org)
* @version $Revision$
*/
-@Test(groups = {"functional"})
+@Test(groups = "unit", sequential = false)
public class MRUConfigurationTest
{
- MRUConfiguration config = null;
+ MRUAlgorithmConfig config = null;
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
- config = new MRUConfiguration();
+ config = new MRUAlgorithmConfig();
}
public void testXMLParsing() throws Exception
@@ -41,7 +40,7 @@
"</region>";
Element element = XmlConfigHelper.stringToElement(xml);
- EvictionElementParser.parseEvictionPolicyConfig(element, config);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config, true);
assertEquals(5000, config.getMaxNodes());
}
@@ -53,7 +52,7 @@
"</region>";
Element element = XmlConfigHelper.stringToElement(xml);
- EvictionElementParser.parseEvictionPolicyConfig(element, config);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config, true);
assertEquals(10000, config.getMaxNodes());
}
@@ -66,7 +65,7 @@
boolean caught = false;
try
{
- EvictionElementParser.parseEvictionPolicyConfig(element, config);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config, true);
}
catch (ConfigurationException ce)
{
@@ -80,7 +79,7 @@
element = XmlConfigHelper.stringToElement(xml);
- EvictionElementParser.parseEvictionPolicyConfig(element, config);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config, true);
assertEquals(10000, config.getMaxNodes());
}
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/MRUPolicyTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/MRUPolicyTest.java 2008-08-14
19:16:15 UTC (rev 6561)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/MRUPolicyTest.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -8,20 +8,19 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.EvictionConfig;
import org.jboss.cache.config.EvictionRegionConfig;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.jboss.cache.lock.IsolationLevel;
+import org.jboss.cache.transaction.DummyTransactionManagerLookup;
import org.jboss.cache.util.TestingUtil;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import java.util.ArrayList;
-import java.util.List;
-
/**
* Unit tests for MRUPolicy.
*
@@ -65,27 +64,17 @@
EvictionConfig evConfig = config.getEvictionConfig();
evConfig.setWakeupInterval(3000);
evConfig.setDefaultEventQueueSize(200000);
-
evConfig.setDefaultEvictionPolicyClass("org.jboss.cache.eviction.MRUPolicy");
- List<EvictionRegionConfig> evictionRegionConfigs = new
ArrayList<EvictionRegionConfig>();
- evictionRegionConfigs.add(buildEvictionRegionConfig("_default_", 100));
-
evictionRegionConfigs.add(buildEvictionRegionConfig("/org/jboss/test/data",
6));
- evConfig.setEvictionRegionConfigs(evictionRegionConfigs);
+ // root ERC
+ evConfig.setDefaultEvictionRegionConfig(new EvictionRegionConfig(Fqn.ROOT, new
MRUAlgorithmConfig(100)));
+ // new region ERC
+ evConfig.addEvictionRegionConfig(new
EvictionRegionConfig(Fqn.fromString("/org/jboss/test/data"), new
MRUAlgorithmConfig(6)));
-
config.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
+
+
config.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
config.setIsolationLevel(IsolationLevel.SERIALIZABLE);
- cache = (CacheSPI) new DefaultCacheFactory<Object,
Object>().createCache(config);
+ cache = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object,
Object>().createCache(config);
}
- private EvictionRegionConfig buildEvictionRegionConfig(String regionName, int
maxNodes)
- {
- EvictionRegionConfig erc = new EvictionRegionConfig();
- erc.setRegionName(regionName);
- MRUConfiguration mruConfiguration = new MRUConfiguration();
- mruConfiguration.setMaxNodes(maxNodes);
- erc.setEvictionPolicyConfig(mruConfiguration);
- return erc;
- }
-
public void testEviction() throws Exception
{
cache.put("/org/jboss/test/data/a", "/org/jboss/test/data/a",
"/org/jboss/test/data/a");
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/NullEvictionConfigTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/eviction/NullEvictionConfigTest.java 2008-08-14
19:16:15 UTC (rev 6561)
+++
core/trunk/src/test/java/org/jboss/cache/eviction/NullEvictionConfigTest.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -8,7 +8,6 @@
import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.jboss.cache.config.parsing.element.EvictionElementParser;
-import static org.testng.AssertJUnit.fail;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
@@ -18,7 +17,7 @@
* @author Daniel Huang (dhuang(a)jboss.org)
* @version $Revision: 4444 $
*/
-@Test(groups = {"functional"})
+@Test(groups = "unit", sequential = false)
public class NullEvictionConfigTest
{
/**
@@ -43,14 +42,7 @@
private void testConfigBlock(String xml) throws Exception
{
Element element = XmlConfigHelper.stringToElement(xml);
- NullEvictionPolicyConfig config = new NullEvictionPolicyConfig();
- try
- {
- EvictionElementParser.parseEvictionPolicyConfig(element, config);
- }
- catch (Exception e)
- {
- fail(e.getMessage());
- }
+ NullEvictionAlgorithmConfig config = new NullEvictionAlgorithmConfig();
+ EvictionElementParser.parseEvictionPolicyConfig(element, config, true);
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/NullEvictionPolicyTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/eviction/NullEvictionPolicyTest.java 2008-08-14
19:16:15 UTC (rev 6561)
+++
core/trunk/src/test/java/org/jboss/cache/eviction/NullEvictionPolicyTest.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -9,6 +9,7 @@
import org.jboss.cache.config.EvictionRegionConfig;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.jboss.cache.lock.IsolationLevel;
+import org.jboss.cache.transaction.DummyTransactionManagerLookup;
import org.jboss.cache.util.TestingUtil;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNull;
@@ -16,34 +17,24 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Unit tests for LRU Policy.
- *
- * @author Ben Wang, Feb 11, 2004
- * @author Daniel Huang - dhuang(a)jboss.org
- * @version $Revision: 4880 $
- */
@Test(groups = {"functional"})
public class NullEvictionPolicyTest
{
- CacheSPI<Object, Object> cache_;
+ CacheSPI<Object, Object> cache;
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
- cache_ = null;
+ cache = null;
}
@AfterMethod(alwaysRun = true)
public void tearDown() throws Exception
{
- if (cache_ != null)
+ if (cache != null)
{
- cache_.stop();
- cache_.destroy();
+ cache.stop();
+ cache.destroy();
}
}
@@ -57,18 +48,14 @@
public void testEviction()
{
Configuration config =
UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL,
true);
- EvictionConfig evConfig = config.getEvictionConfig();
- evConfig.setWakeupInterval(1000);
+ EvictionConfig evConfig = new EvictionConfig(new EvictionRegionConfig(Fqn.ROOT, new
NullEvictionAlgorithmConfig()), 1000);
evConfig.setDefaultEventQueueSize(200000);
-
evConfig.setDefaultEvictionPolicyClass("org.jboss.cache.eviction.NullEvictionPolicy");
- List<EvictionRegionConfig> regionConfigs = new
ArrayList<EvictionRegionConfig>();
- regionConfigs.add(buildEvictionRegionConfig("/_default_"));
- regionConfigs.add(buildEvictionRegionConfig("/test"));
-
regionConfigs.add(UnitTestCacheConfigurationFactory.buildLruEvictionRegionConfig("/lru",
10000, 1000));
- evConfig.setEvictionRegionConfigs(regionConfigs);
-
config.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
+ evConfig.addEvictionRegionConfig(new
EvictionRegionConfig(Fqn.fromString("/test"), new
NullEvictionAlgorithmConfig()));
+ evConfig.addEvictionRegionConfig(new
EvictionRegionConfig(Fqn.fromString("/lru"), new LRUAlgorithmConfig(1000,
10000)));
+ config.setEvictionConfig(evConfig);
+
config.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
config.setIsolationLevel(IsolationLevel.SERIALIZABLE);
- cache_ = (CacheSPI) new DefaultCacheFactory<Object,
Object>().createCache(config);
+ cache = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object,
Object>().createCache(config);
String dfltRootStr = "/a/";
String testRootStr = "/test/";
@@ -79,9 +66,9 @@
Fqn dflt = Fqn.fromString(dfltRootStr + i);
Fqn test = Fqn.fromString(testRootStr + i);
Fqn lru = Fqn.fromString(lruRootStr + i);
- cache_.put(dflt, "key", "value");
- cache_.put(test, "key", "value");
- cache_.put(lru, "key", "value");
+ cache.put(dflt, "key", "value");
+ cache.put(test, "key", "value");
+ cache.put(lru, "key", "value");
}
TestingUtil.sleepThread(3500);
for (int i = 0; i < 20; i++)
@@ -90,19 +77,9 @@
Fqn test = Fqn.fromString(testRootStr + i);
Fqn lru = Fqn.fromString(lruRootStr + i);
- assertEquals("value", cache_.get(dflt, "key"));
- assertEquals("value", cache_.get(test, "key"));
- assertNull(cache_.get(lru, "key"));
+ assertEquals("value", cache.get(dflt, "key"));
+ assertEquals("value", cache.get(test, "key"));
+ assertNull(cache.get(lru, "key"));
}
}
-
- private EvictionRegionConfig buildEvictionRegionConfig(String regionName)
- {
- EvictionRegionConfig evRegConfig = new EvictionRegionConfig();
- evRegConfig.setRegionName(regionName);
- NullEvictionPolicyConfig nullEvictionPolicyConfig = new
NullEvictionPolicyConfig();
- evRegConfig.setEvictionPolicyConfig(nullEvictionPolicyConfig);
- return evRegConfig;
- }
-
}
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/OptimisticEvictionTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/eviction/OptimisticEvictionTest.java 2008-08-14
19:16:15 UTC (rev 6561)
+++
core/trunk/src/test/java/org/jboss/cache/eviction/OptimisticEvictionTest.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -3,7 +3,6 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
-import org.jboss.cache.RegionManagerImpl;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.EvictionConfig;
import org.jboss.cache.config.EvictionRegionConfig;
@@ -54,30 +53,9 @@
private EvictionConfig buildEvictionConfig() throws Exception
{
- EvictionConfig result = new
EvictionConfig("org.jboss.cache.eviction.LRUPolicy");
- result.setWakeupInterval(1000);
-
- LRUConfiguration lruConfiguration = new LRUConfiguration();
- lruConfiguration.setMaxNodes(10);
- lruConfiguration.setTimeToLive(0);
- lruConfiguration.setMaxAge(0);
- EvictionRegionConfig erConfig1 = new
EvictionRegionConfig(RegionManagerImpl.DEFAULT_REGION, lruConfiguration);
-
- LRUConfiguration lruConfiguration2 = new LRUConfiguration();
- lruConfiguration2.setMaxNodes(10);
- lruConfiguration2.setTimeToLive(0);
- lruConfiguration2.setMaxAge(0);
- EvictionRegionConfig erConfig2 = new
EvictionRegionConfig(Fqn.fromString("/testingRegion"), lruConfiguration2);
-
- LRUConfiguration lruConfiguration3 = new LRUConfiguration();
- lruConfiguration3.setMaxNodes(10);
- lruConfiguration3.setTimeToLive(1000);
- lruConfiguration3.setMaxAge(1000);
- EvictionRegionConfig erConfig3 = new
EvictionRegionConfig(Fqn.fromString("/timeBased"), lruConfiguration3);
-
- result.getEvictionRegionConfigs().add(erConfig1);
- result.getEvictionRegionConfigs().add(erConfig2);
- result.getEvictionRegionConfigs().add(erConfig3);
+ EvictionConfig result = new EvictionConfig(new EvictionRegionConfig(Fqn.ROOT, new
LRUAlgorithmConfig(0, 0, 10)), 1000);
+ result.addEvictionRegionConfig(new
EvictionRegionConfig(Fqn.fromString("/testingRegion"), new LRUAlgorithmConfig(0,
0, 10)));
+ result.addEvictionRegionConfig(new
EvictionRegionConfig(Fqn.fromString("/timeBased"), new LRUAlgorithmConfig(1000,
1000, 10)));
return result;
}
Modified:
core/trunk/src/test/java/org/jboss/cache/eviction/ProgrammaticLRUPolicyTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/eviction/ProgrammaticLRUPolicyTest.java 2008-08-14
19:16:15 UTC (rev 6561)
+++
core/trunk/src/test/java/org/jboss/cache/eviction/ProgrammaticLRUPolicyTest.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -33,6 +33,7 @@
import org.jboss.cache.config.EvictionRegionConfig;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.jboss.cache.lock.IsolationLevel;
+import org.jboss.cache.transaction.DummyTransactionManagerLookup;
import org.jboss.cache.util.TestingUtil;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
@@ -69,8 +70,9 @@
Configuration conf =
UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL,
true);
CacheFactory<Object, Object> instance = new DefaultCacheFactory<Object,
Object>();
cache = (CacheSPI<Object, Object>) instance.createCache(conf, false);
- conf.getEvictionConfig().setWakeupInterval(5000);
-
cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
+ EvictionConfig erc = new EvictionConfig(new EvictionRegionConfig(Fqn.ROOT, new
LRUAlgorithmConfig(0, 0, 10)), 5000);
+ conf.setEvictionConfig(erc);
+
cache.getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
cache.getConfiguration().setIsolationLevel(IsolationLevel.SERIALIZABLE);
cache.create();
@@ -85,16 +87,15 @@
private void addStringBasedRegion() throws Exception
{
- LRUConfiguration lruConfig = new LRUConfiguration();
- lruConfig.setMaxNodes(1000);
- lruConfig.setTimeToLive(4000);
- EvictionRegionConfig regConfig = new
EvictionRegionConfig(Fqn.fromString("/dummy"), lruConfig);
+ LRUAlgorithmConfig lru = new LRUAlgorithmConfig(4000, 0, 1000);
+ EvictionRegionConfig regConfig = new
EvictionRegionConfig(Fqn.fromString("/dummy"), lru);
RegionManager regionManager = cache.getRegionManager();
EvictionConfig topConfig = cache.getConfiguration().getEvictionConfig();
+ topConfig.addEvictionRegionConfig(regConfig);
regionManager.setEvictionConfig(topConfig);
// Fqn is the region name
- regionManager.getRegion("/programmatic",
true).setEvictionPolicy(regConfig.getEvictionPolicyConfig());
+ regionManager.getRegion("/programmatic",
true).setEvictionRegionConfig(regConfig);
}
public void testStringBasedFqnEviction() throws Exception
@@ -121,9 +122,14 @@
private void addObjectBasedRegion() throws Exception
{
- LRUConfiguration lruConfig = new LRUConfiguration(4000, 1000);
+ LRUAlgorithmConfig lru = new LRUAlgorithmConfig(4000, 1000);
+ EvictionRegionConfig regConfig = new EvictionRegionConfig(Fqn.fromElements(1),
lru);
+
RegionManager regionManager = cache.getRegionManager();
- regionManager.getRegion(Fqn.fromElements(1), true).setEvictionPolicy(lruConfig);
+ EvictionConfig topConfig = cache.getConfiguration().getEvictionConfig();
+ topConfig.addEvictionRegionConfig(regConfig);
+ regionManager.setEvictionConfig(topConfig);
+ regionManager.getRegion(Fqn.fromElements(1),
true).setEvictionRegionConfig(regConfig);
}
public void testObjectBasedFqnEviction1() throws Exception
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/RegionManagerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/RegionManagerTest.java 2008-08-14
19:16:15 UTC (rev 6561)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/RegionManagerTest.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -5,9 +5,8 @@
import org.jboss.cache.RegionManager;
import org.jboss.cache.RegionManagerImpl;
import org.jboss.cache.RegionRegistry;
-import org.jboss.cache.config.EvictionPolicyConfig;
+import org.jboss.cache.config.EvictionRegionConfig;
import static org.testng.AssertJUnit.*;
-import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.util.List;
@@ -28,26 +27,17 @@
Fqn A_BC = Fqn.fromString("/a/bc");
Fqn AOP = Fqn.fromString("/aop");
+ EvictionRegionConfig config = new EvictionRegionConfig(null, new
NullEvictionAlgorithmConfig());
- EvictionPolicy policy;
- EvictionPolicyConfig config;
-
- @BeforeMethod(alwaysRun = true)
- public void setUp() throws Exception
- {
- policy = new DummyEvictionPolicy();
- config = new DummyEvictionConfiguration();
- }
-
public void testCreateRegion()
{
RegionManager regionManager = new RegionManagerImpl();
((RegionManagerImpl) regionManager).injectDependencies(null, null, null, null,
null, new RegionRegistry());
regionManager.setUsingEvictions(true);
- regionManager.getRegion(DEFAULT_REGION, true).setEvictionPolicy(config);
- regionManager.getRegion(A_B_C, true).setEvictionPolicy(config);
- regionManager.getRegion(A_B, true).setEvictionPolicy(config);
- regionManager.getRegion(AOP, true).setEvictionPolicy(config);
+ regionManager.getRegion(DEFAULT_REGION, true).setEvictionRegionConfig(config);
+ regionManager.getRegion(A_B_C, true).setEvictionRegionConfig(config);
+ regionManager.getRegion(A_B, true).setEvictionRegionConfig(config);
+ regionManager.getRegion(AOP, true).setEvictionRegionConfig(config);
List<Region> regions = regionManager.getAllRegions(Region.Type.ANY);
assertEquals("Region size ", 4, regions.size());
@@ -59,9 +49,9 @@
RegionManager regionManager = new RegionManagerImpl();
((RegionManagerImpl) regionManager).injectDependencies(null, null, null, null,
null, new RegionRegistry());
regionManager.setUsingEvictions(true);
- regionManager.getRegion(A_B_C, true).setEvictionPolicy(config);
- regionManager.getRegion(A_B, true).setEvictionPolicy(config);
- regionManager.getRegion(DEFAULT_REGION, true).setEvictionPolicy(config);
+ regionManager.getRegion(A_B_C, true).setEvictionRegionConfig(config);
+ regionManager.getRegion(A_B, true).setEvictionRegionConfig(config);
+ regionManager.getRegion(DEFAULT_REGION, true).setEvictionRegionConfig(config);
List<Region> regions = regionManager.getAllRegions(Region.Type.ANY);
assertEquals("Region size ", 3, regions.size());
@@ -85,8 +75,8 @@
RegionManager regionManager = new RegionManagerImpl();
((RegionManagerImpl) regionManager).injectDependencies(null, null, null, null,
null, new RegionRegistry());
regionManager.setUsingEvictions(true);
- regionManager.getRegion(A_B_C, true).setEvictionPolicy(config);
- regionManager.getRegion(A_B, true).setEvictionPolicy(config);
+ regionManager.getRegion(A_B_C, true).setEvictionRegionConfig(config);
+ regionManager.getRegion(A_B, true).setEvictionRegionConfig(config);
regionManager.getRegion(Fqn.fromString("/a"), Region.Type.EVICTION,
false);
}
@@ -96,9 +86,9 @@
RegionManager regionManager = new RegionManagerImpl();
((RegionManagerImpl) regionManager).injectDependencies(null, null, null, null,
null, new RegionRegistry());
regionManager.setUsingEvictions(true);
- regionManager.getRegion(DEFAULT_REGION, true).setEvictionPolicy(config);
- regionManager.getRegion(A_BC, true).setEvictionPolicy(config);
- regionManager.getRegion(A_B, true).setEvictionPolicy(config);
+ regionManager.getRegion(DEFAULT_REGION, true).setEvictionRegionConfig(config);
+ regionManager.getRegion(A_BC, true).setEvictionRegionConfig(config);
+ regionManager.getRegion(A_B, true).setEvictionRegionConfig(config);
Region region = regionManager.getRegion(A_BC, true);
assertNotSame("Region ", DEFAULT_REGION, region.getFqn());
@@ -112,10 +102,10 @@
RegionManager rm = new RegionManagerImpl();
((RegionManagerImpl) rm).injectDependencies(null, null, null, null, null, new
RegionRegistry());
rm.setUsingEvictions(true);
- rm.getRegion(DEFAULT_REGION, true).setEvictionPolicy(config);
- rm.getRegion(A_B_C_D_E, true).setEvictionPolicy(config);
- rm.getRegion(A_B_C_D, true).setEvictionPolicy(config);
- rm.getRegion(A_B_C, true).setEvictionPolicy(config);
+ rm.getRegion(DEFAULT_REGION, true).setEvictionRegionConfig(config);
+ rm.getRegion(A_B_C_D_E, true).setEvictionRegionConfig(config);
+ rm.getRegion(A_B_C_D, true).setEvictionRegionConfig(config);
+ rm.getRegion(A_B_C, true).setEvictionRegionConfig(config);
Region region = rm.getRegion("/a/b/c/d/e/f", false);
Region region2 = rm.getRegion("/e/f/g", false);
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/RegionTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/RegionTest.java 2008-08-14 19:16:15
UTC (rev 6561)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/RegionTest.java 2008-08-15 10:59:40
UTC (rev 6562)
@@ -2,15 +2,19 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
+import org.jboss.cache.RegionImpl;
import org.jboss.cache.RegionManager;
import org.jboss.cache.RegionManagerImpl;
import org.jboss.cache.RegionRegistry;
import org.jboss.cache.config.EvictionConfig;
+import org.jboss.cache.config.EvictionRegionConfig;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNull;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import java.util.concurrent.TimeUnit;
+
/**
* @author Ben Wang, Feb 11, 2004
* @author Daniel Huang (dhuang(a)jboss.org)
@@ -27,48 +31,49 @@
algorithm = new LRUAlgorithm();
regionManager = new RegionManagerImpl();
((RegionManagerImpl) regionManager).injectDependencies(null, null, null, null,
null, new RegionRegistry());
- regionManager.getRegion("/a/b", true).setEvictionPolicy(new
DummyEvictionConfiguration());
+ Region r = regionManager.getRegion("/a/b", true);//.setEvictionPolicy(new
DummyEvictionConfiguration());
+ r.setEvictionRegionConfig(new EvictionRegionConfig(r.getFqn(), new
NullEvictionAlgorithmConfig()));
}
- public void testAddedQueue()
+ public void testAddedQueue() throws InterruptedException
{
Fqn fqn1 = Fqn.fromString("/a/b/c");
Fqn fqn2 = Fqn.fromString("/a/b/d");
Fqn fqn3 = Fqn.fromString("/a/b/e");
Region region = regionManager.getRegion("/a/b", true);
- region.putNodeEvent(new EvictedEventNode(fqn1, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn3, NodeEventType.ADD_NODE_EVENT));
+ region.registerEvictionEvent(fqn1, EvictionEvent.Type.ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn2, EvictionEvent.Type.ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn3, EvictionEvent.Type.ADD_NODE_EVENT);
- assertEquals("AddedNode queue size ", 3, region.nodeEventQueueSize());
- EvictedEventNode node = region.takeLastEventNode();
+ assertEquals("AddedNode queue size ", 3, getQueueSize((RegionImpl)
region));
+ EvictionEvent node = takeLastEvent((RegionImpl) region);
Fqn fqn = node.getFqn();
assertEquals("DataNode retrieved should be FILO ", fqn, fqn1);
- assertEquals("AddedNode queue size ", 2, region.nodeEventQueueSize());
- fqn = region.takeLastEventNode().getFqn();
- fqn = region.takeLastEventNode().getFqn();
- node = region.takeLastEventNode();
+ assertEquals("AddedNode queue size ", 2, getQueueSize((RegionImpl)
region));
+ fqn = takeLastEvent((RegionImpl) region).getFqn();
+ fqn = takeLastEvent((RegionImpl) region).getFqn();
+ node = takeLastEvent((RegionImpl) region);
assertNull("DataNode should be null", node);
}
- public void testEventQueue()
+ public void testEventQueue() throws InterruptedException
{
Fqn fqn1 = Fqn.fromString("/a/b/c");
Fqn fqn2 = Fqn.fromString("/a/b/d");
Fqn fqn3 = Fqn.fromString("/a/b/e");
Region region = regionManager.getRegion("/a/b", true);
- region.putNodeEvent(new EvictedEventNode(fqn1, NodeEventType.REMOVE_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
- region.putNodeEvent(new EvictedEventNode(fqn3, NodeEventType.VISIT_NODE_EVENT));
+ region.registerEvictionEvent(fqn1, EvictionEvent.Type.REMOVE_NODE_EVENT);
+ region.registerEvictionEvent(fqn2, EvictionEvent.Type.ADD_NODE_EVENT);
+ region.registerEvictionEvent(fqn3, EvictionEvent.Type.VISIT_NODE_EVENT);
- assertEquals("RemovedNode queue size ", 3, region.nodeEventQueueSize());
- NodeEventType event = region.takeLastEventNode().getEventType();
- assertEquals("DataNode retrieved should be: ",
NodeEventType.REMOVE_NODE_EVENT, event);
- region.takeLastEventNode();
- region.takeLastEventNode();
- EvictedEventNode node = region.takeLastEventNode();
+ assertEquals("RemovedNode queue size ", 3, getQueueSize((RegionImpl)
region));
+ EvictionEvent.Type event = takeLastEvent((RegionImpl) region).getEventType();
+ assertEquals("DataNode retrieved should be: ",
EvictionEvent.Type.REMOVE_NODE_EVENT, event);
+ takeLastEvent((RegionImpl) region);
+ takeLastEvent((RegionImpl) region);
+ EvictionEvent node = takeLastEvent((RegionImpl) region);
assertNull("DataNode should be null", node);
}
@@ -80,7 +85,7 @@
// This should succeed, alhtough it will produce warning over the threshold.
for (int i = 0; i < EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT - 1; i++)
{
- region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
+ region.registerEvictionEvent(fqn2, EvictionEvent.Type.ADD_NODE_EVENT);
}
}
@@ -90,4 +95,14 @@
System.out.println("-- " + msg);
}
+ EvictionEvent takeLastEvent(RegionImpl r) throws InterruptedException
+ {
+ return r.getEvictionEventQueue().poll(0, TimeUnit.MILLISECONDS);
+ }
+
+ int getQueueSize(RegionImpl r)
+ {
+ return r.getEvictionEventQueue().size();
+ }
+
}
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/ReplicatedLRUPolicyTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/eviction/ReplicatedLRUPolicyTest.java 2008-08-14
19:16:15 UTC (rev 6561)
+++
core/trunk/src/test/java/org/jboss/cache/eviction/ReplicatedLRUPolicyTest.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -23,7 +23,7 @@
{
CacheSPI<Object, Object> cache1, cache2, cache3;
long wakeupIntervalMillis = 0;
- EvictionListener listener_ = new EvictionListener();
+ EvictionListener listener = new EvictionListener();
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
@@ -32,8 +32,8 @@
cache1.getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
cache1.getConfiguration().setUseRegionBasedMarshalling(true);
cache1.start();
- cache1.getNotifier().addCacheListener(listener_);
- listener_.resetCounter();
+ cache1.getNotifier().addCacheListener(listener);
+ listener.resetCounter();
cache3 = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object,
Object>().createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC),
false);
cache3.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
@@ -66,10 +66,10 @@
TestingUtil.sleepThread(30000);
Object node = cache1.peek(Fqn.fromString(str), false);
assertNull("DataNode should be evicted already ", node);
- assertEquals("Eviction counter ", 1, listener_.getCounter());
+ assertEquals("Eviction counter ", 1, listener.getCounter());
String val = (String) cache3.get(str, str);
assertNotNull("DataNode should not be evicted here ", val);
- assertEquals("Eviction counter ", 1, listener_.getCounter());
+ assertEquals("Eviction counter ", 1, listener.getCounter());
}
public void testEviction() throws Exception
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/minttl/FIFOMinTTLTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/eviction/minttl/FIFOMinTTLTest.java 2008-08-14
19:16:15 UTC (rev 6561)
+++
core/trunk/src/test/java/org/jboss/cache/eviction/minttl/FIFOMinTTLTest.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -1,9 +1,9 @@
package org.jboss.cache.eviction.minttl;
import org.jboss.cache.Fqn;
+import org.jboss.cache.eviction.EvictionAlgorithmConfigBase;
+import org.jboss.cache.eviction.FIFOAlgorithmConfig;
import org.jboss.cache.util.TestingUtil;
-import org.jboss.cache.eviction.EvictionPolicyConfigBase;
-import org.jboss.cache.eviction.FIFOConfiguration;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
@@ -19,10 +19,10 @@
private boolean busyThreadRunning = true;
@Override
- protected EvictionPolicyConfigBase getEvictionPolicyConfig()
+ protected EvictionAlgorithmConfigBase getEvictionPolicyConfig()
{
startBusyThread();
- FIFOConfiguration cfg = new FIFOConfiguration();
+ FIFOAlgorithmConfig cfg = new FIFOAlgorithmConfig();
cfg.setMaxNodes(1);
return cfg;
}
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/minttl/LFUMinTTLTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/minttl/LFUMinTTLTest.java 2008-08-14
19:16:15 UTC (rev 6561)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/minttl/LFUMinTTLTest.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -1,12 +1,10 @@
package org.jboss.cache.eviction.minttl;
+import org.jboss.cache.eviction.EvictionAlgorithmConfigBase;
+import org.jboss.cache.eviction.LFUAlgorithmConfig;
import org.testng.annotations.Test;
-import org.jboss.cache.eviction.EvictionPolicyConfigBase;
-import org.jboss.cache.eviction.LRUConfiguration;
-import org.jboss.cache.eviction.LFUConfiguration;
/**
- *
* @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
* @since 2.1.0
*/
@@ -14,9 +12,8 @@
public class LFUMinTTLTest extends MinTTLTestBase
{
@Override
- protected EvictionPolicyConfigBase getEvictionPolicyConfig()
+ protected EvictionAlgorithmConfigBase getEvictionPolicyConfig()
{
- LFUConfiguration cfg = new LFUConfiguration();
- return cfg;
+ return new LFUAlgorithmConfig();
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/minttl/LRUMinTTLTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/minttl/LRUMinTTLTest.java 2008-08-14
19:16:15 UTC (rev 6561)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/minttl/LRUMinTTLTest.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -1,11 +1,10 @@
package org.jboss.cache.eviction.minttl;
+import org.jboss.cache.eviction.EvictionAlgorithmConfigBase;
+import org.jboss.cache.eviction.LRUAlgorithmConfig;
import org.testng.annotations.Test;
-import org.jboss.cache.eviction.EvictionPolicyConfigBase;
-import org.jboss.cache.eviction.LRUConfiguration;
/**
- *
* @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
* @since 2.1.0
*/
@@ -13,9 +12,9 @@
public class LRUMinTTLTest extends MinTTLTestBase
{
@Override
- protected EvictionPolicyConfigBase getEvictionPolicyConfig()
+ protected EvictionAlgorithmConfigBase getEvictionPolicyConfig()
{
- LRUConfiguration cfg = new LRUConfiguration();
+ LRUAlgorithmConfig cfg = new LRUAlgorithmConfig();
cfg.setTimeToLive(1000);
return cfg;
}
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/minttl/MRUMinTTLTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/minttl/MRUMinTTLTest.java 2008-08-14
19:16:15 UTC (rev 6561)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/minttl/MRUMinTTLTest.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -2,9 +2,9 @@
import org.jboss.cache.CacheStatus;
import org.jboss.cache.Fqn;
+import org.jboss.cache.eviction.EvictionAlgorithmConfigBase;
+import org.jboss.cache.eviction.MRUAlgorithmConfig;
import org.jboss.cache.util.TestingUtil;
-import org.jboss.cache.eviction.EvictionPolicyConfigBase;
-import org.jboss.cache.eviction.MRUConfiguration;
import org.testng.annotations.Test;
/**
@@ -17,9 +17,9 @@
private Fqn fqn2 = Fqn.fromRelativeElements(region, "b");
@Override
- protected EvictionPolicyConfigBase getEvictionPolicyConfig()
+ protected EvictionAlgorithmConfigBase getEvictionPolicyConfig()
{
- MRUConfiguration cfg = new MRUConfiguration();
+ MRUAlgorithmConfig cfg = new MRUAlgorithmConfig();
cfg.setMaxNodes(1);
startBusyThread();
return cfg;
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/minttl/MinTTLTestBase.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/eviction/minttl/MinTTLTestBase.java 2008-08-14
19:16:15 UTC (rev 6561)
+++
core/trunk/src/test/java/org/jboss/cache/eviction/minttl/MinTTLTestBase.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -5,14 +5,12 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.config.EvictionConfig;
import org.jboss.cache.config.EvictionRegionConfig;
-import org.jboss.cache.eviction.EvictionPolicyConfigBase;
+import org.jboss.cache.eviction.EvictionAlgorithmConfigBase;
import org.jboss.cache.util.TestingUtil;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import java.util.ArrayList;
-import java.util.List;
import java.util.concurrent.CountDownLatch;
/**
@@ -32,7 +30,7 @@
// allows the test methods to notify any support threads in subclasses that data is in
the cache and the test is about to begin
protected CountDownLatch cacheInitialisedLatch;
- protected abstract EvictionPolicyConfigBase getEvictionPolicyConfig();
+ protected abstract EvictionAlgorithmConfigBase getEvictionPolicyConfig();
@BeforeMethod
public void setUp()
@@ -40,22 +38,17 @@
cacheInitialisedLatch = new CountDownLatch(1);
// the LRU policy cfg
- EvictionPolicyConfigBase cfg = getEvictionPolicyConfig();
+ EvictionAlgorithmConfigBase cfg = getEvictionPolicyConfig();
// the region configuration
EvictionRegionConfig regionCfg = new EvictionRegionConfig();
regionCfg.setRegionFqn(region);
regionCfg.setRegionName(region.toString());
- regionCfg.setEvictionPolicyConfig(cfg);
-
- // set regions in a list
- List<EvictionRegionConfig> evictionRegionConfigs = new
ArrayList<EvictionRegionConfig>();
- evictionRegionConfigs.add(regionCfg);
-
+ regionCfg.setEvictionAlgorithmConfig(cfg);
// cache-wide
EvictionConfig ec = new EvictionConfig();
ec.setWakeupInterval(1000);
- ec.setEvictionRegionConfigs(evictionRegionConfigs);
+ ec.addEvictionRegionConfig(regionCfg);
cache = new DefaultCacheFactory<Object, Object>().createCache(false);
cache.getConfiguration().setEvictionConfig(ec);
@@ -83,7 +76,7 @@
public void testWithMinimumTTL()
{
- ((EvictionPolicyConfigBase)
cache.getConfiguration().getEvictionConfig().getEvictionRegionConfigs().get(0).getEvictionPolicyConfig()).setMinTimeToLive(3000);
+ ((EvictionAlgorithmConfigBase)
cache.getConfiguration().getEvictionConfig().getEvictionRegionConfigs().get(0).getEvictionAlgorithmConfig()).setMinTimeToLive(3000);
cache.start();
cache.put(fqn, "k", "v");
Modified:
core/trunk/src/test/java/org/jboss/cache/factories/UnitTestCacheConfigurationFactory.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/factories/UnitTestCacheConfigurationFactory.java 2008-08-14
19:16:15 UTC (rev 6561)
+++
core/trunk/src/test/java/org/jboss/cache/factories/UnitTestCacheConfigurationFactory.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -11,12 +11,10 @@
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.config.ConfigurationException;
-import org.jboss.cache.config.EvictionRegionConfig;
import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.jboss.cache.config.parsing.XmlConfigurationParser;
-import org.jboss.cache.util.FileLookup;
-import org.jboss.cache.eviction.LRUConfiguration;
import org.jboss.cache.transaction.TransactionSetup;
+import org.jboss.cache.util.FileLookup;
import org.jgroups.conf.XmlConfigurator;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
@@ -159,19 +157,6 @@
return jgroupsConfigString.substring(0, jgroupsConfigString.indexOf(":"))
+ delay + jgroupsConfigString.substring(jgroupsConfigString.indexOf(":"));
}
-
- public static EvictionRegionConfig buildLruEvictionRegionConfig(String regionNaame,
int maxNodes, long timeToLive)
- {
- EvictionRegionConfig erc = new EvictionRegionConfig();
- erc.setRegionName(regionNaame);
- LRUConfiguration lruConfig = new LRUConfiguration();
- lruConfig.setEvictionPolicyClass("org.jboss.cache.eviction.LRUPolicy");
- if (maxNodes >= 0) lruConfig.setMaxNodes(maxNodes);
- if (timeToLive >= 0) lruConfig.setTimeToLive(timeToLive);
- erc.setEvictionPolicyConfig(lruConfig);
- return erc;
- }
-
private static class UnitTestXmlConfigurationParser extends XmlConfigurationParser
{
Deleted:
core/trunk/src/test/java/org/jboss/cache/interceptors/EvictionInterceptorTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/interceptors/EvictionInterceptorTest.java 2008-08-14
19:16:15 UTC (rev 6561)
+++
core/trunk/src/test/java/org/jboss/cache/interceptors/EvictionInterceptorTest.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -1,538 +0,0 @@
-/*
- * JBoss, the OpenSource J2EE webOS
- *
- * Distributable under LGPL license.
- * See terms of license at
gnu.org.
- */
-package org.jboss.cache.interceptors;
-
-import org.jboss.cache.CacheSPI;
-import org.jboss.cache.DefaultCacheFactory;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.Node;
-import org.jboss.cache.NodeSPI;
-import org.jboss.cache.Region;
-import org.jboss.cache.RegionManager;
-import org.jboss.cache.commands.CommandsFactory;
-import org.jboss.cache.commands.VisitableCommand;
-import org.jboss.cache.commands.read.GetKeyValueCommand;
-import org.jboss.cache.commands.read.GetNodeCommand;
-import org.jboss.cache.commands.write.ClearDataCommand;
-import org.jboss.cache.commands.write.PutDataMapCommand;
-import org.jboss.cache.commands.write.PutKeyValueCommand;
-import org.jboss.cache.commands.write.RemoveKeyCommand;
-import org.jboss.cache.commands.write.RemoveNodeCommand;
-import org.jboss.cache.config.EvictionConfig;
-import org.jboss.cache.config.EvictionRegionConfig;
-import org.jboss.cache.eviction.DummyEvictionConfiguration;
-import org.jboss.cache.eviction.EvictedEventNode;
-import org.jboss.cache.eviction.NodeEventType;
-import org.jboss.cache.lock.IsolationLevel;
-import org.jboss.cache.util.TestingUtil;
-import static org.testng.AssertJUnit.*;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-/**
- * @author Daniel Huang (dhuang(a)jboss.org)
- * @version $Revision: $
- */
-@Test(groups = "functional")
-public class EvictionInterceptorTest
-{
- private static final String fqn1 = "/a/b/c";
- private static final String fqn2 = "/a/b";
- private static final String fqn3 = "/a/b/d";
- private static final String fqn4 = "/d/e/f";
-
- private CacheSPI<Object, Object> cache;
- private InterceptorChain invoker;
- private RegionManager regionManager;
- private CommandsFactory commandsFactory;
-
- @BeforeMethod(alwaysRun = true)
- public void setUp() throws Exception
- {
- cache = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object,
Object>().createCache(false);
-
cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
- cache.getConfiguration().setIsolationLevel(IsolationLevel.SERIALIZABLE);
- cache.getConfiguration().setCacheMode("LOCAL");
- EvictionConfig ec = new EvictionConfig();
-
- List<EvictionRegionConfig> ercs = new
LinkedList<EvictionRegionConfig>();
- ercs.add(new EvictionRegionConfig(Fqn.ROOT, new DummyEvictionConfiguration()));
- ercs.add(new EvictionRegionConfig(Fqn.fromString("/a/b/c"), new
DummyEvictionConfiguration()));
- ercs.add(new EvictionRegionConfig(Fqn.fromString("/a/b/c/d"), new
DummyEvictionConfiguration()));
- ercs.add(new EvictionRegionConfig(Fqn.fromString("/a/b"), new
DummyEvictionConfiguration()));
- ercs.add(new EvictionRegionConfig(Fqn.fromString("/d/e/f"), new
DummyEvictionConfiguration()));
- ercs.add(new EvictionRegionConfig(Fqn.fromString("/d/e/g"), new
DummyEvictionConfiguration()));
- ercs.add(new EvictionRegionConfig(Fqn.fromString("/d/e"), new
DummyEvictionConfiguration()));
-
- ec.setEvictionRegionConfigs(ercs);
- cache.getConfiguration().setEvictionConfig(ec);
- cache.start();
-
- invoker =
TestingUtil.extractComponentRegistry(cache).getComponent(InterceptorChain.class);
- commandsFactory = TestingUtil.extractCommandsFactory(cache);
- regionManager = cache.getRegionManager();
- }
-
- @AfterMethod(alwaysRun = true)
- public void tearDown() throws Exception
- {
- TestingUtil.killCaches(cache);
- }
-
- private NodeSPI<Object, Object> cast(Node<Object, Object> node)
- {
- return (NodeSPI<Object, Object>) node;
- }
-
- public void testVisitNode() throws Throwable
- {
- // make sure node that doesn't exist does not result in a node visit event.
-
- VisitableCommand command =
commandsFactory.buildGetNodeCommand(Fqn.fromString(fqn1));
- invoker.invoke(command);
- Region regionABC = regionManager.getRegion(fqn1, false);
- assertNull(regionABC.takeLastEventNode());
-
- putQuietly(fqn1, "key", "value");
- NodeSPI<Object, Object> node = cast(cache.peek(Fqn.fromString(fqn1), false,
false));
- assertNotNull(node);
- assertEquals("value", node.getDirect("key"));
-
- putQuietly(fqn3, "key", "value");
- node = cast(cache.peek(Fqn.fromString(fqn3), false, false));
- assertNotNull(node);
- assertEquals("value", node.getDirect("key"));
-
-
- command = commandsFactory.buildGetNodeCommand(Fqn.fromString(fqn1));
- invoker.invoke(command);
-
- regionABC = regionManager.getRegion(fqn1, false);
- EvictedEventNode event = regionABC.takeLastEventNode();
- assertEquals(NodeEventType.VISIT_NODE_EVENT, event.getEventType());
- assertEquals(fqn1, event.getFqn().toString());
- assertNull(regionABC.takeLastEventNode());
-
- command = commandsFactory.buildGetNodeCommand(Fqn.fromString(fqn2));
- invoker.invoke(command);
-
- Region regionAB = regionManager.getRegion(fqn2, false);
- event = regionAB.takeLastEventNode();
- assertEquals(NodeEventType.VISIT_NODE_EVENT, event.getEventType());
- assertEquals(fqn2, event.getFqn().toString());
- assertNull(regionAB.takeLastEventNode());
-
- command = commandsFactory.buildGetNodeCommand(Fqn.fromString(fqn3));
- invoker.invoke(command);
- Region regionABD = regionManager.getRegion(fqn3, false);
- event = regionABD.takeLastEventNode();
- assertEquals(NodeEventType.VISIT_NODE_EVENT, event.getEventType());
- assertEquals(fqn3, event.getFqn().toString());
- assertNull(regionABD.takeLastEventNode());
-
- for (int i = 0; i < 10; i++)
- {
- command = commandsFactory.buildGetNodeCommand(Fqn.fromString(fqn3));
- invoker.invoke(command);
- }
-
- for (int i = 0; i < 10; i++)
- {
- Region region = regionManager.getRegion(fqn3, false);
- event = region.takeLastEventNode();
- assertEquals(NodeEventType.VISIT_NODE_EVENT, event.getEventType());
- assertEquals(fqn3, event.getFqn().toString());
- }
-
- assertNull(regionManager.getRegion(fqn3, false).takeLastEventNode());
-
- // check null handling.
- command = commandsFactory.buildGetDataMapCommand(null);
- invoker.invoke(command);
-
- }
-
- /**
- * Helper to quietly add something into the cache without generating eviction events
- *
- * @param fqn fqn to add
- * @param key key
- * @param value value
- */
- private void putQuietly(String fqn, Object key, Object value)
- {
- putQuietly(Fqn.fromString(fqn), key, value);
- }
-
- /**
- * Helper to quietly add something into the cache without generating eviction events
- *
- * @param fqn fqn to add
- * @param key key
- * @param value value
- */
- private void putQuietly(Fqn fqn, Object key, Object value)
- {
- NodeSPI root = cache.getRoot();
- NodeSPI child = root;
- for (int i = 0; i < fqn.size(); i++)
- {
- child = child.addChildDirect(Fqn.fromElements(fqn.get(i)));
- }
-
- assert child.getFqn().equals(fqn);
-
- child.putDirect(key, value);
- }
-
- public void testVisitElement() throws Throwable
- {
- // make sure a get/visit on an empty node and empty element results in no cache
events being added to event queue
- // aka MarshRegion.
- Fqn fqn = Fqn.fromString(fqn4);
- Object key = "key";
- GetKeyValueCommand command = commandsFactory.buildGetKeyValueCommand(fqn, key,
false);
- invoker.invoke(command);
- Region region = regionManager.getRegion(fqn.toString(), false);
- assertNull(region.takeLastEventNode());
-
- // add the node but try to get on a null element should result in no cache events
being added to Region.
- putQuietly(fqn, "wrongkey", "");
-
- command = commandsFactory.buildGetKeyValueCommand(fqn, key, false);
- invoker.invoke(command);
- assertNull(region.takeLastEventNode());
-
- // now make sure if we try to get on the node/key we just created in cache, that
this DOES add a EvictedEventNode to
- // the MarshRegion.
- command = commandsFactory.buildGetKeyValueCommand(fqn, "wrongkey",
false);
- invoker.invoke(command);
- EvictedEventNode event = region.takeLastEventNode();
- assertEquals(fqn, event.getFqn());
- assertEquals(NodeEventType.VISIT_NODE_EVENT, event.getEventType());
-
- assertNull(region.takeLastEventNode());
-
- putQuietly(fqn4, key, "value");
-
- // test on element granularity configured node.
- fqn = Fqn.fromString(fqn4);
- command = commandsFactory.buildGetKeyValueCommand(fqn, key, false);
- invoker.invoke(command);
-
- region = regionManager.getRegion(fqn.toString(), false);
- event = region.takeLastEventNode();
-
- assertEquals(NodeEventType.VISIT_NODE_EVENT, event.getEventType());
- assertEquals(fqn, event.getFqn());
-
- assertNull(region.takeLastEventNode());
-
- fqn = Fqn.fromString("/d/e/g");
- for (int i = 0; i < 100; i++)
- {
- key = i;
-
- putQuietly("/d/e/g", key, "");
-
- command = commandsFactory.buildGetKeyValueCommand(fqn, key, false);
- invoker.invoke(command);
- }
-
- region = regionManager.getRegion(fqn.toString(), false);
-
- for (int i = 0; i < 100; i++)
- {
- event = region.takeLastEventNode();
- assertEquals(fqn, event.getFqn());
- assertEquals(NodeEventType.VISIT_NODE_EVENT, event.getEventType());
- }
-
- putQuietly("/a/b/c", key, "");
- fqn = Fqn.fromString("/a/b/c");
-
- command = commandsFactory.buildGetKeyValueCommand(fqn, key, false);
- invoker.invoke(command);
-
- region = regionManager.getRegion(fqn.toString(), false);
- event = region.takeLastEventNode();
-
- assertNull(region.takeLastEventNode());
- assertEquals(NodeEventType.VISIT_NODE_EVENT, event.getEventType());
- assertEquals(fqn, event.getFqn());
-
- for (int i = 0; i < 100; i++)
- {
- key = i;
-
- putQuietly(fqn, key, "");
-
- command = commandsFactory.buildGetKeyValueCommand(fqn, key, false);
- invoker.invoke(command);
- }
-
- for (int i = 0; i < 100; i++)
- {
- event = region.takeLastEventNode();
- assertEquals(NodeEventType.VISIT_NODE_EVENT, event.getEventType());
- assertEquals(fqn, event.getFqn());
- }
-
- assertNull(region.takeLastEventNode());
- }
-
- public void testCreateNode() throws Throwable
- {
- Map<Object, Object> data = new HashMap<Object, Object>();
- for (int i = 0; i < 100; i++)
- {
- data.put(i, i);
- }
-
- // this region is node granularity
- Fqn fqn = Fqn.fromString("/a/b/c");
-
- PutDataMapCommand putDataMapCommand = commandsFactory.buildPutDataMapCommand(null,
fqn, data);
- invoker.invoke(putDataMapCommand);
-
- Region region = regionManager.getRegion(fqn.toString(), false);
- EvictedEventNode event = region.takeLastEventNode();
-
- assertEquals(NodeEventType.ADD_NODE_EVENT, event.getEventType());
- assertEquals(fqn, event.getFqn());
- assertEquals(100, event.getElementDifference());
-
- NodeSPI<Object, Object> node = cast(cache.peek(fqn, false, false));
- assertNotNull(node);
-
- for (int i = 0; i < 100; i++)
- {
- assertTrue(node.getDataDirect().containsKey(i));
- assertEquals(i, node.getDirect(i));
- }
-
- for (int i = 0; i < 100; i++)
- {
- PutKeyValueCommand pkvCommand = commandsFactory.buildPutKeyValueCommand(null,
fqn, i, "value");
- invoker.invoke(pkvCommand);
-
- assertEquals("value", cache.peek(fqn, false, false).getDirect(i));
- }
-
- for (int i = 0; i < 100; i++)
- {
- event = region.takeLastEventNode();
- assertNotNull(event);
- assertEquals(fqn, event.getFqn());
- assertEquals(NodeEventType.ADD_ELEMENT_EVENT, event.getEventType());
- }
-
- assertNull(region.takeLastEventNode());
-
- fqn = Fqn.fromString("/a/b");
- PutDataMapCommand putCommand = commandsFactory.buildPutDataMapCommand(null, fqn,
data);
- invoker.invoke(putCommand);
- event = regionManager.getRegion(fqn.toString(), false).takeLastEventNode();
- assertEquals(NodeEventType.ADD_NODE_EVENT, event.getEventType());
- assertEquals(fqn, event.getFqn());
- assertEquals(100, event.getElementDifference());
- assertNull(regionManager.getRegion(fqn.toString(), false).takeLastEventNode());
- node = cast(cache.peek(fqn, false, false));
- assertEquals(100, node.getDataDirect().size());
-
- assertNotNull(node);
-
- for (int i = 0; i < 100; i++)
- {
- assertTrue(node.getDataDirect().containsKey(i));
- assertEquals(i, node.getDirect(i));
- }
-
- PutDataMapCommand putDataMap = commandsFactory.buildPutDataMapCommand(null, fqn,
data);
- invoker.invoke(putDataMap);
- event = regionManager.getRegion(fqn.toString(), false).takeLastEventNode();
- assertEquals(NodeEventType.ADD_NODE_EVENT, event.getEventType());
- assertEquals(fqn, event.getFqn());
- assertEquals(100, event.getElementDifference());
- assertNull(regionManager.getRegion(fqn.toString(), false).takeLastEventNode());
-
-
- node = cast(cache.getNode(fqn));
- assertEquals(100, node.getData().size());
- assertNotNull(node);
-
- for (int i = 0; i < 100; i++)
- {
- assertTrue(node.getDataDirect().containsKey(i));
- assertEquals(i, node.getDirect(i));
- }
-
- }
-
- public void testCreateElement() throws Throwable
- {
- Fqn fqn = Fqn.fromString("/d/e/f");
- Region region = regionManager.getRegion(fqn.toString(), false);
- Object key = "key";
- Object value = "value";
-
- PutKeyValueCommand command = commandsFactory.buildPutKeyValueCommand(null, (Fqn)
fqn, key, value);
- invoker.invoke(command);
- assertEquals("value", cache.peek(fqn, false, false).getDirect(key));
- EvictedEventNode event = region.takeLastEventNode();
- assertEquals(NodeEventType.ADD_ELEMENT_EVENT, event.getEventType());
- assertEquals(1, event.getElementDifference());
- assertEquals(fqn, event.getFqn());
- assertEquals("value", cache.peek(fqn, false, false).getDirect(key));
- assertNull(region.takeLastEventNode());
-
- command = commandsFactory.buildPutKeyValueCommand(null, (Fqn) fqn, key, value);
- invoker.invoke(command);
- assertEquals("value", cache.peek(fqn, false, false).getDirect(key));
- event = region.takeLastEventNode();
- assertEquals(NodeEventType.ADD_ELEMENT_EVENT, event.getEventType());
- assertEquals(1, event.getElementDifference());
- assertEquals(fqn, event.getFqn());
- assertEquals("value", cache.peek(fqn, false, false).getDirect(key));
- assertNull(region.takeLastEventNode());
-
- }
-
- public void testRemoveNode() throws Throwable
- {
- Fqn fqn = Fqn.fromString("/a/b/c");
- putQuietly(fqn, "a", "b");
- putQuietly(fqn, "b", "c");
-
- ClearDataCommand clearDataCommand = commandsFactory.buildClearDataCommand(null,
fqn);
- invoker.invoke(clearDataCommand);
-
- assertEquals(0, cache.peek(fqn, false, false).getDataDirect().size());
- Region region = regionManager.getRegion(fqn.toString(), false);
- EvictedEventNode event = region.takeLastEventNode();
- assertEquals(NodeEventType.REMOVE_NODE_EVENT, event.getEventType());
- assertEquals(fqn, event.getFqn());
- assertNull(region.takeLastEventNode());
-
- RemoveNodeCommand removeNodeCommand = commandsFactory.buildRemoveNodeCommand(null,
fqn);
- invoker.invoke(removeNodeCommand);
-
- assertNull(cache.peek(fqn, false, false));
- event = region.takeLastEventNode();
- assertEquals(NodeEventType.REMOVE_NODE_EVENT, event.getEventType());
- assertEquals(fqn, event.getFqn());
- assertNull(region.takeLastEventNode());
- }
-
- public void testRemoveElement() throws Throwable
- {
- Fqn fqn = Fqn.fromString("/a/b/c");
- putQuietly(fqn, "a", "b");
- putQuietly(fqn, "b", "c");
-
- RemoveKeyCommand removeKeyCommand = commandsFactory.buildRemoveKeyCommand(null,
fqn, "a");
- invoker.invoke(removeKeyCommand);
-
- assertNull(cache.get(fqn, "a"));
- Region region = regionManager.getRegion(fqn.toString(), false);
- EvictedEventNode event = region.takeLastEventNode();
- assertEquals(NodeEventType.REMOVE_ELEMENT_EVENT, event.getEventType());
- assertEquals(fqn, event.getFqn());
- assertEquals(1, event.getElementDifference());
- assertNull(region.takeLastEventNode());
-
- RemoveKeyCommand removeKeyCommand2 = commandsFactory.buildRemoveKeyCommand(null,
fqn, "b");
- invoker.invoke(removeKeyCommand2);
-
- assertNull(cache.get(fqn, "b"));
- event = region.takeLastEventNode();
- assertEquals(NodeEventType.REMOVE_ELEMENT_EVENT, event.getEventType());
- assertEquals(fqn, event.getFqn());
- assertEquals(1, event.getElementDifference());
- assertNull(region.takeLastEventNode());
-
- RemoveKeyCommand removeKeyCommand3 = commandsFactory.buildRemoveKeyCommand(null,
fqn, "a");
- invoker.invoke(removeKeyCommand3);
-
- event = region.takeLastEventNode();
- assertNull(event);
- }
-
- public void testMixedEvent() throws Throwable
- {
- Map<Object, Object> data = new HashMap<Object, Object>();
- for (int i = 0; i < 100; i++)
- {
- data.put(i, i);
- }
-
- // this region is node granularity
- Fqn fqn = Fqn.fromString("/a/b/c");
-
- PutDataMapCommand putDataCommand = commandsFactory.buildPutDataMapCommand(null,
fqn, data);
- invoker.invoke(putDataCommand);
-
- Region region = regionManager.getRegion(fqn.toString(), false);
- EvictedEventNode event = region.takeLastEventNode();
-
- assertEquals(NodeEventType.ADD_NODE_EVENT, event.getEventType());
- assertEquals(fqn, event.getFqn());
- assertEquals(100, event.getElementDifference());
- assertNull(region.takeLastEventNode());
-
- GetNodeCommand getNodeCommand = commandsFactory.buildGetNodeCommand(fqn);
- invoker.invoke(getNodeCommand);
- event = region.takeLastEventNode();
- assertEquals(NodeEventType.VISIT_NODE_EVENT, event.getEventType());
- assertEquals(fqn, event.getFqn());
- assertNull(region.takeLastEventNode());
-
- RemoveNodeCommand removeNodeCommand = commandsFactory.buildRemoveNodeCommand(null,
fqn);
- invoker.invoke(removeNodeCommand);
- assertNull(cache.getNode(fqn));
- event = region.takeLastEventNode();
- assertEquals(NodeEventType.REMOVE_NODE_EVENT, event.getEventType());
- assertEquals(fqn, event.getFqn());
- assertNull(region.takeLastEventNode());
-
- Object key = "key";
- Object value = "value";
- PutKeyValueCommand putKeyValueCommand =
commandsFactory.buildPutKeyValueCommand(null, fqn, key, value);
- invoker.invoke(putKeyValueCommand);
- assertEquals("value", cache.peek(fqn, false, false).getDirect(key));
- event = region.takeLastEventNode();
- assertEquals(NodeEventType.ADD_ELEMENT_EVENT, event.getEventType());
- assertEquals(1, event.getElementDifference());
- assertEquals(fqn, event.getFqn());
- assertEquals("value", cache.peek(fqn, false, false).getDirect(key));
- assertNull(region.takeLastEventNode());
-
- GetKeyValueCommand getKeyValueCommand =
commandsFactory.buildGetKeyValueCommand(fqn, key, false);
- invoker.invoke(getKeyValueCommand);
- region = regionManager.getRegion(fqn.toString(), false);
- event = region.takeLastEventNode();
- assertEquals(NodeEventType.VISIT_NODE_EVENT, event.getEventType());
- assertEquals(fqn, event.getFqn());
- assertNull(region.takeLastEventNode());
-
- RemoveKeyCommand removeKeyCommand = commandsFactory.buildRemoveKeyCommand(null,
fqn, key);
- invoker.invoke(removeKeyCommand);
-
- assertNull(cache.get(fqn, key));
- event = region.takeLastEventNode();
- assertEquals(NodeEventType.REMOVE_ELEMENT_EVENT, event.getEventType());
- assertEquals(fqn, event.getFqn());
- assertEquals(1, event.getElementDifference());
- assertNull(region.takeLastEventNode());
- }
-}
\ No newline at end of file
Modified:
core/trunk/src/test/java/org/jboss/cache/invalidation/TombstoneEvictionTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/invalidation/TombstoneEvictionTest.java 2008-08-14
19:16:15 UTC (rev 6561)
+++
core/trunk/src/test/java/org/jboss/cache/invalidation/TombstoneEvictionTest.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -8,7 +8,7 @@
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.EvictionConfig;
import org.jboss.cache.config.EvictionRegionConfig;
-import org.jboss.cache.eviction.FIFOConfiguration;
+import org.jboss.cache.eviction.FIFOAlgorithmConfig;
import org.jboss.cache.transaction.DummyTransactionManagerLookup;
import org.jboss.cache.util.TestingUtil;
import org.testng.annotations.AfterMethod;
@@ -39,7 +39,7 @@
c1 = (CacheSPI) new DefaultCacheFactory<Object,
Object>().createCache(false);
// the FIFO policy cfg
- FIFOConfiguration cfg = new FIFOConfiguration();
+ FIFOAlgorithmConfig cfg = new FIFOAlgorithmConfig();
cfg.setMaxNodes(1);
cfg.setMinTimeToLive(0);
@@ -47,7 +47,7 @@
EvictionRegionConfig regionCfg = new EvictionRegionConfig();
regionCfg.setRegionFqn(dummy.getParent());
regionCfg.setRegionName(dummy.getParent().toString());
- regionCfg.setEvictionPolicyConfig(cfg);
+ regionCfg.setEvictionAlgorithmConfig(cfg);
// set regions in a list
List<EvictionRegionConfig> evictionRegionConfigs = new
ArrayList<EvictionRegionConfig>();
Modified:
core/trunk/src/test/java/org/jboss/cache/jmx/deprecated/LegacyConfigurationTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/jmx/deprecated/LegacyConfigurationTest.java 2008-08-14
19:16:15 UTC (rev 6561)
+++
core/trunk/src/test/java/org/jboss/cache/jmx/deprecated/LegacyConfigurationTest.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -23,8 +23,6 @@
package org.jboss.cache.jmx.deprecated;
import org.jboss.cache.Version;
-import org.jboss.cache.jmx.CacheJmxWrapperMBean;
-import org.jboss.cache.jmx.CacheJmxWrapper;
import org.jboss.cache.config.BuddyReplicationConfig;
import org.jboss.cache.config.BuddyReplicationConfig.BuddyLocatorConfig;
import org.jboss.cache.config.CacheLoaderConfig;
@@ -42,6 +40,8 @@
import org.jboss.cache.eviction.LRUPolicy;
import org.jboss.cache.eviction.MRUConfiguration;
import org.jboss.cache.eviction.MRUPolicy;
+import org.jboss.cache.jmx.CacheJmxWrapper;
+import org.jboss.cache.jmx.CacheJmxWrapperMBean;
import org.jboss.cache.loader.FileCacheLoader;
import org.jboss.cache.loader.SingletonStoreCacheLoader;
import org.jboss.cache.loader.jdbm.JdbmCacheLoader;
@@ -183,7 +183,7 @@
assertEquals("EvictionPolicyConfig",
getEvictionPolicyConfig().toString(), wrapper.getEvictionPolicyConfig().toString());
EvictionConfig ec = c.getEvictionConfig();
- assertEquals("EC queue size", 20000, ec.getDefaultEventQueueSize());
+ assertEquals("EC queue size", 20000,
ec.getDefaultEvictionRegionConfig().getEventQueueSize());
assertEquals("EC wakeup", 5000, ec.getWakeupInterval());
assertEquals("EC default pol", LRUPolicy.class.getName(),
ec.getDefaultEvictionPolicyClass());
List<EvictionRegionConfig> ercs = ec.getEvictionRegionConfigs();
@@ -193,7 +193,7 @@
LRUConfiguration lru = (LRUConfiguration) erc.getEvictionPolicyConfig();
assertEquals("EPC0 pol", LRUPolicy.class.getName(),
lru.getEvictionPolicyClass());
assertEquals("EPC0 maxnodes", 5000, lru.getMaxNodes());
- assertEquals("EPC0 ttl", 1000000, lru.getTimeToLive());
+ assertEquals("EPC0 ttl", 1000, lru.getTimeToLiveSeconds());
erc = ercs.get(1);
assertEquals("ERC1 name", "/org/jboss/data",
erc.getRegionName());
assertEquals("ERC1 queue size", 20000, erc.getEventQueueSize());
@@ -212,8 +212,8 @@
lru = (LRUConfiguration) erc.getEvictionPolicyConfig();
assertEquals("EPC3 pol", LRUPolicy.class.getName(),
lru.getEvictionPolicyClass());
assertEquals("EPC3 maxnodes", 10000, lru.getMaxNodes());
- assertEquals("EPC3 maxage", 10000, lru.getMaxAge());
- assertEquals("EPC3 ttl", 8000, lru.getTimeToLive());
+ assertEquals("EPC3 maxage", 10, lru.getMaxAgeSeconds());
+ assertEquals("EPC3 ttl", 8, lru.getTimeToLiveSeconds());
}
@@ -309,15 +309,15 @@
{
String xmlStr =
- " <eviction wakeUpInterval=\"5000\"
defaultPolicyClass=\"org.jboss.cache.eviction.LRUPolicy\"
defaultEventQueueSize=\"20000\">\n" +
- " <default eventQueueSize=\"1000\">\n"
+
+ " <eviction wakeUpInterval=\"5000\">\n" +
+ " <default eventQueueSize=\"1000\"
algorithmClass=\"org.jboss.cache.eviction.LRUAlgorithm\">\n" +
" <attribute
name=\"maxNodes\">5000</attribute>\n" +
" <attribute
name=\"timeToLive\">1000000</attribute>\n" +
" </default>\n" +
- "<region name=\"/org/jboss/data\"
policyClass=\"org.jboss.cache.eviction.FIFOPolicy\">\n" +
+ "<region name=\"/org/jboss/data\"
algorithmClass=\"org.jboss.cache.eviction.FIFOAlgorithm\">\n" +
" <attribute
name=\"maxNodes\">5000</attribute>\n" +
"</region>\n" +
- "<region name=\"/test/\"
policyClass=\"org.jboss.cache.eviction.MRUPolicy\">\n" +
+ "<region name=\"/test/\"
algorithmClass=\"org.jboss.cache.eviction.MRUAlgorithm\">\n" +
" <attribute
name=\"maxNodes\">10000</attribute>\n" +
"</region>\n" +
"<region name=\"/maxAgeTest/\">\n" +
Modified:
core/trunk/src/test/java/org/jboss/cache/marshall/CacheLoaderMarshallingJDBCTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/marshall/CacheLoaderMarshallingJDBCTest.java 2008-08-14
19:16:15 UTC (rev 6561)
+++
core/trunk/src/test/java/org/jboss/cache/marshall/CacheLoaderMarshallingJDBCTest.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -4,23 +4,20 @@
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
-import org.jboss.cache.util.TestingUtil;
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.EvictionConfig;
import org.jboss.cache.config.EvictionRegionConfig;
-import org.jboss.cache.eviction.LRUConfiguration;
-import org.jboss.cache.eviction.LRUPolicy;
+import org.jboss.cache.eviction.LRUAlgorithmConfig;
import org.jboss.cache.loader.JDBCCacheLoaderConfig;
+import org.jboss.cache.util.TestingUtil;
import static org.testng.AssertJUnit.assertEquals;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import java.util.ArrayList;
import java.util.Collections;
-import java.util.List;
import java.util.Properties;
/**
@@ -109,19 +106,15 @@
config.setUseRegionBasedMarshalling(useRegionBased);
config.setInactiveOnStartup(useRegionBased);
- EvictionConfig ec = new EvictionConfig();
- ec.setDefaultEvictionPolicyClass(LRUPolicy.class.getName());
- ec.setWakeupInterval(1000000); // a long time; really disabled
- EvictionRegionConfig erc = new EvictionRegionConfig();
- erc.setRegionFqn(Fqn.ROOT);
- erc.setRegionName("_default_");
- LRUConfiguration epc = new LRUConfiguration();
- epc.setMaxNodes(1000);
- epc.setTimeToLive(1000000);
- erc.setEvictionPolicyConfig(epc);
- List<EvictionRegionConfig> ercs = new
ArrayList<EvictionRegionConfig>();
- ercs.add(erc);
- ec.setEvictionRegionConfigs(ercs);
+ int wakeupInterval = 1000000; // a long time; really disabled
+ EvictionConfig ec = new EvictionConfig(
+ new EvictionRegionConfig(
+ Fqn.ROOT,
+ new LRUAlgorithmConfig(1000000, 0, 1000)
+ ),
+ wakeupInterval
+ );
+
config.setEvictionConfig(ec);
CacheLoaderConfig clc = new CacheLoaderConfig();
Modified:
core/trunk/src/test/java/org/jboss/cache/marshall/CacheLoaderMarshallingTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/marshall/CacheLoaderMarshallingTest.java 2008-08-14
19:16:15 UTC (rev 6561)
+++
core/trunk/src/test/java/org/jboss/cache/marshall/CacheLoaderMarshallingTest.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -10,21 +10,17 @@
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.EvictionConfig;
import org.jboss.cache.config.EvictionRegionConfig;
-import org.jboss.cache.eviction.LRUConfiguration;
-import org.jboss.cache.eviction.LRUPolicy;
+import org.jboss.cache.eviction.LRUAlgorithmConfig;
import org.jboss.cache.loader.FileCacheLoaderConfig;
import org.jboss.cache.util.TestingUtil;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNotNull;
-
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.io.File;
-import java.util.ArrayList;
import java.util.Collections;
-import java.util.List;
/**
* Tests marshalling/unmarshalling during cache loader operations involving types
@@ -69,38 +65,38 @@
{
cacheLoaderMarshallingTest(true);
}
-
+
public void testLoadNodesAtRootOfRegion() throws Exception
{
String rootRegionName = "/myregion";
String hereFqn = rootRegionName + "/here";
-
+
cache = createCache(true);
cache.start();
Region r = cache.getRegion(Fqn.fromString(rootRegionName), true);
r.registerContextClassLoader(Thread.currentThread().getContextClassLoader());
r.activate();
-
+
cache.put(rootRegionName, "a key", "a value");
cache.put(hereFqn, "another key", "another value");
r.deactivate();
r.unregisterContextClassLoader();
-
+
cache.stop();
-
+
cache.start();
-
+
r = cache.getRegion(Fqn.fromString(rootRegionName), true);
r.registerContextClassLoader(Thread.currentThread().getContextClassLoader());
r.activate();
-
+
Node<Object, Object> rootRegionNode = cache.getNode(rootRegionName);
Node<Object, Object> hereNode = cache.getNode(hereFqn);
assertNotNull(rootRegionNode);
assertNotNull(hereNode);
-
+
assertEquals(hereNode.get("another key"), "another value");
assertEquals(rootRegionNode.get("a key"), "a value");
}
@@ -140,18 +136,14 @@
config.setInactiveOnStartup(useRegionBased);
EvictionConfig ec = new EvictionConfig();
- ec.setDefaultEvictionPolicyClass(LRUPolicy.class.getName());
ec.setWakeupInterval(1000000); // a long time; really disabled
EvictionRegionConfig erc = new EvictionRegionConfig();
erc.setRegionFqn(Fqn.ROOT);
- erc.setRegionName("_default_");
- LRUConfiguration epc = new LRUConfiguration();
- epc.setMaxNodes(1000);
- epc.setTimeToLive(1000000);
- erc.setEvictionPolicyConfig(epc);
- List<EvictionRegionConfig> ercs = new
ArrayList<EvictionRegionConfig>();
- ercs.add(erc);
- ec.setEvictionRegionConfigs(ercs);
+ LRUAlgorithmConfig lruAlgorithmConfig = new LRUAlgorithmConfig();
+ lruAlgorithmConfig.setMaxNodes(1000);
+ lruAlgorithmConfig.setTimeToLive(1000000);
+ erc.setEvictionAlgorithmConfig(lruAlgorithmConfig);
+ ec.addEvictionRegionConfig(erc);
config.setEvictionConfig(ec);
CacheLoaderConfig clc = new CacheLoaderConfig();
Modified:
core/trunk/src/test/java/org/jboss/cache/passivation/PassivationActivationCallbacksTestCase.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/passivation/PassivationActivationCallbacksTestCase.java 2008-08-14
19:16:15 UTC (rev 6561)
+++
core/trunk/src/test/java/org/jboss/cache/passivation/PassivationActivationCallbacksTestCase.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -13,11 +13,10 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
-import org.jboss.cache.RegionManagerImpl;
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.EvictionConfig;
import org.jboss.cache.config.EvictionRegionConfig;
-import org.jboss.cache.eviction.LRUConfiguration;
+import org.jboss.cache.eviction.LRUAlgorithmConfig;
import org.jboss.cache.loader.CacheLoader;
import org.jboss.cache.loader.DummyInMemoryCacheLoader;
import org.jboss.cache.lock.IsolationLevel;
@@ -29,9 +28,7 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import java.util.ArrayList;
import java.util.HashSet;
-import java.util.List;
import java.util.Set;
/**
@@ -89,26 +86,16 @@
EvictionConfig ec = new EvictionConfig();
ec.setWakeupInterval(1000);
- List<EvictionRegionConfig> ercs = new
ArrayList<EvictionRegionConfig>();
+ LRUAlgorithmConfig lru = new LRUAlgorithmConfig();
+ lru.setMaxNodes(0);
+ lru.setTimeToLive(5000);
+ ec.setDefaultEvictionRegionConfig(new EvictionRegionConfig(Fqn.ROOT, lru));
- EvictionRegionConfig erc = new EvictionRegionConfig();
- erc.setRegionFqn(RegionManagerImpl.DEFAULT_REGION);
- LRUConfiguration epc = new LRUConfiguration();
- epc.setMaxNodes(0);
- epc.setTimeToLive(5000);
- erc.setEvictionPolicyConfig(epc);
- ercs.add(erc);
+ lru = new LRUAlgorithmConfig();
+ lru.setMaxNodes(0);
+ lru.setTimeToLive(1000);
+ ec.addEvictionRegionConfig(new EvictionRegionConfig(BASE, lru));
- erc = new EvictionRegionConfig();
- erc.setRegionFqn(BASE);
- epc = new LRUConfiguration();
- epc.setMaxNodes(0);
- epc.setTimeToLive(1000);
- erc.setEvictionPolicyConfig(epc);
- ercs.add(erc);
-
- ec.setEvictionRegionConfigs(ercs);
-
cache.getConfiguration().setEvictionConfig(ec);
}
Modified:
core/trunk/src/test/java/org/jboss/cache/passivation/ReplicatedPassivationIntegrationTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/passivation/ReplicatedPassivationIntegrationTest.java 2008-08-14
19:16:15 UTC (rev 6561)
+++
core/trunk/src/test/java/org/jboss/cache/passivation/ReplicatedPassivationIntegrationTest.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -34,8 +34,7 @@
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.EvictionConfig;
import org.jboss.cache.config.EvictionRegionConfig;
-import org.jboss.cache.eviction.LRUConfiguration;
-import org.jboss.cache.eviction.LRUPolicy;
+import org.jboss.cache.eviction.LRUAlgorithmConfig;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.jboss.cache.loader.DummyInMemoryCacheLoader;
import org.jboss.cache.loader.DummySharedInMemoryCacheLoader;
@@ -51,9 +50,6 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import java.util.LinkedList;
-import java.util.List;
-
@Test(groups = "functional")
public class ReplicatedPassivationIntegrationTest
{
@@ -117,27 +113,23 @@
EvictionConfig cfg = new EvictionConfig();
cfg.setWakeupInterval(1000);
cfg.setDefaultEventQueueSize(200000);
- cfg.setDefaultEvictionPolicyClass(LRUPolicy.class.getName());
- List<EvictionRegionConfig> erc = new
LinkedList<EvictionRegionConfig>();
- cfg.setEvictionRegionConfigs(erc);
EvictionRegionConfig region1 = new EvictionRegionConfig();
region1.setRegionFqn(Fqn.ROOT);
- LRUConfiguration epc1 = new LRUConfiguration();
+ LRUAlgorithmConfig epc1 = new LRUAlgorithmConfig();
epc1.setMaxNodes(5000);
epc1.setTimeToLive(3000);
- region1.setEvictionPolicyConfig(epc1);
+ region1.setEvictionAlgorithmConfig(epc1);
+ cfg.setDefaultEvictionRegionConfig(region1);
EvictionRegionConfig region2 = new EvictionRegionConfig();
region2.setRegionFqn(base);
- LRUConfiguration epc2 = new LRUConfiguration();
+ LRUAlgorithmConfig epc2 = new LRUAlgorithmConfig();
epc2.setMaxNodes(100);
epc2.setTimeToLive(3000);
- region2.setEvictionPolicyConfig(epc2);
+ region2.setEvictionAlgorithmConfig(epc2);
+ cfg.addEvictionRegionConfig(region2);
- erc.add(region1);
- erc.add(region2);
-
return cfg;
}
Modified:
core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransferConcurrencyTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransferConcurrencyTest.java 2008-08-14
19:16:15 UTC (rev 6561)
+++
core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransferConcurrencyTest.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -14,6 +14,7 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
import org.jboss.cache.Region;
+import org.jboss.cache.RegionImpl;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
@@ -482,13 +483,13 @@
cache2.start();
caches.put("evict2", cache2);
- Region region = cache2.getRegion(Fqn.ROOT, false);
+ RegionImpl region = (RegionImpl) cache2.getRegion(Fqn.ROOT, false);
// We expect a VISIT event for / and ADD events for /a, /a/b and /a/b/c
- int nodeEventQueueSize = region.nodeEventQueueSize();
+ int nodeEventQueueSize = region.getEvictionEventQueue().size();
int i = 0;
- while (region.nodeEventQueueSize() > 0)
+ while (nodeEventQueueSize > 0)
{
- System.out.println(++i + ") Queue contains : " +
region.takeLastEventNode());
+ System.out.println(++i + ") Queue contains : " +
region.getEvictionEventQueue().poll(0, TimeUnit.MILLISECONDS));
}
assertEquals("Saw the expected number of node events", 4,
nodeEventQueueSize);
Modified: core/trunk/src/test/java/org/jboss/cache/util/internals/EvictionController.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/util/internals/EvictionController.java 2008-08-14
19:16:15 UTC (rev 6561)
+++
core/trunk/src/test/java/org/jboss/cache/util/internals/EvictionController.java 2008-08-15
10:59:40 UTC (rev 6562)
@@ -8,7 +8,7 @@
import org.jboss.cache.config.EvictionConfig;
import org.jboss.cache.config.EvictionRegionConfig;
import org.jboss.cache.eviction.EvictionTimerTask;
-import org.jboss.cache.eviction.LRUConfiguration;
+import org.jboss.cache.eviction.LRUAlgorithmConfig;
import org.jboss.cache.util.TestingUtil;
import java.lang.reflect.Method;
@@ -69,9 +69,9 @@
throw new IllegalStateException("No such region!");
}
long ttl = 0;
- if (erConfig.getEvictionPolicyConfig() instanceof LRUConfiguration)
+ if (erConfig.getEvictionAlgorithmConfig() instanceof LRUAlgorithmConfig)
{
- LRUConfiguration configuration = (LRUConfiguration)
erConfig.getEvictionPolicyConfig();
+ LRUAlgorithmConfig configuration = (LRUAlgorithmConfig)
erConfig.getEvictionAlgorithmConfig();
ttl = configuration.getTimeToLive();
}
else
Modified: core/trunk/src/test/resources/unit-test-cache-service.xml
===================================================================
--- core/trunk/src/test/resources/unit-test-cache-service.xml 2008-08-14 19:16:15 UTC (rev
6561)
+++ core/trunk/src/test/resources/unit-test-cache-service.xml 2008-08-15 10:59:40 UTC (rev
6562)
@@ -2,7 +2,7 @@
<jbosscache>
-
+
<locking isolationLevel="REPEATABLE_READ"
lockAcquisitionTimeout="10000"/>
<transaction
transactionManagerLookupClass="org.jboss.cache.transaction.GenericTransactionManagerLookup"/>
<serialization useRegionBasedMarshalling="false"/>
@@ -11,18 +11,18 @@
<replication>
<sync replTimeout="15000"/>
</replication>
- <eviction wakeUpInterval="2000"
defaultPolicyClass="org.jboss.cache.eviction.LRUPolicy">
- <default>
+ <eviction wakeUpInterval="2000">
+ <default algorithmClass="org.jboss.cache.eviction.LRUAlgorithm">
<attribute name="maxNodes">5000</attribute>
- <attribute name="timeToLiveSeconds">1000</attribute>
+ <attribute name="timeToLive">1000</attribute>
</default>
<region name="/org/jboss/data">
<attribute name="maxNodes">5000</attribute>
- <attribute name="timeToLiveSeconds">1000</attribute>
+ <attribute name="timeToLive">1000</attribute>
</region>
<region name="/org/jboss/test/data">
<attribute name="maxNodes">5</attribute>
- <attribute name="timeToLiveSeconds">4</attribute>
+ <attribute name="timeToLive">4</attribute>
</region>
</eviction>
<loaders passivation="true" shared="false">