Author: manik.surtani(a)jboss.com
Date: 2008-08-23 08:40:58 -0400 (Sat, 23 Aug 2008)
New Revision: 6610
Added:
core/trunk/src/main/java/org/jboss/cache/annotations/Compat.java
core/trunk/src/main/java/org/jboss/cache/config/UnsupportedEvictionImplException.java
core/trunk/src/main/java/org/jboss/cache/eviction/EvictedEventNode.java
core/trunk/src/main/java/org/jboss/cache/eviction/ModernizableConfig.java
core/trunk/src/main/java/org/jboss/cache/eviction/ModernizablePolicy.java
core/trunk/src/main/java/org/jboss/cache/factories/CacheConfigsXmlParser.java
core/trunk/src/test/java/org/jboss/cache/eviction/legacy/
core/trunk/src/test/java/org/jboss/cache/eviction/legacy/BackwardCompatibilityTest.java
Modified:
core/trunk/src/main/java/org/jboss/cache/DefaultCacheFactory.java
core/trunk/src/main/java/org/jboss/cache/Fqn.java
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/EvictionConfig.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/eviction/ElementSizeConfiguration.java
core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizePolicy.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/EvictionPolicyConfigBase.java
core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationAlgorithmConfig.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/FIFOConfiguration.java
core/trunk/src/main/java/org/jboss/cache/eviction/FIFOPolicy.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/LRUAlgorithmConfig.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/MRUConfiguration.java
core/trunk/src/main/java/org/jboss/cache/eviction/MRUPolicy.java
core/trunk/src/main/java/org/jboss/cache/eviction/NullEvictionPolicy.java
core/trunk/src/main/java/org/jboss/cache/eviction/NullEvictionPolicyConfig.java
Log:
New compatible interfaces. Now we should be API compatible with 2.x.
Modified: core/trunk/src/main/java/org/jboss/cache/DefaultCacheFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/DefaultCacheFactory.java 2008-08-23 07:14:18
UTC (rev 6609)
+++ core/trunk/src/main/java/org/jboss/cache/DefaultCacheFactory.java 2008-08-23 12:40:58
UTC (rev 6610)
@@ -6,6 +6,7 @@
*/
package org.jboss.cache;
+import org.jboss.cache.annotations.Compat;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.ConfigurationException;
import org.jboss.cache.config.OldFileFormatException;
@@ -32,6 +33,20 @@
{
private ClassLoader defaultClassLoader;
+
+ /**
+ * This is here for backward compatibility only. Use <tt>new
DefaultCacheFactory()</tt> instead.
+ *
+ * @deprecated
+ */
+ @SuppressWarnings("unchecked")
+ @Deprecated
+ @Compat
+ public static DefaultCacheFactory newInstance()
+ {
+ return new DefaultCacheFactory();
+ }
+
public Cache<K, V> createCache() throws ConfigurationException
{
return createCache(true);
Modified: core/trunk/src/main/java/org/jboss/cache/Fqn.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/Fqn.java 2008-08-23 07:14:18 UTC (rev 6609)
+++ core/trunk/src/main/java/org/jboss/cache/Fqn.java 2008-08-23 12:40:58 UTC (rev 6610)
@@ -7,6 +7,10 @@
package org.jboss.cache;
+import net.jcip.annotations.Immutable;
+import org.jboss.cache.annotations.Compat;
+import org.jboss.cache.util.Immutables;
+
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
@@ -16,10 +20,6 @@
import java.util.Collections;
import java.util.List;
-import net.jcip.annotations.Immutable;
-
-import org.jboss.cache.util.Immutables;
-
/**
* A Fully Qualified Name (Fqn) is a list of names (typically Strings but can be any
Object),
* which represent a path to a particular {@link Node} or sometimes a {@link Region} in a
{@link Cache}.
@@ -78,7 +78,8 @@
* @version $Revision$
*/
@Immutable
-public class Fqn implements Comparable<Fqn>, Externalizable
+@Compat(notes = "The generics, while originally intended to be removed in 3.0, have
been retained for backward compat.")
+public class Fqn<E> implements Comparable<Fqn>, Externalizable
{
/**
* Separator between FQN elements.
@@ -110,6 +111,77 @@
size = 0;
}
+ // --- deprecated compat stuff
+
+ /**
+ * Constructs a FQN from a list of names.
+ *
+ * @param names List of names
+ * @deprecated use {@link #fromList(java.util.List)} instead. This constructor will
be removed in 3.0.0.
+ */
+ @Deprecated
+ @Compat
+ public Fqn(List<E> names)
+ {
+ // the list is unsafe - may be referenced externally
+ this(names, false);
+ }
+
+ /**
+ * Constructs a Fqn from an array of names.
+ *
+ * @param names Names that comprose this Fqn
+ * @deprecated use {@link #fromElements(Object[])} instead. This constructor will be
removed in 3.0.0.
+ */
+ @Deprecated
+ @Compat
+ public Fqn(E... names)
+ {
+ // safe - the list is created here.
+ this(Arrays.asList(names), true);
+ }
+
+ /**
+ * Constructs a Fqn from a base and relative Fqn.
+ *
+ * @param base parent Fqn
+ * @param relative Sub-Fqn relative to the parent
+ * @deprecated use {@link #fromRelativeFqn(Fqn, Fqn)} instead. This constructor will
be removed in 3.0.0.
+ */
+ @Deprecated
+ @Compat
+ public Fqn(Fqn<E> base, Fqn<E> relative)
+ {
+ this(base, relative.elements);
+ }
+
+ /**
+ * Constructs a Fqn from a base and two relative names.
+ *
+ * @param base parent Fqn
+ * @param childNames elements that denote the path to the Fqn, under the parent
+ * @deprecated use {@link #fromRelativeElements(Fqn, Object[])} instead. This
constructor will be removed in 3.0.0.
+ */
+ @Deprecated
+ @Compat
+ public Fqn(Fqn<E> base, E... childNames)
+ {
+ this(base, Arrays.asList(childNames));
+ }
+
+ // --- end deprecated stuff
+
+ /**
+ * If safe is false, Collections.unmodifiableList() is used to wrap the list passed
in. This is an optimisation so
+ * Fqn.fromString(), probably the most frequently used factory method, doesn't end
up needing to use the unmodifiableList()
+ * since it creates the list internally.
+ *
+ * @param names List of names
+ * @param safe whether this list is referenced externally (safe = false) or not (safe
= true).
+ * @deprecated use {@link #fromList(java.util.List)} instead. The boolean
"safety" hint is calculated internally. This constructor will be removed in
3.0.0.
+ */
+ @Deprecated
+ @Compat(notes = "Not truly deprecated, this constructor should really be
protected and not public. Marked as deprecated for anyone using it as a public
API.")
@SuppressWarnings("unchecked")
protected Fqn(List<?> names, boolean safe)
{
Modified: core/trunk/src/main/java/org/jboss/cache/Region.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/Region.java 2008-08-23 07:14:18 UTC (rev
6609)
+++ core/trunk/src/main/java/org/jboss/cache/Region.java 2008-08-23 12:40:58 UTC (rev
6610)
@@ -6,9 +6,13 @@
*/
package org.jboss.cache;
+import org.jboss.cache.annotations.Compat;
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.EvictionEvent;
+import org.jboss.cache.eviction.EvictionPolicy;
/**
* Defines characteristics such as class loading and eviction of {@link
org.jboss.cache.Node}s belonging to a Region in a {@link Cache}.
@@ -28,7 +32,8 @@
* @see RegionManager
* @since 2.0.0
*/
-public interface Region extends Comparable<Region>
+@Compat(notes = "Cloneable is extended for backward compat.")
+public interface Region extends Comparable<Region>, Cloneable
{
/**
* Types of regions.
@@ -111,6 +116,8 @@
/**
* Processes the eviction queues (primary and recycle queues) associated with this
region. A no-op if this is not an eviction region.
+ *
+ * @since 3.0
*/
void processEvictionQueues();
@@ -155,7 +162,7 @@
/**
* Marks a {@link org.jboss.cache.Node} as currently in use, by adding an event to the
eviction queue.
* 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
+ * it respects this event (e.g., {@link org.jboss.cache.eviction.LRUSelector} 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
@@ -203,4 +210,77 @@
* @return a new Region instance.
*/
Region copy(Fqn newRoot);
+
+ // -------- deprecated interfaces retained for compatibility with 2.x. -----------
+
+
+ /**
+ * Configures an eviction policy for this region.
+ *
+ * @param evictionPolicyConfig configuration to set
+ * @deprecated
+ */
+ @Deprecated
+ @Compat
+ void setEvictionPolicy(EvictionPolicyConfig evictionPolicyConfig);
+
+ /**
+ * Returns an eviction policy configuration.
+ *
+ * @return an eviction policy configuration
+ * @deprecated
+ */
+ @Deprecated
+ @Compat
+ EvictionPolicyConfig getEvictionPolicyConfig();
+
+ /**
+ * Returns an eviction policy.
+ *
+ * @return an eviction policy
+ * @deprecated
+ */
+ @Deprecated
+ @Compat
+ EvictionPolicy getEvictionPolicy();
+
+ /**
+ * Returns the size of the node event queue, used by the eviction thread.
+ *
+ * @return number of events
+ * @deprecated
+ */
+ @Deprecated
+ @Compat
+ int nodeEventQueueSize();
+
+ /**
+ * Returns the most recent {@link org.jboss.cache.eviction.EvictedEventNode} added to
the event queue by
+ * {@link #putNodeEvent(org.jboss.cache.eviction.EvictedEventNode)}.
+ *
+ * @return the last {@link org.jboss.cache.eviction.EvictedEventNode}, or null if no
more events exist
+ * @deprecated
+ */
+ @Compat
+ @Deprecated
+ 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
+ * @deprecated
+ */
+ @Deprecated
+ @Compat
+ void putNodeEvent(EvictedEventNode event);
+
+ /**
+ * @return a clone
+ * @deprecated
+ */
+ @Deprecated
+ @Compat
+ Region clone() throws CloneNotSupportedException;
}
Modified: core/trunk/src/main/java/org/jboss/cache/RegionImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RegionImpl.java 2008-08-23 07:14:18 UTC (rev
6609)
+++ core/trunk/src/main/java/org/jboss/cache/RegionImpl.java 2008-08-23 12:40:58 UTC (rev
6610)
@@ -8,16 +8,21 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.annotations.Compat;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.EvictionAlgorithmConfig;
+import org.jboss.cache.config.EvictionPolicyConfig;
import org.jboss.cache.config.EvictionRegionConfig;
+import org.jboss.cache.eviction.EvictedEventNode;
import org.jboss.cache.eviction.EvictionActionPolicy;
import org.jboss.cache.eviction.EvictionAlgorithm;
import org.jboss.cache.eviction.EvictionEvent;
+import org.jboss.cache.eviction.EvictionPolicy;
import org.jboss.cache.util.Util;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
/**
* Default implementation of a {@link Region}
@@ -211,6 +216,12 @@
if (evictionAlgorithm.canIgnoreEvent(eventType)) return null;
EvictionEvent event = new EvictionEvent(fqn, eventType, elementDifference);
+ registerEvictionEvent(event);
+ return event;
+ }
+
+ private void registerEvictionEvent(EvictionEvent ee)
+ {
try
{
if (evictionEventQueue == null) createQueue();// in case the queue does not
exist yet.
@@ -221,7 +232,7 @@
" Region: " + fqn +
" You will need to reduce the wakeUpIntervalSeconds
parameter.");
}
- evictionEventQueue.put(event);
+ evictionEventQueue.put(ee);
}
catch (InterruptedException e)
{
@@ -229,7 +240,6 @@
// reinstate interrupt flag
Thread.currentThread().interrupt();
}
- return event;
}
private void createQueue()
@@ -290,4 +300,70 @@
}
return clone;
}
+
+ @Deprecated
+ @Compat
+ @SuppressWarnings("deprecation")
+ public void setEvictionPolicy(EvictionPolicyConfig evictionPolicyConfig)
+ {
+ //TODO: Autogenerated. Implement me properly
+ }
+
+ @Deprecated
+ @Compat
+ @SuppressWarnings("deprecation")
+ public EvictionPolicyConfig getEvictionPolicyConfig()
+ {
+ return null; //TODO: Autogenerated. Implement me properly
+ }
+
+ @Deprecated
+ @Compat
+ @SuppressWarnings("deprecation")
+ public EvictionPolicy getEvictionPolicy()
+ {
+ return null; //TODO: Autogenerated. Implement me properly
+ }
+
+ @Deprecated
+ @Compat
+ public int nodeEventQueueSize()
+ {
+ BlockingQueue<?> q = getEvictionEventQueue();
+ return q == null ? 0 : q.size();
+ }
+
+ @Compat
+ @Deprecated
+ @SuppressWarnings("deprecation")
+ public EvictedEventNode takeLastEventNode()
+ {
+ try
+ {
+ EvictionEvent ee = getEvictionEventQueue().poll(0, TimeUnit.SECONDS);
+ if (ee instanceof EvictedEventNode) return (EvictedEventNode) ee;
+ else return new EvictedEventNode(ee);
+ }
+ catch (InterruptedException e)
+ {
+ log.debug("trace", e);
+ }
+ return null;
+
+ }
+
+ @Deprecated
+ @Compat
+ @SuppressWarnings("deprecation")
+ public void putNodeEvent(EvictedEventNode event)
+ {
+ this.registerEvictionEvent(event);
+ }
+
+ @Deprecated
+ @Compat
+ public Region clone() throws CloneNotSupportedException
+ {
+ return (Region) super.clone();
+ }
}
Modified: core/trunk/src/main/java/org/jboss/cache/RegionManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RegionManager.java 2008-08-23 07:14:18 UTC
(rev 6609)
+++ core/trunk/src/main/java/org/jboss/cache/RegionManager.java 2008-08-23 12:40:58 UTC
(rev 6610)
@@ -1,5 +1,6 @@
package org.jboss.cache;
+import org.jboss.cache.annotations.Compat;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.EvictionConfig;
import org.jboss.cache.eviction.EvictionTimerTask;
@@ -182,4 +183,24 @@
* @return the configuration
*/
Configuration getConfiguration();
+
+
+ // ---------- compatibility interface -----------------
+ /**
+ * Starts the eviction processing thread.
+ *
+ * @deprecated
+ */
+ @Deprecated
+ @Compat
+ void startEvictionThread();
+
+ /**
+ * Stops the eviction processing thread
+ *
+ * @deprecated
+ */
+ @Deprecated
+ @Compat
+ void stopEvictionThread();
}
Modified: core/trunk/src/main/java/org/jboss/cache/RegionManagerImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RegionManagerImpl.java 2008-08-23 07:14:18
UTC (rev 6609)
+++ core/trunk/src/main/java/org/jboss/cache/RegionManagerImpl.java 2008-08-23 12:40:58
UTC (rev 6610)
@@ -766,4 +766,22 @@
{
return cache;
}
+
+
+ // --------- for backward compat --------------
+ /**
+ * Starts the eviction processing thread.
+ */
+ public void startEvictionThread()
+ {
+ evictionTimerTask.init(evictionConfig.getWakeupInterval());
+ }
+
+ /**
+ * Stops the eviction processing thread
+ */
+ public void stopEvictionThread()
+ {
+ evictionTimerTask.stop();
+ }
}
Copied: core/trunk/src/main/java/org/jboss/cache/annotations/Compat.java (from rev 6588,
core/trunk/src/main/java/org/jboss/cache/annotations/Experimental.java)
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/annotations/Compat.java
(rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/annotations/Compat.java 2008-08-23 12:40:58
UTC (rev 6610)
@@ -0,0 +1,22 @@
+package org.jboss.cache.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * A marker annotation to mark that a class, method or field is experimental and as such.
Should never be used for any
+ * new code. Similar to deprecated, but provides additional meaning to developers on why
certain classes exist.
+ * <p/>
+ *
+ * @author Manik Surtani (<a
href="mailto:manik@jboss.org">manik@jboss.org</a>)
+ * @since 3.0
+ */
+(a)Retention(RetentionPolicy.SOURCE)
+(a)Target({ElementType.TYPE, ElementType.CONSTRUCTOR, ElementType.FIELD,
ElementType.LOCAL_VARIABLE,
+ ElementType.METHOD, ElementType.PACKAGE, ElementType.PARAMETER})
+public @interface Compat
+{
+ String notes() default "";
+}
\ No newline at end of file
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-23
07:14:18 UTC (rev 6609)
+++ core/trunk/src/main/java/org/jboss/cache/config/EvictionConfig.java 2008-08-23
12:40:58 UTC (rev 6610)
@@ -21,10 +21,15 @@
*/
package org.jboss.cache.config;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.jboss.cache.Fqn;
+import org.jboss.cache.RegionManagerImpl;
+import org.jboss.cache.annotations.Compat;
import org.jboss.cache.eviction.DefaultEvictionActionPolicy;
import org.jboss.cache.eviction.EvictionAlgorithm;
import org.jboss.cache.eviction.EvictionPolicy;
+import org.jboss.cache.eviction.ModernizablePolicy;
import org.jboss.cache.util.Util;
import java.util.LinkedList;
@@ -129,6 +134,7 @@
@Deprecated
public void setDefaultEvictionPolicyClass(String defaultEvictionPolicyClass)
{
+ assertIsTransformable(defaultEvictionPolicyClass);
try
{
EvictionPolicy policy = (EvictionPolicy)
Util.getInstance(defaultEvictionPolicyClass);
@@ -143,6 +149,39 @@
}
/**
+ * Tests whether an eviction policy class can be transformed from the legacy format to
the new interfaces introduced
+ * in 3.x. If not, this methow throws a {@link UnsupportedEvictionImplException}.
+ *
+ * @param evictionPolicyClass class to test
+ * @throws UnsupportedEvictionImplException
+ * thrown if the eviction policy passed in is unusable
+ */
+ @Compat(notes = "here to test legacy impls")
+ @Deprecated
+ public static final void assertIsTransformable(String evictionPolicyClass) throws
UnsupportedEvictionImplException
+ {
+ boolean throwException = true;
+ if (evictionPolicyClass.indexOf("org.jboss.cache.eviction") > -1)
+ {
+ EvictionPolicy ep = null;
+ try
+ {
+ ep = (EvictionPolicy) Util.getInstance(evictionPolicyClass);
+ if (ep instanceof ModernizablePolicy) throwException = false;
+ }
+ catch (Exception e)
+ {
+ // do nothing
+ Log l = LogFactory.getLog(EvictionConfig.class);
+ if (l.isTraceEnabled()) l.trace(e);
+ }
+ }
+ if (throwException)
+ throw new UnsupportedEvictionImplException("Unsupported custom eviction
policy [" + evictionPolicyClass +
+ "]. Starting with 3.x the eviction API has changed, the code needs to
be manually migrated. Please re-implement your custom policy.");
+ }
+
+ /**
* Creates an EvictionRegionConfig for the
* {@link org.jboss.cache.RegionManagerImpl#DEFAULT_REGION "_default_"}
region using the
* {@link #getDefaultEvictionPolicyClass()} default eviction policy class}. Throws a
@@ -172,13 +211,41 @@
public void setEvictionRegionConfigs(List<EvictionRegionConfig>
evictionRegionConfigs)
{
testImmutability("evictionRegionConfigs");
+ EvictionRegionConfig toRemove = null;
+ for (EvictionRegionConfig erc : evictionRegionConfigs)
+ {
+ if (erc.getRegionFqn().isRoot() ||
erc.getRegionFqn().equals(RegionManagerImpl.DEFAULT_REGION))
+ {
+ mergeWithDefault(erc);
+ toRemove = erc;
+ break;
+ }
+ }
+
+ if (toRemove != null) evictionRegionConfigs.remove(toRemove);
+
this.evictionRegionConfigs = evictionRegionConfigs;
}
+ private void mergeWithDefault(EvictionRegionConfig erc)
+ {
+ erc.setEventQueueSizeIfUnset(defaultEvictionRegionConfig.getEventQueueSize());
+ if (erc.getEvictionAlgorithmConfig() == null)
+
erc.setEvictionAlgorithmConfig(defaultEvictionRegionConfig.getEvictionAlgorithmConfig());
+ defaultEvictionRegionConfig = erc;
+ }
+
public void addEvictionRegionConfig(EvictionRegionConfig evictionRegionConfig)
{
testImmutability("evictionRegionConfigs");
- evictionRegionConfigs.add(evictionRegionConfig);
+ if (evictionRegionConfig.getRegionFqn().isRoot() ||
evictionRegionConfig.getRegionFqn().equals(RegionManagerImpl.DEFAULT_REGION))
+ {
+ mergeWithDefault(evictionRegionConfig);
+ }
+ else
+ {
+ evictionRegionConfigs.add(evictionRegionConfig);
+ }
}
/**
@@ -239,7 +306,8 @@
if (defaultEventQueueSize != that.defaultEventQueueSize) return false;
if (wakeupInterval != that.wakeupInterval) return false;
- if (defaultEvictionRegionConfig != null ?
!defaultEvictionRegionConfig.equals(that.defaultEvictionRegionConfig) :
that.defaultEvictionRegionConfig != null) return false;
+ if (defaultEvictionRegionConfig != null ?
!defaultEvictionRegionConfig.equals(that.defaultEvictionRegionConfig) :
that.defaultEvictionRegionConfig != null)
+ return false;
if (evictionRegionConfigs != null ?
!evictionRegionConfigs.equals(that.evictionRegionConfigs) : that.evictionRegionConfigs !=
null)
return false;
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-23
07:14:18 UTC (rev 6609)
+++ core/trunk/src/main/java/org/jboss/cache/config/EvictionRegionConfig.java 2008-08-23
12:40:58 UTC (rev 6610)
@@ -24,7 +24,7 @@
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.eviction.ModernizableConfig;
import org.jboss.cache.util.Util;
import java.lang.reflect.Method;
@@ -59,9 +59,9 @@
public EvictionRegionConfig(Fqn regionFqn, EvictionPolicyConfig evictionPolicyConfig)
{
this.regionFqn = regionFqn;
- if (evictionPolicyConfig instanceof Modernizable)
+ if (evictionPolicyConfig instanceof ModernizableConfig)
{
- this.evictionAlgorithmConfig = ((Modernizable)
evictionPolicyConfig).modernize();
+ this.evictionAlgorithmConfig = ((ModernizableConfig)
evictionPolicyConfig).modernizeConfig();
deprecatedConfig = evictionPolicyConfig;
}
else
@@ -114,14 +114,14 @@
@Deprecated
public void setEvictionPolicyConfig(EvictionPolicyConfig evictionPolicyConfig)
{
- if (evictionPolicyConfig instanceof Modernizable)
+ if (evictionPolicyConfig instanceof ModernizableConfig)
{
deprecatedConfig = evictionPolicyConfig;
- setEvictionAlgorithmConfig(((Modernizable) evictionPolicyConfig).modernize());
+ setEvictionAlgorithmConfig(((ModernizableConfig)
evictionPolicyConfig).modernizeConfig());
}
else
{
- throw new ConfigurationException("Unable to convert " +
evictionPolicyConfig.getClass().getName() +
+ throw new UnsupportedEvictionImplException("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());
}
Added:
core/trunk/src/main/java/org/jboss/cache/config/UnsupportedEvictionImplException.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/UnsupportedEvictionImplException.java
(rev 0)
+++
core/trunk/src/main/java/org/jboss/cache/config/UnsupportedEvictionImplException.java 2008-08-23
12:40:58 UTC (rev 6610)
@@ -0,0 +1,30 @@
+package org.jboss.cache.config;
+
+/**
+ * Thrown if an eviction configuration that cannot be translated to the new 3.x eviction
interfaces is used.
+ *
+ * @author Manik Surtani (<a
href="mailto:manik@jboss.org">manik@jboss.org</a>)
+ * @since 3.0
+ */
+public class UnsupportedEvictionImplException extends ConfigurationException
+{
+ public UnsupportedEvictionImplException(Exception e)
+ {
+ super(e);
+ }
+
+ public UnsupportedEvictionImplException(String string)
+ {
+ super(string);
+ }
+
+ public UnsupportedEvictionImplException(String string, String erroneousAttribute)
+ {
+ super(string, erroneousAttribute);
+ }
+
+ public UnsupportedEvictionImplException(String string, Throwable throwable)
+ {
+ super(string, throwable);
+ }
+}
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-23
07:14:18 UTC (rev 6609)
+++
core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigHelper.java 2008-08-23
12:40:58 UTC (rev 6610)
@@ -388,7 +388,7 @@
while (child != null && child.getNodeType() != Node.ELEMENT_NODE)
child = child.getNextSibling();
- return (Element)child;
+ return (Element) child;
}
/**
@@ -527,7 +527,7 @@
}
}
if (!setterFound && failOnMissingSetter)
- throw new ConfigurationException("Couldn't find a setter named
[" + setter + "] which takes a single parameter, for parameter " +
propName);
+ throw new ConfigurationException("Couldn't find a setter named
[" + setter + "] which takes a single parameter, for parameter " + propName
+ " on class [" + objectClass + "]");
}
}
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-23
07:14:18 UTC (rev 6609)
+++
core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser2x.java 2008-08-23
12:40:58 UTC (rev 6610)
@@ -8,15 +8,23 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.RegionManagerImpl;
import org.jboss.cache.buddyreplication.NextMemberBuddyLocator;
+import org.jboss.cache.config.BuddyReplicationConfig;
import org.jboss.cache.config.BuddyReplicationConfig.BuddyLocatorConfig;
+import org.jboss.cache.config.CacheLoaderConfig;
import
org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig.SingletonStoreConfig;
-import org.jboss.cache.config.*;
-import org.jboss.cache.config.parsing.element.EvictionElementParser;
+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.EvictionRegionConfig;
+import org.jboss.cache.config.MissingPolicyException;
import org.jboss.cache.eviction.EvictionAlgorithm;
+import org.jboss.cache.eviction.EvictionPolicy;
+import org.jboss.cache.eviction.ModernizablePolicy;
import org.jboss.cache.util.FileLookup;
import org.jboss.cache.util.Util;
-import org.jboss.cache.RegionManagerImpl;
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
@@ -24,8 +32,12 @@
import org.w3c.dom.NodeList;
import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import java.util.Map.Entry;
-import java.util.*;
+import java.util.Properties;
/**
* Reads in XMLconfiguration files and spits out a {@link
org.jboss.cache.config.Configuration} object. When deployed as a
@@ -331,7 +343,7 @@
}
@SuppressWarnings("unchecked")
- static EvictionConfig parseEvictionConfig(Element element)
+ public static EvictionConfig parseEvictionConfig(Element element)
{
EvictionConfig evictionConfig = new EvictionConfig();
@@ -455,17 +467,16 @@
private static EvictionAlgorithmConfig getEvictionAlgorithmConfig(String
evictionClass)
{
- if (evictionClass.indexOf("org.jboss.cache.eviction") < 0)
- {
- throw new ConfigurationException("Unsupported custom eviction policy:
" + evictionClass +
- ". Starting with 3.x the eviction API has changed, the code needs to
be manually migrated.");
- }
- String evictionAlgorithmClass = evictionClass.substring(0,evictionClass.length() -
"Policy".length()) + "Algorithm";
+ EvictionConfig.assertIsTransformable(evictionClass);
EvictionAlgorithm algorithm;
+
try
{
- algorithm = (EvictionAlgorithm)
Util.loadClass(evictionAlgorithmClass).newInstance();
+ EvictionPolicy ep = (EvictionPolicy) Util.getInstance(evictionClass);
+ Class<? extends EvictionAlgorithm> algoClass = ((ModernizablePolicy)
ep).modernizePolicy();
+ if (log.isTraceEnabled()) log.trace("Using algo class " + algoClass);
+ algorithm = Util.getInstance(algoClass);
}
catch (RuntimeException e)
{
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-23
07:14:18 UTC (rev 6609)
+++
core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizeConfiguration.java 2008-08-23
12:40:58 UTC (rev 6610)
@@ -32,7 +32,7 @@
* @deprecated see {@link org.jboss.cache.eviction.ElementSizeAlgorithmConfig}
*/
@Deprecated
-public class ElementSizeConfiguration extends EvictionPolicyConfigBase
+public class ElementSizeConfiguration extends EvictionPolicyConfigBase implements
ModernizableConfig
{
/**
* The serialVersionUID
@@ -55,8 +55,7 @@
setEvictionPolicyClass(ElementSizePolicy.class.getName());
}
- @Override
- public EvictionAlgorithmConfig modernize()
+ public EvictionAlgorithmConfig modernizeConfig()
{
ElementSizeAlgorithmConfig modernCfg = new ElementSizeAlgorithmConfig();
modernCfg.setMaxElementsPerNode(getMaxElementsPerNode());
@@ -65,6 +64,7 @@
return modernCfg;
}
+
public int getMaxElementsPerNode()
{
return maxElementsPerNode;
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-23
07:14:18 UTC (rev 6609)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizePolicy.java 2008-08-23
12:40:58 UTC (rev 6610)
@@ -12,7 +12,7 @@
* @deprecated see ElementSizeAlgorithm
*/
@Deprecated
-public class ElementSizePolicy extends BaseEvictionPolicy
+public class ElementSizePolicy extends BaseEvictionPolicy implements ModernizablePolicy
{
private ElementSizeAlgorithm algorithm;
@@ -31,4 +31,9 @@
{
return ElementSizeConfiguration.class;
}
+
+ public Class<? extends EvictionAlgorithm> modernizePolicy()
+ {
+ return ElementSizeAlgorithm.class;
+ }
}
Added: core/trunk/src/main/java/org/jboss/cache/eviction/EvictedEventNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/EvictedEventNode.java
(rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/EvictedEventNode.java 2008-08-23
12:40:58 UTC (rev 6610)
@@ -0,0 +1,27 @@
+package org.jboss.cache.eviction;
+
+import org.jboss.cache.Fqn;
+import org.jboss.cache.annotations.Compat;
+
+/**
+ * This is here for backward compat.
+ *
+ * @deprecated please use {@link org.jboss.cache.eviction.EvictionEvent} instead.
+ */
+@Deprecated
+@Compat
+public class EvictedEventNode extends EvictionEvent
+{
+ public EvictedEventNode(Fqn fqn, Type type, int elementDifference)
+ {
+ super(fqn, type, elementDifference);
+ }
+
+ public EvictedEventNode(EvictionEvent ee)
+ {
+ setElementDifference(ee.getElementDifference());
+ setEventType(ee.getEventType());
+ setFqn(ee.getFqn());
+ setInUseTimeout(ee.getInUseTimeout());
+ }
+}
Modified:
core/trunk/src/main/java/org/jboss/cache/eviction/EvictionAlgorithmConfigBase.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/eviction/EvictionAlgorithmConfigBase.java 2008-08-23
07:14:18 UTC (rev 6609)
+++
core/trunk/src/main/java/org/jboss/cache/eviction/EvictionAlgorithmConfigBase.java 2008-08-23
12:40:58 UTC (rev 6610)
@@ -1,5 +1,6 @@
package org.jboss.cache.eviction;
+import org.jboss.cache.annotations.Compat;
import org.jboss.cache.config.ConfigurationComponent;
import org.jboss.cache.config.ConfigurationException;
import org.jboss.cache.config.Dynamic;
@@ -69,6 +70,13 @@
minTimeToLive = timeUnit.toMillis(time);
}
+ @Deprecated
+ @Compat
+ public void setMinTimeToLiveSeconds(long time)
+ {
+ setMinTimeToLive(time, TimeUnit.SECONDS);
+ }
+
public void validate() throws ConfigurationException
{
if (evictionAlgorithmClassName == null)
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/EvictionEvent.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/EvictionEvent.java 2008-08-23
07:14:18 UTC (rev 6609)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/EvictionEvent.java 2008-08-23
12:40:58 UTC (rev 6610)
@@ -24,6 +24,10 @@
private long inUseTimeout;
private long creationTimestamp;
+ public EvictionEvent()
+ {
+ }
+
public static enum Type
{
ADD_NODE_EVENT,
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-23
07:14:18 UTC (rev 6609)
+++
core/trunk/src/main/java/org/jboss/cache/eviction/EvictionPolicyConfigBase.java 2008-08-23
12:40:58 UTC (rev 6610)
@@ -3,7 +3,6 @@
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;
/**
@@ -16,7 +15,7 @@
@Deprecated
public abstract class EvictionPolicyConfigBase
extends ConfigurationComponent
- implements EvictionPolicyConfig, Modernizable
+ implements EvictionPolicyConfig
{
/**
* The serialVersionUID
@@ -118,16 +117,4 @@
* 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/ExpirationAlgorithmConfig.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationAlgorithmConfig.java 2008-08-23
07:14:18 UTC (rev 6609)
+++
core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationAlgorithmConfig.java 2008-08-23
12:40:58 UTC (rev 6610)
@@ -1,5 +1,6 @@
package org.jboss.cache.eviction;
+import org.jboss.cache.annotations.Compat;
import org.jboss.cache.config.Dynamic;
import java.util.concurrent.TimeUnit;
@@ -90,6 +91,13 @@
this.timeToLive = timeUnit.toMillis(timeToLive);
}
+ @Deprecated
+ @Compat
+ public void setTimeToLiveSeconds(long time)
+ {
+ setTimeToLive(time, TimeUnit.SECONDS);
+ }
+
@Override
public ExpirationAlgorithmConfig clone() throws CloneNotSupportedException
{
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-23
07:14:18 UTC (rev 6609)
+++
core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationConfiguration.java 2008-08-23
12:40:58 UTC (rev 6610)
@@ -11,7 +11,7 @@
* @deprecated see {@link org.jboss.cache.eviction.ExpirationAlgorithmConfig}
*/
@Deprecated
-public class ExpirationConfiguration extends EvictionPolicyConfigBase
+public class ExpirationConfiguration extends EvictionPolicyConfigBase implements
ModernizableConfig
{
private static final long serialVersionUID = 47338798734219507L;
@@ -39,8 +39,7 @@
setEvictionPolicyClass(ExpirationPolicy.class.getName());
}
- @Override
- public EvictionAlgorithmConfig modernize()
+ public EvictionAlgorithmConfig modernizeConfig()
{
ExpirationAlgorithmConfig modernCfg = new ExpirationAlgorithmConfig();
modernCfg.setExpirationKeyName(getExpirationKeyName());
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-23
07:14:18 UTC (rev 6609)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationPolicy.java 2008-08-23
12:40:58 UTC (rev 6610)
@@ -9,7 +9,7 @@
* @deprecated see ExpirationAlgorithm
*/
@Deprecated
-public class ExpirationPolicy extends BaseEvictionPolicy
+public class ExpirationPolicy extends BaseEvictionPolicy implements ModernizablePolicy
{
private EvictionAlgorithm algorithm;
@@ -37,4 +37,9 @@
{
return (eventType == EvictionEventType.VISIT_NODE_EVENT);
}
+
+ public Class<? extends EvictionAlgorithm> modernizePolicy()
+ {
+ return ExpirationAlgorithm.class;
+ }
}
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-23
07:14:18 UTC (rev 6609)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/FIFOConfiguration.java 2008-08-23
12:40:58 UTC (rev 6610)
@@ -29,7 +29,7 @@
* @deprecated see {@link org.jboss.cache.eviction.FIFOAlgorithmConfig}
*/
@Deprecated
-public class FIFOConfiguration extends EvictionPolicyConfigBase
+public class FIFOConfiguration extends EvictionPolicyConfigBase implements
ModernizableConfig
{
/**
* The serialVersionUID
@@ -43,8 +43,7 @@
setMaxNodes(-1);
}
- @Override
- public EvictionAlgorithmConfig modernize()
+ public EvictionAlgorithmConfig modernizeConfig()
{
FIFOAlgorithmConfig modernCfg = new FIFOAlgorithmConfig();
modernCfg.setMaxNodes(getMaxNodes());
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-23 07:14:18
UTC (rev 6609)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/FIFOPolicy.java 2008-08-23 12:40:58
UTC (rev 6610)
@@ -16,7 +16,7 @@
* @deprecated see FIFOAlgorithm
*/
@Deprecated
-public class FIFOPolicy extends BaseEvictionPolicy
+public class FIFOPolicy extends BaseEvictionPolicy implements ModernizablePolicy
{
private FIFOAlgorithm algorithm;
@@ -35,4 +35,9 @@
{
return FIFOConfiguration.class;
}
+
+ public Class<? extends EvictionAlgorithm> modernizePolicy()
+ {
+ return FIFOAlgorithm.class;
+ }
}
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-23
07:14:18 UTC (rev 6609)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/LFUConfiguration.java 2008-08-23
12:40:58 UTC (rev 6610)
@@ -28,7 +28,7 @@
* @deprecated see {@link org.jboss.cache.eviction.LFUAlgorithmConfig}
*/
@Deprecated
-public class LFUConfiguration extends EvictionPolicyConfigBase
+public class LFUConfiguration extends EvictionPolicyConfigBase implements
ModernizableConfig
{
/**
* The serialVersionUID
@@ -55,8 +55,7 @@
this.minNodes = minNodes;
}
- @Override
- public EvictionAlgorithmConfig modernize()
+ public EvictionAlgorithmConfig modernizeConfig()
{
LFUAlgorithmConfig modernCfg = new LFUAlgorithmConfig();
modernCfg.setMaxNodes(getMaxNodes());
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-23 07:14:18
UTC (rev 6609)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/LFUPolicy.java 2008-08-23 12:40:58
UTC (rev 6610)
@@ -14,7 +14,7 @@
* @deprecated see LFUAlgorithm
*/
@Deprecated
-public class LFUPolicy extends BaseEvictionPolicy
+public class LFUPolicy extends BaseEvictionPolicy implements ModernizablePolicy
{
private LFUAlgorithm algorithm;
@@ -33,4 +33,9 @@
{
return LFUConfiguration.class;
}
+
+ public Class<? extends EvictionAlgorithm> modernizePolicy()
+ {
+ return LFUAlgorithm.class;
+ }
}
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/LRUAlgorithmConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/LRUAlgorithmConfig.java 2008-08-23
07:14:18 UTC (rev 6609)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/LRUAlgorithmConfig.java 2008-08-23
12:40:58 UTC (rev 6610)
@@ -6,6 +6,7 @@
*/
package org.jboss.cache.eviction;
+import org.jboss.cache.annotations.Compat;
import org.jboss.cache.config.ConfigurationException;
import org.jboss.cache.config.Dynamic;
@@ -83,6 +84,13 @@
this.timeToLive = timeUnit.toMillis(timeToLive);
}
+ @Deprecated
+ @Compat
+ public void setTimeToLiveSeconds(long time)
+ {
+ setTimeToLive(time, TimeUnit.SECONDS);
+ }
+
/**
* @return the max age per element, in milliseconds
*/
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-23
07:14:18 UTC (rev 6609)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/LRUConfiguration.java 2008-08-23
12:40:58 UTC (rev 6610)
@@ -30,7 +30,7 @@
* @deprecated see {@link org.jboss.cache.eviction.LRUAlgorithmConfig}
*/
@Deprecated
-public class LRUConfiguration extends EvictionPolicyConfigBase
+public class LRUConfiguration extends EvictionPolicyConfigBase implements
ModernizableConfig
{
/**
* The serialVersionUID
@@ -49,8 +49,7 @@
setTimeToLiveSeconds(-1);
}
- @Override
- public EvictionAlgorithmConfig modernize()
+ public EvictionAlgorithmConfig modernizeConfig()
{
LRUAlgorithmConfig modernCfg = new LRUAlgorithmConfig();
modernCfg.setMaxNodes(getMaxNodes());
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-23 07:14:18
UTC (rev 6609)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/LRUPolicy.java 2008-08-23 12:40:58
UTC (rev 6610)
@@ -20,7 +20,7 @@
* @deprecated see LRUAlgorithm
*/
@Deprecated
-public class LRUPolicy extends BaseEvictionPolicy
+public class LRUPolicy extends BaseEvictionPolicy implements ModernizablePolicy
{
protected RegionManager regionManager_;
@@ -48,4 +48,9 @@
super.setCache(cache);
regionManager_ = cache_.getRegionManager();
}
+
+ public Class<? extends EvictionAlgorithm> modernizePolicy()
+ {
+ return LRUAlgorithm.class;
+ }
}
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-23
07:14:18 UTC (rev 6609)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/MRUConfiguration.java 2008-08-23
12:40:58 UTC (rev 6610)
@@ -29,7 +29,7 @@
* @deprecated see {@link org.jboss.cache.eviction.MRUAlgorithmConfig}
*/
@Deprecated
-public class MRUConfiguration extends EvictionPolicyConfigBase
+public class MRUConfiguration extends EvictionPolicyConfigBase implements
ModernizableConfig
{
/**
* The serialVersionUID
@@ -49,8 +49,7 @@
setEvictionPolicyClass(MRUPolicy.class.getName());
}
- @Override
- public EvictionAlgorithmConfig modernize()
+ public EvictionAlgorithmConfig modernizeConfig()
{
MRUAlgorithmConfig modernCfg = new MRUAlgorithmConfig();
modernCfg.setMaxNodes(getMaxNodes());
@@ -58,7 +57,6 @@
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-23 07:14:18
UTC (rev 6609)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/MRUPolicy.java 2008-08-23 12:40:58
UTC (rev 6610)
@@ -16,7 +16,7 @@
* @deprecated see MRUAlgorithm
*/
@Deprecated
-public class MRUPolicy extends BaseEvictionPolicy
+public class MRUPolicy extends BaseEvictionPolicy implements ModernizablePolicy
{
private MRUAlgorithm algorithm;
@@ -36,4 +36,9 @@
{
return MRUConfiguration.class;
}
+
+ public Class<? extends EvictionAlgorithm> modernizePolicy()
+ {
+ return MRUAlgorithm.class;
+ }
}
Copied: core/trunk/src/main/java/org/jboss/cache/eviction/ModernizableConfig.java (from
rev 6597, core/trunk/src/main/java/org/jboss/cache/eviction/Modernizable.java)
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/ModernizableConfig.java
(rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/ModernizableConfig.java 2008-08-23
12:40:58 UTC (rev 6610)
@@ -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 ModernizableConfig
+{
+ EvictionAlgorithmConfig modernizeConfig();
+}
Added: core/trunk/src/main/java/org/jboss/cache/eviction/ModernizablePolicy.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/ModernizablePolicy.java
(rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/ModernizablePolicy.java 2008-08-23
12:40:58 UTC (rev 6610)
@@ -0,0 +1,15 @@
+package org.jboss.cache.eviction;
+
+/**
+ * Attached to deprecated eviction policies 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 ModernizablePolicy
+{
+ Class<? extends EvictionAlgorithm> modernizePolicy();
+}
\ No newline at end of file
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-23
07:14:18 UTC (rev 6609)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/NullEvictionPolicy.java 2008-08-23
12:40:58 UTC (rev 6610)
@@ -21,7 +21,7 @@
* @deprecated see NullEvictionAlgorithm
*/
@Deprecated
-public class NullEvictionPolicy implements EvictionPolicy
+public class NullEvictionPolicy implements EvictionPolicy, ModernizablePolicy
{
private static final Log log = LogFactory.getLog(NullEvictionPolicy.class);
@@ -69,4 +69,8 @@
this.cache = cache;
}
+ public Class<? extends EvictionAlgorithm> modernizePolicy()
+ {
+ return NullEvictionAlgorithm.class;
+ }
}
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-23
07:14:18 UTC (rev 6609)
+++
core/trunk/src/main/java/org/jboss/cache/eviction/NullEvictionPolicyConfig.java 2008-08-23
12:40:58 UTC (rev 6610)
@@ -17,7 +17,7 @@
@Deprecated
public class NullEvictionPolicyConfig
extends ConfigurationComponent
- implements EvictionPolicyConfig, Modernizable
+ implements EvictionPolicyConfig, ModernizableConfig
{
private static final long serialVersionUID = -6591180473728241737L;
@@ -30,7 +30,7 @@
return NullEvictionPolicy.class.getName();
}
- public EvictionAlgorithmConfig modernize()
+ public EvictionAlgorithmConfig modernizeConfig()
{
return new NullEvictionAlgorithmConfig();
}
Added: core/trunk/src/main/java/org/jboss/cache/factories/CacheConfigsXmlParser.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/CacheConfigsXmlParser.java
(rev 0)
+++
core/trunk/src/main/java/org/jboss/cache/factories/CacheConfigsXmlParser.java 2008-08-23
12:40:58 UTC (rev 6610)
@@ -0,0 +1,14 @@
+package org.jboss.cache.factories;
+
+import org.jboss.cache.annotations.Compat;
+
+/**
+ * @author Manik Surtani (<a
href="mailto:manik@jboss.org">manik@jboss.org</a>)
+ * @since 3.0
+ * @deprecated here for compatibility reasons. Use the class with the same name in the
<tt>org.jboss.cache.config.parsing</tt> package.
+ */
+@Compat
+@Deprecated
+public class CacheConfigsXmlParser extends
org.jboss.cache.config.parsing.CacheConfigsXmlParser
+{
+}
Added:
core/trunk/src/test/java/org/jboss/cache/eviction/legacy/BackwardCompatibilityTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/eviction/legacy/BackwardCompatibilityTest.java
(rev 0)
+++
core/trunk/src/test/java/org/jboss/cache/eviction/legacy/BackwardCompatibilityTest.java 2008-08-23
12:40:58 UTC (rev 6610)
@@ -0,0 +1,257 @@
+package org.jboss.cache.eviction.legacy;
+
+import org.jboss.cache.Cache;
+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.EvictionPolicyConfig;
+import org.jboss.cache.config.EvictionRegionConfig;
+import org.jboss.cache.config.UnsupportedEvictionImplException;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
+import org.jboss.cache.config.parsing.XmlConfigurationParser;
+import org.jboss.cache.config.parsing.XmlConfigurationParser2x;
+import org.jboss.cache.eviction.BaseEvictionPolicy;
+import org.jboss.cache.eviction.DefaultEvictionActionPolicy;
+import org.jboss.cache.eviction.EvictionAlgorithm;
+import org.jboss.cache.eviction.EvictionPolicyConfigBase;
+import org.jboss.cache.eviction.FIFOAlgorithm;
+import org.jboss.cache.eviction.FIFOAlgorithmConfig;
+import org.jboss.cache.eviction.FIFOConfiguration;
+import org.jboss.cache.eviction.FIFOPolicy;
+import org.jboss.cache.util.TestingUtil;
+import org.jboss.cache.util.internals.EvictionController;
+import org.testng.annotations.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Test(groups = "functional", sequential = false)
+public class BackwardCompatibilityTest
+{
+
+ private EvictionRegionConfig createEvictionRegionConfig(String regionName, int
maxNodes, EvictionPolicyConfigBase cfg)
+ {
+ EvictionRegionConfig ercDefault = new EvictionRegionConfig();
+ ercDefault.setRegionName(regionName);
+ if (maxNodes >= 0) cfg.setMaxNodes(maxNodes);
+ ercDefault.setEvictionPolicyConfig(cfg);
+ return ercDefault;
+ }
+
+
+ public void testUsingEvictionPolicy()
+ {
+ Configuration c = new Configuration();
+ c.setEvictionConfig(new EvictionConfig());
+ EvictionConfig evConfig = c.getEvictionConfig();
+ evConfig.setWakeupIntervalSeconds(3);
+ evConfig.setDefaultEventQueueSize(20000);
+ evConfig.setDefaultEvictionPolicyClass(FIFOPolicy.class.getName());
+ List<EvictionRegionConfig> erConfigs = new
ArrayList<EvictionRegionConfig>();
+ erConfigs.add(createEvictionRegionConfig("/_default_", 2, new
FIFOConfiguration()));
+ evConfig.setEvictionRegionConfigs(erConfigs);
+ doTest(c);
+ }
+
+ public void testUsingEvictionPolicyXml() throws Exception
+ {
+ String xml = "<attribute
name=\"EvictionPolicyConfig\">\n" +
+ " <config>\n" +
+ " <attribute
name=\"wakeUpIntervalSeconds\">2</attribute>\n" +
+ " <!-- Name of the DEFAULT eviction policy class.
-->\n" +
+ " <attribute
name=\"policyClass\">org.jboss.cache.eviction.FIFOPolicy</attribute>\n"
+
+ "\n" +
+ " <!-- Cache wide default -->\n" +
+ " <region name=\"/_default_\">\n" +
+ " <attribute
name=\"maxNodes\">2</attribute>\n" +
+ " </region>\n" +
+ " </config>\n" +
+ " </attribute>";
+
+ doTest(xml, true);
+ }
+
+ public void testUsingCustomEvictionPolicy()
+ {
+ try
+ {
+ Configuration c = new Configuration();
+ c.setEvictionConfig(new EvictionConfig());
+ EvictionConfig evConfig = c.getEvictionConfig();
+ evConfig.setWakeupIntervalSeconds(3);
+ evConfig.setDefaultEventQueueSize(20000);
+ evConfig.setDefaultEvictionPolicyClass(MyPolicy.class.getName());
+ List<EvictionRegionConfig> erConfigs = new
ArrayList<EvictionRegionConfig>();
+ erConfigs.add(createEvictionRegionConfig("/_default_", 2, new
MyPolicyConfig()));
+ evConfig.setEvictionRegionConfigs(erConfigs);
+ doTest(c);
+ assert false : "Should throw exception";
+ }
+ catch (UnsupportedEvictionImplException ce)
+ {
+ // expected
+ }
+ }
+
+ public void testUsingCustomEvictionPolicyXml() throws Exception
+ {
+ String xml = "<attribute
name=\"EvictionPolicyConfig\">\n" +
+ " <config>\n" +
+ " <attribute
name=\"wakeUpIntervalSeconds\">2</attribute>\n" +
+ " <!-- Name of the DEFAULT eviction policy class.
-->\n" +
+ " <attribute name=\"policyClass\">" +
MyPolicy.class.getName() + "</attribute>\n" +
+ "\n" +
+ " <!-- Cache wide default -->\n" +
+ " <region name=\"/_default_\">\n" +
+ " <attribute
name=\"maxNodes\">2</attribute>\n" +
+ " </region>\n" +
+ " </config>\n" +
+ " </attribute>";
+
+ try
+ {
+ doTest(xml, true);
+ assert false : "Should throw exception";
+ }
+ catch (UnsupportedEvictionImplException ce)
+ {
+ // expected
+ }
+ }
+
+ public void testUsingCustomEvictionPolicyNonDefault()
+ {
+ try
+ {
+ Configuration c = new Configuration();
+ c.setEvictionConfig(new EvictionConfig());
+ EvictionConfig evConfig = c.getEvictionConfig();
+ evConfig.setWakeupIntervalSeconds(3);
+ evConfig.setDefaultEventQueueSize(20000);
+ evConfig.setDefaultEvictionPolicyClass(FIFOPolicy.class.getName());
+ List<EvictionRegionConfig> erConfigs = new
ArrayList<EvictionRegionConfig>();
+ erConfigs.add(createEvictionRegionConfig("/_default_", 2, new
FIFOConfiguration()));
+ erConfigs.add(createEvictionRegionConfig("/a/b/c", 2, new
MyPolicyConfig()));
+ evConfig.setEvictionRegionConfigs(erConfigs);
+ doTest(c);
+ assert false : "Should throw exception";
+ }
+ catch (UnsupportedEvictionImplException ce)
+ {
+ // expected
+ }
+ }
+
+ public void testUsingCustomEvictionPolicyNonDefaultXml() throws Exception
+ {
+ String xml = "<attribute
name=\"EvictionPolicyConfig\">\n" +
+ " <config>\n" +
+ " <attribute
name=\"wakeUpIntervalSeconds\">2</attribute>\n" +
+ " <!-- Name of the DEFAULT eviction policy class.
-->\n" +
+ " <attribute name=\"policyClass\">" +
FIFOPolicy.class.getName() + "</attribute>\n" +
+ "\n" +
+ " <!-- Cache wide default -->\n" +
+ " <region name=\"/_default_\">\n" +
+ " <attribute
name=\"maxNodes\">2</attribute>\n" +
+ " </region>\n" +
+ " <region name=\"/a/b/c\"
policyClass=\"" + MyPolicy.class.getName() + "\">" +
+ " <attribute
name=\"maxNodes\">2</attribute>\n" +
+ " </region>\n" +
+ " </config>\n" +
+ " </attribute>";
+
+ try
+ {
+ doTest(xml, true);
+ assert false : "Should throw exception";
+ }
+ catch (UnsupportedEvictionImplException ce)
+ {
+ // expected
+ }
+ }
+
+ public void testControl()
+ {
+ Configuration c = new Configuration();
+ c.setEvictionConfig(new EvictionConfig());
+ EvictionRegionConfig defaultRegion =
c.getEvictionConfig().getDefaultEvictionRegionConfig();
+ defaultRegion.setEvictionAlgorithmConfig(new FIFOAlgorithmConfig(2));
+ doTest(c);
+ }
+
+ public void testControlXml() throws Exception
+ {
+ String xml = "<jbosscache><eviction
wakeUpInterval=\"6\">" +
+ "<default algorithmClass=\"" +
FIFOAlgorithm.class.getName() + "\">" +
+ "<attribute name=\"maxNodes\">2</attribute>"
+
+ "</default>" +
+ "</eviction></jbosscache>";
+ doTest(xml, false);
+ }
+
+ private void doTest(String xml, boolean legacy) throws Exception
+ {
+ if (legacy)
+ {
+ EvictionConfig ec =
XmlConfigurationParser2x.parseEvictionConfig(XmlConfigHelper.stringToElementInCoreNS(xml));
+ Configuration c = new Configuration();
+ c.setEvictionConfig(ec);
+ doTest(c);
+ }
+ else
+ {
+ doTest(new
XmlConfigurationParser().parseElement(XmlConfigHelper.stringToElementInCoreNS(xml)));
+ }
+ }
+
+ private void doTest(Configuration c)
+ {
+ Cache cache = null;
+ try
+ {
+ cache = new DefaultCacheFactory().createCache(c);
+
+ EvictionRegionConfig erc = cache.getRegion(Fqn.ROOT,
false).getEvictionRegionConfig();
+ assert erc.getEvictionAlgorithmConfig() instanceof FIFOAlgorithmConfig;
+ assert
erc.getEvictionActionPolicyClassName().equals(DefaultEvictionActionPolicy.class.getName());
+
+ cache.put("/a/b/1", "a", "b");
+ cache.put("/a/b/2", "a", "b");
+ cache.put("/a/b/3", "a", "b");
+
+ new EvictionController(cache).startEviction();
+
+ assert cache.getNode("/a/b/1") == null;
+ assert cache.getNode("/a/b/2") != null;
+ assert cache.getNode("/a/b/3") != null;
+ }
+ finally
+ {
+ TestingUtil.killCaches(cache);
+ }
+ }
+
+ public static class MyPolicy extends BaseEvictionPolicy
+ {
+ public EvictionAlgorithm getEvictionAlgorithm()
+ {
+ return null;
+ }
+
+ public Class<? extends EvictionPolicyConfig> getEvictionConfigurationClass()
+ {
+ return null;
+ }
+ }
+
+ public class MyPolicyConfig extends EvictionPolicyConfigBase
+ {
+
+ protected void setEvictionPolicyClassName()
+ {
+ this.setEvictionPolicyClass(MyPolicy.class.getName());
+ }
+ }
+}