You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by tv...@apache.org on 2014/05/02 16:17:39 UTC
svn commit: r1591925 [1/2] - in
/commons/proper/jcs/trunk/commons-jcs-core/src:
main/java/org/apache/commons/jcs/auxiliary/disk/
main/java/org/apache/commons/jcs/auxiliary/lateral/
main/java/org/apache/commons/jcs/auxiliary/lateral/socket/tcp/ main/jav...
Author: tv
Date: Fri May 2 14:17:38 2014
New Revision: 1591925
URL: http://svn.apache.org/r1591925
Log:
Simplify event handling, general cleanup
Modified:
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/disk/PurgatoryElement.java
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/lateral/LateralCacheAbstractManager.java
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/lateral/socket/tcp/LateralTCPCacheFactory.java
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/CacheElement.java
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/CacheElementSerialized.java
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/ElementAttributes.java
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/behavior/IElementAttributes.java
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCache.java
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCacheConfigurator.java
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCacheManager.java
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/event/ElementEventQueue.java
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/event/behavior/IElementEventHandler.java
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/event/behavior/IElementEventQueue.java
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/memory/AbstractMemoryCache.java
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/memory/shrinking/ShrinkerThread.java
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryManager.java
commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/remote/server/BasicRemoteCacheClientServerUnitTest.java
commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/engine/control/CompositeCacheDiskUsageUnitTest.java
commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/engine/control/CompositeCacheUnitTest.java
commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/engine/control/MockCompositeCacheManager.java
commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/engine/memory/fifo/FIFOMemoryCacheUnitTest.java
commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/engine/memory/shrinking/ShrinkerThreadUnitTest.java
Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/disk/PurgatoryElement.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/disk/PurgatoryElement.java?rev=1591925&r1=1591924&r2=1591925&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/disk/PurgatoryElement.java (original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/disk/PurgatoryElement.java Fri May 2 14:17:38 2014
@@ -21,17 +21,19 @@ package org.apache.commons.jcs.auxiliary
import java.io.Serializable;
+import org.apache.commons.jcs.engine.CacheElement;
import org.apache.commons.jcs.engine.behavior.ICacheElement;
import org.apache.commons.jcs.engine.behavior.IElementAttributes;
/**
- * Wrapper for cache elements in purgatory.
+ * Implementation of cache elements in purgatory.
* <p>
- * Elements are stored in purgatory when they are spooled to the auxilliary cache, but have not yet
+ * Elements are stored in purgatory when they are spooled to the auxiliary cache, but have not yet
* been written to disk.
*/
public class PurgatoryElement<K extends Serializable, V extends Serializable>
- implements ICacheElement<K, V>, Serializable
+ extends CacheElement<K, V>
+ implements ICacheElement<K, V>
{
/** Don't change */
private static final long serialVersionUID = -8152034342684135628L;
@@ -45,10 +47,13 @@ public class PurgatoryElement<K extends
/**
* Constructor for the PurgatoryElement<K, V> object
* <p>
- * @param cacheElement CacheElement to wrap.
+ * @param cacheElement CacheElement
*/
public PurgatoryElement( ICacheElement<K, V> cacheElement )
{
+ super(cacheElement.getCacheName(),
+ cacheElement.getKey(), cacheElement.getVal(),
+ cacheElement.getElementAttributes());
this.cacheElement = cacheElement;
}
Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/lateral/LateralCacheAbstractManager.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/lateral/LateralCacheAbstractManager.java?rev=1591925&r1=1591924&r2=1591925&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/lateral/LateralCacheAbstractManager.java (original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/lateral/LateralCacheAbstractManager.java Fri May 2 14:17:38 2014
@@ -30,9 +30,7 @@ import org.apache.commons.jcs.auxiliary.
import org.apache.commons.jcs.auxiliary.lateral.behavior.ILateralCacheManager;
import org.apache.commons.jcs.auxiliary.lateral.behavior.ILateralCacheObserver;
import org.apache.commons.jcs.engine.behavior.ICacheServiceNonLocal;
-import org.apache.commons.jcs.engine.behavior.IElementSerializer;
import org.apache.commons.jcs.engine.behavior.IShutdownObserver;
-import org.apache.commons.jcs.engine.logging.behavior.ICacheEventLogger;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -71,12 +69,6 @@ public abstract class LateralCacheAbstra
*/
private LateralCacheWatchRepairable lateralWatch;
- /** The event logger. */
- private ICacheEventLogger cacheEventLogger;
-
- /** The serializer. */
- private IElementSerializer elementSerializer;
-
/**
* Adds the lateral cache listener to the underlying cache-watch service.
*
Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/lateral/socket/tcp/LateralTCPCacheFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/lateral/socket/tcp/LateralTCPCacheFactory.java?rev=1591925&r1=1591924&r2=1591925&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/lateral/socket/tcp/LateralTCPCacheFactory.java (original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/lateral/socket/tcp/LateralTCPCacheFactory.java Fri May 2 14:17:38 2014
@@ -34,7 +34,6 @@ import org.apache.commons.jcs.auxiliary.
import org.apache.commons.jcs.engine.behavior.ICache;
import org.apache.commons.jcs.engine.behavior.ICompositeCacheManager;
import org.apache.commons.jcs.engine.behavior.IElementSerializer;
-import org.apache.commons.jcs.engine.behavior.IShutdownObservable;
import org.apache.commons.jcs.engine.behavior.IShutdownObserver;
import org.apache.commons.jcs.engine.logging.behavior.ICacheEventLogger;
import org.apache.commons.jcs.utils.discovery.UDPDiscoveryManager;
@@ -98,10 +97,7 @@ public class LateralTCPCacheFactory
elementSerializer );
// register for shutdown notification
- if (cacheMgr instanceof IShutdownObservable )
- {
- ( (IShutdownObservable) cacheMgr ).registerShutdownObserver( lcm );
- }
+ cacheMgr.registerShutdownObserver( lcm );
ICache<K, V> ic = lcm.getCache( lacC.getCacheName() );
noWaits.add( ic );
@@ -154,9 +150,9 @@ public class LateralTCPCacheFactory
listener = LateralTCPListener.getInstance( attr, cacheMgr );
// register for shutdown notification
- if ( listener instanceof IShutdownObserver && cacheMgr instanceof IShutdownObservable )
+ if ( listener instanceof IShutdownObserver )
{
- ( (IShutdownObservable) cacheMgr ).registerShutdownObserver( (IShutdownObserver) listener );
+ cacheMgr.registerShutdownObserver( (IShutdownObserver) listener );
}
}
catch ( Exception e )
Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/CacheElement.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/CacheElement.java?rev=1591925&r1=1591924&r2=1591925&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/CacheElement.java (original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/CacheElement.java Fri May 2 14:17:38 2014
@@ -28,25 +28,25 @@ import org.apache.commons.jcs.engine.beh
* Generic element wrapper. Often stuffed inside another.
*/
public class CacheElement<K extends Serializable, V extends Serializable>
- implements ICacheElement<K, V>, Serializable
+ implements ICacheElement<K, V>
{
/** Don't change */
private static final long serialVersionUID = -6062305728297627263L;
/** The name of the cache region. This is a namespace. */
- public final String cacheName;
+ private final String cacheName;
/** This is the cache key by which the value can be referenced. */
- public final K key;
+ private final K key;
/** This is the cached value, reference by the key. */
- public final V val;
+ private final V val;
/**
* These attributes hold information about the element and what it is
* allowed to do.
*/
- public IElementAttributes attr;
+ private IElementAttributes attr;
/**
* Constructor for the CacheElement object
Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/CacheElementSerialized.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/CacheElementSerialized.java?rev=1591925&r1=1591924&r2=1591925&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/CacheElementSerialized.java (original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/CacheElementSerialized.java Fri May 2 14:17:38 2014
@@ -27,26 +27,16 @@ import org.apache.commons.jcs.engine.beh
/** Either serialized value or the value should be null; */
public class CacheElementSerialized<K extends Serializable, V extends Serializable>
+ extends CacheElement<K, V>
implements ICacheElementSerialized<K, V>
{
/** Don't change. */
private static final long serialVersionUID = -7265084818647601874L;
- /** The name of the cache region. This is a namespace. */
- private final String cacheName;
-
- /** This is the cache key by which the value can be referenced. */
- private final K key;
-
/** The serialized value. */
private final byte[] serializedValue;
/**
- * These attributes hold information about the element and what it is allowed to do.
- */
- private IElementAttributes elementAttributes;
-
- /**
* Constructs a usable wrapper.
* <p>
* @param cacheNameArg
@@ -57,28 +47,8 @@ public class CacheElementSerialized<K ex
public CacheElementSerialized( String cacheNameArg, K keyArg, byte[] serializedValueArg,
IElementAttributes elementAttributesArg )
{
- this.cacheName = cacheNameArg;
- this.key = keyArg;
+ super(cacheNameArg, keyArg, null, elementAttributesArg);
this.serializedValue = serializedValueArg;
- this.elementAttributes = elementAttributesArg;
- }
-
- /**
- * Returns the name of the cache. This is the name of the region.
- * <p>
- * @return this.cacheName;
- */
- @Override
- public String getCacheName()
- {
- return this.cacheName;
- }
-
- /** @return Serializable */
- @Override
- public K getKey()
- {
- return this.key;
}
/** @return byte[] */
@@ -88,33 +58,6 @@ public class CacheElementSerialized<K ex
return this.serializedValue;
}
- /** @return IElementAttributes */
- @Override
- public IElementAttributes getElementAttributes()
- {
- return this.elementAttributes;
- }
-
- /**
- * @param attr
- */
- @Override
- public void setElementAttributes( IElementAttributes attr )
- {
- this.elementAttributes = attr;
- }
-
- /**
- * Backward compatibility.
- * <p>
- * @return Serializable
- */
- @Override
- public V getVal()
- {
- return null;
- }
-
/**
* For debugging only.
* <p>
Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/ElementAttributes.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/ElementAttributes.java?rev=1591925&r1=1591924&r2=1591925&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/ElementAttributes.java (original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/ElementAttributes.java Fri May 2 14:17:38 2014
@@ -21,6 +21,7 @@ package org.apache.commons.jcs.engine;
import java.io.Serializable;
import java.util.ArrayList;
+import java.util.List;
import org.apache.commons.jcs.engine.behavior.IElementAttributes;
import org.apache.commons.jcs.engine.control.event.behavior.IElementEventHandler;
@@ -403,7 +404,7 @@ public class ElementAttributes
* @param eventHandlers List of IElementEventHandler objects
*/
@Override
- public void addElementEventHandlers( ArrayList<IElementEventHandler> eventHandlers )
+ public void addElementEventHandlers( List<IElementEventHandler> eventHandlers )
{
if ( eventHandlers == null )
{
Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/behavior/IElementAttributes.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/behavior/IElementAttributes.java?rev=1591925&r1=1591924&r2=1591925&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/behavior/IElementAttributes.java (original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/behavior/IElementAttributes.java Fri May 2 14:17:38 2014
@@ -20,6 +20,7 @@ package org.apache.commons.jcs.engine.be
*/
import java.util.ArrayList;
+import java.util.List;
import org.apache.commons.jcs.engine.control.event.behavior.IElementEventHandler;
@@ -194,6 +195,6 @@ public interface IElementAttributes
* Sets the eventHandlers of the IElementAttributes object
* @param eventHandlers value
*/
- void addElementEventHandlers( ArrayList<IElementEventHandler> eventHandlers );
+ void addElementEventHandlers( List<IElementEventHandler> eventHandlers );
}
Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCache.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCache.java?rev=1591925&r1=1591924&r2=1591925&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCache.java (original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCache.java Fri May 2 14:17:38 2014
@@ -27,6 +27,8 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
import org.apache.commons.jcs.access.exception.CacheException;
import org.apache.commons.jcs.access.exception.ObjectNotFoundException;
@@ -38,8 +40,8 @@ import org.apache.commons.jcs.engine.beh
import org.apache.commons.jcs.engine.behavior.ICompositeCacheAttributes;
import org.apache.commons.jcs.engine.behavior.ICompositeCacheAttributes.DiskUsagePattern;
import org.apache.commons.jcs.engine.behavior.IElementAttributes;
+import org.apache.commons.jcs.engine.behavior.IRequireScheduler;
import org.apache.commons.jcs.engine.control.event.ElementEvent;
-import org.apache.commons.jcs.engine.control.event.ElementEventQueue;
import org.apache.commons.jcs.engine.control.event.behavior.ElementEventType;
import org.apache.commons.jcs.engine.control.event.behavior.IElementEvent;
import org.apache.commons.jcs.engine.control.event.behavior.IElementEventHandler;
@@ -49,6 +51,7 @@ import org.apache.commons.jcs.engine.mat
import org.apache.commons.jcs.engine.match.behavior.IKeyMatcher;
import org.apache.commons.jcs.engine.memory.behavior.IMemoryCache;
import org.apache.commons.jcs.engine.memory.lru.LRUMemoryCache;
+import org.apache.commons.jcs.engine.memory.shrinking.ShrinkerThread;
import org.apache.commons.jcs.engine.stats.CacheStats;
import org.apache.commons.jcs.engine.stats.StatElement;
import org.apache.commons.jcs.engine.stats.Stats;
@@ -65,11 +68,8 @@ import org.apache.commons.logging.LogFac
* This is the core of a JCS region. Hence, this simple class is the core of JCS.
*/
public class CompositeCache<K extends Serializable, V extends Serializable>
- implements ICache<K, V>, Serializable
+ implements ICache<K, V>, IRequireScheduler
{
- /** For serialization. Don't change. */
- private static final long serialVersionUID = -2838097410378294960L;
-
/** log instance */
private static final Log log = LogFactory.getLog( CompositeCache.class );
@@ -86,9 +86,6 @@ public class CompositeCache<K extends Se
/** is this alive? */
private boolean alive = true;
- /** TODO - this is in the cacheAttr, shouldn't be used, remove */
- final String cacheName;
-
/** Region Elemental Attributes, default. */
private IElementAttributes attr;
@@ -125,13 +122,11 @@ public class CompositeCache<K extends Se
/**
* Constructor for the Cache object
* <p>
- * @param cacheName The name of the region
* @param cattr The cache attribute
* @param attr The default element attributes
*/
- public CompositeCache( String cacheName, ICompositeCacheAttributes cattr, IElementAttributes attr )
+ public CompositeCache( ICompositeCacheAttributes cattr, IElementAttributes attr )
{
- this.cacheName = cacheName;
this.attr = attr;
this.cacheAttr = cattr;
@@ -139,7 +134,31 @@ public class CompositeCache<K extends Se
if ( log.isInfoEnabled() )
{
- log.info( "Constructed cache with name [" + cacheName + "] and cache attributes " + cattr );
+ log.info( "Constructed cache with name [" + cacheAttr.getCacheName() + "] and cache attributes " + cattr );
+ }
+ }
+
+ /**
+ * Injector for Element event queue
+ *
+ * @param queue
+ */
+ public void setElementEventQueue( IElementEventQueue queue )
+ {
+ this.elementEventQ = queue;
+ }
+
+ /**
+ * @see org.apache.commons.jcs.engine.behavior.IRequireScheduler#setScheduledExecutorService(java.util.concurrent.ScheduledExecutorService)
+ */
+ @Override
+ public void setScheduledExecutorService(ScheduledExecutorService scheduledExecutor)
+ {
+ if ( cacheAttr.isUseMemoryShrinker() )
+ {
+ scheduledExecutor.scheduleAtFixedRate(
+ new ShrinkerThread<K, V>(this), 0, cacheAttr.getShrinkerIntervalSeconds(),
+ TimeUnit.SECONDS);
}
}
@@ -485,7 +504,7 @@ public class CompositeCache<K extends Se
{
if ( log.isDebugEnabled() )
{
- log.debug( cacheName + " - Memory cache hit, but element expired" );
+ log.debug( cacheAttr.getCacheName() + " - Memory cache hit, but element expired" );
}
missCountExpired++;
@@ -498,7 +517,7 @@ public class CompositeCache<K extends Se
{
if ( log.isDebugEnabled() )
{
- log.debug( cacheName + " - Memory cache hit" );
+ log.debug( cacheAttr.getCacheName() + " - Memory cache hit" );
}
// Update counters
@@ -550,7 +569,7 @@ public class CompositeCache<K extends Se
{
if ( log.isDebugEnabled() )
{
- log.debug( cacheName + " - Aux cache[" + i + "] hit, but element expired." );
+ log.debug( cacheAttr.getCacheName() + " - Aux cache[" + i + "] hit, but element expired." );
}
missCountExpired++;
@@ -567,7 +586,7 @@ public class CompositeCache<K extends Se
{
if ( log.isDebugEnabled() )
{
- log.debug( cacheName + " - Aux cache[" + i + "] hit" );
+ log.debug( cacheAttr.getCacheName() + " - Aux cache[" + i + "] hit" );
}
// Update counters
@@ -595,7 +614,7 @@ public class CompositeCache<K extends Se
if ( log.isDebugEnabled() )
{
- log.debug( cacheName + " - Miss" );
+ log.debug( cacheAttr.getCacheName() + " - Miss" );
}
}
@@ -678,7 +697,7 @@ public class CompositeCache<K extends Se
if ( log.isDebugEnabled() )
{
- log.debug( cacheName + " - " + ( keys.size() - elements.size() ) + " Misses" );
+ log.debug( cacheAttr.getCacheName() + " - " + ( keys.size() - elements.size() ) + " Misses" );
}
}
@@ -710,7 +729,7 @@ public class CompositeCache<K extends Se
{
if ( log.isDebugEnabled() )
{
- log.debug( cacheName + " - Memory cache hit, but element expired" );
+ log.debug( cacheAttr.getCacheName() + " - Memory cache hit, but element expired" );
}
missCountExpired++;
@@ -722,7 +741,7 @@ public class CompositeCache<K extends Se
{
if ( log.isDebugEnabled() )
{
- log.debug( cacheName + " - Memory cache hit" );
+ log.debug( cacheAttr.getCacheName() + " - Memory cache hit" );
}
// Update counters
@@ -968,7 +987,7 @@ public class CompositeCache<K extends Se
{
if ( log.isDebugEnabled() )
{
- log.debug( cacheName + " - Aux cache[" + i + "] hit, but element expired." );
+ log.debug( cacheAttr.getCacheName() + " - Aux cache[" + i + "] hit, but element expired." );
}
missCountExpired++;
@@ -984,7 +1003,7 @@ public class CompositeCache<K extends Se
{
if ( log.isDebugEnabled() )
{
- log.debug( cacheName + " - Aux cache[" + i + "] hit" );
+ log.debug( cacheAttr.getCacheName() + " - Aux cache[" + i + "] hit" );
}
// Update counters
@@ -1039,69 +1058,6 @@ public class CompositeCache<K extends Se
}
/**
- * Determine if the element has exceeded its max life.
- * <p>
- * @param element
- * @return true if the element is expired, else false.
- */
- protected boolean isExpired( ICacheElement<K, V> element )
- {
- try
- {
- IElementAttributes attributes = element.getElementAttributes();
-
- if ( !attributes.getIsEternal() )
- {
- long now = System.currentTimeMillis();
-
- // Remove if maxLifeSeconds exceeded
-
- long maxLifeSeconds = attributes.getMaxLifeSeconds();
- long createTime = attributes.getCreateTime();
-
- if ( maxLifeSeconds != -1 && ( now - createTime ) > ( maxLifeSeconds * 1000 ) )
- {
- if ( log.isDebugEnabled() )
- {
- log.debug( "Exceeded maxLife: " + element.getKey() );
- }
-
- handleElementEvent( element, ElementEventType.EXCEEDED_MAXLIFE_ONREQUEST );
-
- return true;
- }
- long idleTime = attributes.getIdleTime();
- long lastAccessTime = attributes.getLastAccessTime();
-
- // Remove if maxIdleTime exceeded
- // If you have a 0 size memory cache, then the last access will
- // not get updated.
- // you will need to set the idle time to -1.
-
- if ( ( idleTime != -1 ) && ( now - lastAccessTime ) > idleTime * 1000 )
- {
- if ( log.isDebugEnabled() )
- {
- log.info( "Exceeded maxIdle: " + element.getKey() );
- }
-
- handleElementEvent( element, ElementEventType.EXCEEDED_IDLETIME_ONREQUEST );
-
- return true;
- }
- }
- }
- catch ( Exception e )
- {
- log.error( "Error determining expiration period, expiring", e );
-
- return true;
- }
-
- return false;
- }
-
- /**
* Get a set of the keys for all elements in the cache
* <p>
* @return A set of the key type
@@ -1334,7 +1290,7 @@ public class CompositeCache<K extends Se
{
if ( log.isInfoEnabled() )
{
- log.info( "In DISPOSE, [" + this.cacheName + "] fromRemote [" + fromRemote + "] \n" + this.getStats() );
+ log.info( "In DISPOSE, [" + this.cacheAttr.getCacheName() + "] fromRemote [" + fromRemote + "] \n" + this.getStats() );
}
// If already disposed, return immediately
@@ -1347,7 +1303,7 @@ public class CompositeCache<K extends Se
// Now, shut down the event queue
if (elementEventQ != null)
{
- elementEventQ.destroy();
+ elementEventQ.dispose();
elementEventQ = null;
}
@@ -1369,7 +1325,7 @@ public class CompositeCache<K extends Se
{
if ( log.isInfoEnabled() )
{
- log.info( "In DISPOSE, [" + this.cacheName + "] SKIPPING auxiliary [" + aux + "] fromRemote ["
+ log.info( "In DISPOSE, [" + this.cacheAttr.getCacheName() + "] SKIPPING auxiliary [" + aux + "] fromRemote ["
+ fromRemote + "]" );
}
continue;
@@ -1377,7 +1333,7 @@ public class CompositeCache<K extends Se
if ( log.isInfoEnabled() )
{
- log.info( "In DISPOSE, [" + this.cacheName + "] auxiliary [" + aux + "]" );
+ log.info( "In DISPOSE, [" + this.cacheAttr.getCacheName() + "] auxiliary [" + aux + "]" );
}
// IT USED TO BE THE CASE THAT (If the auxiliary is not a lateral, or the cache
@@ -1395,7 +1351,7 @@ public class CompositeCache<K extends Se
if ( log.isInfoEnabled() )
{
- log.info( "In DISPOSE, [" + this.cacheName + "] put " + numToFree + " into auxiliary " + aux );
+ log.info( "In DISPOSE, [" + this.cacheAttr.getCacheName() + "] put " + numToFree + " into auxiliary " + aux );
}
}
@@ -1410,7 +1366,7 @@ public class CompositeCache<K extends Se
if ( log.isInfoEnabled() )
{
- log.info( "In DISPOSE, [" + this.cacheName + "] disposing of memory cache." );
+ log.info( "In DISPOSE, [" + this.cacheAttr.getCacheName() + "] disposing of memory cache." );
}
try
{
@@ -1464,7 +1420,7 @@ public class CompositeCache<K extends Se
}
if ( log.isDebugEnabled() )
{
- log.debug( "Called save for [" + cacheName + "]" );
+ log.debug( "Called save for [" + cacheAttr.getCacheName() + "]" );
}
}
@@ -1562,7 +1518,7 @@ public class CompositeCache<K extends Se
@Override
public String getCacheName()
{
- return cacheName;
+ return cacheAttr.getCacheName();
}
/**
@@ -1632,6 +1588,124 @@ public class CompositeCache<K extends Se
}
/**
+ * Determine if the element is expired based on the values of the element attributes
+ *
+ * @param element the element
+ *
+ * @return true if the element is expired
+ */
+ public boolean isExpired( ICacheElement<K, V> element)
+ {
+ return isExpired(element, System.currentTimeMillis(),
+ ElementEventType.EXCEEDED_MAXLIFE_ONREQUEST,
+ ElementEventType.EXCEEDED_IDLETIME_ONREQUEST );
+ }
+
+ /**
+ * Check if the element is expired based on the values of the element attributes
+ *
+ * @param element the element
+ * @param timestamp the timestamp to compare to
+ * @param eventMaxlife the event to fire in case the max life time is exceeded
+ * @param eventIdle the event to fire in case the idle time is exceeded
+ *
+ * @return true if the element is expired
+ */
+ public boolean isExpired(ICacheElement<K, V> element, long timestamp,
+ ElementEventType eventMaxlife, ElementEventType eventIdle)
+ {
+ try
+ {
+ IElementAttributes attributes = element.getElementAttributes();
+
+ if ( !attributes.getIsEternal() )
+ {
+ // Remove if maxLifeSeconds exceeded
+
+ long maxLifeSeconds = attributes.getMaxLifeSeconds();
+ long createTime = attributes.getCreateTime();
+
+ if ( maxLifeSeconds != -1 && ( timestamp - createTime ) > ( maxLifeSeconds * 1000 ) )
+ {
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( "Exceeded maxLife: " + element.getKey() );
+ }
+
+ handleElementEvent( element, eventMaxlife );
+
+ return true;
+ }
+ long idleTime = attributes.getIdleTime();
+ long lastAccessTime = attributes.getLastAccessTime();
+
+ // Remove if maxIdleTime exceeded
+ // If you have a 0 size memory cache, then the last access will
+ // not get updated.
+ // you will need to set the idle time to -1.
+
+ if ( ( idleTime != -1 ) && ( timestamp - lastAccessTime ) > idleTime * 1000 )
+ {
+ if ( log.isDebugEnabled() )
+ {
+ log.info( "Exceeded maxIdle: " + element.getKey() );
+ }
+
+ handleElementEvent( element, eventIdle );
+
+ return true;
+ }
+ }
+ }
+ catch ( Exception e )
+ {
+ log.error( "Error determining expiration period, expiring", e );
+
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * If there are event handlers for the item, then create an event and queue it up.
+ * <p>
+ * This does not call handle directly; instead the handler and the event are put into a queue.
+ * This prevents the event handling from blocking normal cache operations.
+ * <p>
+ * @param element the item
+ * @param eventType the event type
+ */
+ public void handleElementEvent( ICacheElement<K, V> element, ElementEventType eventType )
+ {
+ ArrayList<IElementEventHandler> eventHandlers = element.getElementAttributes().getElementEventHandlers();
+ if ( eventHandlers != null )
+ {
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( "Element Handlers are registered. Create event type " + eventType );
+ }
+ if ( elementEventQ == null )
+ {
+ log.warn("No element event queue available for cache " + getCacheName());
+ return;
+ }
+ IElementEvent event = new ElementEvent( element, eventType );
+ for (IElementEventHandler hand : eventHandlers)
+ {
+ try
+ {
+ elementEventQ.addElementEvent( hand, event );
+ }
+ catch ( IOException e )
+ {
+ log.error( "Trouble adding element event to queue", e );
+ }
+ }
+ }
+ }
+
+ /**
* Create the MemoryCache based on the config parameters.
* TODO: consider making this an auxiliary, despite its close tie to the CacheHub.
* TODO: might want to create a memory cache config file separate from that of the hub -- ICompositeCacheAttributes
@@ -1712,65 +1786,6 @@ public class CompositeCache<K extends Se
}
/**
- * If there are event handlers for the item, then create an event and queue it up.
- * <p>
- * This does not call handle directly; instead the handler and the event are put into a queue.
- * This prevents the event handling from blocking normal cache operations.
- * <p>
- * @param ce
- * @param eventType
- */
- private void handleElementEvent( ICacheElement<K, V> ce, ElementEventType eventType )
- {
- // handle event, might move to a new method
- ArrayList<IElementEventHandler> eventHandlers = ce.getElementAttributes().getElementEventHandlers();
- if ( eventHandlers != null )
- {
- if ( log.isDebugEnabled() )
- {
- log.debug( "Element Handlers are registered. Create event type " + eventType );
- }
- IElementEvent event = new ElementEvent( ce, eventType );
- for (IElementEventHandler hand : eventHandlers)
- {
- try
- {
- addElementEvent( hand, event );
- }
- catch ( Exception e )
- {
- log.error( "Trouble adding element event to queue", e );
- }
- }
- }
- }
-
- /**
- * Adds an ElementEvent to be handled to the queue.
- * <p>
- * @param hand The IElementEventHandler
- * @param event The IElementEventHandler IElementEvent event
- * @throws IOException Description of the Exception
- */
- public void addElementEvent( IElementEventHandler hand, IElementEvent event )
- throws IOException
- {
- if ( log.isDebugEnabled() )
- {
- log.debug( "Adding event to Element Event Queue" );
- }
- // lazy init
- synchronized ( this )
- {
- if ( elementEventQ == null )
- {
- elementEventQ = new ElementEventQueue( this.getCacheName() );
- }
- }
- elementEventQ.addElementEvent( hand, event );
- }
-
- /**
* Sets the key matcher used by get matching.
* <p>
* @param keyMatcher
Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCacheConfigurator.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCacheConfigurator.java?rev=1591925&r1=1591924&r2=1591925&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCacheConfigurator.java (original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCacheConfigurator.java Fri May 2 14:17:38 2014
@@ -339,18 +339,23 @@ public class CompositeCacheConfigurator
IElementAttributes ea = parseElementAttributes( props, regName, regionPrefix );
CompositeCache<K, V> cache = ( cca == null )
- ? new CompositeCache<K, V>( regName, parseCompositeCacheAttributes( props, regName, regionPrefix ), ea )
- : new CompositeCache<K, V>( regName, cca, ea );
+ ? new CompositeCache<K, V>( parseCompositeCacheAttributes( props, regName, regionPrefix ), ea )
+ : new CompositeCache<K, V>( cca, ea );
- if (value != null)
+ // Inject scheduler service
+ cache.setScheduledExecutorService(compositeCacheManager.getScheduledExecutorService());
+
+ // Inject element event queue
+ cache.setElementEventQueue(compositeCacheManager.getElementEventQueue());
+
+ if (cache.getMemoryCache() instanceof IRequireScheduler)
{
- // Inject scheduler service
- if (cache.getMemoryCache() instanceof IRequireScheduler)
- {
- ((IRequireScheduler)cache.getMemoryCache()).setScheduledExecutorService(
- compositeCacheManager.getScheduledExecutorService());
- }
+ ((IRequireScheduler)cache.getMemoryCache()).setScheduledExecutorService(
+ compositeCacheManager.getScheduledExecutorService());
+ }
+ if (value != null)
+ {
// Next, create the auxiliaries for the new cache
List<AuxiliaryCache<K, V>> auxList = new ArrayList<AuxiliaryCache<K, V>>();
Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCacheManager.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCacheManager.java?rev=1591925&r1=1591924&r2=1591925&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCacheManager.java (original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCacheManager.java Fri May 2 14:17:38 2014
@@ -25,15 +25,14 @@ import java.io.Serializable;
import java.lang.management.ManagementFactory;
import java.security.AccessControlException;
import java.util.ArrayList;
-import java.util.HashSet;
import java.util.Iterator;
+import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.ThreadFactory;
import javax.management.MBeanServer;
import javax.management.ObjectName;
@@ -53,8 +52,11 @@ import org.apache.commons.jcs.engine.beh
import org.apache.commons.jcs.engine.behavior.IElementAttributes;
import org.apache.commons.jcs.engine.behavior.IProvideScheduler;
import org.apache.commons.jcs.engine.behavior.IShutdownObserver;
+import org.apache.commons.jcs.engine.control.event.ElementEventQueue;
+import org.apache.commons.jcs.engine.control.event.behavior.IElementEventQueue;
import org.apache.commons.jcs.engine.stats.CacheStats;
import org.apache.commons.jcs.engine.stats.behavior.ICacheStats;
+import org.apache.commons.jcs.utils.threadpool.DaemonThreadFactory;
import org.apache.commons.jcs.utils.threadpool.ThreadPoolManager;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -66,8 +68,6 @@ import org.apache.commons.logging.LogFac
* The composite cache manager is responsible for creating / configuring cache regions. It serves as
* a factory for the ComositeCache class. The CompositeCache is the core of JCS, the hub for various
* auxiliaries.
- * <p>
- * It is recommended that you use the JCS convenience class for all cache access.
*/
public class CompositeCacheManager
implements IRemoteCacheConstants, ICompositeCacheManager, IProvideScheduler
@@ -118,11 +118,14 @@ public class CompositeCacheManager
private static final boolean DEFAULT_FORCE_RECONFIGURATION = false;
/** Those waiting for notification of a shutdown. */
- private final Set<IShutdownObserver> shutdownObservers = new HashSet<IShutdownObserver>();
+ private final LinkedHashSet<IShutdownObserver> shutdownObservers = new LinkedHashSet<IShutdownObserver>();
/** The central background scheduler. */
private ScheduledExecutorService scheduledExecutor;
+ /** The central event queue. */
+ private IElementEventQueue elementEventQueue;
+
/** Shutdown hook thread instance */
private ShutdownHook shutdownHook;
@@ -244,19 +247,8 @@ public class CompositeCacheManager
log.error( "Could not register shutdown hook.", e );
}
- this.scheduledExecutor = Executors.newScheduledThreadPool(4, new ThreadFactory()
- {
- @Override
- public Thread newThread(Runnable runner)
- {
- Thread t = new Thread( runner );
- String oldName = t.getName();
- t.setName( "JCS-Scheduler-" + oldName );
- t.setDaemon( true );
- t.setPriority( Thread.MIN_PRIORITY );
- return t;
- }
- });
+ this.scheduledExecutor = Executors.newScheduledThreadPool(4,
+ new DaemonThreadFactory("JCS-Scheduler-", Thread.MIN_PRIORITY));
// Register JMX bean
if (!isJMXRegistered)
@@ -275,11 +267,23 @@ public class CompositeCacheManager
}
}
+ this.elementEventQueue = new ElementEventQueue();
+
isInitialized = true;
}
}
/**
+ * Get the element event queue
+ *
+ * @return the elementEventQueue
+ */
+ public IElementEventQueue getElementEventQueue()
+ {
+ return elementEventQueue;
+ }
+
+ /**
* Get the scheduler service
*
* @return the scheduledExecutor
@@ -641,6 +645,9 @@ public class CompositeCacheManager
{
synchronized (CompositeCacheManager.class)
{
+ // shutdown element event queue
+ this.elementEventQueue.dispose();
+
// shutdown all scheduled jobs
this.scheduledExecutor.shutdownNow();
Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/event/ElementEventQueue.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/event/ElementEventQueue.java?rev=1591925&r1=1591924&r2=1591925&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/event/ElementEventQueue.java (original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/event/ElementEventQueue.java Fri May 2 14:17:38 2014
@@ -20,10 +20,14 @@ package org.apache.commons.jcs.engine.co
*/
import java.io.IOException;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
import org.apache.commons.jcs.engine.control.event.behavior.IElementEvent;
import org.apache.commons.jcs.engine.control.event.behavior.IElementEventHandler;
import org.apache.commons.jcs.engine.control.event.behavior.IElementEventQueue;
+import org.apache.commons.jcs.utils.threadpool.DaemonThreadFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -33,53 +37,28 @@ import org.apache.commons.logging.LogFac
public class ElementEventQueue
implements IElementEventQueue
{
- /** serial version */
- private static final long serialVersionUID = -2966341524571838475L;
+ private static final String THREAD_PREFIX = "JCS-ElementEventQueue-";
/** The logger */
private static final Log log = LogFactory.getLog( ElementEventQueue.class );
- /** The cache (region) name. */
- protected final String cacheName;
-
- /** default */
- private static final int DEFAULT_WAIT_TO_DIE_MILLIS = 10000;
-
- /**
- * time to wait for an event before snuffing the background thread if the queue is empty. make
- * configurable later
- */
- private int waitToDieMillis = DEFAULT_WAIT_TO_DIE_MILLIS;
-
/** shutdown or not */
private boolean destroyed = false;
- /** The worker thread. */
- private Thread processorThread;
-
- /** Internal queue implementation */
- protected final Object queueLock = new Object();
-
- /** Dummy node */
- private Node head = new Node();
-
- /** tail of the doubly linked list */
- private Node tail = head;
+ /** The event queue */
+ private LinkedBlockingQueue<Runnable> queue;
- /** Number of items in the queue */
- private int size = 0;
+ /** The worker thread pool. */
+ private ThreadPoolExecutor queueProcessor;
/**
* Constructor for the ElementEventQueue object
- * <p>
- * @param cacheName
*/
- public ElementEventQueue( String cacheName )
+ public ElementEventQueue()
{
- this.cacheName = cacheName;
-
- processorThread = new QProcessor( this );
- processorThread.start();
+ queue = new LinkedBlockingQueue<Runnable>();
+ queueProcessor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS,
+ queue, new DaemonThreadFactory(THREAD_PREFIX));
if ( log.isDebugEnabled() )
{
@@ -91,86 +70,22 @@ public class ElementEventQueue
* Event Q is empty.
*/
@Override
- public void destroy()
+ public synchronized void dispose()
{
- synchronized ( queueLock )
- {
- if ( !destroyed )
- {
- destroyed = true;
-
- // synchronize on queue so the thread will not wait forever,
- // and then interrupt the QueueProcessor
- processorThread.interrupt();
- processorThread = null;
-
- if ( log.isInfoEnabled() )
- {
- log.info( "Element event queue destroyed: " + this );
- }
- }
- }
- }
-
- /**
- * Kill the processor thread and indicate that the queue is destroyed and no longer alive, but it
- * can still be working.
- */
- public void stopProcessing()
- {
- synchronized ( queueLock )
+ if ( !destroyed )
{
destroyed = true;
- processorThread = null;
- }
- }
-
- /**
- * Returns the time to wait for events before killing the background thread.
- * <p>
- * @return int
- */
- public int getWaitToDieMillis()
- {
- return waitToDieMillis;
- }
-
- /**
- * Sets the time to wait for events before killing the background thread.
- * <p>
- * @param wtdm the ms for the q to sit idle.
- */
- public void setWaitToDieMillis( int wtdm )
- {
- waitToDieMillis = wtdm;
- }
- /**
- * @return the region name for the event queue
- */
- @Override
- public String toString()
- {
- return "cacheName=" + cacheName;
- }
+ // synchronize on queue so the thread will not wait forever,
+ // and then interrupt the QueueProcessor
+ queueProcessor.shutdownNow();
+ queueProcessor = null;
- /**
- * Returns the number of elements in the queue.
- * <p>
- * @return number of items in the queue.
- */
- public int size()
- {
- return size;
- }
-
- /**
- * @return The destroyed value
- */
- @Override
- public boolean isAlive()
- {
- return !destroyed;
+ if ( log.isInfoEnabled() )
+ {
+ log.info( "Element event queue destroyed: " + this );
+ }
+ }
}
/**
@@ -180,7 +95,7 @@ public class ElementEventQueue
* @throws IOException
*/
@Override
- public void addElementEvent( IElementEventHandler hand, IElementEvent event )
+ public synchronized void addElementEvent( IElementEventHandler hand, IElementEvent event )
throws IOException
{
@@ -189,174 +104,25 @@ public class ElementEventQueue
log.debug( "Adding Event Handler to QUEUE, !destroyed = " + !destroyed );
}
- if ( !destroyed )
+ if (destroyed)
{
- ElementEventRunner runner = new ElementEventRunner( hand, event );
-
- if ( log.isDebugEnabled() )
- {
- log.debug( "runner = " + runner );
- }
-
- put( runner );
+ log.warn("Event submitted to disposed element event queue " + event);
}
- }
-
- /**
- * Adds an event to the queue.
- * @param event
- */
- private void put( AbstractElementEventRunner event )
- {
- Node newNode = new Node();
-
- newNode.event = event;
-
- synchronized ( queueLock )
+ else
{
- size++;
- tail.next = newNode;
- tail = newNode;
- if ( !isAlive() )
- {
- destroyed = false;
- processorThread = new QProcessor( this );
- processorThread.start();
- }
- else
- {
- queueLock.notify();
- }
- queueLock.notify();
- }
- }
-
- /**
- * Returns the next item on the queue, or waits if empty.
- * <p>
- * @return AbstractElementEventRunner
- */
- protected AbstractElementEventRunner take()
- {
- synchronized ( queueLock )
- {
- // wait until there is something to read
- if ( head == tail )
- {
- return null;
- }
-
- Node node = head.next;
-
- AbstractElementEventRunner value = node.event;
+ ElementEventRunner runner = new ElementEventRunner( hand, event );
if ( log.isDebugEnabled() )
{
- log.debug( "head.event = " + head.event );
- log.debug( "node.event = " + node.event );
+ log.debug( "runner = " + runner );
}
- // Node becomes the new head (head is always empty)
-
- node.event = null;
- head = node;
-
- size--;
- return value;
+ queueProcessor.execute(runner);
}
}
// /////////////////////////// Inner classes /////////////////////////////
- /** A node in the queue. These are chained forming a singly linked list */
- protected static class Node
- {
- /** The next node. */
- Node next = null;
-
- /** The event to run */
- ElementEventQueue.AbstractElementEventRunner event = null;
- }
-
- /**
- */
- private class QProcessor
- extends Thread
- {
- /** The event queue */
- ElementEventQueue queue;
-
- /**
- * Constructor for the QProcessor object
- * <p>
- * @param aQueue
- */
- QProcessor( ElementEventQueue aQueue )
- {
- super( "ElementEventQueue.QProcessor-" + aQueue.cacheName );
-
- setDaemon( true );
- queue = aQueue;
- }
-
- /**
- * Main processing method for the QProcessor object.
- * <p>
- * Waits for a specified time (waitToDieMillis) for something to come in and if no new
- * events come in during that period the run method can exit and the thread is dereferenced.
- */
- @SuppressWarnings("synthetic-access")
- @Override
- public void run()
- {
- AbstractElementEventRunner event = null;
-
- while ( queue.isAlive() )
- {
- event = queue.take();
-
- if ( log.isDebugEnabled() )
- {
- log.debug( "Event from queue = " + event );
- }
-
- if ( event == null )
- {
- synchronized ( queueLock )
- {
- try
- {
- queueLock.wait( queue.getWaitToDieMillis() );
- }
- catch ( InterruptedException e )
- {
- log.warn( "Interrupted while waiting for another event to come in before we die." );
- return;
- }
- event = queue.take();
- if ( log.isDebugEnabled() )
- {
- log.debug( "Event from queue after sleep = " + event );
- }
- }
- if ( event == null )
- {
- queue.stopProcessing();
- }
- }
-
- if ( queue.isAlive() && event != null )
- {
- event.run();
- }
- }
- if ( log.isDebugEnabled() )
- {
- log.debug( "QProcessor exiting for " + queue );
- }
- }
- }
-
/**
* Retries before declaring failure.
*/
Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/event/behavior/IElementEventHandler.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/event/behavior/IElementEventHandler.java?rev=1591925&r1=1591924&r2=1591925&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/event/behavior/IElementEventHandler.java (original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/event/behavior/IElementEventHandler.java Fri May 2 14:17:38 2014
@@ -24,7 +24,7 @@ package org.apache.commons.jcs.engine.co
* transient. They are not replicated and are not written to disk.
* <p>
* If you want an event handler by default for all elements in a region, then
- * you can add it to the default element attributes. This way it will get create
+ * you can add it to the default element attributes. This way it will get created
* whenever an item gets put into the cache.
*
*/
Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/event/behavior/IElementEventQueue.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/event/behavior/IElementEventQueue.java?rev=1591925&r1=1591924&r2=1591925&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/event/behavior/IElementEventQueue.java (original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/event/behavior/IElementEventQueue.java Fri May 2 14:17:38 2014
@@ -20,16 +20,14 @@ package org.apache.commons.jcs.engine.co
*/
import java.io.IOException;
-import java.io.Serializable;
/**
* Interface for an element event queue. An event queue is used to propagate
* ordered element events in one region.
*
*/
-public interface IElementEventQueue extends Serializable
+public interface IElementEventQueue
{
-
/**
* Adds an ElementEvent to be handled
*
@@ -42,14 +40,9 @@ public interface IElementEventQueue exte
void addElementEvent( IElementEventHandler hand, IElementEvent event )
throws IOException;
- /** Description of the Method */
- void destroy();
-
/**
- * Gets the alive attribute of the IElementEventQueue object
+ * Destroy the event queue
*
- * @return The alive value
*/
- boolean isAlive();
-
+ void dispose();
}
Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/memory/AbstractMemoryCache.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/memory/AbstractMemoryCache.java?rev=1591925&r1=1591924&r2=1591925&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/memory/AbstractMemoryCache.java (original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/memory/AbstractMemoryCache.java Fri May 2 14:17:38 2014
@@ -24,17 +24,13 @@ import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
import org.apache.commons.jcs.engine.CacheStatus;
import org.apache.commons.jcs.engine.behavior.ICacheElement;
import org.apache.commons.jcs.engine.behavior.ICompositeCacheAttributes;
import org.apache.commons.jcs.engine.behavior.IElementAttributes;
-import org.apache.commons.jcs.engine.behavior.IRequireScheduler;
import org.apache.commons.jcs.engine.control.CompositeCache;
import org.apache.commons.jcs.engine.memory.behavior.IMemoryCache;
-import org.apache.commons.jcs.engine.memory.shrinking.ShrinkerThread;
import org.apache.commons.jcs.engine.memory.util.MemoryElementDescriptor;
import org.apache.commons.jcs.engine.stats.Stats;
import org.apache.commons.jcs.engine.stats.behavior.IStats;
@@ -48,11 +44,8 @@ import org.apache.commons.logging.LogFac
* use the shrinker, the clock daemon will be setup to run the shrinker on this region.
*/
public abstract class AbstractMemoryCache<K extends Serializable, V extends Serializable>
- implements IMemoryCache<K, V>, Serializable, IRequireScheduler
+ implements IMemoryCache<K, V>
{
- /** Don't change. */
- private static final long serialVersionUID = -4494626991630099575L;
-
/** Log instance */
private static final Log log = LogFactory.getLog( AbstractMemoryCache.class );
@@ -60,16 +53,16 @@ public abstract class AbstractMemoryCach
protected String cacheName; // TODO privatise (mainly seems to be used externally for debugging)
/** Map where items are stored by key. This is created by the concrete child class. */
- public Map<K, MemoryElementDescriptor<K, V>> map;// TODO privatise
+ public Map<K, MemoryElementDescriptor<K, V>> map;// TODO privatise
/** Region Elemental Attributes, used as a default and copied for each item. */
- public IElementAttributes elementAttributes;// TODO privatise
+ public IElementAttributes elementAttributes;// TODO privatise
/** Cache Attributes. Regions settings. */
- public ICompositeCacheAttributes cacheAttributes;// TODO privatise
+ public ICompositeCacheAttributes cacheAttributes;// TODO privatise
/** The cache region this store is associated with */
- public CompositeCache<K, V> cache;// TODO privatise
+ public CompositeCache<K, V> cache;// TODO privatise
/** status */
private CacheStatus status;
@@ -95,20 +88,6 @@ public abstract class AbstractMemoryCach
}
/**
- * @see org.apache.commons.jcs.engine.behavior.IRequireScheduler#setScheduledExecutorService(java.util.concurrent.ScheduledExecutorService)
- */
- @Override
- public void setScheduledExecutorService(ScheduledExecutorService scheduledExecutor)
- {
- if ( cacheAttributes.isUseMemoryShrinker() )
- {
- scheduledExecutor.scheduleAtFixedRate(
- new ShrinkerThread<K, V>(this), 0, cacheAttributes.getShrinkerIntervalSeconds(),
- TimeUnit.SECONDS);
- }
- }
-
- /**
* Children must implement this method. A FIFO implementation may use a tree map. An LRU might
* use a hashtable. The map returned should be threadsafe.
* <p>
Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/memory/shrinking/ShrinkerThread.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/memory/shrinking/ShrinkerThread.java?rev=1591925&r1=1591924&r2=1591925&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/memory/shrinking/ShrinkerThread.java (original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/memory/shrinking/ShrinkerThread.java Fri May 2 14:17:38 2014
@@ -19,17 +19,13 @@ package org.apache.commons.jcs.engine.me
* under the License.
*/
-import java.io.IOException;
import java.io.Serializable;
-import java.util.ArrayList;
import java.util.Set;
import org.apache.commons.jcs.engine.behavior.ICacheElement;
import org.apache.commons.jcs.engine.behavior.IElementAttributes;
-import org.apache.commons.jcs.engine.control.event.ElementEvent;
+import org.apache.commons.jcs.engine.control.CompositeCache;
import org.apache.commons.jcs.engine.control.event.behavior.ElementEventType;
-import org.apache.commons.jcs.engine.control.event.behavior.IElementEvent;
-import org.apache.commons.jcs.engine.control.event.behavior.IElementEventHandler;
import org.apache.commons.jcs.engine.memory.behavior.IMemoryCache;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -45,8 +41,8 @@ public class ShrinkerThread<K extends Se
/** The logger */
private static final Log log = LogFactory.getLog( ShrinkerThread.class );
- /** The MemoryCache instance which this shrinker is watching */
- private final IMemoryCache<K, V> cache;
+ /** The CompositeCache instance which this shrinker is watching */
+ private final CompositeCache<K, V> cache;
/** Maximum memory idle time for the whole cache */
private final long maxMemoryIdleTime;
@@ -62,7 +58,7 @@ public class ShrinkerThread<K extends Se
* <p>
* @param cache The MemoryCache which the new shrinker should watch.
*/
- public ShrinkerThread( IMemoryCache<K, V> cache )
+ public ShrinkerThread( CompositeCache<K, V> cache )
{
super();
@@ -115,15 +111,14 @@ public class ShrinkerThread<K extends Se
{
if ( log.isDebugEnabled() )
{
- if ( this.cache.getCompositeCache() != null )
- {
- log.debug( "Shrinking memory cache for: " + this.cache.getCompositeCache().getCacheName() );
- }
+ log.debug( "Shrinking memory cache for: " + this.cache.getCacheName() );
}
+ IMemoryCache<K, V> memCache = cache.getMemoryCache();
+
try
{
- Set<K> keys = cache.getKeySet();
+ Set<K> keys = memCache.getKeySet();
int size = keys.size();
if ( log.isDebugEnabled() )
{
@@ -137,7 +132,7 @@ public class ShrinkerThread<K extends Se
for (K key : keys)
{
- cacheElement = cache.getQuiet( key );
+ cacheElement = memCache.getQuiet( key );
if ( cacheElement == null )
{
@@ -154,11 +149,13 @@ public class ShrinkerThread<K extends Se
// removed and remove it if so.
if ( !cacheElement.getElementAttributes().getIsEternal() )
{
- remove = checkForRemoval( cacheElement, now );
+ remove = cache.isExpired( cacheElement, now,
+ ElementEventType.EXCEEDED_MAXLIFE_BACKGROUND,
+ ElementEventType.EXCEEDED_IDLETIME_BACKGROUND );
if ( remove )
{
- cache.remove( cacheElement.getKey() );
+ memCache.remove( cacheElement.getKey() );
}
}
@@ -186,9 +183,9 @@ public class ShrinkerThread<K extends Se
spoolCount++;
- cache.remove( cacheElement.getKey() );
+ memCache.remove( cacheElement.getKey() );
- cache.waterfal( cacheElement );
+ memCache.waterfal( cacheElement );
key = null;
cacheElement = null;
@@ -223,90 +220,4 @@ public class ShrinkerThread<K extends Se
return;
}
}
-
- /**
- * Check if either lifetime or idletime has expired for the provided event, and remove it from
- * the cache if so.
- * <p>
- * @param cacheElement Element to check for expiration
- * @param now Time to consider expirations relative to. This makes it easier to test.
- * @return true if the element should be removed, or false.
- * @throws IOException
- */
- protected boolean checkForRemoval( ICacheElement<?, ?> cacheElement, long now )
- throws IOException
- {
- IElementAttributes attributes = cacheElement.getElementAttributes();
-
- final long maxLifeSeconds = attributes.getMaxLifeSeconds();
- final long createTime = attributes.getCreateTime();
-
- // Check if maxLifeSeconds has been exceeded
- if ( maxLifeSeconds != -1 && now - createTime > maxLifeSeconds * 1000 )
- {
- if ( log.isInfoEnabled() )
- {
- log.info( "Exceeded maxLifeSeconds: " + cacheElement.getKey() );
- }
-
- handleElementEvents( cacheElement, ElementEventType.EXCEEDED_MAXLIFE_BACKGROUND );
-
- return true;
- }
-
- final long idleTime = attributes.getIdleTime();
- final long lastAccessTime = attributes.getLastAccessTime();
-
- // Check maxIdleTime has been exceeded
- if ( idleTime != -1 && now - lastAccessTime > idleTime * 1000 )
- {
- if ( log.isInfoEnabled() )
- {
- log.info( "Exceeded maxIdleTime " + cacheElement.getKey() );
- }
-
- handleElementEvents( cacheElement, ElementEventType.EXCEEDED_IDLETIME_BACKGROUND );
-
- return true;
- }
-
- return false;
- }
-
- /**
- * Handle any events registered for the given element of the given event type.
- * <p>
- * @param cacheElement Element to handle events for
- * @param eventType Type of event to handle
- * @throws IOException If an error occurs
- */
- private void handleElementEvents( ICacheElement<?, ?> cacheElement, ElementEventType eventType )
- throws IOException
- {
- IElementAttributes attributes = cacheElement.getElementAttributes();
-
- ArrayList<IElementEventHandler> eventHandlers = attributes.getElementEventHandlers();
-
- if ( eventHandlers != null )
- {
- if ( log.isDebugEnabled() )
- {
- log.debug( "Handlers are registered, type: " + eventType );
- }
-
- IElementEvent event = new ElementEvent( cacheElement, eventType );
-
- for (IElementEventHandler hand : eventHandlers)
- {
- // extra safety
- // TODO we shouldn't be operating on a variable of another class.
- // we did this to get away from the singleton composite cache.
- // we will need to create an event manager and pass it around instead.
- if ( cache.getCompositeCache() != null )
- {
- cache.getCompositeCache().addElementEvent( hand, event );
- }
- }
- }
- }
}
Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryManager.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryManager.java?rev=1591925&r1=1591924&r2=1591925&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryManager.java (original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryManager.java Fri May 2 14:17:38 2014
@@ -24,7 +24,6 @@ import java.util.Map;
import org.apache.commons.jcs.engine.behavior.ICompositeCacheManager;
import org.apache.commons.jcs.engine.behavior.IProvideScheduler;
-import org.apache.commons.jcs.engine.behavior.IShutdownObservable;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -94,10 +93,7 @@ public class UDPDiscoveryManager
service = new UDPDiscoveryService( attributes );
// register for shutdown notification
- if ( cacheMgr instanceof IShutdownObservable )
- {
- ( (IShutdownObservable) cacheMgr ).registerShutdownObserver( service );
- }
+ cacheMgr.registerShutdownObserver( service );
// inject scheduler
if ( cacheMgr instanceof IProvideScheduler)
Modified: commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/remote/server/BasicRemoteCacheClientServerUnitTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/remote/server/BasicRemoteCacheClientServerUnitTest.java?rev=1591925&r1=1591924&r2=1591925&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/remote/server/BasicRemoteCacheClientServerUnitTest.java (original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/remote/server/BasicRemoteCacheClientServerUnitTest.java Fri May 2 14:17:38 2014
@@ -19,6 +19,9 @@ package org.apache.commons.jcs.auxiliary
* under the License.
*/
+import java.io.IOException;
+import java.net.InetAddress;
+
import org.apache.commons.jcs.auxiliary.AuxiliaryCache;
import org.apache.commons.jcs.auxiliary.MockCacheEventLogger;
import org.apache.commons.jcs.auxiliary.remote.MockRemoteCacheListener;
@@ -38,12 +41,6 @@ import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
-import java.io.IOException;
-import java.net.InetAddress;
-import java.rmi.server.ServerNotActiveException;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
-
/**
* These tests startup the remote server and make requests to it.
* <p/>
@@ -63,8 +60,6 @@ public class BasicRemoteCacheClientServe
*/
private static int remotePort;
- private static final Lock lock = new ReentrantLock();
-
/**
* Starts the server. This is not in a setup, since the server is slow to kill right now.
*/
@@ -77,7 +72,7 @@ public class BasicRemoteCacheClientServe
}
@AfterClass
- public static void stop() throws IOException, ServerNotActiveException
+ public static void stop() throws IOException
{
server.shutdown("localhost", remotePort);
}
Modified: commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/engine/control/CompositeCacheDiskUsageUnitTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/engine/control/CompositeCacheDiskUsageUnitTest.java?rev=1591925&r1=1591924&r2=1591925&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/engine/control/CompositeCacheDiskUsageUnitTest.java (original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/engine/control/CompositeCacheDiskUsageUnitTest.java Fri May 2 14:17:38 2014
@@ -54,6 +54,8 @@ import org.apache.commons.jcs.engine.sta
public class CompositeCacheDiskUsageUnitTest
extends TestCase
{
+ private static final String CACHE_NAME = "testSpoolAllowed";
+
/**
* Test setup
*/
@@ -97,11 +99,12 @@ public class CompositeCacheDiskUsageUnit
{
// SETUP
ICompositeCacheAttributes cattr = new CompositeCacheAttributes();
+ cattr.setCacheName(CACHE_NAME);
cattr.setDiskUsagePattern( ICompositeCacheAttributes.DiskUsagePattern.SWAP );
IElementAttributes attr = new ElementAttributes();
- CompositeCache<String, String> cache = new CompositeCache<String, String>( "testSpoolAllowed", cattr, attr );
+ CompositeCache<String, String> cache = new CompositeCache<String, String>( cattr, attr );
MockAuxCache<String, String> mock = new MockAuxCache<String, String>();
mock.cacheType = CacheType.DISK_CACHE;
@@ -110,7 +113,7 @@ public class CompositeCacheDiskUsageUnit
AuxiliaryCache<String, String>[] auxArray = new AuxiliaryCache[] { mock };
cache.setAuxCaches( auxArray );
- ICacheElement<String, String> inputElement = new CacheElement<String, String>( "testSpoolAllowed", "key", "value" );
+ ICacheElement<String, String> inputElement = new CacheElement<String, String>( CACHE_NAME, "key", "value" );
// DO WORK
cache.spoolToDisk( inputElement );
@@ -128,11 +131,12 @@ public class CompositeCacheDiskUsageUnit
{
// SETUP
ICompositeCacheAttributes cattr = new CompositeCacheAttributes();
+ cattr.setCacheName(CACHE_NAME);
cattr.setDiskUsagePattern( ICompositeCacheAttributes.DiskUsagePattern.UPDATE );
IElementAttributes attr = new ElementAttributes();
- CompositeCache<String, String> cache = new CompositeCache<String, String>( "testSpoolAllowed", cattr, attr );
+ CompositeCache<String, String> cache = new CompositeCache<String, String>( cattr, attr );
MockAuxCache<String, String> mock = new MockAuxCache<String, String>();
mock.cacheType = CacheType.DISK_CACHE;
@@ -141,7 +145,7 @@ public class CompositeCacheDiskUsageUnit
AuxiliaryCache<String, String>[] auxArray = new AuxiliaryCache[] { mock };
cache.setAuxCaches( auxArray );
- ICacheElement<String, String> inputElement = new CacheElement<String, String>( "testSpoolAllowed", "key", "value" );
+ ICacheElement<String, String> inputElement = new CacheElement<String, String>( CACHE_NAME, "key", "value" );
// DO WORK
cache.spoolToDisk( inputElement );
@@ -163,11 +167,12 @@ public class CompositeCacheDiskUsageUnit
{
// SETUP
ICompositeCacheAttributes cattr = new CompositeCacheAttributes();
+ cattr.setCacheName(CACHE_NAME);
cattr.setDiskUsagePattern( ICompositeCacheAttributes.DiskUsagePattern.UPDATE );
IElementAttributes attr = new ElementAttributes();
- CompositeCache<String, String> cache = new CompositeCache<String, String>( "testSpoolAllowed", cattr, attr );
+ CompositeCache<String, String> cache = new CompositeCache<String, String>( cattr, attr );
MockAuxCache<String, String> mock = new MockAuxCache<String, String>();
mock.cacheType = CacheType.DISK_CACHE;
@@ -176,7 +181,7 @@ public class CompositeCacheDiskUsageUnit
AuxiliaryCache<String, String>[] auxArray = new AuxiliaryCache[] { mock };
cache.setAuxCaches( auxArray );
- ICacheElement<String, String> inputElement = new CacheElement<String, String>( "testSpoolAllowed", "key", "value" );
+ ICacheElement<String, String> inputElement = new CacheElement<String, String>( CACHE_NAME, "key", "value" );
// DO WORK
cache.updateAuxiliaries( inputElement, true );
@@ -200,11 +205,12 @@ public class CompositeCacheDiskUsageUnit
{
// SETUP
ICompositeCacheAttributes cattr = new CompositeCacheAttributes();
+ cattr.setCacheName(CACHE_NAME);
cattr.setDiskUsagePattern( ICompositeCacheAttributes.DiskUsagePattern.UPDATE );
IElementAttributes attr = new ElementAttributes();
- CompositeCache<String, String> cache = new CompositeCache<String, String>( "testSpoolAllowed", cattr, attr );
+ CompositeCache<String, String> cache = new CompositeCache<String, String>( cattr, attr );
MockAuxCache<String, String> mock = new MockAuxCache<String, String>();
mock.cacheType = CacheType.DISK_CACHE;
@@ -213,7 +219,7 @@ public class CompositeCacheDiskUsageUnit
AuxiliaryCache<String, String>[] auxArray = new AuxiliaryCache[] { mock };
cache.setAuxCaches( auxArray );
- ICacheElement<String, String> inputElement = new CacheElement<String, String>( "testSpoolAllowed", "key", "value" );
+ ICacheElement<String, String> inputElement = new CacheElement<String, String>( CACHE_NAME, "key", "value" );
// DO WORK
cache.updateAuxiliaries( inputElement, false );
@@ -237,11 +243,12 @@ public class CompositeCacheDiskUsageUnit
{
// SETUP
ICompositeCacheAttributes cattr = new CompositeCacheAttributes();
+ cattr.setCacheName(CACHE_NAME);
cattr.setDiskUsagePattern( ICompositeCacheAttributes.DiskUsagePattern.SWAP );
IElementAttributes attr = new ElementAttributes();
- CompositeCache<String, String> cache = new CompositeCache<String, String>( "testSpoolAllowed", cattr, attr );
+ CompositeCache<String, String> cache = new CompositeCache<String, String>( cattr, attr );
MockAuxCache<String, String> mock = new MockAuxCache<String, String>();
mock.cacheType = CacheType.DISK_CACHE;
@@ -250,7 +257,7 @@ public class CompositeCacheDiskUsageUnit
AuxiliaryCache<String, String>[] auxArray = new AuxiliaryCache[] { mock };
cache.setAuxCaches( auxArray );
- ICacheElement<String, String> inputElement = new CacheElement<String, String>( "testSpoolAllowed", "key", "value" );
+ ICacheElement<String, String> inputElement = new CacheElement<String, String>( CACHE_NAME, "key", "value" );
// DO WORK
cache.updateAuxiliaries( inputElement, true );
@@ -272,11 +279,12 @@ public class CompositeCacheDiskUsageUnit
{
// SETUP
ICompositeCacheAttributes cattr = new CompositeCacheAttributes();
+ cattr.setCacheName(CACHE_NAME);
cattr.setDiskUsagePattern( ICompositeCacheAttributes.DiskUsagePattern.UPDATE );
IElementAttributes attr = new ElementAttributes();
- CompositeCache<String, String> cache = new CompositeCache<String, String>( "testSpoolAllowed", cattr, attr );
+ CompositeCache<String, String> cache = new CompositeCache<String, String>( cattr, attr );
MockAuxCache<String, String> mock = new MockAuxCache<String, String>();
mock.cacheType = CacheType.DISK_CACHE;
@@ -288,7 +296,7 @@ public class CompositeCacheDiskUsageUnit
AuxiliaryCache<String, String>[] auxArray = new AuxiliaryCache[] { mock, mockLateral };
cache.setAuxCaches( auxArray );
- ICacheElement<String, String> inputElement = new CacheElement<String, String>( "testSpoolAllowed", "key", "value" );
+ ICacheElement<String, String> inputElement = new CacheElement<String, String>( CACHE_NAME, "key", "value" );
// DO WORK
cache.updateAuxiliaries( inputElement, false );
Modified: commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/engine/control/CompositeCacheUnitTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/engine/control/CompositeCacheUnitTest.java?rev=1591925&r1=1591924&r2=1591925&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/engine/control/CompositeCacheUnitTest.java (original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/engine/control/CompositeCacheUnitTest.java Fri May 2 14:17:38 2014
@@ -60,7 +60,7 @@ public class CompositeCacheUnitTest
IElementAttributes attr = new ElementAttributes();
- CompositeCache<String, Integer> cache = new CompositeCache<String, Integer>( cacheName, cattr, attr );
+ CompositeCache<String, Integer> cache = new CompositeCache<String, Integer>( cattr, attr );
MockAuxiliaryCache<String, Integer> diskMock = new MockAuxiliaryCache<String, Integer>();
diskMock.cacheType = CacheType.DISK_CACHE;
@@ -100,7 +100,7 @@ public class CompositeCacheUnitTest
IElementAttributes attr = new ElementAttributes();
- CompositeCache<String, Integer> cache = new CompositeCache<String, Integer>( cacheName, cattr, attr );
+ CompositeCache<String, Integer> cache = new CompositeCache<String, Integer>( cattr, attr );
MockAuxiliaryCache<String, Integer> diskMock = new MockAuxiliaryCache<String, Integer>();
diskMock.cacheType = CacheType.REMOTE_CACHE;
@@ -143,7 +143,7 @@ public class CompositeCacheUnitTest
IElementAttributes attr = new ElementAttributes();
- CompositeCache<String, Integer> cache = new CompositeCache<String, Integer>( cacheName, cattr, attr );
+ CompositeCache<String, Integer> cache = new CompositeCache<String, Integer>( cattr, attr );
MockAuxiliaryCache<String, Integer> diskMock = new MockAuxiliaryCache<String, Integer>();
diskMock.cacheType = CacheType.DISK_CACHE;
@@ -189,12 +189,13 @@ public class CompositeCacheUnitTest
String cacheName = "testGetMatching_NotOnDisk";
String memoryCacheClassName = "org.apache.commons.jcs.engine.memory.lru.LRUMemoryCache";
ICompositeCacheAttributes cattr = new CompositeCacheAttributes();
+ cattr.setCacheName(cacheName);
cattr.setMemoryCacheName( memoryCacheClassName );
cattr.setMaxObjects( maxMemorySize );
IElementAttributes attr = new ElementAttributes();
- CompositeCache<String, Integer> cache = new CompositeCache<String, Integer>( cacheName, cattr, attr );
+ CompositeCache<String, Integer> cache = new CompositeCache<String, Integer>( cattr, attr );
MockAuxiliaryCache<String, Integer> diskMock = new MockAuxiliaryCache<String, Integer>();
diskMock.cacheType = CacheType.DISK_CACHE;
@@ -222,12 +223,13 @@ public class CompositeCacheUnitTest
String cacheName = "testGetMatching_NotOnDisk";
String memoryCacheClassName = "org.apache.commons.jcs.engine.memory.lru.LRUMemoryCache";
ICompositeCacheAttributes cattr = new CompositeCacheAttributes();
+ cattr.setCacheName(cacheName);
cattr.setMemoryCacheName( memoryCacheClassName );
cattr.setMaxObjects( maxMemorySize );
IElementAttributes attr = new ElementAttributes();
- CompositeCache<String, Integer> cache = new CompositeCache<String, Integer>( cacheName, cattr, attr );
+ CompositeCache<String, Integer> cache = new CompositeCache<String, Integer>( cattr, attr );
MockAuxiliaryCache<String, Integer> diskMock = new MockAuxiliaryCache<String, Integer>();
diskMock.cacheType = CacheType.REMOTE_CACHE;
Modified: commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/engine/control/MockCompositeCacheManager.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/engine/control/MockCompositeCacheManager.java?rev=1591925&r1=1591924&r2=1591925&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/engine/control/MockCompositeCacheManager.java (original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/engine/control/MockCompositeCacheManager.java Fri May 2 14:17:38 2014
@@ -48,8 +48,8 @@ public class MockCompositeCacheManager
if ( cache == null )
{
// System.out.println( "Creating mock cache" );
- CompositeCache<K, V> newCache = new CompositeCache<K, V>( cacheName, new CompositeCacheAttributes(),
- new ElementAttributes() );
+ CompositeCache<K, V> newCache =
+ new CompositeCache<K, V>( new CompositeCacheAttributes(), new ElementAttributes() );
this.setCache( newCache );
}