This commit was manufactured by cvs2svn to create tag
'jcs-1_2_3-dev'.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/jcs/tags/jcs-1_2_3-dev@224293 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/project.xml b/project.xml
index 2150efc..1ebe0ac 100644
--- a/project.xml
+++ b/project.xml
@@ -5,7 +5,7 @@
<pomVersion>3</pomVersion>
<name>Turbine JCS</name>
<id>jcs</id>
- <currentVersion>1.2.2-dev</currentVersion>
+ <currentVersion>1.2.3-dev</currentVersion>
<organization>
<name>Apache Software Foundation</name>
<url>http://jakarta.apache.org/</url>
@@ -40,13 +40,13 @@
<name>JCS User List</name>
<subscribe>turbine-jcs-user-subscribe@jakarta.apache.org</subscribe>
<unsubscribe>turbine-jcs-user-unsubscribe@jakarta.apache.org</unsubscribe>
- <archive>http://nagoya.apache.org/eyebrowse/SummarizeList?listName=turbine-jcs-user@jakarta.apache.org</archive>
+ <archive>http://mail-archives.apache.org/eyebrowse/SummarizeList?listName=turbine-jcs-user@jakarta.apache.org</archive>
</mailingList>
<mailingList>
<name>JCS Developer List</name>
<subscribe>turbine-jcs-dev-subscribe@jakarta.apache.org</subscribe>
<unsubscribe>turbine-jcs-dev-unsubscribe@jakarta.apache.org</unsubscribe>
- <archive>http://nagoya.apache.org/eyebrowse/SummarizeList?listName=turbine-jcs-dev@jakarta.apache.org</archive>
+ <archive>http://mail-archives.apache.org/eyebrowse/SummarizeList?listName=turbine-jcs-dev@jakarta.apache.org</archive>
</mailingList>
</mailingLists>
@@ -179,6 +179,7 @@
<include>**/TestTCPLateralCache.java</include>
<include>**/TestJCSvHashtablePerf.java</include>
<include>**/TestEventQueueConcurrent.java</include>
+ <include>**/TestSimpleEventHandling.java</include>
</includes>
<resources>
<includes>
diff --git a/src/conf/cache.ccf b/src/conf/cache.ccf
index aaef28f..11e37b7 100644
--- a/src/conf/cache.ccf
+++ b/src/conf/cache.ccf
@@ -20,9 +20,9 @@
##############################################################
################## CACHE REGIONS AVAILABLE ###################
# Regions preconfirgured for caching
-jcs.region.testCache1=DC
+jcs.region.testCache1=LTCP
jcs.region.testCache1.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
-jcs.region.testCache1.cacheattributes.MaxObjects=10
+jcs.region.testCache1.cacheattributes.MaxObjects=1000
jcs.region.testCache1.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
jcs.region.testCache1.cacheattributes.UseMemoryShrinker=true
jcs.region.testCache1.cacheattributes.ShrinkerIntervalSeconds=30
@@ -166,7 +166,7 @@
jcs.auxiliary.LTCP.attributes.TransmissionTypeName=TCP
jcs.auxiliary.LTCP.attributes.TcpServers=localhost:1112
jcs.auxiliary.LTCP.attributes.TcpListenerPort=1111
-jcs.auxiliary.LTCP.attributes.PutOnlyMode=false
+jcs.auxiliary.LTCP.attributes.PutOnlyMode=true
jcs.auxiliary.LTCP2=org.apache.jcs.auxiliary.lateral.LateralCacheFactory
jcs.auxiliary.LTCP2.attributes=org.apache.jcs.auxiliary.lateral.LateralCacheAttributes
diff --git a/src/conf/cache2.ccf b/src/conf/cache2.ccf
index a3559a6..d4e0647 100644
--- a/src/conf/cache2.ccf
+++ b/src/conf/cache2.ccf
@@ -15,7 +15,7 @@
##############################################################
################## CACHE REGIONS AVAILABLE ###################
-jcs.region.testCache1=RC
+jcs.region.testCache1=LTCP
jcs.region.testCache1.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
jcs.region.testCache1.cacheattributes.MaxObjects=1000
jcs.region.testCache1.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
@@ -75,7 +75,7 @@
jcs.auxiliary.LTCP.attributes.TransmissionTypeName=TCP
jcs.auxiliary.LTCP.attributes.TcpServers=localhost:1111
jcs.auxiliary.LTCP.attributes.TcpListenerPort=1112
-jcs.auxiliary.LTCP.attributes.PutOnlyMode=false
+jcs.auxiliary.LTCP.attributes.PutOnlyMode=true
jcs.auxiliary.XMLRPC=org.apache.jcs.auxiliary.lateral.LateralCacheFactory
jcs.auxiliary.XMLRPC.attributes=org.apache.jcs.auxiliary.lateral.LateralCacheAttributes
diff --git a/src/experimental/org/apache/jcs/auxiliary/lateral/socket/udp/LateralUDPReceiver.java b/src/experimental/org/apache/jcs/auxiliary/lateral/socket/udp/LateralUDPReceiver.java
index 5ad855a..af111c2 100644
--- a/src/experimental/org/apache/jcs/auxiliary/lateral/socket/udp/LateralUDPReceiver.java
+++ b/src/experimental/org/apache/jcs/auxiliary/lateral/socket/udp/LateralUDPReceiver.java
@@ -17,23 +17,20 @@
*/
import java.io.ByteArrayInputStream;
-import java.io.InputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
-
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;
-import org.apache.jcs.auxiliary.lateral.LateralCacheInfo;
-import org.apache.jcs.auxiliary.lateral.LateralElementDescriptor;
-
-import org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheAttributes;
-import org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheListener;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.jcs.auxiliary.lateral.LateralCacheInfo;
+import org.apache.jcs.auxiliary.lateral.LateralElementDescriptor;
+import org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheAttributes;
+import org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheListener;
+
/**
* A highly unreliable UDP receiver. It is easy to outrun. Uncaught message will
* die.
diff --git a/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCache.java b/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCache.java
index 650eda5..6f77e1d 100644
--- a/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCache.java
+++ b/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCache.java
@@ -217,6 +217,9 @@
}
/**
+ * Check to see if the item is in purgatory. If so, return it. If not,
+ * check to see if we have it on disk.
+ *
* @param key
* @return ICacheElement or null
*
@@ -255,7 +258,9 @@
// since the mem cache may be set to 0. If an item is active, it will keep
// getting put into purgatory and removed. The CompositeCache now does
// not put an item to memory from disk ifthe size is 0;
-
+ // Do not set spoolable to false. Just let it go to disk. This
+ // will allow the memory size = 0 setting to work well.
+
log.debug( "Found element in purgatory, cacheName: " + cacheName
+ ", key: " + key );
diff --git a/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCacheAttributes.java b/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCacheAttributes.java
index 6b644c4..204c6e5 100644
--- a/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCacheAttributes.java
+++ b/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCacheAttributes.java
@@ -20,6 +20,12 @@
import org.apache.jcs.auxiliary.AuxiliaryCacheAttributes;
import org.apache.jcs.auxiliary.disk.behavior.IDiskCacheAttributes;
+/**
+ * This has common attributes that any conceivable disk cache would need.
+ *
+ * @author aaronsm
+ *
+ */
public abstract class AbstractDiskCacheAttributes extends
AbstractAuxiliaryCacheAttributes implements IDiskCacheAttributes
{
@@ -73,7 +79,7 @@
/**
* Description of the Method
*
- * @return
+ * @return AuxiliaryCacheAttributes
*/
public AuxiliaryCacheAttributes copy()
{
@@ -90,7 +96,7 @@
/**
* Description of the Method
*
- * @return
+ * @return String
*/
public String toString()
{
diff --git a/src/java/org/apache/jcs/auxiliary/disk/LRUMapJCS.java b/src/java/org/apache/jcs/auxiliary/disk/LRUMapJCS.java
index b1fff5b..c9adcd6 100644
--- a/src/java/org/apache/jcs/auxiliary/disk/LRUMapJCS.java
+++ b/src/java/org/apache/jcs/auxiliary/disk/LRUMapJCS.java
@@ -1,36 +1,56 @@
package org.apache.jcs.auxiliary.disk;
+import org.apache.commons.collections.map.LRUMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.commons.collections.map.LRUMap;
/**
- * Extension of LRUMap for logging of removals.
- * Can switch this back to a HashMap easily.
- */
+ * Extension of LRUMap for logging of removals. Can switch this back to a
+ * HashMap easily.
+ */
public class LRUMapJCS extends LRUMap
{
- private static final Log log =
- LogFactory.getLog( LRUMapJCS.class );
+ private static final Log log = LogFactory.getLog( LRUMapJCS.class );
- public LRUMapJCS()
- {
- super();
- }
+ /**
+ * This creates an unbounded version.
+ */
+ public LRUMapJCS()
+ {
+ super();
+ }
- public LRUMapJCS( int maxKeySize )
- {
- super( maxKeySize );
- }
+ /**
+ * This creates a list bounded by the max key size argument. The
+ * Boundary is enforces by an LRU eviction policy.
+ * <p>
+ * This is used in the Disk cache to store keys and purgatory elements if a boundary
+ * is requested.
+ * <p>
+ * The LRU memory cache uses its own LRU implementation.
+ *
+ * @param maxKeySize
+ */
+ public LRUMapJCS(int maxKeySize)
+ {
+ super( maxKeySize );
+ }
- protected void processRemovedLRU( Object key, Object value )
- {
- if ( log.isDebugEnabled() )
- {
- log.debug( "Removing key: '" + key + "' from key store." );
- log.debug( "Key store size: '" + this.size() + "'." );
- }
+ /**
+ * This is called when an item is removed from the LRU. We just log some
+ * information.
+ *
+ * @param key
+ * @param value
+ */
+ protected void processRemovedLRU( Object key, Object value )
+ {
+ if (log.isDebugEnabled())
+ {
+ log.debug( "Removing key: [" + key + "] from key store, value = [" + value +"]" );
+ log.debug( "Key store size: '" + this.size() + "'." );
+ }
- }
-}
+ }
+}
\ No newline at end of file
diff --git a/src/java/org/apache/jcs/auxiliary/disk/PurgatoryElement.java b/src/java/org/apache/jcs/auxiliary/disk/PurgatoryElement.java
index 73e6f30..7f3419f 100644
--- a/src/java/org/apache/jcs/auxiliary/disk/PurgatoryElement.java
+++ b/src/java/org/apache/jcs/auxiliary/disk/PurgatoryElement.java
@@ -74,6 +74,7 @@
/**
* Get the wrapped cache element.
+ * @return ICacheElement
*/
public ICacheElement getCacheElement()
{
@@ -115,6 +116,8 @@
}
/**
+ * @param attr
+ *
* @see ICacheElement#setElementAttributes
*/
public void setElementAttributes( IElementAttributes attr )
diff --git a/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDisk.java b/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDisk.java
index abf934d..d01d43d 100644
--- a/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDisk.java
+++ b/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDisk.java
@@ -63,10 +63,15 @@
/**
- * Description of the Method
+ * This reads an object from the given starting position on the file.
+ * <p>
+ * The firt four bytes of the record should tell us how long it is.
+ * The data is read into a byte array and then an object is constructed
+ * from the byte array.
*
- * @return
+ * @return Serializable
* @param pos
+ * @throws IOException
*/
Serializable readObject( long pos ) throws IOException
{
diff --git a/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheAttributes.java b/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheAttributes.java
index a6272eb..d7bb8a2 100644
--- a/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheAttributes.java
+++ b/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheAttributes.java
@@ -61,8 +61,8 @@
/**
* Sets the maxKeySize attribute of the DiskCacheAttributes object
- *
- * @param name The new maxKeySize value
+ *
+ * @param maxKeySize The new maxKeySize value
*/
public void setMaxKeySize( int maxKeySize )
{
@@ -88,7 +88,7 @@
* This number determines how often the disk cache should run real time
* optimizations.
*
- * @param name The new optimizeAtRemoveCount value
+ * @param cnt The new optimizeAtRemoveCount value
*/
public void setOptimizeAtRemoveCount( int cnt)
{
@@ -131,7 +131,7 @@
/**
* Description of the Method
*
- * @return
+ * @return AuxiliaryCacheAttributes
*/
public AuxiliaryCacheAttributes copy()
{
@@ -149,7 +149,7 @@
/**
* Description of the Method
*
- * @return
+ * @return String
*/
public String toString()
{
diff --git a/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheFactory.java b/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheFactory.java
index 544dba2..50b7c3a 100644
--- a/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheFactory.java
+++ b/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheFactory.java
@@ -21,6 +21,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
import org.apache.jcs.auxiliary.AuxiliaryCache;
import org.apache.jcs.auxiliary.AuxiliaryCacheAttributes;
import org.apache.jcs.auxiliary.AuxiliaryCacheFactory;
@@ -37,15 +38,25 @@
private String name;
/**
- * Description of the Method
+ * Get an instance of the IndexDiskCacheManager for the attributes and then
+ * get an IndexedDiskCache from the manager.
+ * <p>
+ * The manager is a singleton.
+ * <p>
+ * One disk cache is returned per region fromt he maanger.
*
- * @return
- * @param iaca
+ * @param iaca The auxiliary attributes.
+ * @param cache The CacheHub
+ * @return AuxiliaryCache
*/
public AuxiliaryCache createCache( AuxiliaryCacheAttributes iaca,
CompositeCache cache )
{
IndexedDiskCacheAttributes idca = ( IndexedDiskCacheAttributes ) iaca;
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( "Creating DiskCache for attributes = " + idca );
+ }
IndexedDiskCacheManager dcm = IndexedDiskCacheManager.getInstance( idca );
return dcm.getCache( idca );
}
diff --git a/src/java/org/apache/jcs/auxiliary/lateral/LateralCache.java b/src/java/org/apache/jcs/auxiliary/lateral/LateralCache.java
index 323300b..dad637a 100644
--- a/src/java/org/apache/jcs/auxiliary/lateral/LateralCache.java
+++ b/src/java/org/apache/jcs/auxiliary/lateral/LateralCache.java
@@ -20,44 +20,31 @@
import java.io.IOException;
import java.io.Serializable;
-
-import java.util.HashMap;
import java.util.Set;
-import org.apache.jcs.auxiliary.AuxiliaryCacheAttributes;
-import org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheAttributes;
-import org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheService;
-
-import org.apache.jcs.engine.behavior.IElementAttributes;
-import org.apache.jcs.engine.CacheConstants;
-
-import org.apache.jcs.engine.behavior.ICache;
-import org.apache.jcs.engine.behavior.ICacheElement;
-import org.apache.jcs.engine.behavior.ICacheType;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.jcs.auxiliary.AuxiliaryCacheAttributes;
+import org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheAttributes;
+import org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheService;
+import org.apache.jcs.engine.CacheConstants;
+import org.apache.jcs.engine.behavior.ICache;
+import org.apache.jcs.engine.behavior.ICacheElement;
+import org.apache.jcs.engine.behavior.ICacheType;
import org.apache.jcs.engine.behavior.IZombie;
/**
- * Lateral distributor. Returns null on get. Net search not implemented.
+ * Lateral distributor. Returns null on get by default. Net search not implemented.
*
*/
public class LateralCache implements ICache
{
private final static Log log =
LogFactory.getLog( LateralCache.class );
-
- private static int numCreated = 0;
-
- IElementAttributes attr = null;
-
- private HashMap keyHash;
- // not synchronized to maximize concurrency.
-
+
// generalize this, use another interface
- public ILateralCacheAttributes cattr;
+ private ILateralCacheAttributes cattr;
final String cacheName;
@@ -86,19 +73,25 @@
protected LateralCache( ILateralCacheAttributes cattr )
{
this.cacheName = cattr.getCacheName();
- //this.servers = servers;
-
this.cattr = cattr ;
}
- /** Description of the Method */
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
public String toString()
{
- return "LateralCache: " + this.cattr.getCacheName();
+ return "LateralCache: " + cattr.getCacheName();
}
- /** Description of the Method */
+ /**
+ * Update lateral.
+ *
+ * @param ce
+ * @throws IOException
+ */
public void update( ICacheElement ce )
throws IOException
{
@@ -124,7 +117,14 @@
}
// end update
- /** Returns null. The performace costs are too great. */
+ /**
+ * The performace costs are too great. It is not recommended that you enable lateral
+ * gets.
+ *
+ * @param key
+ * @return
+ * @throws IOException
+ */
public ICacheElement get( Serializable key )
throws IOException
{
@@ -146,6 +146,12 @@
return obj;
}
+
+ /**
+ *
+ * @param groupName
+ * @return A set og group keys.
+ */
public Set getGroupKeys(String groupName)
{
return lateral.getGroupKeys(cacheName, groupName);
@@ -155,6 +161,9 @@
/**
* Synchronously remove from the remote cache; if failed, replace the remote
* handle with a zombie.
+ * @param key
+ * @return
+ * @throws IOException
*/
public boolean remove( Serializable key )
throws IOException
@@ -178,6 +187,8 @@
/**
* Synchronously removeAll from the remote cache; if failed, replace the
* remote handle with a zombie.
+ *
+ * @throws IOException
*/
public void removeAll()
throws IOException
@@ -195,7 +206,8 @@
}
- /** Synchronously dispose the cache. Not sure we want this. */
+ /** Synchronously dispose the cache. Not sure we want this.
+ * @throws IOException*/
public void dispose()
throws IOException
{
@@ -259,7 +271,11 @@
}
- /** Not yet sure what to do here. */
+ /** Not yet sure what to do here.
+ * @param ex
+ * @param msg
+ * @throws IOException
+ */
private void handleException( Exception ex, String msg )
throws IOException
{
@@ -282,6 +298,7 @@
/**
* Replaces the current remote cache service handle with the given handle.
+ * @param lateral
*/
public void fixCache( ILateralCacheService lateral )
{
diff --git a/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheAttributes.java b/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheAttributes.java
index 632b2f3..6792349 100644
--- a/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheAttributes.java
+++ b/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheAttributes.java
@@ -25,7 +25,7 @@
import org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheAttributes;
/**
- * Description of the Class
+ * This class stores attributes for all of the available lateral cache auxiliaries.
*
*/
public class LateralCacheAttributes extends AbstractAuxiliaryCacheAttributes
@@ -387,10 +387,9 @@
}
- /**
- * Description of the Method
- *
- * @return
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Object#toString()
*/
public String toString()
{
diff --git a/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheFactory.java b/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheFactory.java
index f6de4de..4da6a00 100644
--- a/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheFactory.java
+++ b/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheFactory.java
@@ -48,8 +48,9 @@
* Interface method. Allows classforname construction, making caches
* pluggable.
*
- * @return
+ * @return AuxiliaryCache
* @param iaca
+ * @param cache
*/
public AuxiliaryCache createCache( AuxiliaryCacheAttributes iaca,
CompositeCache cache )
@@ -102,7 +103,7 @@
}
else
{
- //p( "noWait is null" );
+ log.debug( "noWait is null, no lateral connection made" );
}
}
diff --git a/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheManager.java b/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheManager.java
index 0c847cc..d61049c 100644
--- a/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheManager.java
+++ b/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheManager.java
@@ -44,7 +44,9 @@
* configured cache hub, then lateral removals may be necessary. For flat
* webserver production environments, without a strong machine at the app server
* level, distribution and search may need to occur at the lateral cache level.
- * This is currently not implemented in the lateral cache. TODO: - need
+ * This is currently not implemented in the lateral cache.
+ * <p>
+ * @TODO: - need
* freeCache, release, getStats - need to find an interface acceptible for all -
* cache managers or a manager within a type
*/
@@ -119,7 +121,7 @@
/**
* Constructor for the LateralCacheManager object
*
- * @param lca
+ * @param lcaA
*/
private LateralCacheManager( ILateralCacheAttributes lcaA )
{
@@ -259,7 +261,7 @@
/**
* Gets the cacheType attribute of the LateralCacheManager object
*
- * @return The {3} value
+ * @return The cache type value
*/
public int getCacheType()
{
diff --git a/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheNoWait.java b/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheNoWait.java
index cd0c915..f23b70c 100644
--- a/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheNoWait.java
+++ b/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheNoWait.java
@@ -26,6 +26,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
import org.apache.jcs.auxiliary.AuxiliaryCache;
import org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheService;
import org.apache.jcs.engine.CacheAdaptor;
@@ -38,7 +39,6 @@
import org.apache.jcs.engine.stats.behavior.IStatElement;
import org.apache.jcs.engine.stats.behavior.IStats;
-//import org.apache.jcs.auxiliary.lateral.socket.tcp.*;
/**
* Used to queue up update requests to the underlying cache. These requests will
@@ -81,7 +81,10 @@
}
}
- /** Description of the Method */
+ /**
+ * @param ce
+ * @throws IOException
+ */
public void update( ICacheElement ce ) throws IOException
{
try
@@ -95,7 +98,10 @@
}
}
- /** Synchronously reads from the lateral cache. */
+ /** Synchronously reads from the lateral cache.
+ * @param key
+ * @return ICacheElement if found, else null
+ */
public ICacheElement get( Serializable key )
{
@@ -131,7 +137,10 @@
return cache.getGroupKeys( groupName );
}
- /** Adds a remove request to the lateral cache. */
+ /** Adds a remove request to the lateral cache.
+ * @param key
+ * @return always false
+ */
public boolean remove( Serializable key )
{
try
@@ -219,6 +228,8 @@
/**
* Replaces the lateral cache service handle with the given handle and reset
* the queue by starting up a new instance.
+ *
+ * @param lateral
*/
public void fixCache( ILateralCacheService lateral )
{
@@ -245,7 +256,10 @@
cache.getAuxiliaryCacheAttributes().getEventQueueTypeFactoryCode() );
}
- /** Description of the Method */
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
public String toString()
{
return "LateralCacheNoWait: " + cache.toString();
@@ -273,8 +287,7 @@
ArrayList elems = new ArrayList();
- IStatElement se = null;
-
+ //IStatElement se = null;
// no data gathered here
// get the stats from the event queue too
diff --git a/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheNoWaitFacade.java b/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheNoWaitFacade.java
index 848e467..56adbca 100644
--- a/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheNoWaitFacade.java
+++ b/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheNoWaitFacade.java
@@ -21,6 +21,8 @@
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
import java.util.Set;
import java.util.HashSet;
@@ -64,7 +66,10 @@
this.cacheName = cacheName;
}
- /** Description of the Method */
+ /*
+ * (non-Javadoc)
+ * @see org.apache.jcs.engine.behavior.ICache#update(org.apache.jcs.engine.behavior.ICacheElement)
+ */
public void update( ICacheElement ce )
throws IOException
{
@@ -85,7 +90,12 @@
}
}
- /** Synchronously reads from the lateral cache. */
+ /**
+ * Synchronously reads from the lateral cache.
+ *
+ * @param key
+ * @return ICacheElement
+ */
public ICacheElement get( Serializable key )
{
for ( int i = 0; i < noWaits.length; i++ )
@@ -111,8 +121,9 @@
return null;
}
- /**
- * Gets the set of keys of objects currently in the group
+ /*
+ * (non-Javadoc)
+ * @see org.apache.jcs.auxiliary.AuxiliaryCache#getGroupKeys(java.lang.String)
*/
public Set getGroupKeys(String group)
{
@@ -134,7 +145,12 @@
return allKeys;
}
- /** Adds a remove request to the lateral cache. */
+ /**
+ * Adds a remove request to the lateral cache.
+ *
+ * @param key
+ * @return always false.
+ */
public boolean remove( Serializable key )
{
try
@@ -151,7 +167,9 @@
return false;
}
- /** Adds a removeAll request to the lateral cache. */
+ /**
+ * Adds a removeAll request to the lateral cache.
+ */
public void removeAll()
{
try
@@ -228,7 +246,10 @@
//q.isAlive() ? cache.getStatus() : cache.STATUS_ERROR;
}
- /** Description of the Method */
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
public String toString()
{
return "LateralCacheNoWaitFacade: " + cacheName;
@@ -264,6 +285,17 @@
se.setName( "Number of No Waits" );
se.setData( "" + noWaits.length );
elems.add( se );
+
+ for ( int i = 0; i < noWaits.length; i++ )
+ {
+ // get the stats from the super too
+ // get as array, convert to list, add list to our outer list
+ IStats sStats = noWaits[i].getStatistics();
+ IStatElement[] sSEs = sStats.getStatElements();
+ List sL = Arrays.asList( sSEs );
+ elems.addAll( sL );
+ }
+
}
// get an array and put them in the Stats object
diff --git a/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheRestore.java b/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheRestore.java
index 9492ea9..d5d5e4f 100644
--- a/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheRestore.java
+++ b/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheRestore.java
@@ -59,6 +59,8 @@
/**
* Returns true iff the connection to the lateral host for the corresponding
* cache manager can be successfully re-established.
+ *
+ * @return whether or not the cache can be fixed.
*/
public boolean canFix()
{
diff --git a/src/java/org/apache/jcs/auxiliary/lateral/ZombieLateralCacheService.java b/src/java/org/apache/jcs/auxiliary/lateral/ZombieLateralCacheService.java
index e4c5d64..8013385 100644
--- a/src/java/org/apache/jcs/auxiliary/lateral/ZombieLateralCacheService.java
+++ b/src/java/org/apache/jcs/auxiliary/lateral/ZombieLateralCacheService.java
@@ -29,23 +29,38 @@
import org.apache.jcs.engine.behavior.ICacheElement;
/**
- * Description of the Class
+ * The ZombieLateralCacheService is used a facade when the lateral is not available.
+ * It balks when the lateral is in error. When lateral service is restored, this
+ * is replaced by a live facade.
*
*/
public class ZombieLateralCacheService extends ZombieCacheService implements ILateralCacheService
{
- /** Description of the Method */
+ /*
+ * (non-Javadoc)
+ * @see org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheService#update(org.apache.jcs.engine.behavior.ICacheElement, long)
+ */
public void update( ICacheElement item, long listenerId ) { }
- /** Description of the Method */
+ /*
+ * (non-Javadoc)
+ * @see org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheService#remove(java.lang.String, java.io.Serializable, long)
+ */
public void remove( String cacheName, Serializable key, long listenerId ) { }
- /** Description of the Method */
+ /*
+ * (non-Javadoc)
+ * @see org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheService#removeAll(java.lang.String, long)
+ */
public void removeAll( String cacheName, long listenerId ) { }
+ /*
+ * (non-Javadoc)
+ * @see org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheService#getGroupKeys(java.lang.String, java.lang.String)
+ */
public Set getGroupKeys(String cacheName, String groupName)
{
return Collections.EMPTY_SET;
diff --git a/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPListener.java b/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPListener.java
index 10f0a8a..b9b2145 100644
--- a/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPListener.java
+++ b/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPListener.java
@@ -74,8 +74,9 @@
// -------------------------------------------------------- factory methods
/**
- * Gets the instance attribute of the LateralCacheTCPListener class
- *
+ * Gets the instance attribute of the LateralCacheTCPListener class.
+ *
+ * @param ilca
* @return The instance value
*/
public synchronized static ILateralCacheListener
@@ -140,6 +141,7 @@
* reconnect.
*
* @param id The new listenerId value
+ * @throws IOException
*/
public void setListenerId( long id )
throws IOException
@@ -155,6 +157,7 @@
* Gets the listenerId attribute of the LateralCacheTCPListener object
*
* @return The listenerId value
+ * @throws IOException
*/
public long getListenerId()
throws IOException
@@ -220,6 +223,12 @@
getCache( cacheName ).localRemoveAll();
}
+ /**
+ * @param cacheName
+ * @param key
+ * @return Serializable
+ * @throws IOException
+ */
public Serializable handleGet( String cacheName, Serializable key )
throws IOException
{
@@ -244,7 +253,10 @@
}
/**
- * Gets the cacheManager attribute of the LateralCacheTCPListener object
+ * Gets the cacheManager attribute of the LateralCacheTCPListener object.
+ *
+ * @param name
+ * @return CompositeCache
*/
protected CompositeCache getCache( String name )
{
@@ -316,7 +328,9 @@
{
private Socket socket;
- /** Construct for a given socket */
+ /** Construct for a given socket
+ * @param socket
+ */
public ConnectionHandler( Socket socket )
{
this.socket = socket;
diff --git a/src/java/org/apache/jcs/engine/ElementAttributes.java b/src/java/org/apache/jcs/engine/ElementAttributes.java
index 5e31d3f..76bd458 100644
--- a/src/java/org/apache/jcs/engine/ElementAttributes.java
+++ b/src/java/org/apache/jcs/engine/ElementAttributes.java
@@ -30,486 +30,487 @@
import org.apache.jcs.engine.behavior.IElementAttributes;
/**
- * Element attribute descriptor class.
- *
- *@version $Id: ILateralCacheTCPListener.java,v 1.2 2002/01/18 22:08:26
+ * Element attribute descriptor class.
+ *
+ * @version $Id: ILateralCacheTCPListener.java,v 1.2 2002/01/18 22:08:26
*/
-public class ElementAttributes
- implements IElementAttributes, Serializable, Cloneable
+public class ElementAttributes implements IElementAttributes, Serializable,
+ Cloneable
{
- /**
- * Is this item distributable at all.
- */
- public boolean IS_DISTRIBUTE = true;
-
- // lateral
-
- /**
- * can this item be flushed to disk
- */
- public boolean IS_SPOOL = true;
-
- /**
- * Is this item laterally distributable
- */
- public boolean IS_LATERAL = true;
-
- /**
- * Can this item be sent to the remote cache
- */
- public boolean IS_REMOTE = true;
-
- /**
- * can turn off expiration
- */
- public boolean IS_ETERNAL = true;
-
- /**
- * Description of the Field
- */
- public long version = 0;
-
- /**
- * Max life seconds
- */
- public long mls = -1;
-
- /**
- * Description of the Field
- */
- public long idle = -1;
-
- /**
- * The byte size of teh field. Must be manually set.
- */
- public int size = 0;
-
- /**
- * The creation time
- */
- public long createTime = 0;
-
- /**
- * The last access time
- */
- public long lastAccessTime = 0;
-
- /**
- * The last access time
- */
- public ArrayList eventHandlers;
-
- /**
- * Constructor for the IElementAttributes object
- */
- public ElementAttributes()
- {
- this.createTime = System.currentTimeMillis();
- this.lastAccessTime = this.createTime;
- }
-
- /**
- * Constructor for the IElementAttributes object
- *
- *@param attr
- */
- private ElementAttributes( ElementAttributes attr )
- {
-
- IS_ETERNAL = attr.IS_ETERNAL;
-
- // waterfal onto disk, for pure disk set memory to 0
- IS_SPOOL = attr.IS_SPOOL;
-
- IS_DISTRIBUTE = attr.IS_DISTRIBUTE;
+ /**
+ * Is this item distributable at all.
+ */
+ public boolean IS_DISTRIBUTE = true;
// lateral
- IS_LATERAL = attr.IS_LATERAL;
- // central rmi store
- IS_REMOTE = attr.IS_REMOTE;
+ /**
+ * can this item be flushed to disk
+ */
+ public boolean IS_SPOOL = true;
- mls = attr.mls;
- // timetolive
- idle = attr.idle;
- size = attr.size;
+ /**
+ * Is this item laterally distributable
+ */
+ public boolean IS_LATERAL = true;
- }
+ /**
+ * Can this item be sent to the remote cache
+ */
+ public boolean IS_REMOTE = true;
- /**
- * Description of the Method
- *
- *@return
- */
- public IElementAttributes copy()
- {
- try
+ /**
+ * can turn off expiration
+ */
+ public boolean IS_ETERNAL = true;
+
+ /**
+ * Description of the Field
+ */
+ public long version = 0;
+
+ /**
+ * Max life seconds
+ */
+ public long mls = -1;
+
+ /**
+ * Description of the Field
+ */
+ public long idle = -1;
+
+ /**
+ * The byte size of teh field. Must be manually set.
+ */
+ public int size = 0;
+
+ /**
+ * The creation time
+ */
+ public long createTime = 0;
+
+ /**
+ * The last access time
+ */
+ public long lastAccessTime = 0;
+
+ /**
+ * The list of Event handlers to use.
+ */
+ public transient ArrayList eventHandlers;
+
+ /**
+ * Constructor for the IElementAttributes object
+ */
+ public ElementAttributes()
{
-// ElementAttributes attr = ( ElementAttributes ) this.clone();
-// attr.createTime = System.currentTimeMillis();
-// attr.setLastAccessTimeNow();
-// return attr;
-
- // need to make this more efficient. Just want to insure
- // a proper copy
- ElementAttributes attr = new ElementAttributes();
- attr.setIdleTime( this.getIdleTime() );
- attr.setIsEternal( this.getIsEternal() );
- attr.setIsDistribute( this.getIsDistribute() );
- attr.setIsLateral( this.getIsLateral() );
- attr.setIsRemote( this.getIsRemote() );
- attr.setIsSpool( this.getIsSpool() );
- attr.setMaxLifeSeconds( this.getMaxLifeSeconds() );
- attr.addElementEventHandlers( this.eventHandlers );
- return attr;
- }
- catch ( Exception e )
- {
- return new ElementAttributes();
- }
- }
-
- /**
- * Description of the Method
- *
- * @return a clone of these attributes
- */
- public Object clone2()
- {
-
- try
- {
- ByteArrayOutputStream baos =
- new ByteArrayOutputStream( 100 );
- ObjectOutputStream oos = new
- ObjectOutputStream( baos );
- oos.writeObject( this );
- byte buf[] = baos.toByteArray();
- oos.close();
-
- // deserialize byte array into ArrayList
-
- ByteArrayInputStream bais =
- new ByteArrayInputStream( buf );
- ObjectInputStream ois = new
- ObjectInputStream( bais );
- ElementAttributes attr =
- ( ElementAttributes ) ois.readObject();
- ois.close();
-
- attr.createTime = System.currentTimeMillis();
- return attr;
- }
- catch ( Exception e )
- {
- }
- return null;
- }
-
- /**
- * Sets the version attribute of the IElementAttributes object
- *
- *@param version The new version value
- */
- public void setVersion( long version )
- {
- this.version = version;
- }
-
- /**
- * Sets the maxLifeSeconds attribute of the IElementAttributes object
- *
- *@param mls The new {3} value
- */
- public void setMaxLifeSeconds( long mls )
- {
- this.mls = mls;
- }
-
- /**
- * Gets the {3} attribute of the ElementAttributes object
- *
- *@return The {3} value
- */
- public long getMaxLifeSeconds()
- {
- return this.mls;
- }
-
- /**
- * Sets the idleTime attribute of the IElementAttributes object
- *
- *@param idle The new idleTime value
- */
- public void setIdleTime( long idle )
- {
- this.idle = idle;
- }
-
- //public void setListener( int event, CacheEventListener listerner) {}
-
- /**
- * Size in bytes.
- *
- *@param size The new size value
- */
- public void setSize( int size )
- {
- this.size = size;
- }
-
- /**
- * Gets the size attribute of the IElementAttributes object
- *
- *@return The size value
- */
- public int getSize()
- {
- return size;
- }
-
- /**
- * Gets the createTime attribute of the IElementAttributes object
- *
- *@return The createTime value
- */
- public long getCreateTime()
- {
- return createTime;
- }
-
- /**
- * Sets the createTime attribute of the IElementAttributes object
- */
- public void setCreateTime()
- {
- createTime = System.currentTimeMillis();
- }
-
- /**
- * Gets the version attribute of the IElementAttributes object
- *
- *@return The version value
- */
- public long getVersion()
- {
- return version;
- }
-
- /**
- * Gets the idleTime attribute of the IElementAttributes object. Keeping
- * track of this will require storing the last access time. This could get
- * expensive.
- *
- *@return The idleTime value
- */
- public long getIdleTime()
- {
- return this.idle;
- }
-
- /**
- * If the returned value is negative, the item has expired
- *
- *@return The timeToLive value
- */
- public long getTimeToLiveSeconds()
- {
- long now = System.currentTimeMillis();
- return ( this.getCreateTime() + ( this.getMaxLifeSeconds() * 1000 ) ) - now;
- }
-
- /**
- * Gets the LastAccess attribute of the IAttributes object
- *
- *@return The LastAccess value
- */
- public long getLastAccessTime()
- {
- return this.lastAccessTime;
- }
-
- /**
- * Sets the LastAccessTime as now of the IElementAttributes object
- */
- public void setLastAccessTimeNow()
- {
- this.lastAccessTime = System.currentTimeMillis();
- }
-
- /**
- * Gets the {3} attribute of the IElementAttributes object
- *
- *@return The {3} value
- */
- public boolean getIsDistribute()
- {
- return this.IS_DISTRIBUTE;
- }
-
- /**
- * Sets the isDistribute attribute of the ElementAttributes object
- *
- *@param val The new isDistribute value
- */
- public void setIsDistribute( boolean val )
- {
- this.IS_DISTRIBUTE = val;
- }
-
- /**
- * can this item be flushed to disk
- *
- *@return The {3} value
- */
- public boolean getIsSpool()
- {
- return this.IS_SPOOL;
- }
-
- /**
- * Sets the isSpool attribute of the ElementAttributes object
- *
- *@param val The new isSpool value
- */
- public void setIsSpool( boolean val )
- {
- this.IS_SPOOL = val;
- }
-
- /**
- * Is this item laterally distributable
- *
- *@return The {3} value
- */
- public boolean getIsLateral()
- {
- return this.IS_LATERAL;
- }
-
- /**
- * Sets the isLateral attribute of the ElementAttributes object
- *
- *@param val The new isLateral value
- */
- public void setIsLateral( boolean val )
- {
- this.IS_LATERAL = val;
- }
-
- /**
- * Can this item be sent to the remote cache
- *
- *@return The {3} value
- */
- public boolean getIsRemote()
- {
- return this.IS_REMOTE;
- }
-
- /**
- * Sets the isRemote attribute of the ElementAttributes object
- *
- *@param val The new isRemote value
- */
- public void setIsRemote( boolean val )
- {
- this.IS_REMOTE = val;
- }
-
- /**
- * can turn off expiration
- *
- *@return The {3} value
- */
- public boolean getIsEternal()
- {
- return this.IS_ETERNAL;
- }
-
- /**
- * Sets the isEternal attribute of the ElementAttributes object
- *
- *@param val The new isEternal value
- */
- public void setIsEternal( boolean val )
- {
- this.IS_ETERNAL = val;
- }
-
- /**
- * Adds a ElementEventHandler. Handler's can be registered for multiple
- * events. A registered handler will be called at every recognized event.
- *
- * The alternative would be to register handlers for each event. Or maybe
- * The handler interface should ahve a method to return whether it cares
- * about certain events.
- *
- *@param eventHandler The ElementEventHandler to be added to the list.
- */
- public void addElementEventHandler( IElementEventHandler eventHandler )
- {
- // lazy here, no concurrency problems expected
- if ( this.eventHandlers == null )
- {
- this.eventHandlers = new ArrayList();
- }
- this.eventHandlers.add( eventHandler );
- }
-
- /**
- * Sets the eventHandlers of the IElementAttributes object
- *
- *@param eventHandlers value
- */
- public void addElementEventHandlers( ArrayList eventHandlers )
- {
- if ( eventHandlers == null )
- {
- return;
+ this.createTime = System.currentTimeMillis();
+ this.lastAccessTime = this.createTime;
}
- for ( Iterator iter = eventHandlers.iterator(); iter.hasNext(); )
+ /**
+ * Constructor for the IElementAttributes object
+ *
+ * @param attr
+ */
+ private ElementAttributes(ElementAttributes attr)
{
- addElementEventHandler( ( IElementEventHandler ) iter.next() );
+
+ IS_ETERNAL = attr.IS_ETERNAL;
+
+ // waterfal onto disk, for pure disk set memory to 0
+ IS_SPOOL = attr.IS_SPOOL;
+
+ IS_DISTRIBUTE = attr.IS_DISTRIBUTE;
+
+ // lateral
+ IS_LATERAL = attr.IS_LATERAL;
+
+ // central rmi store
+ IS_REMOTE = attr.IS_REMOTE;
+
+ mls = attr.mls;
+ // timetolive
+ idle = attr.idle;
+ size = attr.size;
+
}
- }
- /**
- * Gets the elementEventHandlers. Returns null if none exist. Makes
- * checking easy.
- *
- *@return The elementEventHandlers value
- */
+ /**
+ * Copies the attributes, including references to event handlers.
+ *
+ * @return a copy of the Attributes
+ */
+ public IElementAttributes copy()
+ {
+ try
+ {
+ // need to make this more efficient. Just want to insure
+ // a proper copy
+ ElementAttributes attr = new ElementAttributes();
+ attr.setIdleTime( this.getIdleTime() );
+ attr.setIsEternal( this.getIsEternal() );
+ attr.setIsDistribute( this.getIsDistribute() );
+ attr.setIsLateral( this.getIsLateral() );
+ attr.setIsRemote( this.getIsRemote() );
+ attr.setIsSpool( this.getIsSpool() );
+ attr.setMaxLifeSeconds( this.getMaxLifeSeconds() );
+ attr.addElementEventHandlers( this.eventHandlers );
+ return attr;
+ }
+ catch (Exception e)
+ {
+ return new ElementAttributes();
+ }
+ }
- public ArrayList getElementEventHandlers()
- {
- return this.eventHandlers;
- }
+ /**
+ * Deep clone the attributes.
+ *
+ * @return a clone of these attributes
+ */
+ public Object clone2()
+ {
- /**
- * For logging and debugging the element IElementAttributes.
- *
- *@return
- */
- public String toString()
- {
- StringBuffer dump = new StringBuffer();
+ try
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream( 100 );
+ ObjectOutputStream oos = new ObjectOutputStream( baos );
+ oos.writeObject( this );
+ byte buf[] = baos.toByteArray();
+ oos.close();
- dump.append( "[ IS_LATERAL = " ).append( IS_LATERAL )
- .append( ", IS_SPOOL = " ).append( IS_SPOOL )
- .append( ", IS_REMOTE = " ).append( IS_REMOTE )
- .append( ", IS_ETERNAL = " ).append( IS_ETERNAL )
- .append( ", MaxLifeSeconds = " ).append( this.getMaxLifeSeconds() )
- .append( ", IdleTime = " ).append( this.getIdleTime() )
- .append( ", CreateTime = " ).append( this.getCreateTime() )
- .append( ", LastAccessTime = " ).append( this.getLastAccessTime() )
- .append( ", getTimeToLiveSeconds() = " ).append( String.valueOf(
- getTimeToLiveSeconds() ) )
- .append( ", createTime = " ).append( String.valueOf( createTime ) )
- .append( " ]" );
+ // deserialize byte array into ArrayList
- return dump.toString();
- }
-}
+ ByteArrayInputStream bais = new ByteArrayInputStream( buf );
+ ObjectInputStream ois = new ObjectInputStream( bais );
+ ElementAttributes attr = (ElementAttributes) ois.readObject();
+ ois.close();
+
+ attr.createTime = System.currentTimeMillis();
+ return attr;
+ }
+ catch (Exception e)
+ {
+ }
+ return null;
+ }
+
+ /**
+ * Sets the version attribute of the IElementAttributes object
+ *
+ * @param version
+ * The new version value
+ */
+ public void setVersion( long version )
+ {
+ this.version = version;
+ }
+
+ /**
+ * Sets the maxLifeSeconds attribute of the IElementAttributes object
+ *
+ * @param mls
+ * The new {3} value
+ */
+ public void setMaxLifeSeconds( long mls )
+ {
+ this.mls = mls;
+ }
+
+ /**
+ * Gets the {3} attribute of the ElementAttributes object
+ *
+ * @return The {3} value
+ */
+ public long getMaxLifeSeconds()
+ {
+ return this.mls;
+ }
+
+ /**
+ * Sets the idleTime attribute of the IElementAttributes object
+ *
+ * @param idle
+ * The new idleTime value
+ */
+ public void setIdleTime( long idle )
+ {
+ this.idle = idle;
+ }
+
+ //public void setListener( int event, CacheEventListener listerner) {}
+
+ /**
+ * Size in bytes.
+ *
+ * @param size
+ * The new size value
+ */
+ public void setSize( int size )
+ {
+ this.size = size;
+ }
+
+ /**
+ * Gets the size attribute of the IElementAttributes object
+ *
+ * @return The size value
+ */
+ public int getSize()
+ {
+ return size;
+ }
+
+ /**
+ * Gets the createTime attribute of the IElementAttributes object
+ *
+ * @return The createTime value
+ */
+ public long getCreateTime()
+ {
+ return createTime;
+ }
+
+ /**
+ * Sets the createTime attribute of the IElementAttributes object
+ */
+ public void setCreateTime()
+ {
+ createTime = System.currentTimeMillis();
+ }
+
+ /**
+ * Gets the version attribute of the IElementAttributes object
+ *
+ * @return The version value
+ */
+ public long getVersion()
+ {
+ return version;
+ }
+
+ /**
+ * Gets the idleTime attribute of the IElementAttributes object. Keeping
+ * track of this will require storing the last access time. This could get
+ * expensive.
+ *
+ * @return The idleTime value
+ */
+ public long getIdleTime()
+ {
+ return this.idle;
+ }
+
+ /**
+ * If the returned value is negative, the item has expired
+ *
+ * @return The timeToLive value
+ */
+ public long getTimeToLiveSeconds()
+ {
+ long now = System.currentTimeMillis();
+ return (this.getCreateTime() + (this.getMaxLifeSeconds() * 1000)) - now;
+ }
+
+ /**
+ * Gets the LastAccess attribute of the IAttributes object
+ *
+ * @return The LastAccess value
+ */
+ public long getLastAccessTime()
+ {
+ return this.lastAccessTime;
+ }
+
+ /**
+ * Sets the LastAccessTime as now of the IElementAttributes object
+ */
+ public void setLastAccessTimeNow()
+ {
+ this.lastAccessTime = System.currentTimeMillis();
+ }
+
+ /**
+ * Gets the {3} attribute of the IElementAttributes object
+ *
+ * @return The {3} value
+ */
+ public boolean getIsDistribute()
+ {
+ return this.IS_DISTRIBUTE;
+ }
+
+ /**
+ * Sets the isDistribute attribute of the ElementAttributes object
+ *
+ * @param val
+ * The new isDistribute value
+ */
+ public void setIsDistribute( boolean val )
+ {
+ this.IS_DISTRIBUTE = val;
+ }
+
+ /**
+ * can this item be flushed to disk
+ *
+ * @return The {3} value
+ */
+ public boolean getIsSpool()
+ {
+ return this.IS_SPOOL;
+ }
+
+ /**
+ * Sets the isSpool attribute of the ElementAttributes object
+ *
+ * @param val
+ * The new isSpool value
+ */
+ public void setIsSpool( boolean val )
+ {
+ this.IS_SPOOL = val;
+ }
+
+ /**
+ * Is this item laterally distributable
+ *
+ * @return The {3} value
+ */
+ public boolean getIsLateral()
+ {
+ return this.IS_LATERAL;
+ }
+
+ /**
+ * Sets the isLateral attribute of the ElementAttributes object
+ *
+ * @param val
+ * The new isLateral value
+ */
+ public void setIsLateral( boolean val )
+ {
+ this.IS_LATERAL = val;
+ }
+
+ /**
+ * Can this item be sent to the remote cache
+ *
+ * @return The {3} value
+ */
+ public boolean getIsRemote()
+ {
+ return this.IS_REMOTE;
+ }
+
+ /**
+ * Sets the isRemote attribute of the ElementAttributes object
+ *
+ * @param val
+ * The new isRemote value
+ */
+ public void setIsRemote( boolean val )
+ {
+ this.IS_REMOTE = val;
+ }
+
+ /**
+ * can turn off expiration
+ *
+ * @return The {3} value
+ */
+ public boolean getIsEternal()
+ {
+ return this.IS_ETERNAL;
+ }
+
+ /**
+ * Sets the isEternal attribute of the ElementAttributes object
+ *
+ * @param val
+ * The new isEternal value
+ */
+ public void setIsEternal( boolean val )
+ {
+ this.IS_ETERNAL = val;
+ }
+
+ /**
+ * Adds a ElementEventHandler. Handler's can be registered for multiple
+ * events. A registered handler will be called at every recognized event.
+ *
+ * The alternative would be to register handlers for each event. Or maybe
+ * The handler interface should have a method to return whether it cares
+ * about certain events.
+ *
+ * @param eventHandler
+ * The ElementEventHandler to be added to the list.
+ */
+ public void addElementEventHandler( IElementEventHandler eventHandler )
+ {
+ // lazy here, no concurrency problems expected
+ if (this.eventHandlers == null)
+ {
+ this.eventHandlers = new ArrayList();
+ }
+ this.eventHandlers.add( eventHandler );
+ }
+
+ /**
+ * Sets the eventHandlers of the IElementAttributes object
+ *
+ * @param eventHandlers
+ * value
+ */
+ public void addElementEventHandlers( ArrayList eventHandlers )
+ {
+ if (eventHandlers == null)
+ {
+ return;
+ }
+
+ for (Iterator iter = eventHandlers.iterator(); iter.hasNext();)
+ {
+ addElementEventHandler( (IElementEventHandler) iter.next() );
+ }
+ }
+
+ /**
+ * Gets the elementEventHandlers. Returns null if none exist. Makes checking
+ * easy.
+ *
+ * @return The elementEventHandlers value
+ */
+
+ public ArrayList getElementEventHandlers()
+ {
+ return this.eventHandlers;
+ }
+
+ /**
+ * For logging and debugging the element IElementAttributes.
+ *
+ * @return String info about the values.
+ */
+ public String toString()
+ {
+ StringBuffer dump = new StringBuffer();
+
+ dump.append( "[ IS_LATERAL = " ).append( IS_LATERAL )
+ .append( ", IS_SPOOL = " ).append( IS_SPOOL )
+ .append( ", IS_REMOTE = " ).append( IS_REMOTE )
+ .append( ", IS_ETERNAL = " ).append( IS_ETERNAL )
+ .append( ", MaxLifeSeconds = " ).append( this.getMaxLifeSeconds() )
+ .append( ", IdleTime = " ).append( this.getIdleTime() )
+ .append( ", CreateTime = " ).append( this.getCreateTime() )
+ .append( ", LastAccessTime = " ).append( this.getLastAccessTime() )
+ .append( ", getTimeToLiveSeconds() = " ).append(
+ String.valueOf( getTimeToLiveSeconds() ) )
+ .append( ", createTime = " ).append( String.valueOf( createTime ) )
+ .append( " ]" );
+
+ return dump.toString();
+ }
+}
\ No newline at end of file
diff --git a/src/java/org/apache/jcs/engine/control/CompositeCache.java b/src/java/org/apache/jcs/engine/control/CompositeCache.java
index 418592b..f8b7951 100644
--- a/src/java/org/apache/jcs/engine/control/CompositeCache.java
+++ b/src/java/org/apache/jcs/engine/control/CompositeCache.java
@@ -323,6 +323,8 @@
// if the item is not spoolable, return
if ( !ce.getElementAttributes().getIsSpool() )
{
+ //TODO define an event for this.
+ handleElementEvent( ce, IElementEventConstants.ELEMENT_EVENT_SPOOLED_NOT_ALLOWED );
return;
}
@@ -338,26 +340,10 @@
diskAvailable = true;
- // write the last item to disk.2
+ // write the last items to disk.2
try
{
- // handle event, might move to a new method
- ArrayList eventHandlers = ce.getElementAttributes().getElementEventHandlers();
- if ( eventHandlers != null )
- {
- if ( log.isDebugEnabled() )
- {
- log.debug( "Handlers are registered. Event -- ELEMENT_EVENT_SPOOLED_DISK_AVAILABLE" );
- }
- IElementEvent event = new ElementEvent( ce, IElementEventConstants.ELEMENT_EVENT_SPOOLED_DISK_AVAILABLE );
- Iterator hIt = eventHandlers.iterator();
- while ( hIt.hasNext() )
- {
- IElementEventHandler hand = ( IElementEventHandler ) hIt.next();
- //hand.handleElementEvent( event );
- addElementEvent( hand, event );
- }
- }
+ handleElementEvent( ce, IElementEventConstants.ELEMENT_EVENT_SPOOLED_DISK_AVAILABLE );
aux.update( ce );
}
@@ -383,28 +369,12 @@
try
{
- // handle event, might move to a new method
- ArrayList eventHandlers = ce.getElementAttributes().getElementEventHandlers();
- if ( eventHandlers != null )
- {
- if ( log.isDebugEnabled() )
- {
- log.debug( "Handlers are registered. Event -- ELEMENT_EVENT_SPOOLED_DISK_NOT_AVAILABLE" );
- }
- IElementEvent event = new ElementEvent( ce, IElementEventConstants.ELEMENT_EVENT_SPOOLED_DISK_NOT_AVAILABLE );
- Iterator hIt = eventHandlers.iterator();
- while ( hIt.hasNext() )
- {
- IElementEventHandler hand = ( IElementEventHandler ) hIt.next();
- //hand.handleElementEvent( event );
- addElementEvent( hand, event );
- }
- }
+ handleElementEvent( ce, IElementEventConstants.ELEMENT_EVENT_SPOOLED_DISK_NOT_AVAILABLE );
}
catch ( Exception e )
{
- log.error( "Trouble handling the event", e );
+ log.error( "Trouble handling the ELEMENT_EVENT_SPOOLED_DISK_NOT_AVAILABLE element event", e );
}
}
@@ -739,7 +709,7 @@
try
{
- removed = memCache.remove( key );
+ removed = memCache.remove( key );
}
catch ( IOException e )
{
@@ -1056,7 +1026,7 @@
* This returns data gathered for this region and all the
* auxiliaries it currently uses.
*
- * @return
+ * @return Statistics and Info on the Region.
*/
public ICacheStats getStatistics()
{
@@ -1171,24 +1141,6 @@
/**
- * Adds an ElementEvent to be handled
- *
- *@param hand The IElementEventHandler
- *@param event The IElementEventHandler IElementEvent event
- *@exception IOException Description of the Exception
- */
- public void addElementEvent( IElementEventHandler hand, IElementEvent event )
- throws IOException
- {
- if ( log.isDebugEnabled() )
- {
- log.debug( "Adding to Q" );
- }
- elementEventQ.addElementEvent( hand, event );
- }
-
-
- /**
* 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
@@ -1271,4 +1223,58 @@
{
return missCountExpired;
}
+
+
+ /**
+ * If there are event handlers for the item, then create an event and
+ * queue it up.
+ *
+ * @param ce
+ * @param eventType
+ */
+ private void handleElementEvent( ICacheElement ce, int eventType )
+ {
+ // handle event, might move to a new method
+ ArrayList 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 );
+ Iterator hIt = eventHandlers.iterator();
+ while ( hIt.hasNext() )
+ {
+ IElementEventHandler hand = ( IElementEventHandler ) hIt.next();
+ try
+ {
+ addElementEvent( hand, event );
+ }
+ catch ( Exception e )
+ {
+ log.error( "Trouble adding element event to queue", e );
+ }
+ }
+ }
+
+ }
+
+
+ /**
+ * Adds an ElementEvent to be handled
+ *
+ *@param hand The IElementEventHandler
+ *@param event The IElementEventHandler IElementEvent event
+ *@exception 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" );
+ }
+ elementEventQ.addElementEvent( hand, event );
+ }
}
diff --git a/src/java/org/apache/jcs/engine/control/event/behavior/IElementEvent.java b/src/java/org/apache/jcs/engine/control/event/behavior/IElementEvent.java
index c4d6dd1..423bbf8 100644
--- a/src/java/org/apache/jcs/engine/control/event/behavior/IElementEvent.java
+++ b/src/java/org/apache/jcs/engine/control/event/behavior/IElementEvent.java
@@ -28,7 +28,8 @@
{
/**
- * Gets the elementEvent attribute of the IElementEvent object
+ * Gets the elementEvent attribute of the IElementEvent object. This code is
+ * Contained in the IElememtEventConstants class.
*
*@return The elementEvent value
*/
diff --git a/src/java/org/apache/jcs/engine/control/event/behavior/IElementEventConstants.java b/src/java/org/apache/jcs/engine/control/event/behavior/IElementEventConstants.java
index 36e2e66..38a21e6 100644
--- a/src/java/org/apache/jcs/engine/control/event/behavior/IElementEventConstants.java
+++ b/src/java/org/apache/jcs/engine/control/event/behavior/IElementEventConstants.java
@@ -19,7 +19,7 @@
/**
- * Description of the Interface
+ * This describes the events that an item can encounter.
*
*/
public interface IElementEventConstants
@@ -56,16 +56,22 @@
*/
public final static int ELEMENT_EVENT_SPOOLED_DISK_NOT_AVAILABLE = 5;
+
+ /**
+ * Moving from memory to disk, but item is not spoolable
+ */
+ public final static int ELEMENT_EVENT_SPOOLED_NOT_ALLOWED = 6;
+
/**
* Removed activley by a remove command. (Could distinguish between local
* and remote)
*/
- public final static int ELEMENT_EVENT_REMOVED = 6;
+ //public final static int ELEMENT_EVENT_REMOVED = 7;
/**
* Element was requested from cache.
* Not sure we ever want to implement this.
*/
- //public final static int ELEMENT_EVENT_GET = 7;
+ //public final static int ELEMENT_EVENT_GET = 8;
}
diff --git a/src/java/org/apache/jcs/engine/control/event/behavior/IElementEventHandler.java b/src/java/org/apache/jcs/engine/control/event/behavior/IElementEventHandler.java
index e15567f..41346a8 100644
--- a/src/java/org/apache/jcs/engine/control/event/behavior/IElementEventHandler.java
+++ b/src/java/org/apache/jcs/engine/control/event/behavior/IElementEventHandler.java
@@ -18,21 +18,24 @@
*/
-import java.io.Serializable;
/**
- * Description of the Interface
+ * This interface defines the behavior for event handler. Event handlers are
+ * 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
+ * whenever an item gets put into the cache.
*
*/
-public interface IElementEventHandler extends Serializable
+public interface IElementEventHandler extends IElementEventConstants
{
/**
- * Description of the Method
+ * Handle events for this element. The events are typed.
*
- *@param event Description of the Parameter
- *@return Description of the Return Value
+ *@param event The event created by the cache.
*/
- public Serializable handleElementEvent( IElementEvent event );
+ public void handleElementEvent( IElementEvent event );
}
diff --git a/src/java/org/apache/jcs/engine/memory/MemoryCache.java b/src/java/org/apache/jcs/engine/memory/MemoryCache.java
index 7180321..f20febc 100644
--- a/src/java/org/apache/jcs/engine/memory/MemoryCache.java
+++ b/src/java/org/apache/jcs/engine/memory/MemoryCache.java
@@ -46,8 +46,9 @@
/**
* Destroy the memory cache
+ * @throws IOException
*/
- public void dispose() throws IOException;;
+ public void dispose() throws IOException;
/**
@@ -60,7 +61,7 @@
/**
* Returns the historical and statistical data for a region's memory cache.
*
- * @return
+ * @return Statistics and Infor for the Memory Cache.
*/
public IStats getStatistics();
@@ -168,6 +169,8 @@
/**
* Gets the set of keys of objects currently in the group
+ * @param group
+ * @return a Set of group keys.
*/
public Set getGroupKeys(String group);
}
diff --git a/src/test-conf/TestSimpleEventHandling.ccf b/src/test-conf/TestSimpleEventHandling.ccf
new file mode 100644
index 0000000..340d03a
--- /dev/null
+++ b/src/test-conf/TestSimpleEventHandling.ccf
@@ -0,0 +1,35 @@
+# Cache configuration for the 'TestDiskCache' test. The memory cache has a
+# a maximum of 100 objects, so objects should get pushed into the disk cache
+
+jcs.default=indexedDiskCache
+jcs.default.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
+jcs.default.cacheattributes.MaxObjects=100
+jcs.default.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
+
+
+##### CACHE REGIONS FOR TEST
+jcs.region.WithDisk=indexedDiskCache
+jcs.region.WithDisk.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
+jcs.region.WithDisk.cacheattributes.MaxObjects=0
+jcs.region.WithDisk.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
+jcs.region.WithDisk.elementattributes.IsSpool=true
+
+jcs.region.NoDisk=
+jcs.region.NoDisk.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
+jcs.region.NoDisk.cacheattributes.MaxObjects=0
+jcs.region.NoDisk.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
+jcs.region.NoDisk.elementattributes.IsSpool=true
+
+jcs.region.DiskButNotAllowed=indexedDiskCache
+jcs.region.DiskButNotAllowed.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
+jcs.region.DiskButNotAllowed.cacheattributes.MaxObjects=0
+jcs.region.DiskButNotAllowed.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
+jcs.region.DiskButNotAllowed.elementattributes.IsSpool=false
+
+
+##### AUXILIARY CACHES
+# Indexed Disk Cache
+jcs.auxiliary.indexedDiskCache=org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheFactory
+jcs.auxiliary.indexedDiskCache.attributes=org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheAttributes
+jcs.auxiliary.indexedDiskCache.attributes.DiskPath=target/test-sandbox/indexed-disk-cache
+
diff --git a/src/test/org/apache/jcs/TestDiskCache.java b/src/test/org/apache/jcs/TestDiskCache.java
index 758eb45..d50f5e5 100644
--- a/src/test/org/apache/jcs/TestDiskCache.java
+++ b/src/test/org/apache/jcs/TestDiskCache.java
@@ -38,6 +38,7 @@
/**
* Constructor for the TestDiskCache object.
+ * @param testName
*/
public TestDiskCache( String testName )
{
@@ -46,6 +47,7 @@
/**
* Main method passes this test to the text test runner.
+ * @param args
*/
public static void main( String args[] )
{
@@ -123,7 +125,7 @@
{
String value = ( String ) jcs.get( i + ":key" );
- this.assertEquals( region + " data " + i, value );
+ assertEquals( region + " data " + i, value );
}
// Remove all the items
diff --git a/src/test/org/apache/jcs/TestDiskCacheConcurrent.java b/src/test/org/apache/jcs/TestDiskCacheConcurrent.java
index 6aa2bc1..6ad24f4 100644
--- a/src/test/org/apache/jcs/TestDiskCacheConcurrent.java
+++ b/src/test/org/apache/jcs/TestDiskCacheConcurrent.java
@@ -32,6 +32,7 @@
{
/**
* Constructor for the TestDiskCache object.
+ * @param testName
*/
public TestDiskCacheConcurrent( String testName )
{
@@ -40,6 +41,7 @@
/**
* Main method passes this test to the text test runner.
+ * @param args
*/
public static void main( String args[] )
{
@@ -131,6 +133,8 @@
* than the size of the memory cache, so items should spool to disk.
*
* @param region Name of the region to access
+ * @param start
+ * @param end
*
* @exception Exception If an error occurs
*/
@@ -152,7 +156,7 @@
{
String value = ( String ) jcs.get( i + ":key" );
- this.assertEquals( region + " data " + i, value );
+ assertEquals( region + " data " + i, value );
}
/*// you can't remove in one thread and expect them to be in another
diff --git a/src/test/org/apache/jcs/TestDiskCacheConcurrentForDeadLock.java b/src/test/org/apache/jcs/TestDiskCacheConcurrentForDeadLock.java
index 95ebc5c..7677529 100644
--- a/src/test/org/apache/jcs/TestDiskCacheConcurrentForDeadLock.java
+++ b/src/test/org/apache/jcs/TestDiskCacheConcurrentForDeadLock.java
@@ -34,6 +34,7 @@
{
/**
* Constructor for the TestDiskCache object.
+ * @param testName
*/
public TestDiskCacheConcurrentForDeadLock( String testName )
{
@@ -42,6 +43,7 @@
/**
* Main method passes this test to the text test runner.
+ * @param args
*/
public static void main( String args[] )
{
diff --git a/src/test/org/apache/jcs/TestDiskCacheConcurrentRandom.java b/src/test/org/apache/jcs/TestDiskCacheConcurrentRandom.java
index 82ca7a6..1eb9239 100644
--- a/src/test/org/apache/jcs/TestDiskCacheConcurrentRandom.java
+++ b/src/test/org/apache/jcs/TestDiskCacheConcurrentRandom.java
@@ -4,11 +4,15 @@
import org.apache.jcs.access.TestCacheAccess;
+/**
+ * This is used by other tests to generate a random load on the disk cache.
+ */
public class TestDiskCacheConcurrentRandom
extends TestCase {
/**
* Constructor for the TestDiskCache object.
+ * @param testName
*/
public TestDiskCacheConcurrentRandom(String testName) {
super(testName);
@@ -20,6 +24,9 @@
* so items should spool to disk.
*
* @param region Name of the region to access
+ * @param range
+ * @param numOps
+ * @param testNum
*
* @exception Exception If an error occurs
*/
@@ -38,7 +45,7 @@
String data = "testData" + testNum;
jcs.put( key, data );
String value = ( String ) jcs.get( key );
- this.assertEquals( data, value );
+ assertEquals( data, value );
}
diff --git a/src/test/org/apache/jcs/TestDiskCacheNoMemory.java b/src/test/org/apache/jcs/TestDiskCacheNoMemory.java
index 2021833..9a08408 100644
--- a/src/test/org/apache/jcs/TestDiskCacheNoMemory.java
+++ b/src/test/org/apache/jcs/TestDiskCacheNoMemory.java
@@ -39,6 +39,7 @@
/**
* Constructor for the TestDiskCache object.
+ * @param testName
*/
public TestDiskCacheNoMemory( String testName )
{
@@ -47,6 +48,7 @@
/**
* Main method passes this test to the text test runner.
+ * @param args
*/
public static void main( String args[] )
{
@@ -124,7 +126,7 @@
{
String value = ( String ) jcs.get( i + ":key" );
- this.assertEquals( region + " data " + i, value );
+ assertEquals( region + " data " + i, value );
}
// Remove all the items
diff --git a/src/test/org/apache/jcs/TestJCS.java b/src/test/org/apache/jcs/TestJCS.java
index a427288..176a68e 100644
--- a/src/test/org/apache/jcs/TestJCS.java
+++ b/src/test/org/apache/jcs/TestJCS.java
@@ -37,22 +37,34 @@
{
Random random = new Random();
+ /**
+ * @param testName
+ */
public TestJCS( String testName )
{
super( testName );
}
+ /**
+ * @return Test
+ */
public static Test suite()
{
return new TestSuite( TestJCS.class );
}
+ /**
+ * @param args
+ */
public static void main( String args[] )
{
String[] testCaseName = { TestJCS.class.getName() };
junit.textui.TestRunner.main( testCaseName );
}
+ /**
+ * @throws Exception
+ */
public void testJCS() throws Exception
{
JCS jcs = JCS.getInstance( "testCache1" );
diff --git a/src/test/org/apache/jcs/TestJCSvHashtablePerf.java b/src/test/org/apache/jcs/TestJCSvHashtablePerf.java
index ef2823c..c825fbb 100644
--- a/src/test/org/apache/jcs/TestJCSvHashtablePerf.java
+++ b/src/test/org/apache/jcs/TestJCSvHashtablePerf.java
@@ -6,162 +6,181 @@
import junit.framework.TestCase;
import junit.framework.TestSuite;
-public class TestJCSvHashtablePerf
- extends TestCase
+/**
+ * This test ensures that basic memory operations are with a speficified order
+ * of magnitude of the java.util.Hashtable.
+ * <p>
+ * Currenlty JCS is un 2x a hashtable for gets, and under 1.2x for puts.
+ *
+ */
+public class TestJCSvHashtablePerf extends TestCase
{
- float ratioPut = 0;
- float ratioGet = 0;
- float target = 2.50f;
+ float ratioPut = 0;
- int loops = 20;
- int tries = 50000;
+ float ratioGet = 0;
- public TestJCSvHashtablePerf(String testName)
- {
- super(testName);
- }
+ float target = 2.50f;
- /**
- * A unit test suite for JUnit
- *
- *@return The test suite
- */
- public static Test suite()
- {
- return new TestSuite(TestJCSvHashtablePerf.class);
- }
+ int loops = 20;
- /**
- * A unit test for JUnit
- *
- *@exception Exception Description of the Exception
- */
- public void testSimpleLoad() throws Exception
- {
- doWork();
- this.assertTrue(this.ratioPut < target);
- this.assertTrue(this.ratioGet < target);
- }
+ int tries = 50000;
- public void doWork()
- {
-
- long start = 0;
- long end = 0;
- long time = 0;
- float tPer = 0;
-
- long putTotalJCS = 0;
- long getTotalJCS = 0;
- long putTotalHashtable = 0;
- long getTotalHashtable = 0;
-
- try
+ /**
+ * @param testName
+ */
+ public TestJCSvHashtablePerf(String testName)
{
-
- JCS.setConfigFilename("/TestJCSvHashtablePerf.ccf");
- JCS cache = JCS.getInstance("testCache1");
-
- for (int j = 0; j < loops; j++)
- {
-
- String name = "JCS ";
- start = System.currentTimeMillis();
- for (int i = 0; i < tries; i++)
- {
- cache.put("key:" + i, "data" + i);
- }
- end = System.currentTimeMillis();
- time = end - start;
- putTotalJCS += time;
- tPer = Float.intBitsToFloat( (int) time) /
- Float.intBitsToFloat( (int) tries);
- System.out.println(name + " put time for " + tries + " = " + time +
- "; millis per = " + tPer);
-
- start = System.currentTimeMillis();
- for (int i = 0; i < tries; i++)
- {
- cache.get("key:" + i);
- }
- end = System.currentTimeMillis();
- time = end - start;
- getTotalJCS += time;
- tPer = Float.intBitsToFloat( (int) time) /
- Float.intBitsToFloat( (int) tries);
- System.out.println(name + " get time for " + tries + " = " + time +
- "; millis per = " + tPer);
-
- ///////////////////////////////////////////////////////////////
- name = "Hashtable";
- Hashtable cache2 = new Hashtable();
- start = System.currentTimeMillis();
- for (int i = 0; i < tries; i++)
- {
- cache2.put("key:" + i, "data" + i);
- }
- end = System.currentTimeMillis();
- time = end - start;
- putTotalHashtable += time;
- tPer = Float.intBitsToFloat( (int) time) /
- Float.intBitsToFloat( (int) tries);
- System.out.println(name + " put time for " + tries + " = " + time +
- "; millis per = " + tPer);
-
- start = System.currentTimeMillis();
- for (int i = 0; i < tries; i++)
- {
- cache2.get("key:" + i);
- }
- end = System.currentTimeMillis();
- time = end - start;
- getTotalHashtable += time;
- tPer = Float.intBitsToFloat( (int) time) /
- Float.intBitsToFloat( (int) tries);
- System.out.println(name + " get time for " + tries + " = " + time +
- "; millis per = " + tPer);
-
- System.out.println("\n");
- }
-
- }
- catch (Exception e)
- {
- e.printStackTrace(System.out);
- System.out.println(e);
+ super( testName );
}
- long putAvJCS = putTotalJCS / loops;
- long getAvJCS = getTotalJCS / loops;
- long putAvHashtable = putTotalHashtable / loops;
- long getAvHashtable = getTotalHashtable / loops;
+ /**
+ * A unit test suite for JUnit
+ *
+ * @return The test suite
+ */
+ public static Test suite()
+ {
+ return new TestSuite( TestJCSvHashtablePerf.class );
+ }
- System.out.println("Finished " + loops + " loops of " + tries +
- " gets and puts");
+ /**
+ * A unit test for JUnit
+ *
+ * @exception Exception
+ * Description of the Exception
+ */
+ public void testSimpleLoad() throws Exception
+ {
+ doWork();
+ assertTrue( this.ratioPut < target );
+ assertTrue( this.ratioGet < target );
+ }
- System.out.println("\n");
- System.out.println("Put average for JCS = " + putAvJCS);
- System.out.println("Put average for Hashtable = " + putAvHashtable);
- ratioPut = Float.intBitsToFloat( (int) putAvJCS) /
- Float.intBitsToFloat( (int) putAvHashtable);
- System.out.println("JCS puts took " + ratioPut +
- " times the Hashtable, the goal is <" + target + "x");
+ /**
+ *
+ */
+ public void doWork()
+ {
- System.out.println("\n");
- System.out.println("Get average for JCS = " + getAvJCS);
- System.out.println("Get average for Hashtable = " + getAvHashtable);
- ratioGet = Float.intBitsToFloat( (int) getAvJCS) /
- Float.intBitsToFloat( (int) getAvHashtable);
- System.out.println("JCS gets took " + ratioGet +
- " times the Hashtable, the goal is <" + target + "x");
+ long start = 0;
+ long end = 0;
+ long time = 0;
+ float tPer = 0;
- }
+ long putTotalJCS = 0;
+ long getTotalJCS = 0;
+ long putTotalHashtable = 0;
+ long getTotalHashtable = 0;
- public static void main(String args[])
- {
- TestJCSvHashtablePerf test = new TestJCSvHashtablePerf("command");
- test.doWork();
- }
+ try
+ {
-}
+ JCS.setConfigFilename( "/TestJCSvHashtablePerf.ccf" );
+ JCS cache = JCS.getInstance( "testCache1" );
+
+ for (int j = 0; j < loops; j++)
+ {
+
+ String name = "JCS ";
+ start = System.currentTimeMillis();
+ for (int i = 0; i < tries; i++)
+ {
+ cache.put( "key:" + i, "data" + i );
+ }
+ end = System.currentTimeMillis();
+ time = end - start;
+ putTotalJCS += time;
+ tPer = Float.intBitsToFloat( (int) time )
+ / Float.intBitsToFloat( tries );
+ System.out.println( name + " put time for " + tries + " = "
+ + time + "; millis per = " + tPer );
+
+ start = System.currentTimeMillis();
+ for (int i = 0; i < tries; i++)
+ {
+ cache.get( "key:" + i );
+ }
+ end = System.currentTimeMillis();
+ time = end - start;
+ getTotalJCS += time;
+ tPer = Float.intBitsToFloat( (int) time )
+ / Float.intBitsToFloat( tries );
+ System.out.println( name + " get time for " + tries + " = "
+ + time + "; millis per = " + tPer );
+
+ ///////////////////////////////////////////////////////////////
+ name = "Hashtable";
+ Hashtable cache2 = new Hashtable();
+ start = System.currentTimeMillis();
+ for (int i = 0; i < tries; i++)
+ {
+ cache2.put( "key:" + i, "data" + i );
+ }
+ end = System.currentTimeMillis();
+ time = end - start;
+ putTotalHashtable += time;
+ tPer = Float.intBitsToFloat( (int) time )
+ / Float.intBitsToFloat( tries );
+ System.out.println( name + " put time for " + tries + " = "
+ + time + "; millis per = " + tPer );
+
+ start = System.currentTimeMillis();
+ for (int i = 0; i < tries; i++)
+ {
+ cache2.get( "key:" + i );
+ }
+ end = System.currentTimeMillis();
+ time = end - start;
+ getTotalHashtable += time;
+ tPer = Float.intBitsToFloat( (int) time )
+ / Float.intBitsToFloat( tries );
+ System.out.println( name + " get time for " + tries + " = "
+ + time + "; millis per = " + tPer );
+
+ System.out.println( "\n" );
+ }
+
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace( System.out );
+ System.out.println( e );
+ }
+
+ long putAvJCS = putTotalJCS / loops;
+ long getAvJCS = getTotalJCS / loops;
+ long putAvHashtable = putTotalHashtable / loops;
+ long getAvHashtable = getTotalHashtable / loops;
+
+ System.out.println( "Finished " + loops + " loops of " + tries
+ + " gets and puts" );
+
+ System.out.println( "\n" );
+ System.out.println( "Put average for JCS = " + putAvJCS );
+ System.out.println( "Put average for Hashtable = " + putAvHashtable );
+ ratioPut = Float.intBitsToFloat( (int) putAvJCS )
+ / Float.intBitsToFloat( (int) putAvHashtable );
+ System.out.println( "JCS puts took " + ratioPut
+ + " times the Hashtable, the goal is <" + target + "x" );
+
+ System.out.println( "\n" );
+ System.out.println( "Get average for JCS = " + getAvJCS );
+ System.out.println( "Get average for Hashtable = " + getAvHashtable );
+ ratioGet = Float.intBitsToFloat( (int) getAvJCS )
+ / Float.intBitsToFloat( (int) getAvHashtable );
+ System.out.println( "JCS gets took " + ratioGet
+ + " times the Hashtable, the goal is <" + target + "x" );
+
+ }
+
+ /**
+ * @param args
+ */
+ public static void main( String args[] )
+ {
+ TestJCSvHashtablePerf test = new TestJCSvHashtablePerf( "command" );
+ test.doWork();
+ }
+
+}
\ No newline at end of file
diff --git a/src/test/org/apache/jcs/TestSimpleEventHandling.java b/src/test/org/apache/jcs/TestSimpleEventHandling.java
new file mode 100644
index 0000000..b5a83f8
--- /dev/null
+++ b/src/test/org/apache/jcs/TestSimpleEventHandling.java
@@ -0,0 +1,261 @@
+package org.apache.jcs;
+
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License")
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.jcs.engine.control.event.behavior.IElementEvent;
+import org.apache.jcs.engine.control.event.behavior.IElementEventConstants;
+import org.apache.jcs.engine.control.event.behavior.IElementEventHandler;
+
+/**
+ * This test suite verifies that the basic ElementEvent are called as they should be.
+ *
+ *
+ * @version $Id$
+ */
+public class TestSimpleEventHandling extends TestCase
+{
+
+ private static int items = 20000;
+
+ /**
+ * Constructor for test case.
+ *
+ * @param testName
+ * Description of the Parameter
+ */
+ public TestSimpleEventHandling(String testName)
+ {
+ super( testName );
+ }
+
+ /**
+ * Run at command line.
+ *
+ * @param args
+ * Description of the Parameter
+ */
+ public static void main( String args[] )
+ {
+ String[] testCaseName = { TestSimpleEventHandling.class.getName() };
+ junit.textui.TestRunner.main( testCaseName );
+ }
+
+ /**
+ * A unit test suite for JUnit
+ *
+ * @return The test suite
+ */
+ public static Test suite()
+ {
+ return new TestSuite( TestSimpleEventHandling.class );
+ }
+
+
+ /**
+ * Test setup with expected configuration parameters.
+ *
+ */
+ public void setUp()
+ {
+ JCS.setConfigFilename( "/TestSimpleEventHandling.ccf" );
+ }
+
+ /**
+ * Verify that the spooled event is called as expected.
+ *
+ *
+ * @exception Exception
+ * Description of the Exception
+ */
+ public void testSpoolEvent() throws Exception
+ {
+ MyEventHandler meh = new MyEventHandler();
+
+ JCS jcs = JCS.getInstance( "WithDisk" );
+ // this should add the event handler to all items as they are created.
+ jcs.getElementAttributes()
+ .addElementEventHandler( meh );
+
+ // put them in
+ for (int i = 0; i <= items; i++)
+ {
+ jcs.put( i + ":key", "data" + i );
+ }
+
+ // wait a bit for it to finish
+ Thread.sleep( items / 20 );
+
+ // test to see if the count is right
+ assertTrue(
+ "The number of ELEMENT_EVENT_SPOOLED_DISK_AVAILABLE events [" + meh.getSpoolCount() + "] does not equal the number expected [" + items + "]",
+ meh.getSpoolCount() >= items );
+
+ }
+
+ /**
+ * Test overflow with no disk configured for the region.
+ * @throws Exception
+ */
+ public void testSpoolNoDiskEvent() throws Exception
+ {
+ MyEventHandler meh = new MyEventHandler();
+
+ JCS jcs = JCS.getInstance( "NoDisk" );
+ // this should add the event handler to all items as they are created.
+ jcs.getElementAttributes()
+ .addElementEventHandler( meh );
+
+ // put them in
+ for (int i = 0; i <= items; i++)
+ {
+ jcs.put( i + ":key", "data" + i );
+ }
+
+ // wait a bit for it to finish
+ Thread.sleep( items / 20 );
+
+ // test to see if the count is right
+ assertTrue(
+ "The number of ELEMENT_EVENT_SPOOLED_DISK_NOT_AVAILABLE events [" + meh.getSpoolNoDiskCount() + "] does not equal the number expected.",
+ meh.getSpoolNoDiskCount() >= items );
+
+ }
+
+ /**
+ * Test the ELEMENT_EVENT_SPOOLED_NOT_ALLOWED event.
+ *
+ * @throws Exception
+ */
+ public void testSpoolNotAllowedEvent() throws Exception
+ {
+ MyEventHandler meh = new MyEventHandler();
+
+ JCS jcs = JCS.getInstance( "DiskButNotAllowed" );
+ // this should add the event handler to all items as they are created.
+ jcs.getElementAttributes()
+ .addElementEventHandler( meh );
+
+ // put them in
+ for (int i = 0; i <= items; i++)
+ {
+ jcs.put( i + ":key", "data" + i );
+ }
+
+ // wait a bit for it to finish
+ Thread.sleep( items / 20 );
+
+ // test to see if the count is right
+ assertTrue(
+ "The number of ELEMENT_EVENT_SPOOLED_NOT_ALLOWED events [" + meh.getSpoolNotAllowedCount() + "] does not equal the number expected.",
+ meh.getSpoolNotAllowedCount() >= items );
+
+ }
+
+ /**
+ * Simple event counter used to verify test results.
+ *
+ * @author aaronsm
+ *
+ */
+ public class MyEventHandler implements IElementEventHandler
+ {
+
+ private int spoolCount = 0;
+
+ private int spoolNotAllowedCount = 0;
+
+ private int spoolNoDiskCount = 0;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.jcs.engine.control.event.behavior.IElementEventHandler#handleElementEvent(org.apache.jcs.engine.control.event.behavior.IElementEvent)
+ */
+ public synchronized void handleElementEvent( IElementEvent event )
+ {
+ //System.out.println( "Handling Event of Type " + event.getElementEvent() );
+
+ if (event.getElementEvent() == IElementEventConstants.ELEMENT_EVENT_SPOOLED_DISK_AVAILABLE)
+ {
+ //System.out.println( "Handling Event of Type ELEMENT_EVENT_SPOOLED_DISK_AVAILABLE, " + getSpoolCount() );
+ setSpoolCount( getSpoolCount() + 1 );
+ }
+ else if (event.getElementEvent() == IElementEventConstants.ELEMENT_EVENT_SPOOLED_NOT_ALLOWED)
+ {
+ setSpoolNotAllowedCount( getSpoolNotAllowedCount() + 1 );
+ }
+ else if (event.getElementEvent() == IElementEventConstants.ELEMENT_EVENT_SPOOLED_DISK_NOT_AVAILABLE)
+ {
+ setSpoolNoDiskCount( getSpoolNoDiskCount() + 1 );
+ }
+ }
+
+ /**
+ * @param spoolCount The spoolCount to set.
+ */
+ protected void setSpoolCount( int spoolCount )
+ {
+ this.spoolCount = spoolCount;
+ }
+
+ /**
+ * @return Returns the spoolCount.
+ */
+ protected int getSpoolCount()
+ {
+ return spoolCount;
+ }
+
+ /**
+ * @param spoolNotAllowedCount The spoolNotAllowedCount to set.
+ */
+ protected void setSpoolNotAllowedCount( int spoolNotAllowedCount )
+ {
+ this.spoolNotAllowedCount = spoolNotAllowedCount;
+ }
+
+ /**
+ * @return Returns the spoolNotAllowedCount.
+ */
+ protected int getSpoolNotAllowedCount()
+ {
+ return spoolNotAllowedCount;
+ }
+
+ /**
+ * @param spoolNoDiskCount The spoolNoDiskCount to set.
+ */
+ protected void setSpoolNoDiskCount( int spoolNoDiskCount )
+ {
+ this.spoolNoDiskCount = spoolNoDiskCount;
+ }
+
+ /**
+ * @return Returns the spoolNoDiskCount.
+ */
+ protected int getSpoolNoDiskCount()
+ {
+ return spoolNoDiskCount;
+ }
+
+ }
+
+}
\ No newline at end of file
diff --git a/src/test/org/apache/jcs/TestSimpleLoad.java b/src/test/org/apache/jcs/TestSimpleLoad.java
index 38ff84a..a253f43 100644
--- a/src/test/org/apache/jcs/TestSimpleLoad.java
+++ b/src/test/org/apache/jcs/TestSimpleLoad.java
@@ -22,9 +22,6 @@
import junit.framework.TestCase;
import junit.framework.TestSuite;
-import org.apache.jcs.JCS;
-import org.apache.jcs.engine.behavior.ICompositeCacheAttributes;
-
/**
* Description of the Class
*
@@ -88,12 +85,12 @@
String res = ( String ) jcs.get( i + ":key" );
if ( res == null )
{
- this.assertNotNull( "[" + i + ":key] should not be null", res );
+ assertNotNull( "[" + i + ":key] should not be null", res );
}
}
// test removal
- jcs.destroy( "300:key" );
+ jcs.remove( "300:key" );
assertNull( jcs.get( "300:key" ) );
}
diff --git a/src/test/org/apache/jcs/TestTCPLateralCache.java b/src/test/org/apache/jcs/TestTCPLateralCache.java
index d6d7726..c3ebf58 100644
--- a/src/test/org/apache/jcs/TestTCPLateralCache.java
+++ b/src/test/org/apache/jcs/TestTCPLateralCache.java
@@ -38,6 +38,7 @@
/**
* Constructor for the TestDiskCache object.
+ * @param testName
*/
public TestTCPLateralCache( String testName )
{
@@ -46,6 +47,7 @@
/**
* Main method passes this test to the text test runner.
+ * @param args
*/
public static void main( String args[] )
{
@@ -123,7 +125,7 @@
{
String value = ( String ) jcs.get( i + ":key" );
- this.assertEquals( region + " data " + i, value );
+ assertEquals( region + " data " + i, value );
}
// Remove all the items
diff --git a/src/test/org/apache/jcs/access/TestCacheAccess.java b/src/test/org/apache/jcs/access/TestCacheAccess.java
index 02001c6..2bd05b6 100644
--- a/src/test/org/apache/jcs/access/TestCacheAccess.java
+++ b/src/test/org/apache/jcs/access/TestCacheAccess.java
@@ -24,6 +24,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
import org.apache.jcs.JCS;
import org.apache.jcs.engine.ElementAttributes;
import org.apache.jcs.engine.behavior.IElementAttributes;
@@ -33,910 +34,907 @@
/**
* Allows the user to run common cache commands from the command line for a test
* cache.
- *
+ *
* This also provide basic methods for use in unit tests.
- *
+ *
*/
public class TestCacheAccess
{
- private final static Log log =
- LogFactory.getLog(TestCacheAccess.class);
+ private final static Log log = LogFactory
+ .getLog( TestCacheAccess.class );
- private GroupCacheAccess cache_control = null;
- private CompositeCacheManager cache_manager = null;
- private static boolean isSysOut = false;
+ private GroupCacheAccess cache_control = null;
- /**
- * Construct and initialize the cachecontrol based on the config file.
- *
- * @param ccfFileName String
- */
- public TestCacheAccess(String ccfFileName)
- {
- try
+ private static boolean isSysOut = false;
+
+ /**
+ * Construct and initialize the cachecontrol based on the config file.
+ *
+ */
+ public TestCacheAccess()
{
- cache_manager = CompositeCacheManager.getInstance(ccfFileName);
- cache_control = GroupCacheAccess.getGroupAccess("testCache1");
+ this( "testCache1" );
}
- catch (Exception e)
+
+
+ /**
+ * @param ccfFileName
+ */
+ public TestCacheAccess(String ccfFileName)
{
- log.error(e);
- p(e.toString());
- }
- }
-
- /**
- * This is the main loop called by the main method.
- *
- * @param ccfFileName String
- */
- public void runLoop()
- {
-
- try
- {
- try
- {
-
- // process user input till done
- boolean notDone = true;
- String message = null;
- // wait to dispose
- BufferedReader br = new BufferedReader(new InputStreamReader(System.
- in));
-
- help();
-
- while (notDone)
+ try
{
- p("enter command:");
+ cache_control = GroupCacheAccess.getGroupAccess( ccfFileName );
+ }
+ catch (Exception e)
+ {
+ log.error( e );
+ p( e.toString() );
+ }
+ }
- message = br.readLine();
+ /**
+ * This is the main loop called by the main method.
+ */
+ public void runLoop()
+ {
- if (message.startsWith("help"))
- {
- help();
- }
- else
- if (message.startsWith("getAttributeNames"))
- {
- long n_start = System.currentTimeMillis();
- String groupName = null;
- StringTokenizer toke = new StringTokenizer(message);
- int tcnt = 0;
- while (toke.hasMoreElements())
- {
- tcnt++;
- String t = (String) toke.nextElement();
- if (tcnt == 2)
- {
- groupName = t.trim();
- }
- }
- getAttributeNames(groupName);
- long n_end = System.currentTimeMillis();
- p("---got attrNames for " + groupName + " in " +
- String.valueOf(n_end - n_start) + " millis ---");
- }
- else
- if (message.startsWith("shutDown"))
- {
- CompositeCacheManager.getInstance().shutDown();
- //cache_control.dispose();
- notDone = false;
- System.exit( -1);
- }
- else
-
- /////////////////////////////////////////////////////////////////////
- // get multiple from a region
- if (message.startsWith("getm"))
- {
-
- int num = 0;
- boolean show = true;
-
- StringTokenizer toke = new StringTokenizer(message);
- int tcnt = 0;
- while (toke.hasMoreElements())
- {
- tcnt++;
- String t = (String) toke.nextElement();
- if (tcnt == 2)
- {
- try
- {
- num = Integer.parseInt(t.trim());
- }
- catch (NumberFormatException nfe)
- {
- p(t + "not a number");
- }
- }
- else
- if (tcnt == 3)
- {
- show = new Boolean(t).booleanValue();
- }
- }
-
- if (tcnt < 2)
- {
- p("usage: get numbertoget show values[true|false]");
- }
- else
- {
- getMultiple(num, show);
- }
- }
- else
-
- /////////////////////////////////////////////////////////////////////
- if (message.startsWith("getg"))
- {
-
- String key = null;
- String group = null;
- boolean show = true;
- boolean auto = true;
-
- StringTokenizer toke = new StringTokenizer(message);
- int tcnt = 0;
- while (toke.hasMoreElements())
- {
- tcnt++;
- String t = (String) toke.nextElement();
- if (tcnt == 2)
- {
- key = t.trim();
- }
- else
- if (tcnt == 3)
- {
- group = t.trim();
- }
- else
- if (tcnt == 4)
- {
- show = new Boolean(t).booleanValue();
- }
- if (tcnt == 5)
- {
- auto = new Boolean(t).booleanValue();
- }
- }
-
- if (tcnt < 2)
- {
- p("usage: get key show values[true|false]");
- }
- else
- {
-
- long n_start = System.currentTimeMillis();
- try
- {
- Object obj = cache_control.getFromGroup(key,
- group);
- if (show && obj != null)
- {
- p(obj.toString());
- }
- }
- catch (Exception e)
- {
- log.error(e);
- }
- long n_end = System.currentTimeMillis();
- p("---got " + key + " from group " + group + " in " +
- String.valueOf(n_end - n_start) + " millis ---");
- }
- }
- else
-
- /////////////////////////////////////////////////////////////////////
- if (message.startsWith("getag"))
- {
- // get auto from group
-
- int num = 0;
- String group = null;
- boolean show = true;
- boolean auto = true;
-
- StringTokenizer toke = new StringTokenizer(message);
- int tcnt = 0;
- while (toke.hasMoreElements())
- {
- tcnt++;
- String t = (String) toke.nextElement();
- if (tcnt == 2)
- {
- num = Integer.parseInt(t.trim());
- }
- else
- if (tcnt == 3)
- {
- group = t.trim();
- }
- else
- if (tcnt == 4)
- {
- show = new Boolean(t).booleanValue();
- }
- if (tcnt == 5)
- {
- auto = new Boolean(t).booleanValue();
- }
- }
-
- if (tcnt < 2)
- {
- p("usage: get key show values[true|false]");
- }
- else
- {
-
- long n_start = System.currentTimeMillis();
- try
- {
- for (int a = 0; a < num; a++)
- {
- Object obj = cache_control.getFromGroup("keygr" + a, group);
- if (show && obj != null)
- {
- p(obj.toString());
- }
- }
- }
- catch (Exception e)
- {
- log.error(e);
- }
- long n_end = System.currentTimeMillis();
- p("---got " + num + " from group " + group + " in " +
- String.valueOf(n_end - n_start) + " millis ---");
- }
- }
- else
-
- /////////////////////////////////////////////////////////////////////
- if (message.startsWith("get"))
- {
- // plain old get
-
- String key = null;
- boolean show = true;
-
- StringTokenizer toke = new StringTokenizer(message);
- int tcnt = 0;
- while (toke.hasMoreElements())
- {
- tcnt++;
- String t = (String) toke.nextElement();
- if (tcnt == 2)
- {
- key = t.trim();
- }
- else
- if (tcnt == 3)
- {
- show = new Boolean(t).booleanValue();
- }
- }
-
- if (tcnt < 2)
- {
- p("usage: get key show values[true|false]");
- }
- else
- {
-
- long n_start = System.currentTimeMillis();
- try
- {
- Object obj = cache_control.get(key);
- if (show && obj != null)
- {
- p(obj.toString());
- }
- }
- catch (Exception e)
- {
- log.error(e);
- }
- long n_end = System.currentTimeMillis();
- p("---got " + key + " in " + String.valueOf(n_end - n_start) +
- " millis ---");
- }
- }
- else if (message.startsWith("putg"))
- {
-
- String group = null;
- String key = null;
- StringTokenizer toke = new StringTokenizer(message);
- int tcnt = 0;
- while (toke.hasMoreElements())
- {
- tcnt++;
- String t = (String) toke.nextElement();
- if (tcnt == 2)
- {
- key = t.trim();
- }
- else
- if (tcnt == 3)
- {
- group = t.trim();
- }
- }
-
- if (tcnt < 3)
- {
- p("usage: putg key group");
- }
- else
- {
- long n_start = System.currentTimeMillis();
- cache_control.putInGroup(key,
- group,
- "data from putg ----asdfasfas-asfasfas-asfas in group " +
- group);
- long n_end = System.currentTimeMillis();
- p("---put " + key + " in group " + group + " in " +
- String.valueOf(n_end - n_start) + " millis ---");
- }
- }
- else
-
- // put automatically
- if (message.startsWith("putag"))
- {
-
- String group = null;
- int num = 0;
- StringTokenizer toke = new StringTokenizer(message);
- int tcnt = 0;
- while (toke.hasMoreElements())
- {
- tcnt++;
- String t = (String) toke.nextElement();
- if (tcnt == 2)
- {
- num = Integer.parseInt(t.trim());
- }
- else
- if (tcnt == 3)
- {
- group = t.trim();
- }
- }
-
- if (tcnt < 3)
- {
- p("usage: putag num group");
- }
- else
- {
- long n_start = System.currentTimeMillis();
- for (int a = 0; a < num; a++)
- {
- cache_control.putInGroup("keygr" + a,
- group,
- "data " + a +
- " from putag ----asdfasfas-asfasfas-asfas in group " +
- group);
- }
- long n_end = System.currentTimeMillis();
- p("---put " + num + " in group " + group + " in " +
- String.valueOf(n_end - n_start) + " millis ---");
- }
- }
- else
-
- /////////////////////////////////////////////////////////////////////
- if (message.startsWith("putm"))
- {
- String numS = message.substring(message.indexOf(" ") + 1,
- message.length());
- int num = Integer.parseInt(numS.trim());
- if (numS == null)
- {
- p("usage: putm numbertoput");
- }
- else
- {
- putMultiple(num);
- }
- }
- else
-
- /////////////////////////////////////////////////////////////////////
- if (message.startsWith("pute"))
- {
- String numS = message.substring(message.indexOf(" ") + 1,
- message.length());
- int num = Integer.parseInt(numS.trim());
- if (numS == null)
- {
- p("usage: putme numbertoput");
- }
- else
- {
- long n_start = System.currentTimeMillis();
- for (int n = 0; n < num; n++)
- {
- IElementAttributes attrp = cache_control.getElementAttributes();
- TestElementEventHandler hand = new TestElementEventHandler();
- attrp.addElementEventHandler(hand);
- cache_control.put("key" + n,
- "data" + n + " put from ta = junk", attrp);
- }
- long n_end = System.currentTimeMillis();
- p("---put " + num + " in " + String.valueOf(n_end - n_start) +
- " millis ---");
- }
- }
- else
- if (message.startsWith("put"))
- {
-
- String key = null;
- String val = null;
- StringTokenizer toke = new StringTokenizer(message);
- int tcnt = 0;
- while (toke.hasMoreElements())
- {
- tcnt++;
- String t = (String) toke.nextElement();
- if (tcnt == 2)
- {
- key = t.trim();
- }
- else
- if (tcnt == 3)
- {
- val = t.trim();
- }
- }
-
- if (tcnt < 3)
- {
- p("usage: put key val");
- }
- else
- {
-
- long n_start = System.currentTimeMillis();
- cache_control.put(key, val);
- long n_end = System.currentTimeMillis();
- p("---put " + key + " | " + val + " in " +
- String.valueOf(n_end - n_start) + " millis ---");
- }
- }
- /////////////////////////////////////////////////////////////////////
- if (message.startsWith("removem"))
- {
- String numS = message.substring(message.indexOf(" ") + 1,
- message.length());
- int num = Integer.parseInt(numS.trim());
- if (numS == null)
- {
- p("usage: removem numbertoremove");
- }
- else
- {
- removeMultiple(num);
- }
- }
-
- else
- if (message.startsWith("removeall"))
- {
- String key = message.substring(message.indexOf(" ") + 1,
- message.length());
- cache_control.remove();
- p("removed all");
- }
- else
- if (message.startsWith("remove"))
- {
- String key = message.substring(message.indexOf(" ") + 1,
- message.length());
- cache_control.remove(key);
- p("removed " + key);
- }
- else
- if (message.startsWith("deattr"))
- {
- IElementAttributes ae = cache_control.getElementAttributes();
- p("Default IElementAttributes " + ae);
- }
- else
- if (message.startsWith("cloneattr"))
- {
- String numS = message.substring(message.indexOf(" ") + 1,
- message.length());
- int num = Integer.parseInt(numS.trim());
- if (numS == null)
- {
- p("usage: put numbertoput");
- }
- else
- {
- IElementAttributes attrp = new ElementAttributes();
- long n_start = System.currentTimeMillis();
- for (int n = 0; n < num; n++)
- {
- attrp.copy();
- }
- long n_end = System.currentTimeMillis();
- p("---cloned attr " + num + " in " +
- String.valueOf(n_end - n_start) + " millis ---");
- }
- }
- else
- if (message.startsWith("switch"))
- {
- String numS = message.substring(message.indexOf(" ") + 1,
- message.length());
+ try
+ {
try
{
- int num = Integer.parseInt(numS.trim());
+
+ // process user input till done
+ boolean notDone = true;
+ String message = null;
+ // wait to dispose
+ BufferedReader br = new BufferedReader( new InputStreamReader(
+ System.in ) );
+
+ help();
+
+ while (notDone)
+ {
+ p( "enter command:" );
+
+ message = br.readLine();
+
+ if (message.startsWith( "help" ))
+ {
+ help();
+ }
+ else if (message.startsWith( "getAttributeNames" ))
+ {
+ long n_start = System.currentTimeMillis();
+ String groupName = null;
+ StringTokenizer toke = new StringTokenizer( message );
+ int tcnt = 0;
+ while (toke.hasMoreElements())
+ {
+ tcnt++;
+ String t = (String) toke.nextElement();
+ if (tcnt == 2)
+ {
+ groupName = t.trim();
+ }
+ }
+ getAttributeNames( groupName );
+ long n_end = System.currentTimeMillis();
+ p( "---got attrNames for " + groupName + " in "
+ + String.valueOf( n_end - n_start )
+ + " millis ---" );
+ }
+ else if (message.startsWith( "shutDown" ))
+ {
+ CompositeCacheManager.getInstance().shutDown();
+ //cache_control.dispose();
+ notDone = false;
+ System.exit( -1 );
+ }
+ else
+
+ /////////////////////////////////////////////////////////////////////
+ // get multiple from a region
+ if (message.startsWith( "getm" ))
+ {
+
+ int num = 0;
+ boolean show = true;
+
+ StringTokenizer toke = new StringTokenizer( message );
+ int tcnt = 0;
+ while (toke.hasMoreElements())
+ {
+ tcnt++;
+ String t = (String) toke.nextElement();
+ if (tcnt == 2)
+ {
+ try
+ {
+ num = Integer.parseInt( t.trim() );
+ }
+ catch (NumberFormatException nfe)
+ {
+ p( t + "not a number" );
+ }
+ }
+ else if (tcnt == 3)
+ {
+ show = new Boolean( t ).booleanValue();
+ }
+ }
+
+ if (tcnt < 2)
+ {
+ p( "usage: get numbertoget show values[true|false]" );
+ }
+ else
+ {
+ getMultiple( num, show );
+ }
+ }
+ else
+
+ /////////////////////////////////////////////////////////////////////
+ if (message.startsWith( "getg" ))
+ {
+
+ String key = null;
+ String group = null;
+ boolean show = true;
+
+ StringTokenizer toke = new StringTokenizer( message );
+ int tcnt = 0;
+ while (toke.hasMoreElements())
+ {
+ tcnt++;
+ String t = (String) toke.nextElement();
+ if (tcnt == 2)
+ {
+ key = t.trim();
+ }
+ else if (tcnt == 3)
+ {
+ group = t.trim();
+ }
+ else if (tcnt == 4)
+ {
+ show = new Boolean( t ).booleanValue();
+ }
+ }
+
+ if (tcnt < 2)
+ {
+ p( "usage: get key show values[true|false]" );
+ }
+ else
+ {
+
+ long n_start = System.currentTimeMillis();
+ try
+ {
+ Object obj = cache_control.getFromGroup( key,
+ group );
+ if (show && obj != null)
+ {
+ p( obj.toString() );
+ }
+ }
+ catch (Exception e)
+ {
+ log.error( e );
+ }
+ long n_end = System.currentTimeMillis();
+ p( "---got " + key + " from group " + group
+ + " in " + String.valueOf( n_end - n_start )
+ + " millis ---" );
+ }
+ }
+ else
+
+ /////////////////////////////////////////////////////////////////////
+ if (message.startsWith( "getag" ))
+ {
+ // get auto from group
+
+ int num = 0;
+ String group = null;
+ boolean show = true;
+
+ StringTokenizer toke = new StringTokenizer( message );
+ int tcnt = 0;
+ while (toke.hasMoreElements())
+ {
+ tcnt++;
+ String t = (String) toke.nextElement();
+ if (tcnt == 2)
+ {
+ num = Integer.parseInt( t.trim() );
+ }
+ else if (tcnt == 3)
+ {
+ group = t.trim();
+ }
+ else if (tcnt == 4)
+ {
+ show = new Boolean( t ).booleanValue();
+ }
+ }
+
+ if (tcnt < 2)
+ {
+ p( "usage: get key show values[true|false]" );
+ }
+ else
+ {
+
+ long n_start = System.currentTimeMillis();
+ try
+ {
+ for (int a = 0; a < num; a++)
+ {
+ Object obj = cache_control.getFromGroup(
+ "keygr" + a, group );
+ if (show && obj != null)
+ {
+ p( obj.toString() );
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ log.error( e );
+ }
+ long n_end = System.currentTimeMillis();
+ p( "---got " + num + " from group " + group
+ + " in " + String.valueOf( n_end - n_start )
+ + " millis ---" );
+ }
+ }
+ else
+
+ /////////////////////////////////////////////////////////////////////
+ if (message.startsWith( "get" ))
+ {
+ // plain old get
+
+ String key = null;
+ boolean show = true;
+
+ StringTokenizer toke = new StringTokenizer( message );
+ int tcnt = 0;
+ while (toke.hasMoreElements())
+ {
+ tcnt++;
+ String t = (String) toke.nextElement();
+ if (tcnt == 2)
+ {
+ key = t.trim();
+ }
+ else if (tcnt == 3)
+ {
+ show = new Boolean( t ).booleanValue();
+ }
+ }
+
+ if (tcnt < 2)
+ {
+ p( "usage: get key show values[true|false]" );
+ }
+ else
+ {
+
+ long n_start = System.currentTimeMillis();
+ try
+ {
+ Object obj = cache_control.get( key );
+ if (show && obj != null)
+ {
+ p( obj.toString() );
+ }
+ }
+ catch (Exception e)
+ {
+ log.error( e );
+ }
+ long n_end = System.currentTimeMillis();
+ p( "---got " + key + " in "
+ + String.valueOf( n_end - n_start )
+ + " millis ---" );
+ }
+ }
+ else if (message.startsWith( "putg" ))
+ {
+
+ String group = null;
+ String key = null;
+ StringTokenizer toke = new StringTokenizer( message );
+ int tcnt = 0;
+ while (toke.hasMoreElements())
+ {
+ tcnt++;
+ String t = (String) toke.nextElement();
+ if (tcnt == 2)
+ {
+ key = t.trim();
+ }
+ else if (tcnt == 3)
+ {
+ group = t.trim();
+ }
+ }
+
+ if (tcnt < 3)
+ {
+ p( "usage: putg key group" );
+ }
+ else
+ {
+ long n_start = System.currentTimeMillis();
+ cache_control.putInGroup( key, group,
+ "data from putg ----asdfasfas-asfasfas-asfas in group "
+ + group );
+ long n_end = System.currentTimeMillis();
+ p( "---put " + key + " in group " + group + " in "
+ + String.valueOf( n_end - n_start )
+ + " millis ---" );
+ }
+ }
+ else
+
+ // put automatically
+ if (message.startsWith( "putag" ))
+ {
+
+ String group = null;
+ int num = 0;
+ StringTokenizer toke = new StringTokenizer( message );
+ int tcnt = 0;
+ while (toke.hasMoreElements())
+ {
+ tcnt++;
+ String t = (String) toke.nextElement();
+ if (tcnt == 2)
+ {
+ num = Integer.parseInt( t.trim() );
+ }
+ else if (tcnt == 3)
+ {
+ group = t.trim();
+ }
+ }
+
+ if (tcnt < 3)
+ {
+ p( "usage: putag num group" );
+ }
+ else
+ {
+ long n_start = System.currentTimeMillis();
+ for (int a = 0; a < num; a++)
+ {
+ cache_control
+ .putInGroup(
+ "keygr" + a,
+ group,
+ "data "
+ + a
+ + " from putag ----asdfasfas-asfasfas-asfas in group "
+ + group );
+ }
+ long n_end = System.currentTimeMillis();
+ p( "---put " + num + " in group " + group + " in "
+ + String.valueOf( n_end - n_start )
+ + " millis ---" );
+ }
+ }
+ else
+
+ /////////////////////////////////////////////////////////////////////
+ if (message.startsWith( "putm" ))
+ {
+ String numS = message.substring(
+ message.indexOf( " " ) + 1, message.length() );
+ int num = Integer.parseInt( numS.trim() );
+ if (numS == null)
+ {
+ p( "usage: putm numbertoput" );
+ }
+ else
+ {
+ putMultiple( num );
+ }
+ }
+ else
+
+ /////////////////////////////////////////////////////////////////////
+ if (message.startsWith( "pute" ))
+ {
+ String numS = message.substring(
+ message.indexOf( " " ) + 1, message.length() );
+ int num = Integer.parseInt( numS.trim() );
+ if (numS == null)
+ {
+ p( "usage: putme numbertoput" );
+ }
+ else
+ {
+ long n_start = System.currentTimeMillis();
+ for (int n = 0; n < num; n++)
+ {
+ IElementAttributes attrp = cache_control
+ .getElementAttributes();
+ TestElementEventHandler hand = new TestElementEventHandler();
+ attrp.addElementEventHandler( hand );
+ cache_control.put( "key" + n, "data" + n
+ + " put from ta = junk", attrp );
+ }
+ long n_end = System.currentTimeMillis();
+ p( "---put " + num + " in "
+ + String.valueOf( n_end - n_start )
+ + " millis ---" );
+ }
+ }
+ else if (message.startsWith( "put" ))
+ {
+
+ String key = null;
+ String val = null;
+ StringTokenizer toke = new StringTokenizer( message );
+ int tcnt = 0;
+ while (toke.hasMoreElements())
+ {
+ tcnt++;
+ String t = (String) toke.nextElement();
+ if (tcnt == 2)
+ {
+ key = t.trim();
+ }
+ else if (tcnt == 3)
+ {
+ val = t.trim();
+ }
+ }
+
+ if (tcnt < 3)
+ {
+ p( "usage: put key val" );
+ }
+ else
+ {
+
+ long n_start = System.currentTimeMillis();
+ cache_control.put( key, val );
+ long n_end = System.currentTimeMillis();
+ p( "---put " + key + " | " + val + " in "
+ + String.valueOf( n_end - n_start )
+ + " millis ---" );
+ }
+ }
+ /////////////////////////////////////////////////////////////////////
+ if (message.startsWith( "removem" ))
+ {
+ String numS = message.substring(
+ message.indexOf( " " ) + 1, message.length() );
+ int num = Integer.parseInt( numS.trim() );
+ if (numS == null)
+ {
+ p( "usage: removem numbertoremove" );
+ }
+ else
+ {
+ removeMultiple( num );
+ }
+ }
+
+ else if (message.startsWith( "removeall" ))
+ {
+ cache_control.clear();
+ p( "removed all" );
+ }
+ else if (message.startsWith( "remove" ))
+ {
+ String key = message.substring(
+ message.indexOf( " " ) + 1, message.length() );
+ cache_control.remove( key );
+ p( "removed " + key );
+ }
+ else if (message.startsWith( "deattr" ))
+ {
+ IElementAttributes ae = cache_control
+ .getElementAttributes();
+ p( "Default IElementAttributes " + ae );
+ }
+ else if (message.startsWith( "cloneattr" ))
+ {
+ String numS = message.substring(
+ message.indexOf( " " ) + 1, message.length() );
+ int num = Integer.parseInt( numS.trim() );
+ if (numS == null)
+ {
+ p( "usage: put numbertoput" );
+ }
+ else
+ {
+ IElementAttributes attrp = new ElementAttributes();
+ long n_start = System.currentTimeMillis();
+ for (int n = 0; n < num; n++)
+ {
+ attrp.copy();
+ }
+ long n_end = System.currentTimeMillis();
+ p( "---cloned attr " + num + " in "
+ + String.valueOf( n_end - n_start )
+ + " millis ---" );
+ }
+ }
+ else if (message.startsWith( "switch" ))
+ {
+ String numS = message.substring(
+ message.indexOf( " " ) + 1, message.length() );
+ try
+ {
+ Integer.parseInt( numS.trim() );
+ }
+ catch (Exception e)
+ {
+ p( "usage: switch number" );
+ p( " 1 == testCache1" );
+ }
+ if (numS == null)
+ {
+ p( "usage: switch number" );
+ p( " 1 == testCache1" );
+ }
+ else
+ {
+ setRegion( "testCache" + numS );
+ p( "switched to cache = " + "testCache" + numS );
+ p( cache_control.toString() );
+ }
+ }
+ else if (message.startsWith( "stats" ))
+ {
+ p( cache_control.getStats() );
+ }
+ else if (message.startsWith( "gc" ))
+ {
+ System.gc();
+ p( "Called system.gc()" );
+ }
+ else if (message.startsWith( "random" ))
+ if (message.startsWith( "random" ))
+ {
+ String rangeS = "";
+ String numOpsS = "";
+ boolean show = true;
+
+ StringTokenizer toke = new StringTokenizer( message );
+ int tcnt = 0;
+ while (toke.hasMoreElements())
+ {
+ tcnt++;
+ String t = (String) toke.nextElement();
+ if (tcnt == 2)
+ {
+ rangeS = t.trim();
+ }
+ else if (tcnt == 3)
+ {
+ numOpsS = t.trim();
+ }
+ else if (tcnt == 4)
+ {
+ show = new Boolean( t ).booleanValue();
+ }
+ }
+
+ String numS = message.substring( message
+ .indexOf( " " ) + 1, message.length() );
+
+ int range = 0;
+ int numOps = 0;
+ try
+ {
+ range = Integer.parseInt( rangeS.trim() );
+ numOps = Integer.parseInt( numOpsS.trim() );
+ }
+ catch (Exception e)
+ {
+ p( "usage: random range numOps show" );
+ p( "ex. random 100 1000 false" );
+ }
+ if (numS == null)
+ {
+ p( "usage: random range numOps show" );
+ p( "ex. random 100 1000 false" );
+ }
+ else
+ {
+ random( range, numOps, show );
+ }
+ }
+
+ }
}
catch (Exception e)
{
- p("usage: switch number");
- p(" 1 == testCache1");
+ p( e.toString() );
+ e.printStackTrace( System.out );
}
- if (numS == null)
+
+ }
+ catch (Exception e)
+ {
+ p( e.toString() );
+ e.printStackTrace( System.out );
+ }
+
+ } // end runLoop
+
+ /**
+ * Test harness.
+ *
+ * @param args
+ * The command line arguments
+ */
+ public static void main( String[] args )
+ {
+ isSysOut = true;
+ String ccfFileName = args[0];
+ TestCacheAccess tca = new TestCacheAccess( ccfFileName );
+ tca.runLoop();
+ }
+
+ // end main
+ /////////////////////////////////////////////////////////////////////////////
+
+ /**
+ * Gets multiple items from the cache with keys of the form key1, key2, key3
+ * up to key[num].
+ *
+ * @param num
+ * int
+ */
+ public void getMultiple( int num )
+ {
+ getMultiple( num, false );
+ }
+
+ /**
+ * @param num
+ * @param show
+ */
+ public void getMultiple( int num, boolean show )
+ {
+ long n_start = System.currentTimeMillis();
+ for (int n = 0; n < num; n++)
+ {
+ try
{
- p("usage: switch number");
- p(" 1 == testCache1");
+ Object obj = cache_control.get( "key" + n );
+ if (show && obj != null)
+ {
+ p( obj.toString() );
+ }
}
- else
+ catch (Exception e)
{
- setRegion("testCache" + numS);
- p("switched to cache = " + "testCache" + numS);
- p(cache_control.toString());
+ log.error( e );
}
- }
- else
- if (message.startsWith("stats"))
- {
- p(cache_control.getStats());
- }
- else
- if (message.startsWith("gc"))
- {
- System.gc();
- p("Called system.gc()");
- }
- else
- if (message.startsWith("random"))
- if (message.startsWith("random"))
- {
- String rangeS = "";
- String numOpsS = "";
- boolean show = true;
-
- StringTokenizer toke = new StringTokenizer(message);
- int tcnt = 0;
- while (toke.hasMoreElements())
- {
- tcnt++;
- String t = (String) toke.nextElement();
- if (tcnt == 2)
- {
- rangeS = t.trim();
- }
- else
- if (tcnt == 3)
- {
- numOpsS = t.trim();
- }
- else
- if (tcnt == 4)
- {
- show = new Boolean(t).booleanValue();
- }
- }
-
- String numS = message.substring(message.indexOf(" ") + 1,
- message.length());
- //p( numS );
-
- String numS2 = numS.substring(0, numS.indexOf(" "));
- //p( numS2 );
-
- String numS3 = numS.substring(numS.indexOf(" ") + 1,
- numS.length());
- //p( numS3 );
-
- int range = 0;
- int numOps = 0;
- try
- {
- range = Integer.parseInt(rangeS.trim());
- numOps = Integer.parseInt(numOpsS.trim());
- }
- catch (Exception e)
- {
- p("usage: random range numOps show");
- p("ex. random 100 1000 false");
- }
- if (numS == null)
- {
- p("usage: random range numOps show");
- p("ex. random 100 1000 false");
- }
- else
- {
- random(range, numOps, show);
- }
- }
-
}
- }
- catch (Exception e)
- {
- p(e.toString());
- e.printStackTrace(System.out);
- }
-
- }
- catch (Exception e)
- {
- p(e.toString());
- e.printStackTrace(System.out);
+ long n_end = System.currentTimeMillis();
+ p( "---got " + num + " in " + String.valueOf( n_end - n_start )
+ + " millis ---" );
}
- } // end runLoop
-
- /**
- * Test harness.
- *
- * @param args The command line arguments
- */
- public static void main(String[] args)
- {
- isSysOut = true;
- String ccfFileName = args[0];
- TestCacheAccess tca = new TestCacheAccess(ccfFileName);
- tca.runLoop();
- }
-
- // end main
-/////////////////////////////////////////////////////////////////////////////
-
- /**
- * Gets multiple items from the cache with keys of the form key1, key2, key3
- * up to key[num].
- *
- * @param num int
- */
- public void getMultiple(int num)
- {
- getMultiple(num, false);
- }
-
- public void getMultiple(int num, boolean show)
- {
- long n_start = System.currentTimeMillis();
- for (int n = 0; n < num; n++)
+ /**
+ * Puts multiple items into the cache.
+ *
+ * @param num
+ * int
+ */
+ public void putMultiple( int num )
{
- try
- {
- Object obj = cache_control.get("key" + n);
- if (show && obj != null)
+ try
{
- p(obj.toString());
+ long n_start = System.currentTimeMillis();
+ for (int n = 0; n < num; n++)
+ {
+ cache_control.put( "key" + n, "data" + n
+ + " put from ta = junk" );
+ }
+ long n_end = System.currentTimeMillis();
+ p( "---put " + num + " in " + String.valueOf( n_end - n_start )
+ + " millis ---" );
}
- }
- catch (Exception e)
- {
- log.error(e);
- }
- }
- long n_end = System.currentTimeMillis();
- p("---got " + num + " in " + String.valueOf(n_end - n_start) +
- " millis ---");
- }
-
- /**
- * Puts multiple items into the cache.
- * @param num int
- */
- public void putMultiple(int num)
- {
- try
- {
- long n_start = System.currentTimeMillis();
- for (int n = 0; n < num; n++)
- {
- cache_control.put("key" + n,
- "data" + n + " put from ta = junk");
- }
- long n_end = System.currentTimeMillis();
- p("---put " + num + " in " + String.valueOf(n_end - n_start) +
- " millis ---");
- }
- catch (Exception e)
- {
- log.error(e);
- }
- }
-
-
- /**
- * Removes multiple items from the cache.
- * @param num int
- */
- public void removeMultiple(int num)
- {
- try
- {
- long n_start = System.currentTimeMillis();
- for (int n = 0; n < num; n++)
- {
- cache_control.remove("key" + n);
- }
- long n_end = System.currentTimeMillis();
- p("---removed " + num + " in " + String.valueOf(n_end - n_start) +
- " millis ---");
- }
- catch (Exception e)
- {
- log.error(e);
- }
- }
-
- /**
- * The random method performs numOps number of operations. The operations
- * will be a mix of puts, gets, and removes. The key range will be from
- * 0 to range.
- *
- * @param range int The end of the key range.
- * @param numOps int The number of operations to perform
- */
- public void random(int range, int numOps)
- {
- random( range, numOps, false );
- }
- public void random(int range, int numOps, boolean show)
- {
- try
- {
- for (int i = 0; i < numOps; i++)
- {
- Random ran = new Random(i);
- int n = ran.nextInt(4);
- int kn = ran.nextInt(range);
- String key = "key" + kn;
- if (n == 1)
+ catch (Exception e)
{
- cache_control.put(key,
- "data" + i + " junk asdfffffffadfasdfasf " + kn +
- ":" + n);
- if ( show ) {
- p("put " + key);
- }
+ log.error( e );
}
- else if (n == 2)
+ }
+
+ /**
+ * Removes multiple items from the cache.
+ *
+ * @param num
+ * int
+ */
+ public void removeMultiple( int num )
+ {
+ try
{
- cache_control.remove(key);
- if ( show ) {
- p("removed " + key);
- }
+ long n_start = System.currentTimeMillis();
+ for (int n = 0; n < num; n++)
+ {
+ cache_control.remove( "key" + n );
+ }
+ long n_end = System.currentTimeMillis();
+ p( "---removed " + num + " in " + String.valueOf( n_end - n_start )
+ + " millis ---" );
+ }
+ catch (Exception e)
+ {
+ log.error( e );
+ }
+ }
+
+ /**
+ * The random method performs numOps number of operations. The operations
+ * will be a mix of puts, gets, and removes. The key range will be from 0 to
+ * range.
+ *
+ * @param range
+ * int The end of the key range.
+ * @param numOps
+ * int The number of operations to perform
+ */
+ public void random( int range, int numOps )
+ {
+ random( range, numOps, false );
+ }
+
+ /**
+ * @param range
+ * @param numOps
+ * @param show
+ */
+ public void random( int range, int numOps, boolean show )
+ {
+ try
+ {
+ for (int i = 0; i < numOps; i++)
+ {
+ Random ran = new Random( i );
+ int n = ran.nextInt( 4 );
+ int kn = ran.nextInt( range );
+ String key = "key" + kn;
+ if (n == 1)
+ {
+ cache_control.put( key, "data" + i
+ + " junk asdfffffffadfasdfasf " + kn + ":" + n );
+ if (show)
+ {
+ p( "put " + key );
+ }
+ }
+ else if (n == 2)
+ {
+ cache_control.remove( key );
+ if (show)
+ {
+ p( "removed " + key );
+ }
+ }
+ else
+ {
+ // slightly greater chance of get
+ Object obj = cache_control.get( key );
+ if (show && obj != null)
+ {
+ p( obj.toString() );
+ }
+ }
+
+ if (i % 10000 == 0)
+ {
+ p( cache_control.getStats() );
+ }
+
+ }
+ p( "Finished random cycle of " + numOps );
+ }
+ catch (Exception e)
+ {
+ p( e.toString() );
+ e.printStackTrace( System.out );
+ }
+ }
+
+ /**
+ * Sets the region to be used by test methods.
+ *
+ * @param name
+ * String -- Name of region
+ */
+ public void setRegion( String name )
+ {
+ try
+ {
+ cache_control = JCS.getInstance( name );
+ }
+ catch (Exception e)
+ {
+ p( e.toString() );
+ e.printStackTrace( System.out );
+ }
+
+ }
+
+ /////////////////////////////////////////////////////////////////////////////
+ /**
+ * The tester will print to the console if isSysOut is true, else it will
+ * log. It is false by default. When run via the main method, isSysOut will
+ * be set to true
+ *
+ * @param s
+ * String to print or log
+ */
+ public static void p( String s )
+ {
+ if (isSysOut)
+ {
+ System.out.println( s );
}
else
{
- // slightly greater chance of get
- Object obj = cache_control.get(key);
- if (show && obj != null)
- {
- p(obj.toString());
- }
+ if (log.isDebugEnabled())
+ {
+ log.debug( s );
+ }
}
+ }
- if ( i % 10000 == 0 ) {
- p( cache_control.getStats() );
+ /**
+ * Displays usage information for command line testing.
+ */
+ public static void help()
+ {
+ p( "\n\n\n\n" );
+ p( "type 'shutDown' to shutdown the cache" );
+ p( "type 'getm num show[false|true]' to get num automatically from a region" );
+ p( "type 'putm num' to put num automatically to a region" );
+ p( "type 'removeall' to remove all items in a region" );
+ p( "type 'remove key' to remove" );
+ p( "type 'removem num' to remove a number automatically" );
+ p( "type 'get key show' to get" );
+ p( "type 'getg key group show' to get" );
+ p( "type 'getag num group show' to get automatically from a group" );
+ p( "type 'getAttributeNames group' to get a list og the group elements" );
+ p( "type 'putg key group val' to put" );
+ p( "type 'putag num group' to put automatically from a group" );
+ p( "type 'put key val' to put" );
+ p( "type 'stats' to get stats" );
+ p( "type 'deattr' to get the default element attributes" );
+ p( "type 'cloneattr num' to clone attr" );
+ p( "type 'random range numOps' to put, get, and remove randomly" );
+ p( "type 'switch number' to switch to testCache[number], 1 == testCache1" );
+ p( "type 'help' for commands" );
+
+ }
+
+ /**
+ * Gets the attributeNames attribute of the TestCacheAccess class
+ * @param groupName
+ */
+ public void getAttributeNames( String groupName )
+ {
+ Iterator iter = cache_control.getGroupKeys( groupName ).iterator();
+
+ while (iter.hasNext())
+ {
+ p( "=" + (String) iter.next() );
}
-
- }
- p("Finished random cycle of " + numOps);
}
- catch (Exception e)
- {
- p(e.toString());
- e.printStackTrace(System.out);
- }
- }
-
-
- /**
- * Sets the region to be used by test methods.
- *
- * @param name String -- Name of region
- */
- public void setRegion(String name)
- {
- try
- {
- cache_control = JCS.getInstance(name);
- }
- catch (Exception e)
- {
- p(e.toString());
- e.printStackTrace(System.out);
- }
-
- }
-
- /////////////////////////////////////////////////////////////////////////////
- /**
- * The tester will print to the console if isSysOut is true, else it will log.
- * It is false by default. When run via the main method, isSysOut will be set
- * to true
- *
- * @param s String to print or log
- */
- public static void p(String s)
- {
- if (isSysOut)
- {
- System.out.println(s);
- }
- else
- {
- if (log.isDebugEnabled())
- {
- log.debug(s);
- }
- }
- }
-
- /**
- * Displays usage information for command line testing.
- */
- public static void help()
- {
- p("\n\n\n\n");
- p("type 'shutDown' to shutdown the cache");
- p(
- "type 'getm num show[false|true]' to get num automatically from a region");
- p("type 'putm num' to put num automatically to a region");
- p("type 'removeall' to remove all items in a region");
- p("type 'remove key' to remove");
- p("type 'removem num' to remove a number automatically");
- p("type 'get key show' to get");
- p("type 'getg key group show' to get");
- p("type 'getag num group show' to get automatically from a group");
- p("type 'getAttributeNames group' to get a list og the group elements");
- p("type 'putg key group val' to put");
- p("type 'putag num group' to put automatically from a group");
- p("type 'put key val' to put");
- p("type 'stats' to get stats");
- p("type 'deattr' to get teh default element attributes");
- p("type 'cloneattr num' to clone attr");
- p("type 'random range numOps' to put, get, and remove randomly");
- p("type 'switch number' to switch to testCache[number], 1 == testCache1");
- p("type 'help' for commands");
-
- }
-
- /**
- * Gets the attributeNames attribute of the TestCacheAccess class
- */
- public void getAttributeNames(String groupName)
- {
- Iterator iter = cache_control.getGroupKeys(groupName).iterator();
-
- while (iter.hasNext())
- {
- p("=" + (String) iter.next());
- }
- }
} // end class
diff --git a/src/test/org/apache/jcs/engine/TestEventQueueConcurrent.java b/src/test/org/apache/jcs/engine/TestEventQueueConcurrent.java
index 16b3520..132f213 100644
--- a/src/test/org/apache/jcs/engine/TestEventQueueConcurrent.java
+++ b/src/test/org/apache/jcs/engine/TestEventQueueConcurrent.java
@@ -49,6 +49,7 @@
/**
* Constructor for the TestDiskCache object.
+ * @param testName
*/
public TestEventQueueConcurrent(String testName)
{
@@ -57,6 +58,7 @@
/**
* Main method passes this test to the text test runner.
+ * @param args
*/
public static void main(String args[])
{
@@ -273,8 +275,14 @@
private class CacheListenerImpl implements ICacheListener
{
+ /**
+ * <code>putCount</code>
+ */
protected int putCount = 0;
+ /**
+ * <code>removeCount</code>
+ */
protected int removeCount = 0;
/*
diff --git a/src/test/org/apache/jcs/engine/control/CompositeCacheManagerTester.java b/src/test/org/apache/jcs/engine/control/CompositeCacheManagerTester.java
index 1c026b1..b1aca6a 100644
--- a/src/test/org/apache/jcs/engine/control/CompositeCacheManagerTester.java
+++ b/src/test/org/apache/jcs/engine/control/CompositeCacheManagerTester.java
@@ -16,14 +16,17 @@
* limitations under the License.
*/
+/**
+ */
public class CompositeCacheManagerTester
{
- /** Description of the Method */
+ /** Description of the Method
+ * @param args*/
public static void main( String args[] )
{
- CompositeCacheManagerTester ccmt = new CompositeCacheManagerTester();
+ //CompositeCacheManagerTester ccmt = new CompositeCacheManagerTester();
String propsFile = "/cache.ccf";
if ( args.length > 0 )
diff --git a/src/test/org/apache/jcs/engine/control/event/TestElementEventHandler.java b/src/test/org/apache/jcs/engine/control/event/TestElementEventHandler.java
index 4e963e8..68bb95e 100644
--- a/src/test/org/apache/jcs/engine/control/event/TestElementEventHandler.java
+++ b/src/test/org/apache/jcs/engine/control/event/TestElementEventHandler.java
@@ -16,26 +16,28 @@
* limitations under the License.
*/
-import java.io.Serializable;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.jcs.engine.control.event.behavior.IElementEventHandler;
import org.apache.jcs.engine.control.event.behavior.IElementEvent;
+import org.apache.jcs.engine.control.event.behavior.IElementEventHandler;
-
+/**
+ *
+ * @author aaronsm
+ *
+ */
public class TestElementEventHandler implements IElementEventHandler {
private final static Log log = LogFactory.getLog( TestElementEventHandler.class );
- public Serializable handleElementEvent(IElementEvent event )
+ public void handleElementEvent(IElementEvent event )
{
log.debug( "HANDLER -- HANDLER -- HANDLER -- ---EVENT CODE = " + event.getElementEvent() );
log.debug( "/n/n EVENT CODE = " + event.getElementEvent() + " ***************************" );
- return "Done";
+ //return "Done";
}
}
diff --git a/src/test/org/apache/jcs/engine/memory/lru/TestLRUMemoryCache.java b/src/test/org/apache/jcs/engine/memory/lru/TestLRUMemoryCache.java
index 928a9f8..718af41 100644
--- a/src/test/org/apache/jcs/engine/memory/lru/TestLRUMemoryCache.java
+++ b/src/test/org/apache/jcs/engine/memory/lru/TestLRUMemoryCache.java
@@ -28,8 +28,8 @@
import org.apache.jcs.engine.control.CompositeCacheManager;
/**
- * Test which exercises the indexed disk cache. This one uses three different
- * regions for thre threads.
+ * Test which exercises the LRUMemory cache. This one uses three different
+ * regions for three threads.
*
* @version $Id$
*/
@@ -43,6 +43,7 @@
/**
* Constructor for the TestDiskCache object.
+ * @param testName
*/
public TestLRUMemoryCache( String testName )
{
@@ -51,6 +52,7 @@
/**
* Main method passes this test to the text test runner.
+ * @param args
*/
public static void main( String args[] )
{
@@ -144,7 +146,7 @@
for ( int i = 102; i < items; i++ )
{
String value = (String)
- ((ICacheElement)lru.get( i + ":key" )).getVal();
+ lru.get( i + ":key" ).getVal();
assertEquals( region + " data " + i, value );
}
diff --git a/tempbuild/jcs-1.2.3-dev.jar b/tempbuild/jcs-1.2.3-dev.jar
new file mode 100644
index 0000000..713fd3f
--- /dev/null
+++ b/tempbuild/jcs-1.2.3-dev.jar
Binary files differ