You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by tv...@apache.org on 2012/05/30 20:14:51 UTC
svn commit: r1344374 [9/14] - in /commons/proper/jcs/trunk: ./
auxiliary-builds/javagroups/src/java/org/apache/jcs/auxiliary/javagroups/
auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/javagroups/
auxiliary-builds/jdk14/src/java/org/apache/jcs...
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/memory/lru/LHMLRUMemoryCache.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/memory/lru/LHMLRUMemoryCache.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/memory/lru/LHMLRUMemoryCache.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/memory/lru/LHMLRUMemoryCache.java Wed May 30 18:14:43 2012
@@ -24,7 +24,9 @@ import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
+import java.util.LinkedHashSet;
import java.util.Map;
+import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -32,7 +34,6 @@ import org.apache.jcs.engine.CacheConsta
import org.apache.jcs.engine.behavior.ICacheElement;
import org.apache.jcs.engine.control.CompositeCache;
import org.apache.jcs.engine.control.group.GroupAttrName;
-import org.apache.jcs.engine.control.group.GroupId;
import org.apache.jcs.engine.memory.AbstractMemoryCache;
import org.apache.jcs.engine.memory.util.MemoryElementDescriptor;
import org.apache.jcs.engine.stats.StatElement;
@@ -43,8 +44,8 @@ import org.apache.jcs.engine.stats.behav
/**
* This is a test memory manager using the jdk1.4 LinkedHashMap.
*/
-public class LHMLRUMemoryCache
- extends AbstractMemoryCache
+public class LHMLRUMemoryCache<K extends Serializable, V extends Serializable>
+ extends AbstractMemoryCache<K, V>
{
/** Don't change */
private static final long serialVersionUID = 6403738094136424101L;
@@ -67,7 +68,7 @@ public class LHMLRUMemoryCache
* @param hub
*/
@Override
- public synchronized void initialize( CompositeCache hub )
+ public synchronized void initialize( CompositeCache<K, V> hub )
{
super.initialize( hub );
log.info( "initialized LHMLRUMemoryCache for " + cacheName );
@@ -79,7 +80,7 @@ public class LHMLRUMemoryCache
* @return Collections.synchronizedMap( new LHMSpooler() )
*/
@Override
- public Map<Serializable, MemoryElementDescriptor> createMap()
+ public Map<K, MemoryElementDescriptor<K, V>> createMap()
{
return Collections.synchronizedMap( new LHMSpooler() );
}
@@ -91,12 +92,12 @@ public class LHMLRUMemoryCache
* @exception IOException
*/
@Override
- public void update( ICacheElement ce )
+ public void update( ICacheElement<K, V> ce )
throws IOException
{
putCnt++;
ce.getElementAttributes().setLastAccessTimeNow();
- map.put( ce.getKey(), new MemoryElementDescriptor(ce) );
+ map.put( ce.getKey(), new MemoryElementDescriptor<K, V>(ce) );
}
/**
@@ -108,7 +109,7 @@ public class LHMLRUMemoryCache
* @exception IOException
*/
@Override
- public ICacheElement getQuiet( Serializable key )
+ public ICacheElement<K, V> getQuiet( K key )
throws IOException
{
return map.get( key ).ce;
@@ -118,14 +119,14 @@ public class LHMLRUMemoryCache
* Get an item from the cache
* <p>
* @param key Identifies item to find
- * @return ICacheElement if found, else null
+ * @return ICacheElement<K, V> if found, else null
* @exception IOException
*/
@Override
- public synchronized ICacheElement get( Serializable key )
+ public synchronized ICacheElement<K, V> get( K key )
throws IOException
{
- MemoryElementDescriptor me = null;
+ MemoryElementDescriptor<K, V> me = null;
if ( log.isDebugEnabled() )
{
@@ -163,7 +164,7 @@ public class LHMLRUMemoryCache
* @exception IOException
*/
@Override
- public synchronized boolean remove( Serializable key )
+ public synchronized boolean remove( K key )
throws IOException
{
if ( log.isDebugEnabled() )
@@ -179,10 +180,10 @@ public class LHMLRUMemoryCache
// remove all keys of the same name hierarchy.
synchronized ( map )
{
- for (Iterator<Map.Entry<Serializable, MemoryElementDescriptor>> itr = map.entrySet().iterator(); itr.hasNext(); )
+ for (Iterator<Map.Entry<K, MemoryElementDescriptor<K, V>>> itr = map.entrySet().iterator(); itr.hasNext(); )
{
- Map.Entry<Serializable, MemoryElementDescriptor> entry = itr.next();
- Object k = entry.getKey();
+ Map.Entry<K, MemoryElementDescriptor<K, V>> entry = itr.next();
+ K k = entry.getKey();
if ( k instanceof String && ( (String) k ).startsWith( key.toString() ) )
{
@@ -192,17 +193,18 @@ public class LHMLRUMemoryCache
}
}
}
- else if ( key instanceof GroupId )
+ else if ( key instanceof GroupAttrName && ((GroupAttrName<?>)key).attrName == null )
{
// remove all keys of the same name hierarchy.
synchronized ( map )
{
- for (Iterator<Map.Entry<Serializable, MemoryElementDescriptor>> itr = map.entrySet().iterator(); itr.hasNext(); )
+ for (Iterator<Map.Entry<K, MemoryElementDescriptor<K, V>>> itr = map.entrySet().iterator(); itr.hasNext(); )
{
- Map.Entry<Serializable, MemoryElementDescriptor> entry = itr.next();
- Object k = entry.getKey();
+ Map.Entry<K, MemoryElementDescriptor<K, V>> entry = itr.next();
+ K k = entry.getKey();
- if ( k instanceof GroupAttrName && ( (GroupAttrName) k ).groupId.equals( key ) )
+ if ( k instanceof GroupAttrName &&
+ ((GroupAttrName<?>)k).groupId.equals(((GroupAttrName<?>)key).groupId) )
{
itr.remove();
removed = true;
@@ -213,7 +215,7 @@ public class LHMLRUMemoryCache
else
{
// remove single item.
- MemoryElementDescriptor me = map.remove( key );
+ MemoryElementDescriptor<K, V> me = map.remove( key );
if ( me != null )
{
removed = true;
@@ -229,13 +231,13 @@ public class LHMLRUMemoryCache
* @return An Object[]
*/
@Override
- public Object[] getKeyArray()
+ public Set<K> getKeySet()
{
// need a better locking strategy here.
synchronized ( this )
{
// may need to lock to map here?
- return map.keySet().toArray();
+ return new LinkedHashSet<K>(map.keySet());
}
}
@@ -315,7 +317,7 @@ public class LHMLRUMemoryCache
* Implementation of removeEldestEntry in LinkedHashMap
*/
public class LHMSpooler
- extends java.util.LinkedHashMap<Serializable, MemoryElementDescriptor>
+ extends java.util.LinkedHashMap<K, MemoryElementDescriptor<K, V>>
{
/** Don't change. */
private static final long serialVersionUID = -1255907868906762484L;
@@ -336,9 +338,9 @@ public class LHMLRUMemoryCache
* @return true if removed
*/
@Override
- protected boolean removeEldestEntry( Map.Entry<Serializable, MemoryElementDescriptor> eldest )
+ protected boolean removeEldestEntry( Map.Entry<K, MemoryElementDescriptor<K, V>> eldest )
{
- ICacheElement element = eldest.getValue().ce;
+ ICacheElement<K, V> element = eldest.getValue().ce;
if ( size() <= cache.getCacheAttributes().getMaxObjects() )
{
@@ -367,13 +369,13 @@ public class LHMLRUMemoryCache
* <p>
* @param element The CacheElement
*/
- private void spoolToDisk( ICacheElement element )
+ private void spoolToDisk( ICacheElement<K, V> element )
{
cache.spoolToDisk( element );
if ( log.isDebugEnabled() )
{
- log.debug( cache.getCacheName() + "Spoolled element to disk: " + element.getKey() );
+ log.debug( cache.getCacheName() + "Spooled element to disk: " + element.getKey() );
}
}
}
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/memory/lru/LRUMemoryCache.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/memory/lru/LRUMemoryCache.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/memory/lru/LRUMemoryCache.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/memory/lru/LRUMemoryCache.java Wed May 30 18:14:43 2012
@@ -20,6 +20,7 @@ package org.apache.jcs.engine.memory.lru
*/
import java.io.IOException;
+import java.io.Serializable;
import org.apache.jcs.engine.behavior.ICacheElement;
import org.apache.jcs.engine.memory.AbstractDoulbeLinkedListMemoryCache;
@@ -36,8 +37,8 @@ import org.apache.jcs.engine.memory.util
* The LRUMemoryCache is most efficient when the first element is selected. The smaller the region,
* the better the chance that this will be the case. < .04 ms per put, p3 866, 1/10 of that per get
*/
-public class LRUMemoryCache
- extends AbstractDoulbeLinkedListMemoryCache
+public class LRUMemoryCache<K extends Serializable, V extends Serializable>
+ extends AbstractDoulbeLinkedListMemoryCache<K, V>
{
/** Don't change */
private static final long serialVersionUID = 6403738094136424201L;
@@ -50,7 +51,7 @@ public class LRUMemoryCache
* @return MemoryElementDescriptor the new node
* @exception IOException
*/
- protected MemoryElementDescriptor adjustListForUpdate( ICacheElement ce )
+ protected MemoryElementDescriptor<K, V> adjustListForUpdate( ICacheElement<K, V> ce )
throws IOException
{
return addFirst( ce );
@@ -61,7 +62,7 @@ public class LRUMemoryCache
* <p>
* @param me
*/
- protected void adjustListForGet( MemoryElementDescriptor me )
+ protected void adjustListForGet( MemoryElementDescriptor<K, V> me )
{
list.makeFirst( me );
}
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/memory/mru/MRUMemoryCache.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/memory/mru/MRUMemoryCache.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/memory/mru/MRUMemoryCache.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/memory/mru/MRUMemoryCache.java Wed May 30 18:14:43 2012
@@ -20,6 +20,7 @@ package org.apache.jcs.engine.memory.mru
*/
import java.io.IOException;
+import java.io.Serializable;
import org.apache.jcs.engine.behavior.ICacheElement;
import org.apache.jcs.engine.memory.AbstractDoulbeLinkedListMemoryCache;
@@ -29,8 +30,8 @@ import org.apache.jcs.engine.memory.util
* The most recently used items move to the front of the list and get spooled to disk if the cache
* hub is configured to use a disk cache.
*/
-public class MRUMemoryCache
- extends AbstractDoulbeLinkedListMemoryCache
+public class MRUMemoryCache<K extends Serializable, V extends Serializable>
+ extends AbstractDoulbeLinkedListMemoryCache<K, V>
{
/** Don't change */
private static final long serialVersionUID = 5013101678192336129L;
@@ -45,7 +46,7 @@ public class MRUMemoryCache
* @return MemoryElementDescriptor the new node
* @exception IOException
*/
- protected MemoryElementDescriptor adjustListForUpdate( ICacheElement ce )
+ protected MemoryElementDescriptor<K, V> adjustListForUpdate( ICacheElement<K, V> ce )
throws IOException
{
return addFirst( ce );
@@ -56,7 +57,7 @@ public class MRUMemoryCache
* <p>
* @param me
*/
- protected void adjustListForGet( MemoryElementDescriptor me )
+ protected void adjustListForGet( MemoryElementDescriptor<K, V> me )
{
list.makeLast( me );
}
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/memory/shrinking/ShrinkerThread.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/memory/shrinking/ShrinkerThread.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/memory/shrinking/ShrinkerThread.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/memory/shrinking/ShrinkerThread.java Wed May 30 18:14:43 2012
@@ -22,6 +22,7 @@ package org.apache.jcs.engine.memory.shr
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
+import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -31,21 +32,21 @@ import org.apache.jcs.engine.control.eve
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;
-import org.apache.jcs.engine.memory.MemoryCache;
+import org.apache.jcs.engine.memory.behavior.IMemoryCache;
/**
* A background memory shrinker. Memory problems and concurrent modification exception caused by
* acting directly on an iterator of the underlying memory cache should have been solved.
* @version $Id$
*/
-public class ShrinkerThread
+public class ShrinkerThread<K extends Serializable, V extends Serializable>
implements Runnable
{
/** The logger */
private final static Log log = LogFactory.getLog( ShrinkerThread.class );
/** The MemoryCache instance which this shrinker is watching */
- private final MemoryCache cache;
+ private final IMemoryCache<K, V> cache;
/** Maximum memory idle time for the whole cache */
private final long maxMemoryIdleTime;
@@ -61,7 +62,7 @@ public class ShrinkerThread
* <p>
* @param cache The MemoryCache which the new shrinker should watch.
*/
- public ShrinkerThread( MemoryCache cache )
+ public ShrinkerThread( IMemoryCache<K, V> cache )
{
super();
@@ -95,7 +96,7 @@ public class ShrinkerThread
}
/**
- * This method is called when the thread wakes up. Frist the method obtains an array of keys for
+ * This method is called when the thread wakes up. First the method obtains an array of keys for
* the cache region. It iterates through the keys and tries to get the item from the cache
* without affecting the last access or position of the item. The item is checked for
* expiration, the expiration check has 3 parts:
@@ -103,7 +104,7 @@ public class ShrinkerThread
* <li>Has the cacheattributes.MaxMemoryIdleTimeSeconds defined for the region been exceeded? If
* so, the item should be move to disk.</li> <li>Has the item exceeded MaxLifeSeconds defined in
* the element attributes? If so, remove it.</li> <li>Has the item exceeded IdleTime defined in
- * the element atributes? If so, remove it. If there are event listeners registered for the
+ * the element attributes? If so, remove it. If there are event listeners registered for the
* cache element, they will be called.</li>
* </ol>
* @todo Change element event handling to use the queue, then move the queue to the region and
@@ -121,22 +122,20 @@ public class ShrinkerThread
try
{
- Object[] keys = cache.getKeyArray();
- int size = keys.length;
+ Set<K> keys = cache.getKeySet();
+ int size = keys.size();
if ( log.isDebugEnabled() )
{
log.debug( "Keys size: " + size );
}
- Serializable key;
- ICacheElement cacheElement;
+ ICacheElement<K, V> cacheElement;
IElementAttributes attributes;
int spoolCount = 0;
- for ( int i = 0; i < size; i++ )
+ for (K key : keys)
{
- key = (Serializable) keys[i];
cacheElement = cache.getQuiet( key );
if ( cacheElement == null )
@@ -233,7 +232,7 @@ public class ShrinkerThread
* @return true if the element should be removed, or false.
* @throws IOException
*/
- protected boolean checkForRemoval( ICacheElement cacheElement, long now )
+ protected boolean checkForRemoval( ICacheElement<?, ?> cacheElement, long now )
throws IOException
{
IElementAttributes attributes = cacheElement.getElementAttributes();
@@ -280,7 +279,7 @@ public class ShrinkerThread
* @param eventType Type of event to handle
* @throws IOException If an error occurs
*/
- private void handleElementEvents( ICacheElement cacheElement, int eventType )
+ private void handleElementEvents( ICacheElement<?, ?> cacheElement, int eventType )
throws IOException
{
IElementAttributes attributes = cacheElement.getElementAttributes();
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/memory/util/MemoryElementDescriptor.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/memory/util/MemoryElementDescriptor.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/memory/util/MemoryElementDescriptor.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/memory/util/MemoryElementDescriptor.java Wed May 30 18:14:43 2012
@@ -19,27 +19,29 @@ package org.apache.jcs.engine.memory.uti
* under the License.
*/
+import java.io.Serializable;
+
import org.apache.jcs.engine.behavior.ICacheElement;
import org.apache.jcs.utils.struct.DoubleLinkedListNode;
/**
* This wrapper is needed for double linked lists.
*/
-public class MemoryElementDescriptor
- extends DoubleLinkedListNode<ICacheElement>
+public class MemoryElementDescriptor<K extends Serializable, V extends Serializable>
+ extends DoubleLinkedListNode<ICacheElement<K, V>>
{
/** Don't change */
private static final long serialVersionUID = -1905161209035522460L;
/** The CacheElement wrapped by this descriptor */
- public ICacheElement ce;
+ public ICacheElement<K, V> ce;
/**
* Constructs a usable MemoryElementDescriptor.
* <p>
* @param ce
*/
- public MemoryElementDescriptor( ICacheElement ce )
+ public MemoryElementDescriptor( ICacheElement<K, V> ce )
{
super( ce );
this.ce = ce;
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/access/JCSWorker.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/access/JCSWorker.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/access/JCSWorker.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/access/JCSWorker.java Wed May 30 18:14:43 2012
@@ -35,9 +35,9 @@ import org.apache.jcs.access.exception.C
* org.apache.jcs.utils.access.AbstractJCSWorkerHelper and implement Object
* doWork() and do the work in there, returning the object to be cached. Then
* call .getResult() with the key and the AbstractJCSWorkerHelper to get the
- * result of the work. If the object isn't allready in the Cache,
+ * result of the work. If the object isn't already in the Cache,
* AbstractJCSWorkerHelper.doWork() will get called, and the result will be put
- * into the cache. If the object is allready in cache, the cached result will be
+ * into the cache. If the object is already in cache, the cached result will be
* returned instead.
* <p>
* As an added bonus, multiple JCSWorkers with the same region, and key won't do
@@ -90,13 +90,13 @@ import org.apache.jcs.access.exception.C
* <p>
* @author Travis Savo
*/
-public class JCSWorker
+public class JCSWorker<K extends Serializable, V extends Serializable>
{
/** The logger */
private static final Log logger = LogFactory.getLog( JCSWorker.class );
/** The cache we are working with */
- private JCS cache;
+ private JCS<K, V> cache;
/**
* Map to hold who's doing work presently.
@@ -139,7 +139,7 @@ public class JCSWorker
* Gets the cached result for this region/key OR does the work and caches
* the result, returning the result. If the result has not been cached yet,
* this calls doWork() on the JCSWorkerHelper to do the work and cache the
- * result. This is also an opertunity to do any post processing of the
+ * result. This is also an opportunity to do any post processing of the
* result in your CachedWorker implementation.
* @param aKey
* The key to get/put with on the Cache.
@@ -152,7 +152,7 @@ public class JCSWorker
* Throws an exception if anything goes wrong while doing the
* work.
*/
- public Object getResult( Serializable aKey, JCSWorkerHelper aWorker )
+ public V getResult( K aKey, JCSWorkerHelper aWorker )
throws Exception
{
return run( aKey, null, aWorker );
@@ -177,7 +177,7 @@ public class JCSWorker
* Throws an exception if anything goes wrong while doing the
* work.
*/
- public Object getResult( Serializable aKey, String aGroup, JCSWorkerHelper aWorker )
+ public V getResult( K aKey, String aGroup, JCSWorkerHelper aWorker )
throws Exception
{
return run( aKey, aGroup, aWorker );
@@ -197,17 +197,17 @@ public class JCSWorker
* If something goes wrong while doing the work, throw an
* exception.
*/
- private Object run( Serializable aKey, String aGroup, JCSWorkerHelper aHelper )
+ private V run( K aKey, String aGroup, JCSWorkerHelper aHelper )
throws Exception
{
- Serializable result = null;
+ V result = null;
// long start = 0;
// long dbTime = 0;
JCSWorkerHelper helper = null;
synchronized ( map )
{
- // Check to see if we allready have a thread doing this work.
+ // Check to see if we already have a thread doing this work.
helper = map.get( getRegion() + aKey );
if ( helper == null )
{
@@ -255,7 +255,7 @@ public class JCSWorker
// If the cache dosn't have it, do the work.
if ( result == null )
{
- result = (Serializable)aHelper.doWork();
+ result = (V)aHelper.doWork();
if ( logger.isDebugEnabled() )
{
logger.debug( "Work Done, caching: key:" + aKey + ", group:" + aGroup + ", result:" + result + "." );
Propchange: commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/config/OptionConverter.java
('svn:mergeinfo' removed)
Propchange: commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/config/PropertySetter.java
('svn:mergeinfo' removed)
Propchange: commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/config/PropertySetterException.java
('svn:mergeinfo' removed)
Propchange: commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/config/package.html
('svn:mergeinfo' removed)
Propchange: commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/discovery/UDPDiscoveryManager.java
('svn:mergeinfo' removed)
Propchange: commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/discovery/UDPDiscoveryMessage.java
('svn:mergeinfo' removed)
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/discovery/UDPDiscoveryReceiver.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/discovery/UDPDiscoveryReceiver.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/discovery/UDPDiscoveryReceiver.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/discovery/UDPDiscoveryReceiver.java Wed May 30 18:14:43 2012
@@ -166,9 +166,18 @@ public class UDPDiscoveryReceiver
final ObjectInputStream objectStream = new ObjectInputStream( byteStream );
obj = objectStream.readObject();
- if ( log.isDebugEnabled() )
+ if ( (obj != null) && (obj instanceof UDPDiscoveryMessage) )
{
- log.debug( "Read object from address [" + packet.getSocketAddress() + "], object=[" + obj + "]" );
+ // Ensure that the address we're supposed to send to is, indeed, the address
+ // of the machine on the other end of this connection. This guards against
+ // instances where we don't exactly get the right local host address
+ UDPDiscoveryMessage msg = (UDPDiscoveryMessage) obj;
+ msg.setHost(packet.getAddress().getHostAddress());
+
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( "Read object from address [" + packet.getSocketAddress() + "], object=[" + obj + "]" );
+ }
}
}
catch ( Exception e )
Propchange: commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/discovery/UDPDiscoveryReceiver.java
('svn:mergeinfo' removed)
Propchange: commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/discovery/UDPDiscoverySender.java
('svn:mergeinfo' removed)
Propchange: commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/discovery/UDPDiscoverySenderThread.java
('svn:mergeinfo' removed)
Propchange: commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/discovery/UDPDiscoveryService.java
('svn:mergeinfo' removed)
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/serialization/CompressingSerializer.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/serialization/CompressingSerializer.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/serialization/CompressingSerializer.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/serialization/CompressingSerializer.java Wed May 30 18:14:43 2012
@@ -37,13 +37,13 @@ public class CompressingSerializer
implements IElementSerializer
{
/**
- * Serializes an object using default serilaization. Compresses the byte array.
+ * Serializes an object using default serialization. Compresses the byte array.
* <p>
* @param obj object
* @return byte[]
* @throws IOException on i/o problem
*/
- public byte[] serialize( Serializable obj )
+ public <T extends Serializable> byte[] serialize( T obj )
throws IOException
{
byte[] uncompressed = serializeObject( obj );
@@ -58,7 +58,7 @@ public class CompressingSerializer
* @return byte[]
* @throws IOException on i/o problem
*/
- protected byte[] serializeObject( Serializable obj )
+ protected <T extends Serializable> byte[] serializeObject( T obj )
throws IOException
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -84,7 +84,7 @@ public class CompressingSerializer
* @throws IOException on i/o problem
* @throws ClassNotFoundException if class is not found during deserialization
*/
- public Object deSerialize( byte[] data )
+ public <T extends Serializable> T deSerialize( byte[] data )
throws IOException, ClassNotFoundException
{
if ( data == null )
@@ -103,7 +103,7 @@ public class CompressingSerializer
* @throws IOException on i/o error
* @throws ClassNotFoundException if class is not found during deserialization
*/
- protected Object deserializeObject( byte[] decompressedByteArray )
+ protected <T extends Serializable> T deserializeObject( byte[] decompressedByteArray )
throws IOException, ClassNotFoundException
{
ByteArrayInputStream bais = new ByteArrayInputStream( decompressedByteArray );
@@ -114,7 +114,7 @@ public class CompressingSerializer
{
try
{
- return ois.readObject();
+ return (T) ois.readObject();
}
catch ( IOException e )
{
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/serialization/SerializationConversionUtil.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/serialization/SerializationConversionUtil.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/serialization/SerializationConversionUtil.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/serialization/SerializationConversionUtil.java Wed May 30 18:14:43 2012
@@ -20,6 +20,7 @@ package org.apache.jcs.utils.serializati
*/
import java.io.IOException;
+import java.io.Serializable;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -49,7 +50,7 @@ public class SerializationConversionUtil
* @return null for null;
* @throws IOException
*/
- public static ICacheElementSerialized getSerializedCacheElement( ICacheElement element,
+ public static <K extends Serializable, V extends Serializable> ICacheElementSerialized<K, V> getSerializedCacheElement( ICacheElement<K, V> element,
IElementSerializer elementSerializer )
throws IOException
{
@@ -58,12 +59,12 @@ public class SerializationConversionUtil
return null;
}
- byte[] serialzedValue = null;
+ byte[] serializedValue = null;
// if it has already been serialized, don't do it again.
if ( element instanceof ICacheElementSerialized )
{
- serialzedValue = ( (ICacheElementSerialized) element ).getSerializedValue();
+ serializedValue = ( (ICacheElementSerialized<K, V>) element ).getSerializedValue();
}
else
{
@@ -71,7 +72,7 @@ public class SerializationConversionUtil
{
try
{
- serialzedValue = elementSerializer.serialize( element.getVal() );
+ serializedValue = elementSerializer.serialize( element.getVal() );
}
catch ( IOException e )
{
@@ -86,8 +87,8 @@ public class SerializationConversionUtil
throw new IOException( "Could not serialize object. The ElementSerializer is null." );
}
}
- ICacheElementSerialized serialized = new CacheElementSerialized( element.getCacheName(), element.getKey(),
- serialzedValue, element.getElementAttributes() );
+ ICacheElementSerialized<K, V> serialized = new CacheElementSerialized<K, V>(
+ element.getCacheName(), element.getKey(), serializedValue, element.getElementAttributes() );
return serialized;
}
@@ -103,7 +104,7 @@ public class SerializationConversionUtil
* @throws IOException
* @throws ClassNotFoundException
*/
- public static ICacheElement getDeSerializedCacheElement( ICacheElementSerialized serialized,
+ public static <K extends Serializable, V extends Serializable> ICacheElement<K, V> getDeSerializedCacheElement( ICacheElementSerialized<K, V> serialized,
IElementSerializer elementSerializer )
throws IOException, ClassNotFoundException
{
@@ -112,7 +113,7 @@ public class SerializationConversionUtil
return null;
}
- Object deSerialzedValue = null;
+ V deSerializedValue = null;
if ( elementSerializer != null )
{
@@ -120,7 +121,7 @@ public class SerializationConversionUtil
{
try
{
- deSerialzedValue = elementSerializer.deSerialize( serialized.getSerializedValue() );
+ deSerializedValue = elementSerializer.deSerialize( serialized.getSerializedValue() );
}
catch ( ClassNotFoundException e )
{
@@ -139,7 +140,7 @@ public class SerializationConversionUtil
// we could just use the default.
log.warn( "ElementSerializer is null. Could not serialize object." );
}
- ICacheElement deSerialized = new CacheElement( serialized.getCacheName(), serialized.getKey(), deSerialzedValue );
+ ICacheElement<K, V> deSerialized = new CacheElement<K, V>( serialized.getCacheName(), serialized.getKey(), deSerializedValue );
deSerialized.setElementAttributes( serialized.getElementAttributes() );
return deSerialized;
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/serialization/StandardSerializer.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/serialization/StandardSerializer.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/serialization/StandardSerializer.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/serialization/StandardSerializer.java Wed May 30 18:14:43 2012
@@ -40,14 +40,14 @@ public class StandardSerializer
/**
* Serializes an object using default serialization.
* <p>
- * @param obj
+ * @param obj
* @return byte[]
- * @throws IOException
+ * @throws IOException
*/
- public byte[] serialize( Serializable obj )
+ public <T extends Serializable> byte[] serialize( T obj )
throws IOException
{
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream( baos );
try
{
@@ -69,7 +69,7 @@ public class StandardSerializer
* @throws IOException
* @throws ClassNotFoundException
*/
- public Object deSerialize( byte[] data )
+ public <T extends Serializable> T deSerialize( byte[] data )
throws IOException, ClassNotFoundException
{
ByteArrayInputStream bais = new ByteArrayInputStream( data );
@@ -79,7 +79,7 @@ public class StandardSerializer
{
try
{
- return ois.readObject();
+ return (T) ois.readObject();
}
catch ( IOException e )
{
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/struct/LRUMap.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/struct/LRUMap.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/struct/LRUMap.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/struct/LRUMap.java Wed May 30 18:14:43 2012
@@ -455,7 +455,7 @@ public class LRUMap<K, V>
log.error( "key toString=" + key.toString() );
if ( key instanceof GroupAttrName )
{
- GroupAttrName name = (GroupAttrName) key;
+ GroupAttrName<?> name = (GroupAttrName<?>) key;
log.error( "GroupID hashcode=" + name.groupId.hashCode() );
log.error( "GroupID.class=" + name.groupId.getClass() );
log.error( "AttrName hashcode=" + name.attrName.hashCode() );
Modified: commons/proper/jcs/trunk/src/test/org/apache/jcs/JCSCacheElementRetrievalUnitTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/test/org/apache/jcs/JCSCacheElementRetrievalUnitTest.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/test/org/apache/jcs/JCSCacheElementRetrievalUnitTest.java (original)
+++ commons/proper/jcs/trunk/src/test/org/apache/jcs/JCSCacheElementRetrievalUnitTest.java Wed May 30 18:14:43 2012
@@ -38,12 +38,12 @@ public class JCSCacheElementRetrievalUni
public void testSimpleElementRetrieval()
throws Exception
{
- JCS jcs = JCS.getInstance( "testCache1" );
+ JCS<String, String> jcs = JCS.getInstance( "testCache1" );
jcs.put( "test_key", "test_data" );
long now = System.currentTimeMillis();
- ICacheElement elem = jcs.getCacheElement( "test_key" );
+ ICacheElement<String, String> elem = jcs.getCacheElement( "test_key" );
assertEquals( "Name wasn't right", "testCache1", elem.getCacheName() );
long diff = now - elem.getElementAttributes().getCreateTime();
Modified: commons/proper/jcs/trunk/src/test/org/apache/jcs/JCSLightLoadUnitTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/test/org/apache/jcs/JCSLightLoadUnitTest.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/test/org/apache/jcs/JCSLightLoadUnitTest.java (original)
+++ commons/proper/jcs/trunk/src/test/org/apache/jcs/JCSLightLoadUnitTest.java Wed May 30 18:14:43 2012
@@ -78,7 +78,7 @@ public class JCSLightLoadUnitTest
public void testSimpleLoad()
throws Exception
{
- JCS jcs = JCS.getInstance( "testCache1" );
+ JCS<String, String> jcs = JCS.getInstance( "testCache1" );
// ICompositeCacheAttributes cattr = jcs.getCacheAttributes();
// cattr.setMaxObjects( 20002 );
// jcs.setCacheAttributes( cattr );
Modified: commons/proper/jcs/trunk/src/test/org/apache/jcs/JCSRemovalSimpleConcurrentTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/test/org/apache/jcs/JCSRemovalSimpleConcurrentTest.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/test/org/apache/jcs/JCSRemovalSimpleConcurrentTest.java (original)
+++ commons/proper/jcs/trunk/src/test/org/apache/jcs/JCSRemovalSimpleConcurrentTest.java Wed May 30 18:14:43 2012
@@ -71,7 +71,7 @@ public class JCSRemovalSimpleConcurrentT
System.out.println( "testTwoDeepRemoval" );
int count = 500;
- JCS jcs = JCS.getInstance( "testCache1" );
+ JCS<String, String> jcs = JCS.getInstance( "testCache1" );
for ( int i = 0; i <= count; i++ )
{
@@ -109,7 +109,7 @@ public class JCSRemovalSimpleConcurrentT
System.out.println( "testSingleDepthRemoval" );
int count = 500;
- JCS jcs = JCS.getInstance( "testCache1" );
+ JCS<String, String> jcs = JCS.getInstance( "testCache1" );
for ( int i = 0; i <= count; i++ )
{
@@ -147,7 +147,7 @@ public class JCSRemovalSimpleConcurrentT
System.out.println( "testRemoveAll" );
int count = 500;
- JCS jcs = JCS.getInstance( "testCache1" );
+ JCS<String, String> jcs = JCS.getInstance( "testCache1" );
for ( int i = 0; i <= count; i++ )
{
@@ -190,7 +190,7 @@ public class JCSRemovalSimpleConcurrentT
System.out.println( "testRemoveAll" );
int count = 500;
- JCS jcs = JCS.getInstance( "testCache1" );
+ JCS<String, String> jcs = JCS.getInstance( "testCache1" );
jcs.clear();
Modified: commons/proper/jcs/trunk/src/test/org/apache/jcs/JCSThrashTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/test/org/apache/jcs/JCSThrashTest.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/test/org/apache/jcs/JCSThrashTest.java (original)
+++ commons/proper/jcs/trunk/src/test/org/apache/jcs/JCSThrashTest.java Wed May 30 18:14:43 2012
@@ -19,6 +19,7 @@ package org.apache.jcs;
* under the License.
*/
+import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
@@ -43,7 +44,7 @@ public class JCSThrashTest
/**
* the cache instance
*/
- protected JCS jcs;
+ protected JCS<String, Serializable> jcs;
/**
* @param args
Modified: commons/proper/jcs/trunk/src/test/org/apache/jcs/JCSUnitTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/test/org/apache/jcs/JCSUnitTest.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/test/org/apache/jcs/JCSUnitTest.java (original)
+++ commons/proper/jcs/trunk/src/test/org/apache/jcs/JCSUnitTest.java Wed May 30 18:14:43 2012
@@ -67,7 +67,7 @@ public class JCSUnitTest
public void testJCS()
throws Exception
{
- JCS jcs = JCS.getInstance( "testCache1" );
+ JCS<String, LinkedList<HashMap<String, String>>> jcs = JCS.getInstance( "testCache1" );
LinkedList<HashMap<String, String>> list = buildList();
Propchange: commons/proper/jcs/trunk/src/test/org/apache/jcs/JCSUnitTest.java
('svn:mergeinfo' removed)
Modified: commons/proper/jcs/trunk/src/test/org/apache/jcs/JCSvsHashtablePerformanceTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/test/org/apache/jcs/JCSvsHashtablePerformanceTest.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/test/org/apache/jcs/JCSvsHashtablePerformanceTest.java (original)
+++ commons/proper/jcs/trunk/src/test/org/apache/jcs/JCSvsHashtablePerformanceTest.java Wed May 30 18:14:43 2012
@@ -114,7 +114,7 @@ public class JCSvsHashtablePerformanceTe
{
JCS.setConfigFilename( "/TestJCSvHashtablePerf.ccf" );
- JCS cache = JCS.getInstance( "testCache1" );
+ JCS<String, String> cache = JCS.getInstance( "testCache1" );
for ( int j = 0; j < loops; j++ )
{
@@ -144,7 +144,7 @@ public class JCSvsHashtablePerformanceTe
// /////////////////////////////////////////////////////////////
name = "Hashtable";
- Hashtable cache2 = new Hashtable();
+ Hashtable<String, String> cache2 = new Hashtable<String, String>();
start = System.currentTimeMillis();
for ( int i = 0; i < tries; i++ )
{
Modified: commons/proper/jcs/trunk/src/test/org/apache/jcs/RemovalTestUtil.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/test/org/apache/jcs/RemovalTestUtil.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/test/org/apache/jcs/RemovalTestUtil.java (original)
+++ commons/proper/jcs/trunk/src/test/org/apache/jcs/RemovalTestUtil.java Wed May 30 18:14:43 2012
@@ -53,7 +53,7 @@ public class RemovalTestUtil
public void runTestPutThenRemoveCategorical( int start, int end )
throws Exception
{
- JCS jcs = JCS.getInstance( "testCache1" );
+ JCS<String, String> jcs = JCS.getInstance( "testCache1" );
for ( int i = start; i <= end; i++ )
{
@@ -91,7 +91,7 @@ public class RemovalTestUtil
public void runPutInRange( int start, int end )
throws Exception
{
- JCS jcs = JCS.getInstance( "testCache1" );
+ JCS<String, String> jcs = JCS.getInstance( "testCache1" );
for ( int i = start; i <= end; i++ )
{
@@ -119,7 +119,7 @@ public class RemovalTestUtil
public void runGetInRange( int start, int end, boolean check )
throws Exception
{
- JCS jcs = JCS.getInstance( "testCache1" );
+ JCS<String, String> jcs = JCS.getInstance( "testCache1" );
// don't care if they are found
for ( int i = end; i >= start; i-- )
Modified: commons/proper/jcs/trunk/src/test/org/apache/jcs/TestTCPLateralCache.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/test/org/apache/jcs/TestTCPLateralCache.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/test/org/apache/jcs/TestTCPLateralCache.java (original)
+++ commons/proper/jcs/trunk/src/test/org/apache/jcs/TestTCPLateralCache.java Wed May 30 18:14:43 2012
@@ -117,7 +117,7 @@ public class TestTCPLateralCache
public void runTestForRegion( String region )
throws Exception
{
- JCS jcs = JCS.getInstance( region );
+ JCS<String, String> jcs = JCS.getInstance( region );
// Add items to cache
Modified: commons/proper/jcs/trunk/src/test/org/apache/jcs/ZeroSizeCacheUnitTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/test/org/apache/jcs/ZeroSizeCacheUnitTest.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/test/org/apache/jcs/ZeroSizeCacheUnitTest.java (original)
+++ commons/proper/jcs/trunk/src/test/org/apache/jcs/ZeroSizeCacheUnitTest.java Wed May 30 18:14:43 2012
@@ -54,7 +54,7 @@ public class ZeroSizeCacheUnitTest
public void testPutGetRemove()
throws Exception
{
- JCS jcs = JCS.getInstance( "testCache1" );
+ JCS<String, String> jcs = JCS.getInstance( "testCache1" );
for ( int i = 0; i <= items; i++ )
{
Modified: commons/proper/jcs/trunk/src/test/org/apache/jcs/access/CacheAccessUnitTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/test/org/apache/jcs/access/CacheAccessUnitTest.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/test/org/apache/jcs/access/CacheAccessUnitTest.java (original)
+++ commons/proper/jcs/trunk/src/test/org/apache/jcs/access/CacheAccessUnitTest.java Wed May 30 18:14:43 2012
@@ -49,7 +49,7 @@ public class CacheAccessUnitTest
public void testPutSafe()
throws Exception
{
- CacheAccess access = CacheAccess.getAccess( "test" );
+ CacheAccess<String, String> access = CacheAccess.getAccess( "test" );
assertNotNull( "We should have an access class", access );
String key = "mykey";
@@ -57,7 +57,7 @@ public class CacheAccessUnitTest
access.put( key, value );
- String returnedValue1 = (String) access.get( key );
+ String returnedValue1 = access.get( key );
assertEquals( "Wrong value returned.", value, returnedValue1 );
try
@@ -71,7 +71,7 @@ public class CacheAccessUnitTest
assertTrue( "Should have the key in the error message.", e.getMessage().indexOf( "[" + key + "]" ) != -1 );
}
- String returnedValue2 = (String) access.get( key );
+ String returnedValue2 = access.get( key );
assertEquals( "Wrong value returned. Shoudl still be the original.", value, returnedValue2 );
}
@@ -82,7 +82,7 @@ public class CacheAccessUnitTest
public void testPutNullKey()
throws Exception
{
- CacheAccess access = CacheAccess.getAccess( "test" );
+ CacheAccess<String, String> access = CacheAccess.getAccess( "test" );
assertNotNull( "We should have an access class", access );
String key = null;
@@ -106,7 +106,7 @@ public class CacheAccessUnitTest
public void testPutNullValue()
throws Exception
{
- CacheAccess access = CacheAccess.getAccess( "test" );
+ CacheAccess<String, String> access = CacheAccess.getAccess( "test" );
assertNotNull( "We should have an access class", access );
String key = "myKey";
@@ -124,13 +124,13 @@ public class CacheAccessUnitTest
}
/**
- * Verify that elements that go in the region after this call takethe new attributes.
+ * Verify that elements that go in the region after this call take the new attributes.
* @throws Exception
*/
public void testSetDefaultElementAttributes()
throws Exception
{
- CacheAccess access = CacheAccess.getAccess( "test" );
+ CacheAccess<String, String> access = CacheAccess.getAccess( "test" );
assertNotNull( "We should have an access class", access );
long maxLife = 9876;
@@ -147,7 +147,7 @@ public class CacheAccessUnitTest
access.put( key, value );
- ICacheElement element = access.getCacheElement( key );
+ ICacheElement<String, String> element = access.getCacheElement( key );
assertEquals( "Wrong max life. Should have the new value.", maxLife, element.getElementAttributes()
.getMaxLifeSeconds() );
@@ -161,7 +161,7 @@ public class CacheAccessUnitTest
throws Exception
{
//SETUP
- CacheAccess access = CacheAccess.getAccess( "test" );
+ CacheAccess<String, String> access = CacheAccess.getAccess( "test" );
assertNotNull( "We should have an access class", access );
String keyOne = "mykeyone";
@@ -175,19 +175,19 @@ public class CacheAccessUnitTest
access.put( keyTwo, valueTwo );
access.put( keyThree, valueThree );
- Set input = new HashSet();
+ Set<String> input = new HashSet<String>();
input.add( keyOne );
input.add( keyTwo );
//DO WORK
- Map result = access.getCacheElements( input );
+ Map<String, ICacheElement<String, String>> result = access.getCacheElements( input );
//VERIFY
assertEquals( "map size", 2, result.size() );
- ICacheElement elementOne = (ICacheElement) result.get( keyOne );
+ ICacheElement<String, String> elementOne = result.get( keyOne );
assertEquals( "value one", keyOne, elementOne.getKey() );
assertEquals( "value one", valueOne, elementOne.getVal() );
- ICacheElement elementTwo = (ICacheElement) result.get( keyTwo );
+ ICacheElement<String, String> elementTwo = result.get( keyTwo );
assertEquals( "value two", keyTwo, elementTwo.getKey() );
assertEquals( "value two", valueTwo, elementTwo.getVal() );
}
@@ -199,7 +199,7 @@ public class CacheAccessUnitTest
public void testRegionDefiniton()
throws Exception
{
- CacheAccess access = CacheAccess.defineRegion( "test" );
+ CacheAccess<String, String> access = CacheAccess.defineRegion( "test" );
assertNotNull( "We should have an access class", access );
}
@@ -215,7 +215,7 @@ public class CacheAccessUnitTest
long maxIdleTime = 8765;
ca.setMaxMemoryIdleTimeSeconds( maxIdleTime );
- CacheAccess access = CacheAccess.defineRegion( "testRegionDefinitonWithAttributes", ca );
+ CacheAccess<String, String> access = CacheAccess.defineRegion( "testRegionDefinitonWithAttributes", ca );
assertNotNull( "We should have an access class", access );
ICompositeCacheAttributes ca2 = access.getCacheAttributes();
@@ -239,7 +239,7 @@ public class CacheAccessUnitTest
IElementAttributes attr = new ElementAttributes();
attr.setMaxLifeSeconds( maxLife );
- CacheAccess access = CacheAccess.defineRegion( "testRegionDefinitonWithAttributes", ca, attr );
+ CacheAccess<String, String> access = CacheAccess.defineRegion( "testRegionDefinitonWithAttributes", ca, attr );
assertNotNull( "We should have an access class", access );
ICompositeCacheAttributes ca2 = access.getCacheAttributes();
@@ -267,7 +267,7 @@ public class CacheAccessUnitTest
IElementAttributes attr = new ElementAttributes();
attr.setMaxLifeSeconds( maxLife );
- CacheAccess access = CacheAccess.defineRegion( "testGetMatching_Normal", cattr, attr );
+ CacheAccess<String, Integer> access = CacheAccess.defineRegion( "testGetMatching_Normal", cattr, attr );
// DO WORK
int numToInsertPrefix1 = 10;
@@ -284,17 +284,17 @@ public class CacheAccessUnitTest
access.put( keyprefix2 + String.valueOf( i ), Integer.valueOf( i ) );
}
- Map result1 = access.getMatching( keyprefix1 + ".+" );
- Map result2 = access.getMatching( keyprefix2 + "\\S+" );
+ Map<String, Integer> result1 = access.getMatching( keyprefix1 + ".+" );
+ Map<String, Integer> result2 = access.getMatching( keyprefix2 + "\\S+" );
// VERIFY
assertEquals( "Wrong number returned 1:", numToInsertPrefix1, result1.size() );
assertEquals( "Wrong number returned 2:", numToInsertPrefix2, result2.size() );
//System.out.println( result1 );
-
+
// verify that the elements are unwrapped
- Set keySet1 = result1.keySet();
- Iterator it1 = keySet1.iterator();
+ Set<String> keySet1 = result1.keySet();
+ Iterator<String> it1 = keySet1.iterator();
while ( it1.hasNext() )
{
Object key = it1.next();
@@ -302,7 +302,7 @@ public class CacheAccessUnitTest
assertFalse( "Should not be a cache element.", value instanceof ICacheElement );
}
}
-
+
/**
* Verify we can get some matching elements..
* <p>
@@ -324,7 +324,7 @@ public class CacheAccessUnitTest
IElementAttributes attr = new ElementAttributes();
attr.setMaxLifeSeconds( maxLife );
- CacheAccess access = CacheAccess.defineRegion( "testGetMatching_Normal", cattr, attr );
+ CacheAccess<String, Integer> access = CacheAccess.defineRegion( "testGetMatching_Normal", cattr, attr );
// DO WORK
int numToInsertPrefix1 = 10;
@@ -341,22 +341,22 @@ public class CacheAccessUnitTest
access.put( keyprefix2 + String.valueOf( i ), Integer.valueOf( i ) );
}
- Map result1 = access.getMatchingCacheElements( keyprefix1 + "\\S+" );
- Map result2 = access.getMatchingCacheElements( keyprefix2 + ".+" );
+ Map<String, ICacheElement<String, Integer>> result1 = access.getMatchingCacheElements( keyprefix1 + "\\S+" );
+ Map<String, ICacheElement<String, Integer>> result2 = access.getMatchingCacheElements( keyprefix2 + ".+" );
// VERIFY
assertEquals( "Wrong number returned 1:", numToInsertPrefix1, result1.size() );
assertEquals( "Wrong number returned 2:", numToInsertPrefix2, result2.size() );
//System.out.println( result1 );
-
+
// verify that the elements are wrapped
- Set keySet1 = result1.keySet();
- Iterator it1 = keySet1.iterator();
+ Set<String> keySet1 = result1.keySet();
+ Iterator<String> it1 = keySet1.iterator();
while ( it1.hasNext() )
{
Object key = it1.next();
Object value = result1.get( key );
assertTrue( "Should be a cache element.", value instanceof ICacheElement );
- }
+ }
}
}
Modified: commons/proper/jcs/trunk/src/test/org/apache/jcs/access/SystemPropetyUnitTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/test/org/apache/jcs/access/SystemPropetyUnitTest.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/test/org/apache/jcs/access/SystemPropetyUnitTest.java (original)
+++ commons/proper/jcs/trunk/src/test/org/apache/jcs/access/SystemPropetyUnitTest.java Wed May 30 18:14:43 2012
@@ -50,7 +50,7 @@ public class SystemPropetyUnitTest
JCS.setConfigFilename( "/TestSystemProperties.ccf" );
- JCS cache = JCS.getInstance( "test1" );
+ JCS<String, String> cache = JCS.getInstance( "test1" );
assertEquals( "We should have used the system property for the memory size", maxMemory, cache
.getCacheAttributes().getMaxObjects() );
@@ -72,7 +72,7 @@ public class SystemPropetyUnitTest
CompositeCacheManager mgr = CompositeCacheManager.getUnconfiguredInstance();
mgr.configure( "/TestSystemProperties.ccf" );
- JCS cache = JCS.getInstance( "missing" );
+ JCS<String, String> cache = JCS.getInstance( "missing" );
// TODO check against the actual default def
assertEquals( "We should have used the default property for the memory size", 100, cache.getCacheAttributes()
.getMaxObjects() );
Modified: commons/proper/jcs/trunk/src/test/org/apache/jcs/access/TestCacheAccess.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/test/org/apache/jcs/access/TestCacheAccess.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/test/org/apache/jcs/access/TestCacheAccess.java (original)
+++ commons/proper/jcs/trunk/src/test/org/apache/jcs/access/TestCacheAccess.java Wed May 30 18:14:43 2012
@@ -46,7 +46,7 @@ public class TestCacheAccess
private final static Log log = LogFactory.getLog( TestCacheAccess.class );
/** cache instance to use in testing */
- private JCS cache_control = null;
+ private JCS<String, String> cache_control = null;
/** do we use system.out.println to print out debug data? */
private static boolean isSysOut = false;
@@ -696,7 +696,7 @@ public class TestCacheAccess
long n_start = System.currentTimeMillis();
try
{
- Map results = cache_control.getMatching( pattern );
+ Map<String, String> results = cache_control.getMatching( pattern );
if ( show && results != null )
{
p( results.toString() );
@@ -951,11 +951,11 @@ public class TestCacheAccess
*/
public void getAttributeNames( String groupName )
{
- Iterator iter = cache_control.getGroupKeys( groupName ).iterator();
+ Iterator<String> iter = cache_control.getGroupKeys( groupName ).iterator();
while ( iter.hasNext() )
{
- p( "=" + (String) iter.next() );
+ p( "=" + iter.next() );
}
}
}
Modified: commons/proper/jcs/trunk/src/test/org/apache/jcs/admin/AdminBeanUnitTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/test/org/apache/jcs/admin/AdminBeanUnitTest.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/test/org/apache/jcs/admin/AdminBeanUnitTest.java (original)
+++ commons/proper/jcs/trunk/src/test/org/apache/jcs/admin/AdminBeanUnitTest.java Wed May 30 18:14:43 2012
@@ -19,7 +19,6 @@ package org.apache.jcs.admin;
* under the License.
*/
-import java.util.Iterator;
import java.util.List;
import junit.framework.TestCase;
@@ -46,20 +45,18 @@ public class AdminBeanUnitTest
throws Exception
{
String regionName = "myRegion";
- JCS cache = JCS.getInstance( regionName );
+ JCS<String, String> cache = JCS.getInstance( regionName );
cache.put( "key", "value" );
JCSAdminBean admin = new JCSAdminBean();
- List regions = admin.buildCacheInfo();
+ List<CacheRegionInfo> regions = admin.buildCacheInfo();
boolean foundRegion = false;
- Iterator it = regions.iterator();
- while ( it.hasNext() )
+ for (CacheRegionInfo info : regions)
{
- CacheRegionInfo info = (CacheRegionInfo) it.next();
System.out.println( info );
if ( info.getCache().getCacheName().equals( regionName ) )
@@ -84,7 +81,7 @@ public class AdminBeanUnitTest
throws Exception
{
String regionName = "myRegion";
- JCS cache = JCS.getInstance( regionName );
+ JCS<String, String> cache = JCS.getInstance( regionName );
// clear the region
cache.clear();
@@ -94,11 +91,11 @@ public class AdminBeanUnitTest
JCSAdminBean admin = new JCSAdminBean();
- List elements = admin.buildElementInfo( regionName );
+ List<CacheElementInfo> elements = admin.buildElementInfo( regionName );
assertEquals( "Wrong number of elements in the region.", 1, elements.size() );
- CacheElementInfo elementInfo = (CacheElementInfo) elements.get( 0 );
+ CacheElementInfo elementInfo = elements.get( 0 );
System.out.println( elementInfo );
assertEquals( "Wrong key.", key, elementInfo.getKey() );
}
@@ -114,7 +111,7 @@ public class AdminBeanUnitTest
JCSAdminBean admin = new JCSAdminBean();
String regionName = "myRegion";
- JCS cache = JCS.getInstance( regionName );
+ JCS<String, String> cache = JCS.getInstance( regionName );
// clear the region
cache.clear();
@@ -123,17 +120,17 @@ public class AdminBeanUnitTest
String key = "myKey";
cache.put( key, "value" );
- List elements = admin.buildElementInfo( regionName );
+ List<CacheElementInfo> elements = admin.buildElementInfo( regionName );
assertEquals( "Wrong number of elements in the region.", 1, elements.size() );
- CacheElementInfo elementInfo = (CacheElementInfo) elements.get( 0 );
+ CacheElementInfo elementInfo = elements.get( 0 );
assertEquals( "Wrong key.", key, elementInfo.getKey() );
admin.removeItem( regionName, key );
- List elements2 = admin.buildElementInfo( regionName );
+ List<CacheElementInfo> elements2 = admin.buildElementInfo( regionName );
assertEquals( "Wrong number of elements in the region after remove.", 0, elements2.size() );
}
@@ -148,14 +145,14 @@ public class AdminBeanUnitTest
JCSAdminBean admin = new JCSAdminBean();
String regionName = "myRegion";
- JCS cache = JCS.getInstance( regionName );
+ JCS<String, String> cache = JCS.getInstance( regionName );
String key = "myKey";
cache.put( key, "value" );
admin.clearAllRegions();
- List elements2 = admin.buildElementInfo( regionName );
+ List<CacheElementInfo> elements2 = admin.buildElementInfo( regionName );
assertEquals( "Wrong number of elements in the region after remove.", 0, elements2.size() );
}
}
Modified: commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/MockAuxiliaryCache.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/MockAuxiliaryCache.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/MockAuxiliaryCache.java (original)
+++ commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/MockAuxiliaryCache.java Wed May 30 18:14:43 2012
@@ -35,8 +35,8 @@ import org.apache.jcs.engine.stats.behav
* <p>
* @author Aaron Smuts
*/
-public class MockAuxiliaryCache
- extends AbstractAuxiliaryCache
+public class MockAuxiliaryCache<K extends Serializable, V extends Serializable>
+ extends AbstractAuxiliaryCache<K, V>
{
/** Don't change */
private static final long serialVersionUID = 1L;
@@ -54,7 +54,7 @@ public class MockAuxiliaryCache
* @param ce
* @throws IOException
*/
- public void update( ICacheElement ce )
+ public void update( ICacheElement<K, V> ce )
throws IOException
{
// TODO Auto-generated method stub
@@ -66,7 +66,7 @@ public class MockAuxiliaryCache
* @return ICacheElement
* @throws IOException
*/
- public ICacheElement get( Serializable key )
+ public ICacheElement<K, V> get( K key )
throws IOException
{
// TODO Auto-generated method stub
@@ -78,23 +78,23 @@ public class MockAuxiliaryCache
* @return Map
* @throws IOException
*/
- public Map<Serializable, ICacheElement> getMatching(String pattern)
+ public Map<K, ICacheElement<K, V>> getMatching(String pattern)
throws IOException
{
getMatchingCallCount++;
- return new HashMap<Serializable, ICacheElement>();
+ return new HashMap<K, ICacheElement<K, V>>();
}
/**
* Gets multiple items from the cache based on the given set of keys.
* <p>
* @param keys
- * @return a map of Serializable key to ICacheElement element, or an empty map if there is no
+ * @return a map of K key to ICacheElement<String, String> element, or an empty map if there is no
* data in cache for any of these keys
*/
- public Map<Serializable, ICacheElement> getMultiple(Set<Serializable> keys)
+ public Map<K, ICacheElement<K, V>> getMultiple(Set<K> keys)
{
- return new HashMap<Serializable, ICacheElement>();
+ return new HashMap<K, ICacheElement<K, V>>();
}
/**
@@ -102,7 +102,7 @@ public class MockAuxiliaryCache
* @return boolean
* @throws IOException
*/
- public boolean remove( Serializable key )
+ public boolean remove( K key )
throws IOException
{
// TODO Auto-generated method stub
@@ -159,7 +159,7 @@ public class MockAuxiliaryCache
* @return null
* @throws IOException
*/
- public Set<Serializable> getGroupKeys( String group )
+ public Set<K> getGroupKeys( String group )
throws IOException
{
return null;
Propchange: commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/MockAuxiliaryCache.java
('svn:mergeinfo' removed)
Modified: commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/MockAuxiliaryCacheFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/MockAuxiliaryCacheFactory.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/MockAuxiliaryCacheFactory.java (original)
+++ commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/MockAuxiliaryCacheFactory.java Wed May 30 18:14:43 2012
@@ -1,5 +1,7 @@
package org.apache.jcs.auxiliary;
+import java.io.Serializable;
+
import org.apache.jcs.engine.behavior.ICompositeCacheManager;
import org.apache.jcs.engine.behavior.IElementSerializer;
import org.apache.jcs.engine.logging.behavior.ICacheEventLogger;
@@ -20,10 +22,11 @@ public class MockAuxiliaryCacheFactory
* @param elementSerializer
* @return AuxiliaryCache
*/
- public AuxiliaryCache createCache( AuxiliaryCacheAttributes attr, ICompositeCacheManager cacheMgr,
- ICacheEventLogger cacheEventLogger, IElementSerializer elementSerializer )
+ public <K extends Serializable, V extends Serializable> AuxiliaryCache<K, V>
+ createCache( AuxiliaryCacheAttributes attr, ICompositeCacheManager cacheMgr,
+ ICacheEventLogger cacheEventLogger, IElementSerializer elementSerializer )
{
- MockAuxiliaryCache auxCache = new MockAuxiliaryCache();
+ MockAuxiliaryCache<K, V> auxCache = new MockAuxiliaryCache<K, V>();
auxCache.setCacheEventLogger( cacheEventLogger );
auxCache.setElementSerializer( elementSerializer );
return auxCache;
Modified: commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/MockCacheEventLogger.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/MockCacheEventLogger.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/MockCacheEventLogger.java (original)
+++ commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/MockCacheEventLogger.java Wed May 30 18:14:43 2012
@@ -4,7 +4,6 @@ import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
-import org.apache.jcs.engine.behavior.ICacheElement;
import org.apache.jcs.engine.logging.CacheEvent;
import org.apache.jcs.engine.logging.behavior.ICacheEvent;
import org.apache.jcs.engine.logging.behavior.ICacheEventLogger;
@@ -44,7 +43,7 @@ public class MockCacheEventLogger
/**
* @param cacheEvent
*/
- public void logICacheEvent( ICacheEvent cacheEvent )
+ public <T extends Serializable> void logICacheEvent( ICacheEvent<T> event )
{
endICacheEventCalls++;
}
@@ -68,25 +67,10 @@ public class MockCacheEventLogger
* @param key
* @return ICacheEvent
*/
- public ICacheEvent createICacheEvent( String source, String region, String eventName, String optionalDetails,
- Serializable key )
+ public <T extends Serializable> ICacheEvent<T> createICacheEvent( String source, String region,
+ String eventName, String optionalDetails, T key )
{
startICacheEventCalls++;
- return new CacheEvent();
- }
-
- /**
- * @param source
- * @param region
- * @param eventName
- * @param optionalDetails
- * @param item
- * @return ICacheEvent
- */
- public ICacheEvent createICacheEvent( String source, String region, String eventName, String optionalDetails,
- ICacheElement item )
- {
- startICacheEventCalls++;
- return new CacheEvent();
+ return new CacheEvent<T>();
}
}
Modified: commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/AbstractDiskCacheUnitTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/AbstractDiskCacheUnitTest.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/AbstractDiskCacheUnitTest.java (original)
+++ commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/AbstractDiskCacheUnitTest.java Wed May 30 18:14:43 2012
@@ -37,17 +37,17 @@ public class AbstractDiskCacheUnitTest
IDiskCacheAttributes diskCacheAttributes = new IndexedDiskCacheAttributes();
diskCacheAttributes.setCacheName( cacheName );
- AbstractDiskCacheTestInstance diskCache = new AbstractDiskCacheTestInstance( diskCacheAttributes );
+ AbstractDiskCacheTestInstance<String, String> diskCache = new AbstractDiskCacheTestInstance<String, String>( diskCacheAttributes );
String key = "myKey";
String value = "myValue";
IElementAttributes elementAttributes = new ElementAttributes();
- ICacheElement cacheElement = new CacheElement( cacheName, key, value, elementAttributes );
+ ICacheElement<String, String> cacheElement = new CacheElement<String, String>( cacheName, key, value, elementAttributes );
diskCache.update( cacheElement );
// DO WORK
- ICacheElement result = diskCache.get( key );
+ ICacheElement<String, String> result = diskCache.get( key );
// VERIFY
//System.out.println( diskCache.getStats() );
@@ -67,12 +67,12 @@ public class AbstractDiskCacheUnitTest
IDiskCacheAttributes diskCacheAttributes = new IndexedDiskCacheAttributes();
diskCacheAttributes.setCacheName( cacheName );
- AbstractDiskCacheTestInstance diskCache = new AbstractDiskCacheTestInstance( diskCacheAttributes );
+ AbstractDiskCacheTestInstance<String, String> diskCache = new AbstractDiskCacheTestInstance<String, String>( diskCacheAttributes );
String key = "myKey";
String value = "myValue";
IElementAttributes elementAttributes = new ElementAttributes();
- ICacheElement cacheElement = new CacheElement( cacheName, key, value, elementAttributes );
+ ICacheElement<String, String> cacheElement = new CacheElement<String, String>( cacheName, key, value, elementAttributes );
diskCache.update( cacheElement );
@@ -99,13 +99,13 @@ public class AbstractDiskCacheUnitTest
IDiskCacheAttributes diskCacheAttributes = new IndexedDiskCacheAttributes();
diskCacheAttributes.setAllowRemoveAll( false );
- AbstractDiskCacheTestInstance diskCache = new AbstractDiskCacheTestInstance( diskCacheAttributes );
+ AbstractDiskCacheTestInstance<String, String> diskCache = new AbstractDiskCacheTestInstance<String, String>( diskCacheAttributes );
String cacheName = "testRemoveAll_notAllowed";
String key = "myKey";
String value = "myValue";
IElementAttributes elementAttributes = new ElementAttributes();
- ICacheElement cacheElement = new CacheElement( cacheName, key, value, elementAttributes );
+ ICacheElement<String, String> cacheElement = new CacheElement<String, String>( cacheName, key, value, elementAttributes );
diskCache.update( cacheElement );
@@ -130,13 +130,13 @@ public class AbstractDiskCacheUnitTest
IDiskCacheAttributes diskCacheAttributes = new IndexedDiskCacheAttributes();
diskCacheAttributes.setAllowRemoveAll( true );
- AbstractDiskCacheTestInstance diskCache = new AbstractDiskCacheTestInstance( diskCacheAttributes );
+ AbstractDiskCacheTestInstance<String, String> diskCache = new AbstractDiskCacheTestInstance<String, String>( diskCacheAttributes );
String cacheName = "testRemoveAll_allowed";
String key = "myKey";
String value = "myValue";
IElementAttributes elementAttributes = new ElementAttributes();
- ICacheElement cacheElement = new CacheElement( cacheName, key, value, elementAttributes );
+ ICacheElement<String, String> cacheElement = new CacheElement<String, String>( cacheName, key, value, elementAttributes );
diskCache.update( cacheElement );
@@ -148,11 +148,11 @@ public class AbstractDiskCacheUnitTest
}
/** Concrete, testable instance. */
- protected static class AbstractDiskCacheTestInstance
- extends AbstractDiskCache
+ protected static class AbstractDiskCacheTestInstance<K extends Serializable, V extends Serializable>
+ extends AbstractDiskCache<K, V>
{
/** Internal map */
- protected Map<Serializable, ICacheElement> map = new HashMap<Serializable, ICacheElement>();
+ protected Map<K, ICacheElement<K, V>> map = new HashMap<K, ICacheElement<K, V>>();
/** used by the abstract aux class */
protected IDiskCacheAttributes diskCacheAttributes;
@@ -188,7 +188,7 @@ public class AbstractDiskCacheUnitTest
* @return Collections.EMPTY_SET
*/
@Override
- public Set<Serializable> getGroupKeys(String groupName)
+ public Set<K> getGroupKeys(String groupName)
{
return Collections.emptySet();
}
@@ -218,7 +218,7 @@ public class AbstractDiskCacheUnitTest
* @throws IOException
*/
@Override
- protected ICacheElement processGet( Serializable key )
+ protected ICacheElement<K, V> processGet( K key )
throws IOException
{
//System.out.println( "processGet: " + key );
@@ -231,7 +231,7 @@ public class AbstractDiskCacheUnitTest
* @throws IOException
*/
@Override
- protected Map<Serializable, ICacheElement> processGetMatching( String pattern )
+ protected Map<K, ICacheElement<K, V>> processGetMatching( String pattern )
throws IOException
{
return Collections.emptyMap();
@@ -243,7 +243,7 @@ public class AbstractDiskCacheUnitTest
* @throws IOException
*/
@Override
- protected boolean processRemove( Serializable key )
+ protected boolean processRemove( K key )
throws IOException
{
return map.remove( key ) != null;
@@ -265,7 +265,7 @@ public class AbstractDiskCacheUnitTest
* @throws IOException
*/
@Override
- protected void processUpdate( ICacheElement cacheElement )
+ protected void processUpdate( ICacheElement<K, V> cacheElement )
throws IOException
{
//System.out.println( "processUpdate: " + cacheElement );
Modified: commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/LRUMapJCSUnitTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/LRUMapJCSUnitTest.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/LRUMapJCSUnitTest.java (original)
+++ commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/LRUMapJCSUnitTest.java Wed May 30 18:14:43 2012
@@ -16,7 +16,7 @@ public class LRUMapJCSUnitTest
// SETUP
// DO WORK
- LRUMapJCS map = new LRUMapJCS();
+ LRUMapJCS<String, String> map = new LRUMapJCS<String, String>();
// VERIFY
assertEquals( "Should be unlimted", -1, map.getMaxObjects() );
@@ -29,7 +29,7 @@ public class LRUMapJCSUnitTest
int expected = 100;
// DO WORK
- LRUMapJCS map = new LRUMapJCS( expected );
+ LRUMapJCS<String, String> map = new LRUMapJCS<String, String>( expected );
// VERIFY
assertEquals( "Should be expected", expected, map.getMaxObjects() );
@@ -42,7 +42,7 @@ public class LRUMapJCSUnitTest
StringWriter stringWriter = new StringWriter();
TestLogConfigurationUtil.configureLogger( stringWriter, LRUMapJCS.class.getName() );
- LRUMapJCS map = new LRUMapJCS();
+ LRUMapJCS<String, String> map = new LRUMapJCS<String, String>();
String key = "myKey";
String value = "myValue";
Modified: commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/PurgatoryElementUnitTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/PurgatoryElementUnitTest.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/PurgatoryElementUnitTest.java (original)
+++ commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/PurgatoryElementUnitTest.java Wed May 30 18:14:43 2012
@@ -19,8 +19,8 @@ public class PurgatoryElementUnitTest
String key = "myKey";
String value = "myValue";
IElementAttributes elementAttributes = new ElementAttributes();
- ICacheElement cacheElement = new CacheElement( cacheName, key, value, elementAttributes );
- PurgatoryElement purgatoryElement = new PurgatoryElement( cacheElement );
+ ICacheElement<String, String> cacheElement = new CacheElement<String, String>( cacheName, key, value, elementAttributes );
+ PurgatoryElement<String, String> purgatoryElement = new PurgatoryElement<String, String>( cacheElement );
purgatoryElement.setSpoolable( false );
// DO WORK
@@ -39,8 +39,8 @@ public class PurgatoryElementUnitTest
String value = "myValue";
IElementAttributes elementAttributes = new ElementAttributes();
- ICacheElement cacheElement = new CacheElement( cacheName, key, value );
- PurgatoryElement purgatoryElement = new PurgatoryElement( cacheElement );
+ ICacheElement<String, String> cacheElement = new CacheElement<String, String>( cacheName, key, value );
+ PurgatoryElement<String, String> purgatoryElement = new PurgatoryElement<String, String>( cacheElement );
purgatoryElement.setElementAttributes( elementAttributes );
// DO WORK
@@ -58,8 +58,8 @@ public class PurgatoryElementUnitTest
String key = "myKey";
String value = "myValue";
IElementAttributes elementAttributes = new ElementAttributes();
- ICacheElement cacheElement = new CacheElement( cacheName, key, value, elementAttributes );
- PurgatoryElement purgatoryElement = new PurgatoryElement( cacheElement );
+ ICacheElement<String, String> cacheElement = new CacheElement<String, String>( cacheName, key, value, elementAttributes );
+ PurgatoryElement<String, String> purgatoryElement = new PurgatoryElement<String, String>( cacheElement );
// DO WORK
String result = purgatoryElement.toString();
Modified: commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/block/BlockDiskCacheConcurrentUnitTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/block/BlockDiskCacheConcurrentUnitTest.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/block/BlockDiskCacheConcurrentUnitTest.java (original)
+++ commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/block/BlockDiskCacheConcurrentUnitTest.java Wed May 30 18:14:43 2012
@@ -142,7 +142,7 @@ public class BlockDiskCacheConcurrentUni
public void runTestForRegion( String region )
throws Exception
{
- JCS jcs = JCS.getInstance( region );
+ JCS<String, String> jcs = JCS.getInstance( region );
// Add items to cache
for ( int i = 0; i <= items; i++ )
@@ -153,22 +153,22 @@ public class BlockDiskCacheConcurrentUni
// Test that all items are in cache
for ( int i = 0; i <= items; i++ )
{
- String value = (String) jcs.get( i + ":key" );
+ String value = jcs.get( i + ":key" );
assertEquals( region + " data " + i, value );
}
// Test that getElements returns all the expected values
- Set keys = new HashSet();
+ Set<String> keys = new HashSet<String>();
for ( int i = 0; i <= items; i++ )
{
keys.add( i + ":key" );
}
- Map elements = jcs.getCacheElements( keys );
+ Map<String, ICacheElement<String, String>> elements = jcs.getCacheElements( keys );
for ( int i = 0; i <= items; i++ )
{
- ICacheElement element = (ICacheElement) elements.get( i + ":key" );
+ ICacheElement<String, String> element = elements.get( i + ":key" );
assertNotNull( "element " + i + ":key is missing", element );
assertEquals( "value " + i + ":key", region + " data " + i, element.getVal() );
}
@@ -203,7 +203,7 @@ public class BlockDiskCacheConcurrentUni
public void runTestForRegionInRange( String region, int start, int end )
throws Exception
{
- JCS jcs = JCS.getInstance( region );
+ JCS<String, String> jcs = JCS.getInstance( region );
// Add items to cache
for ( int i = start; i <= end; i++ )
@@ -214,22 +214,22 @@ public class BlockDiskCacheConcurrentUni
// Test that all items are in cache
for ( int i = start; i <= end; i++ )
{
- String value = (String) jcs.get( i + ":key" );
+ String value = jcs.get( i + ":key" );
assertEquals( region + " data " + i, value );
}
// Test that getElements returns all the expected values
- Set keys = new HashSet();
+ Set<String> keys = new HashSet<String>();
for ( int i = start; i <= end; i++ )
{
keys.add( i + ":key" );
}
- Map elements = jcs.getCacheElements( keys );
+ Map<String, ICacheElement<String, String>> elements = jcs.getCacheElements( keys );
for ( int i = start; i <= end; i++ )
{
- ICacheElement element = (ICacheElement) elements.get( i + ":key" );
+ ICacheElement<String, String> element = elements.get( i + ":key" );
assertNotNull( "element " + i + ":key is missing", element );
assertEquals( "value " + i + ":key", region + " data " + i, element.getVal() );
}
Modified: commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/block/BlockDiskCacheKeyStoreUnitTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/block/BlockDiskCacheKeyStoreUnitTest.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/block/BlockDiskCacheKeyStoreUnitTest.java (original)
+++ commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/block/BlockDiskCacheKeyStoreUnitTest.java Wed May 30 18:14:43 2012
@@ -30,7 +30,7 @@ public class BlockDiskCacheKeyStoreUnitT
extends TestCase
{
/** Directory name */
- private String rootDirName = "target/test-sandbox/block";
+ private final String rootDirName = "target/test-sandbox/block";
/**
* Put a bunch of keys inthe key store and verify that they are present.
@@ -51,9 +51,9 @@ public class BlockDiskCacheKeyStoreUnitT
attributes.setMaxKeySize( maxKeys );
attributes.setBlockSizeBytes( bytesPerBlock );
- BlockDiskCache blockDiskCache = new BlockDiskCache( attributes );
+ BlockDiskCache<String, String> blockDiskCache = new BlockDiskCache<String, String>( attributes );
- BlockDiskKeyStore keyStore = new BlockDiskKeyStore( attributes, blockDiskCache );
+ BlockDiskKeyStore<String> keyStore = new BlockDiskKeyStore<String>( attributes, blockDiskCache );
// DO WORK
int numElements = 100;
@@ -92,9 +92,9 @@ public class BlockDiskCacheKeyStoreUnitT
attributes.setMaxKeySize( maxKeys );
attributes.setBlockSizeBytes( bytesPerBlock );
- BlockDiskCache blockDiskCache = new BlockDiskCache( attributes );
+ BlockDiskCache<String, String> blockDiskCache = new BlockDiskCache<String, String>( attributes );
- BlockDiskKeyStore keyStore = new BlockDiskKeyStore( attributes, blockDiskCache );
+ BlockDiskKeyStore<String> keyStore = new BlockDiskKeyStore<String>( attributes, blockDiskCache );
// DO WORK
int numElements = 1000;