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 2011/07/27 20:08:57 UTC
svn commit: r1151575 [5/6] - in /commons/proper/jcs/trunk: ./
src/experimental/org/apache/jcs/engine/memory/arc/
src/java/org/apache/jcs/access/ src/java/org/apache/jcs/access/behavior/
src/java/org/apache/jcs/admin/ src/java/org/apache/jcs/auxiliary/ ...
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCache.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCache.java?rev=1151575&r1=1151574&r2=1151575&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCache.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCache.java Wed Jul 27 18:08:23 2011
@@ -51,6 +51,7 @@ import org.apache.jcs.engine.match.KeyMa
import org.apache.jcs.engine.match.behavior.IKeyMatcher;
import org.apache.jcs.engine.memory.MemoryCache;
import org.apache.jcs.engine.memory.lru.LRUMemoryCache;
+import org.apache.jcs.engine.memory.util.MemoryElementDescriptor;
import org.apache.jcs.engine.stats.CacheStats;
import org.apache.jcs.engine.stats.StatElement;
import org.apache.jcs.engine.stats.Stats;
@@ -574,7 +575,7 @@ public class CompositeCache
break;
}
}
- }
+ }
}
}
catch ( Exception e )
@@ -602,7 +603,7 @@ public class CompositeCache
* @return a map of Serializable key to ICacheElement element, or an empty map if there is no
* data in cache for any of these keys
*/
- public Map getMultiple( Set keys )
+ public Map<Serializable, ICacheElement> getMultiple( Set<Serializable> keys )
{
return getMultiple( keys, false );
}
@@ -615,7 +616,7 @@ public class CompositeCache
* @return a map of Serializable key to ICacheElement element, or an empty map if there is no
* data in cache for any of these keys
*/
- public Map localGetMultiple( Set keys )
+ public Map<Serializable, ICacheElement> localGetMultiple( Set<Serializable> keys )
{
return getMultiple( keys, true );
}
@@ -632,9 +633,9 @@ public class CompositeCache
* @param localOnly
* @return ICacheElement
*/
- protected Map getMultiple( Set keys, boolean localOnly )
+ protected Map<Serializable, ICacheElement> getMultiple( Set<Serializable> keys, boolean localOnly )
{
- Map elements = new HashMap();
+ Map<Serializable, ICacheElement> elements = new HashMap<Serializable, ICacheElement>();
if ( log.isDebugEnabled() )
{
@@ -646,10 +647,10 @@ public class CompositeCache
// First look in memory cache
elements.putAll( getMultipleFromMemory( keys ) );
- // If fewer than all items were found in memory, then keep looking.
+ // If fewer than all items were found in memory, then keep looking.
if ( elements.size() != keys.size() )
{
- Set remainingKeys = pruneKeysFound( keys, elements );
+ Set<Serializable> remainingKeys = pruneKeysFound( keys, elements );
elements.putAll( getMultipleFromAuxiliaryCaches( remainingKeys, localOnly ) );
}
}
@@ -679,16 +680,16 @@ public class CompositeCache
* @return the elements found in the memory cache
* @throws IOException
*/
- private Map getMultipleFromMemory( Set keys )
+ private Map<Serializable, ICacheElement> getMultipleFromMemory( Set<Serializable> keys )
throws IOException
{
- Map elementsFromMemory = memCache.getMultiple( keys );
+ Map<Serializable, ICacheElement> elementsFromMemory = memCache.getMultiple( keys );
- Iterator elementFromMemoryIterator = new HashMap( elementsFromMemory ).values().iterator();
+ Iterator<ICacheElement> elementFromMemoryIterator = new HashMap<Serializable, ICacheElement>( elementsFromMemory ).values().iterator();
while ( elementFromMemoryIterator.hasNext() )
{
- ICacheElement element = (ICacheElement) elementFromMemoryIterator.next();
+ ICacheElement element = elementFromMemoryIterator.next();
if ( element != null )
{
@@ -728,11 +729,11 @@ public class CompositeCache
* @return the elements found in the auxiliary caches
* @throws IOException
*/
- private Map getMultipleFromAuxiliaryCaches( Set keys, boolean localOnly )
+ private Map<Serializable, ICacheElement> getMultipleFromAuxiliaryCaches( Set<Serializable> keys, boolean localOnly )
throws IOException
{
- Map elements = new HashMap();
- Set remainingKeys = new HashSet( keys );
+ Map<Serializable, ICacheElement> elements = new HashMap<Serializable, ICacheElement>();
+ Set<Serializable> remainingKeys = new HashSet<Serializable>( keys );
for ( int i = 0; i < auxCaches.length; i++ )
{
@@ -740,7 +741,8 @@ public class CompositeCache
if ( aux != null )
{
- Map elementsFromAuxiliary = new HashMap();
+ Map<Serializable, ICacheElement> elementsFromAuxiliary =
+ new HashMap<Serializable, ICacheElement>();
long cacheType = aux.getCacheType();
@@ -792,7 +794,7 @@ public class CompositeCache
* @return a map of Serializable key to ICacheElement element, or an empty map if there is no
* data in cache for any matching keys
*/
- public Map getMatching( String pattern )
+ public Map<Serializable, ICacheElement> getMatching( String pattern )
{
return getMatching( pattern, false );
}
@@ -805,7 +807,7 @@ public class CompositeCache
* @return a map of Serializable key to ICacheElement element, or an empty map if there is no
* data in cache for any matching keys
*/
- public Map localGetMatching( String pattern )
+ public Map<Serializable, ICacheElement> localGetMatching( String pattern )
{
return getMatching( pattern, true );
}
@@ -823,9 +825,9 @@ public class CompositeCache
* @return a map of Serializable key to ICacheElement element, or an empty map if there is no
* data in cache for any matching keys
*/
- protected Map getMatching( String pattern, boolean localOnly )
+ protected Map<Serializable, ICacheElement> getMatching( String pattern, boolean localOnly )
{
- Map elements = new HashMap();
+ Map<Serializable, ICacheElement> elements = new HashMap<Serializable, ICacheElement>();
if ( log.isDebugEnabled() )
{
@@ -857,14 +859,14 @@ public class CompositeCache
* data in cache for any matching keys
* @throws IOException
*/
- protected Map getMatchingFromMemory( String pattern )
+ protected Map<Serializable, ICacheElement> getMatchingFromMemory( String pattern )
throws IOException
{
// find matches in key array
// this avoids locking the memory cache, but it uses more memory
Object[] keyArray = memCache.getKeyArray();
- Set matchingKeys = getKeyMatcher().getMatchingKeysFromArray( pattern, keyArray );
+ Set<Serializable> matchingKeys = getKeyMatcher().getMatchingKeysFromArray( pattern, keyArray );
// call get multiple
return getMultipleFromMemory( matchingKeys );
@@ -882,10 +884,10 @@ public class CompositeCache
* data in cache for any matching keys
* @throws IOException
*/
- private Map getMatchingFromAuxiliaryCaches( String pattern, boolean localOnly )
+ private Map<Serializable, ICacheElement> getMatchingFromAuxiliaryCaches( String pattern, boolean localOnly )
throws IOException
{
- Map elements = new HashMap();
+ Map<Serializable, ICacheElement> elements = new HashMap<Serializable, ICacheElement>();
for ( int i = auxCaches.length - 1; i >= 0; i-- )
{
@@ -893,7 +895,8 @@ public class CompositeCache
if ( aux != null )
{
- Map elementsFromAuxiliary = new HashMap();
+ Map<Serializable, ICacheElement> elementsFromAuxiliary =
+ new HashMap<Serializable, ICacheElement>();
long cacheType = aux.getCacheType();
@@ -936,14 +939,14 @@ public class CompositeCache
* @param elementsFromAuxiliary
* @throws IOException
*/
- private void processRetrievedElements( int i, Map elementsFromAuxiliary )
+ private void processRetrievedElements( int i, Map<Serializable, ICacheElement> elementsFromAuxiliary )
throws IOException
{
- Iterator elementFromAuxiliaryIterator = new HashMap( elementsFromAuxiliary ).values().iterator();
+ Iterator<ICacheElement> elementFromAuxiliaryIterator = new HashMap<Serializable, ICacheElement>( elementsFromAuxiliary ).values().iterator();
while ( elementFromAuxiliaryIterator.hasNext() )
{
- ICacheElement element = (ICacheElement) elementFromAuxiliaryIterator.next();
+ ICacheElement element = elementFromAuxiliaryIterator.next();
// Item found in one of the auxiliary caches.
if ( element != null )
@@ -1012,15 +1015,12 @@ public class CompositeCache
* @return the original set of cache keys, minus any cache keys present in the map keys of the
* foundElements map
*/
- private Set pruneKeysFound( Set keys, Map foundElements )
+ private Set<Serializable> pruneKeysFound( Set<Serializable> keys, Map<Serializable, ICacheElement> foundElements )
{
- Set remainingKeys = new HashSet( keys );
-
- Iterator foundKeys = foundElements.keySet().iterator();
+ Set<Serializable> remainingKeys = new HashSet<Serializable>( keys );
- while ( foundKeys.hasNext() )
+ for (Serializable key : foundElements.keySet())
{
- Serializable key = (Serializable) foundKeys.next();
remainingKeys.remove( key );
}
@@ -1096,9 +1096,9 @@ public class CompositeCache
* @param group
* @return A Set of keys, or null.
*/
- public Set getGroupKeys( String group )
+ public Set<Serializable> getGroupKeys( String group )
{
- HashSet allKeys = new HashSet();
+ HashSet<Serializable> allKeys = new HashSet<Serializable>();
allKeys.addAll( memCache.getGroupKeys( group ) );
for ( int i = 0; i < auxCaches.length; i++ )
{
@@ -1267,15 +1267,13 @@ public class CompositeCache
{
ICache aux = auxCaches[i];
- int cacheType = aux.getCacheType();
-
- if ( aux != null && ( cacheType == ICache.DISK_CACHE || !localOnly ) )
+ if ( aux != null && ( aux.getCacheType() == ICache.DISK_CACHE || !localOnly ) )
{
try
{
if ( log.isDebugEnabled() )
{
- log.debug( "Removing All keys from cacheType" + cacheType );
+ log.debug( "Removing All keys from cacheType" + aux.getCacheType() );
}
aux.removeAll();
@@ -1418,13 +1416,14 @@ public class CompositeCache
if ( aux.getStatus() == CacheConstants.STATUS_ALIVE )
{
- Iterator itr = memCache.getIterator();
+ Iterator<Map.Entry<Serializable, MemoryElementDescriptor>> itr =
+ memCache.getIterator();
- while ( itr.hasNext() )
+ while (itr.hasNext())
{
- Map.Entry entry = (Map.Entry) itr.next();
+ Map.Entry<Serializable, MemoryElementDescriptor> entry = itr.next();
- ICacheElement ce = (ICacheElement) entry.getValue();
+ ICacheElement ce = entry.getValue().ce;
aux.update( ce );
}
@@ -1613,7 +1612,7 @@ public class CompositeCache
{
try
{
- Class c = Class.forName( cattr.getMemoryCacheName() );
+ Class<?> c = Class.forName( cattr.getMemoryCacheName() );
memCache = (MemoryCache) c.newInstance();
memCache.initialize( this );
}
@@ -1690,7 +1689,7 @@ public class CompositeCache
private void handleElementEvent( ICacheElement ce, int eventType )
{
// handle event, might move to a new method
- ArrayList eventHandlers = ce.getElementAttributes().getElementEventHandlers();
+ ArrayList<IElementEventHandler> eventHandlers = ce.getElementAttributes().getElementEventHandlers();
if ( eventHandlers != null )
{
if ( log.isDebugEnabled() )
@@ -1698,10 +1697,8 @@ public class CompositeCache
log.debug( "Element Handlers are registered. Create event type " + eventType );
}
IElementEvent event = new ElementEvent( ce, eventType );
- Iterator hIt = eventHandlers.iterator();
- while ( hIt.hasNext() )
+ for (IElementEventHandler hand : eventHandlers)
{
- IElementEventHandler hand = (IElementEventHandler) hIt.next();
try
{
addElementEvent( hand, event );
@@ -1799,6 +1796,7 @@ public class CompositeCache
* <p>
* @return getStats()
*/
+ @Override
public String toString()
{
return getStats();
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCacheConfigurator.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCacheConfigurator.java?rev=1151575&r1=1151574&r2=1151575&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCacheConfigurator.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCacheConfigurator.java Wed Jul 27 18:08:23 2011
@@ -82,9 +82,9 @@ public class CompositeCacheConfigurator
* jcs.auxiliary.NAME.keymatcher.attributes.CUSTOMPROPERTY=VALUE
*/
public final static String KEY_MATCHER_PREFIX = ".keymatcher";
-
+
/** Can't operate on the interface. */
- private CompositeCacheManager compositeCacheManager;
+ private final CompositeCacheManager compositeCacheManager;
/**
* Constructor for the CompositeCacheConfigurator object
@@ -218,7 +218,7 @@ public class CompositeCacheConfigurator
*/
protected void parseSystemRegions( Properties props )
{
- Enumeration en = props.propertyNames();
+ Enumeration<?> en = props.propertyNames();
while ( en.hasMoreElements() )
{
String key = (String) en.nextElement();
@@ -246,9 +246,9 @@ public class CompositeCacheConfigurator
*/
protected void parseRegions( Properties props )
{
- List regionNames = new ArrayList();
+ List<String> regionNames = new ArrayList<String>();
- Enumeration en = props.propertyNames();
+ Enumeration<?> en = props.propertyNames();
while ( en.hasMoreElements() )
{
String key = (String) en.nextElement();
@@ -329,8 +329,7 @@ public class CompositeCacheConfigurator
CompositeCache cache = new CompositeCache( regName, cca, ea );
// Next, create the auxiliaries for the new cache
-
- List auxList = new ArrayList();
+ List<AuxiliaryCache> auxList = new ArrayList<AuxiliaryCache>();
if ( log.isDebugEnabled() )
{
@@ -373,7 +372,7 @@ public class CompositeCacheConfigurator
// Associate the auxiliaries with the cache
- cache.setAuxCaches( (AuxiliaryCache[]) auxList.toArray( new AuxiliaryCache[0] ) );
+ cache.setAuxCaches( auxList.toArray( new AuxiliaryCache[0] ) );
// Return the new cache
@@ -575,7 +574,7 @@ public class CompositeCacheConfigurator
// CONFIGURE THE KEYMATCHER
//IKeyMatcher keyMatcher = parseKeyMatcher( props, auxPrefix );
// TODO add to factory interface
-
+
// Consider putting the compositeCache back in the factory interface
// since the manager may not know about it at this point.
// need to make sure the manager already has the cache
@@ -584,7 +583,7 @@ public class CompositeCacheConfigurator
return auxCache;
}
-
+
/**
* Creates a custom key matcher if one is defined. Else, it uses the default.
* <p>
@@ -621,5 +620,5 @@ public class CompositeCacheConfigurator
}
}
return keyMatcher;
- }
+ }
}
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCacheManager.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCacheManager.java?rev=1151575&r1=1151574&r2=1151575&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCacheManager.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCacheManager.java Wed Jul 27 18:08:23 2011
@@ -24,7 +24,6 @@ import java.io.InputStream;
import java.io.Serializable;
import java.security.AccessControlException;
import java.util.ArrayList;
-import java.util.Enumeration;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
@@ -39,6 +38,7 @@ import org.apache.jcs.auxiliary.remote.b
import org.apache.jcs.engine.CacheConstants;
import org.apache.jcs.engine.CompositeCacheAttributes;
import org.apache.jcs.engine.ElementAttributes;
+import org.apache.jcs.engine.behavior.ICache;
import org.apache.jcs.engine.behavior.ICacheType;
import org.apache.jcs.engine.behavior.ICompositeCacheAttributes;
import org.apache.jcs.engine.behavior.ICompositeCacheManager;
@@ -66,13 +66,13 @@ public class CompositeCacheManager
private static final long serialVersionUID = 7598584393134401756L;
/** The logger */
- private final static Log log = LogFactory.getLog( CompositeCacheManager.class );
+ protected final static Log log = LogFactory.getLog( CompositeCacheManager.class );
/** Caches managed by this cache manager */
- protected Hashtable caches = new Hashtable();
+ protected Hashtable<String, ICache> caches = new Hashtable<String, ICache>();
/** Internal system caches for this cache manager */
- protected Hashtable systemCaches = new Hashtable();
+ protected Hashtable<String, ICache> systemCaches = new Hashtable<String, ICache>();
/** Number of clients accessing this cache manager */
private int clients;
@@ -84,10 +84,12 @@ public class CompositeCacheManager
protected IElementAttributes defaultElementAttr = new ElementAttributes();
/** Used to keep track of configured auxiliaries */
- protected Hashtable auxiliaryFactoryRegistry = new Hashtable( 11 );
+ protected Hashtable<String, AuxiliaryCacheFactory> auxiliaryFactoryRegistry =
+ new Hashtable<String, AuxiliaryCacheFactory>( 11 );
/** Used to keep track of attributes for auxiliaries. */
- protected Hashtable auxiliaryAttributeRegistry = new Hashtable( 11 );
+ protected Hashtable<String, AuxiliaryCacheAttributes> auxiliaryAttributeRegistry =
+ new Hashtable<String, AuxiliaryCacheAttributes>( 11 );
/** Properties with which this manager was configured. This is exposed for other managers. */
private Properties configurationProperties;
@@ -108,7 +110,7 @@ public class CompositeCacheManager
private static final boolean DEFAULT_FORCE_RECONFIGURATION = false;
/** Those waiting for notification of a shutdown. */
- private Set shutdownObservers = new HashSet();
+ private final Set<IShutdownObserver> shutdownObservers = new HashSet<IShutdownObserver>();
/** Indicates whether shutdown has been called. */
private boolean isShutdown = false;
@@ -360,8 +362,8 @@ public class CompositeCacheManager
{
// override any setting with values from the system properties.
Properties sysProps = System.getProperties();
- Set keys = sysProps.keySet();
- Iterator keyIt = keys.iterator();
+ Set<Object> keys = sysProps.keySet();
+ Iterator<Object> keyIt = keys.iterator();
while ( keyIt.hasNext() )
{
String key = (String) keyIt.next();
@@ -567,10 +569,8 @@ public class CompositeCacheManager
// We don't need to worry about locking the set.
// since this is a shutdown command, nor do we need
// to queue these up.
- Iterator it = shutdownObservers.iterator();
- while ( it.hasNext() )
+ for (IShutdownObserver observer : shutdownObservers)
{
- IShutdownObserver observer = (IShutdownObserver) it.next();
observer.shutdown();
}
}
@@ -619,11 +619,9 @@ public class CompositeCacheManager
log.debug( "Last client called release. There are " + caches.size() + " caches which will be disposed" );
}
- Enumeration allCaches = caches.elements();
-
- while ( allCaches.hasMoreElements() )
+ for (ICache c : caches.values() )
{
- CompositeCache cache = (CompositeCache) allCaches.nextElement();
+ CompositeCache cache = (CompositeCache) c;
if ( cache != null )
{
@@ -641,9 +639,9 @@ public class CompositeCacheManager
{
String[] list = new String[caches.size()];
int i = 0;
- for ( Iterator itr = caches.keySet().iterator(); itr.hasNext(); )
+ for (String key : caches.keySet())
{
- list[i++] = (String) itr.next();
+ list[i++] = key;
}
return list;
}
@@ -678,7 +676,7 @@ public class CompositeCacheManager
*/
AuxiliaryCacheFactory registryFacGet( String name )
{
- return (AuxiliaryCacheFactory) auxiliaryFactoryRegistry.get( name );
+ return auxiliaryFactoryRegistry.get( name );
}
/**
@@ -695,7 +693,7 @@ public class CompositeCacheManager
*/
AuxiliaryCacheAttributes registryAttrGet( String name )
{
- return (AuxiliaryCacheAttributes) auxiliaryAttributeRegistry.get( name );
+ return auxiliaryAttributeRegistry.get( name );
}
/**
@@ -730,17 +728,16 @@ public class CompositeCacheManager
*/
public ICacheStats[] getStatistics()
{
- ArrayList cacheStats = new ArrayList();
- Enumeration allCaches = caches.elements();
- while ( allCaches.hasMoreElements() )
+ ArrayList<ICacheStats> cacheStats = new ArrayList<ICacheStats>();
+ for (ICache c : caches.values())
{
- CompositeCache cache = (CompositeCache) allCaches.nextElement();
+ CompositeCache cache = (CompositeCache) c;
if ( cache != null )
{
cacheStats.add( cache.getStatistics() );
}
}
- ICacheStats[] stats = (ICacheStats[]) cacheStats.toArray( new CacheStats[0] );
+ ICacheStats[] stats = cacheStats.toArray( new CacheStats[0] );
return stats;
}
@@ -822,6 +819,7 @@ public class CompositeCacheManager
* <p>
* @see java.lang.Thread#run()
*/
+ @Override
public void run()
{
if ( !isShutdown() )
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/control/event/ElementEventQueue.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/control/event/ElementEventQueue.java?rev=1151575&r1=1151574&r2=1151575&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/control/event/ElementEventQueue.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/control/event/ElementEventQueue.java Wed Jul 27 18:08:23 2011
@@ -34,10 +34,10 @@ public class ElementEventQueue
implements IElementEventQueue
{
/** The logger */
- private final static Log log = LogFactory.getLog( ElementEventQueue.class );
+ protected final static Log log = LogFactory.getLog( ElementEventQueue.class );
/** The cache (region) name. */
- private String cacheName;
+ protected final String cacheName;
/** default */
private static final int DEFAULT_WAIT_TO_DIE_MILLIS = 10000;
@@ -55,7 +55,7 @@ public class ElementEventQueue
private Thread processorThread;
/** Internal queue implementation */
- private Object queueLock = new Object();
+ protected final Object queueLock = new Object();
/** Dummy node */
private Node head = new Node();
@@ -142,6 +142,7 @@ public class ElementEventQueue
/**
* @return the region name for the event queue
*/
+ @Override
public String toString()
{
return "cacheName=" + cacheName;
@@ -227,7 +228,7 @@ public class ElementEventQueue
* <p>
* @return AbstractElementEventRunner
*/
- private AbstractElementEventRunner take()
+ protected AbstractElementEventRunner take()
{
synchronized ( queueLock )
{
@@ -260,7 +261,7 @@ public class ElementEventQueue
// /////////////////////////// Inner classes /////////////////////////////
/** A node in the queue. These are chained forming a singly linked list */
- private static class Node
+ protected static class Node
{
/** The next node. */
Node next = null;
@@ -280,7 +281,7 @@ public class ElementEventQueue
/**
* Constructor for the QProcessor object
* <p>
- * @param aQueue
+ * @param aQueue
*/
QProcessor( ElementEventQueue aQueue )
{
@@ -296,6 +297,7 @@ public class ElementEventQueue
* Waits for a specified time (waitToDieMillis) for something to come in and if no new
* events come in during that period the run method can exit and the thread is dereferenced.
*/
+ @Override
public void run()
{
AbstractElementEventRunner event = null;
@@ -349,7 +351,7 @@ public class ElementEventQueue
/**
* Retries before declaring failure.
*/
- private abstract class AbstractElementEventRunner
+ protected abstract class AbstractElementEventRunner
implements Runnable
{
/**
@@ -357,27 +359,16 @@ public class ElementEventQueue
*/
public void run()
{
- IOException ex = null;
-
try
{
- ex = null;
doRun();
- return;
// happy and done.
}
catch ( IOException e )
{
- ex = e;
- }
-
- // Too bad. The handler has problems.
- if ( ex != null )
- {
- log.warn( "Giving up element event handling " + ElementEventQueue.this, ex );
-
+ // Too bad. The handler has problems.
+ log.warn( "Giving up element event handling " + ElementEventQueue.this, e );
}
- return;
}
/**
@@ -396,10 +387,10 @@ public class ElementEventQueue
extends AbstractElementEventRunner
{
/** the handler */
- private IElementEventHandler hand;
+ private final IElementEventHandler hand;
/** event */
- private IElementEvent event;
+ private final IElementEvent event;
/**
* Constructor for the PutEvent object.
@@ -424,6 +415,7 @@ public class ElementEventQueue
* <p>
* @exception IOException
*/
+ @Override
protected void doRun()
throws IOException
{
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/match/KeyMatcherPatternImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/match/KeyMatcherPatternImpl.java?rev=1151575&r1=1151574&r2=1151575&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/match/KeyMatcherPatternImpl.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/match/KeyMatcherPatternImpl.java Wed Jul 27 18:08:23 2011
@@ -1,5 +1,6 @@
package org.apache.jcs.engine.match;
+import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Matcher;
@@ -18,11 +19,11 @@ public class KeyMatcherPatternImpl
* @param keyArray
* @return Set of the matching keys
*/
- public Set getMatchingKeysFromArray( String pattern, Object[] keyArray )
+ public Set<Serializable> getMatchingKeysFromArray( String pattern, Object[] keyArray )
{
Pattern compiledPattern = Pattern.compile( pattern );
- Set matchingKeys = new HashSet();
+ Set<Serializable> matchingKeys = new HashSet<Serializable>();
// Look for matches
for ( int i = 0; i < keyArray.length; i++ )
@@ -34,7 +35,7 @@ public class KeyMatcherPatternImpl
Matcher matcher = compiledPattern.matcher( (String) key );
if ( matcher.matches() )
{
- matchingKeys.add( key );
+ matchingKeys.add( (Serializable) key );
}
}
}
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/match/behavior/IKeyMatcher.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/match/behavior/IKeyMatcher.java?rev=1151575&r1=1151574&r2=1151575&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/match/behavior/IKeyMatcher.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/match/behavior/IKeyMatcher.java Wed Jul 27 18:08:23 2011
@@ -1,5 +1,6 @@
package org.apache.jcs.engine.match.behavior;
+import java.io.Serializable;
import java.util.Set;
/** Key matchers need to implement this interface. */
@@ -12,5 +13,5 @@ public interface IKeyMatcher
* @param keyArray
* @return Set of the matching keys
*/
- Set getMatchingKeysFromArray( String pattern, Object[] keyArray );
+ Set<Serializable> getMatchingKeysFromArray( String pattern, Object[] keyArray );
}
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/memory/AbstractDoulbeLinkedListMemoryCache.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/memory/AbstractDoulbeLinkedListMemoryCache.java?rev=1151575&r1=1151574&r2=1151575&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/memory/AbstractDoulbeLinkedListMemoryCache.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/memory/AbstractDoulbeLinkedListMemoryCache.java Wed Jul 27 18:08:23 2011
@@ -6,7 +6,7 @@ import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
-import java.util.NoSuchElementException;
+import java.util.Map.Entry;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -40,7 +40,7 @@ public abstract class AbstractDoulbeLink
private final static Log log = LogFactory.getLog( AbstractDoulbeLinkedListMemoryCache.class );
/** thread-safe double linked list for lru */
- protected DoubleLinkedList list;
+ protected DoubleLinkedList<MemoryElementDescriptor> list;
/** number of hits */
protected int hitCnt = 0;
@@ -56,10 +56,11 @@ public abstract class AbstractDoulbeLink
* <p>
* @param hub
*/
+ @Override
public synchronized void initialize( CompositeCache hub )
{
super.initialize( hub );
- list = new DoubleLinkedList();
+ list = new DoubleLinkedList<MemoryElementDescriptor>();
log.info( "initialized MemoryCache for " + cacheName );
}
@@ -68,9 +69,10 @@ public abstract class AbstractDoulbeLink
* <p>
* @return new Hashtable()
*/
- public Map createMap()
+ @Override
+ public Map<Serializable, MemoryElementDescriptor> createMap()
{
- return new Hashtable();
+ return new Hashtable<Serializable, MemoryElementDescriptor>();
}
/**
@@ -81,6 +83,7 @@ public abstract class AbstractDoulbeLink
* @param ce The cache element, or entry wrapper
* @exception IOException
*/
+ @Override
public final void update( ICacheElement ce )
throws IOException
{
@@ -93,7 +96,7 @@ public abstract class AbstractDoulbeLink
MemoryElementDescriptor newNode = adjustListForUpdate( ce );
// this must be synchronized
- MemoryElementDescriptor oldNode = (MemoryElementDescriptor) map.put( newNode.ce.getKey(), newNode );
+ MemoryElementDescriptor oldNode = map.put( newNode.ce.getKey(), newNode );
// If the node was the same as an existing node, remove it.
if ( oldNode != null && ( newNode.ce.getKey().equals( oldNode.ce.getKey() ) ) )
@@ -167,6 +170,7 @@ public abstract class AbstractDoulbeLink
* @return ICacheElement if found, else null
* @exception IOException
*/
+ @Override
public final synchronized ICacheElement get( Serializable key )
throws IOException
{
@@ -177,7 +181,7 @@ public abstract class AbstractDoulbeLink
log.debug( "getting item from cache " + cacheName + " for key " + key );
}
- MemoryElementDescriptor me = (MemoryElementDescriptor) map.get( key );
+ MemoryElementDescriptor me = map.get( key );
if ( me != null )
{
@@ -251,20 +255,20 @@ public abstract class AbstractDoulbeLink
{
if ( list.getLast() != null )
{
- toSpool = ( (MemoryElementDescriptor) list.getLast() ).ce;
+ toSpool = list.getLast().ce;
if ( toSpool != null )
{
- cache.spoolToDisk( ( (MemoryElementDescriptor) list.getLast() ).ce );
- if ( !map.containsKey( ( (MemoryElementDescriptor) list.getLast() ).ce.getKey() ) )
+ cache.spoolToDisk( list.getLast().ce );
+ if ( !map.containsKey( list.getLast().ce.getKey() ) )
{
log.error( "update: map does not contain key: "
- + ( (MemoryElementDescriptor) list.getLast() ).ce.getKey() );
+ + list.getLast().ce.getKey() );
verifyCache();
}
- if ( map.remove( ( (MemoryElementDescriptor) list.getLast() ).ce.getKey() ) == null )
+ if ( map.remove( list.getLast().ce.getKey() ) == null )
{
log.warn( "update: remove failed for key: "
- + ( (MemoryElementDescriptor) list.getLast() ).ce.getKey() );
+ + list.getLast().ce.getKey() );
verifyCache();
}
}
@@ -300,6 +304,7 @@ public abstract class AbstractDoulbeLink
* @return true if the removal was successful
* @exception IOException
*/
+ @Override
public synchronized boolean remove( Serializable key )
throws IOException
{
@@ -316,14 +321,14 @@ public abstract class AbstractDoulbeLink
// remove all keys of the same name hierarchy.
synchronized ( map )
{
- for ( Iterator itr = map.entrySet().iterator(); itr.hasNext(); )
+ for (Iterator<Map.Entry<Serializable, MemoryElementDescriptor>> itr = map.entrySet().iterator(); itr.hasNext(); )
{
- Map.Entry entry = (Map.Entry) itr.next();
+ Map.Entry<Serializable, MemoryElementDescriptor> entry = itr.next();
Object k = entry.getKey();
if ( k instanceof String && ( (String) k ).startsWith( key.toString() ) )
{
- list.remove( (MemoryElementDescriptor) entry.getValue() );
+ list.remove( entry.getValue() );
itr.remove();
removed = true;
}
@@ -335,15 +340,15 @@ public abstract class AbstractDoulbeLink
// remove all keys of the same name hierarchy.
synchronized ( map )
{
- for ( Iterator itr = map.entrySet().iterator(); itr.hasNext(); )
+ for (Iterator<Map.Entry<Serializable, MemoryElementDescriptor>> itr = map.entrySet().iterator(); itr.hasNext(); )
{
- Map.Entry entry = (Map.Entry) itr.next();
+ Map.Entry<Serializable, MemoryElementDescriptor> entry = itr.next();
Object k = entry.getKey();
if ( k instanceof GroupAttrName && ( (GroupAttrName) k ).groupId.equals( key ) )
{
+ list.remove( entry.getValue() );
itr.remove();
- list.remove( (MemoryElementDescriptor) entry.getValue() );
removed = true;
}
}
@@ -352,7 +357,7 @@ public abstract class AbstractDoulbeLink
else
{
// remove single item.
- MemoryElementDescriptor me = (MemoryElementDescriptor) map.remove( key );
+ MemoryElementDescriptor me = map.remove( key );
if ( me != null )
{
@@ -370,6 +375,7 @@ public abstract class AbstractDoulbeLink
* <p>
* @throws IOException
*/
+ @Override
public synchronized void removeAll()
throws IOException
{
@@ -409,26 +415,12 @@ public abstract class AbstractDoulbeLink
// ---------------------------------------------------------- debug methods
/**
- * Dump the cache map for debugging.
- */
- public void dumpMap()
- {
- log.debug( "dumpingMap" );
- for ( Iterator itr = map.entrySet().iterator(); itr.hasNext(); )
- {
- Map.Entry e = (Map.Entry) itr.next();
- MemoryElementDescriptor me = (MemoryElementDescriptor) e.getValue();
- log.debug( "dumpMap> key=" + e.getKey() + ", val=" + me.ce.getVal() );
- }
- }
-
- /**
* Dump the cache entries from first to list for debugging.
*/
public void dumpCacheEntries()
{
log.debug( "dumpingCacheEntries" );
- for ( MemoryElementDescriptor me = (MemoryElementDescriptor) list.getFirst(); me != null; me = (MemoryElementDescriptor) me.next )
+ for ( MemoryElementDescriptor me = list.getFirst(); me != null; me = (MemoryElementDescriptor) me.next )
{
log.debug( "dumpCacheEntries> key=" + me.ce.getKey() + ", val=" + me.ce.getVal() );
}
@@ -459,7 +451,7 @@ public abstract class AbstractDoulbeLink
log.debug( "verifycache[" + cacheName + "]: mapContains " + map.size() + " elements, linked list contains "
+ dumpCacheSize() + " elements" );
log.debug( "verifycache: checking linked list by key " );
- for ( MemoryElementDescriptor li = (MemoryElementDescriptor) list.getFirst(); li != null; li = (MemoryElementDescriptor) li.next )
+ for ( MemoryElementDescriptor li = list.getFirst(); li != null; li = (MemoryElementDescriptor) li.next )
{
Object key = li.ce.getKey();
if ( !map.containsKey( key ) )
@@ -487,7 +479,7 @@ public abstract class AbstractDoulbeLink
}
log.debug( "verifycache: checking linked list by value " );
- for ( MemoryElementDescriptor li3 = (MemoryElementDescriptor) list.getFirst(); li3 != null; li3 = (MemoryElementDescriptor) li3.next )
+ for ( MemoryElementDescriptor li3 = list.getFirst(); li3 != null; li3 = (MemoryElementDescriptor) li3.next )
{
if ( map.containsValue( li3 ) == false )
{
@@ -497,20 +489,11 @@ public abstract class AbstractDoulbeLink
}
log.debug( "verifycache: checking via keysets!" );
- for ( Iterator itr2 = map.keySet().iterator(); itr2.hasNext(); )
+ for (Serializable val : map.keySet())
{
found = false;
- Serializable val = null;
- try
- {
- val = (Serializable) itr2.next();
- }
- catch ( NoSuchElementException nse )
- {
- log.error( "verifycache: no such element exception" );
- }
- for ( MemoryElementDescriptor li2 = (MemoryElementDescriptor) list.getFirst(); li2 != null; li2 = (MemoryElementDescriptor) li2.next )
+ for ( MemoryElementDescriptor li2 = list.getFirst(); li2 != null; li2 = (MemoryElementDescriptor) li2.next )
{
if ( val.equals( li2.ce.getKey() ) )
{
@@ -549,7 +532,7 @@ public abstract class AbstractDoulbeLink
boolean found = false;
// go through the linked list looking for the key
- for ( MemoryElementDescriptor li = (MemoryElementDescriptor) list.getFirst(); li != null; li = (MemoryElementDescriptor) li.next )
+ for ( MemoryElementDescriptor li = list.getFirst(); li != null; li = (MemoryElementDescriptor) li.next )
{
if ( li.ce.getKey() == key )
{
@@ -569,16 +552,16 @@ public abstract class AbstractDoulbeLink
* iteration aid
*/
public class IteratorWrapper
- implements Iterator
+ implements Iterator<Entry<Serializable, MemoryElementDescriptor>>
{
/** The internal iterator */
- private final Iterator i;
+ private final Iterator<Entry<Serializable, MemoryElementDescriptor>> i;
/**
* Wrapped to remove our wrapper object
* @param m
*/
- private IteratorWrapper( Map m )
+ protected IteratorWrapper(Map<Serializable, MemoryElementDescriptor> m)
{
i = m.entrySet().iterator();
}
@@ -590,9 +573,10 @@ public abstract class AbstractDoulbeLink
}
/** @return new MapEntryWrapper( (Map.Entry) i.next() ) */
- public Object next()
+ public Entry<Serializable, MemoryElementDescriptor> next()
{
- return new MapEntryWrapper( (Map.Entry) i.next() );
+ // return new MapEntryWrapper<Serializable>( i.next() );
+ return i.next();
}
/** i.remove(); */
@@ -605,12 +589,14 @@ public abstract class AbstractDoulbeLink
* @param o
* @return i.equals( o ))
*/
+ @Override
public boolean equals( Object o )
{
return i.equals( o );
}
/** @return i.hashCode() */
+ @Override
public int hashCode()
{
return i.hashCode();
@@ -620,16 +606,16 @@ public abstract class AbstractDoulbeLink
/**
* @author Aaron Smuts
*/
- public class MapEntryWrapper
- implements Map.Entry
+ public class MapEntryWrapper<K>
+ implements Map.Entry<K, ICacheElement>
{
/** The internal entry */
- private final Map.Entry e;
+ private final Map.Entry<K, MemoryElementDescriptor> e;
/**
* @param e
*/
- private MapEntryWrapper( Map.Entry e )
+ private MapEntryWrapper( Map.Entry<K, MemoryElementDescriptor> e )
{
this.e = e;
}
@@ -638,24 +624,26 @@ public abstract class AbstractDoulbeLink
* @param o
* @return e.equals( o )
*/
+ @Override
public boolean equals( Object o )
{
return e.equals( o );
}
/** @return e.getKey() */
- public Object getKey()
+ public K getKey()
{
return e.getKey();
}
/** @return ( (MemoryElementDescriptor) e.getValue() ).ce */
- public Object getValue()
+ public ICacheElement getValue()
{
- return ( (MemoryElementDescriptor) e.getValue() ).ce;
+ return e.getValue().ce;
}
/** @return e.hashCode() */
+ @Override
public int hashCode()
{
return e.hashCode();
@@ -666,7 +654,7 @@ public abstract class AbstractDoulbeLink
* @param value
* @return always throws
*/
- public Object setValue( Object value )
+ public ICacheElement setValue(ICacheElement value)
{
throw new UnsupportedOperationException( "Use normal cache methods"
+ " to alter the contents of the cache." );
@@ -678,7 +666,8 @@ public abstract class AbstractDoulbeLink
* <p>
* @return The iterator value
*/
- public Iterator getIterator()
+ @Override
+ public Iterator<Entry<Serializable, MemoryElementDescriptor>> getIterator()
{
return new IteratorWrapper( map );
}
@@ -687,6 +676,7 @@ public abstract class AbstractDoulbeLink
* Get an Array of the keys for all elements in the memory cache
* @return An Object[]
*/
+ @Override
public Object[] getKeyArray()
{
// need a better locking strategy here.
@@ -703,12 +693,13 @@ public abstract class AbstractDoulbeLink
* <p>
* @see org.apache.jcs.engine.memory.MemoryCache#getStatistics()
*/
+ @Override
public synchronized IStats getStatistics()
{
IStats stats = new Stats();
stats.setTypeName( /*add algorithm name*/"Memory Cache" );
- ArrayList elems = new ArrayList();
+ ArrayList<IStatElement> elems = new ArrayList<IStatElement>();
IStatElement se = null;
@@ -738,7 +729,7 @@ public abstract class AbstractDoulbeLink
elems.add( se );
// get an array and put them in the Stats object
- IStatElement[] ses = (IStatElement[]) elems.toArray( new StatElement[0] );
+ IStatElement[] ses = elems.toArray( new StatElement[0] );
stats.setStatElements( ses );
return stats;
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/memory/AbstractMemoryCache.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/memory/AbstractMemoryCache.java?rev=1151575&r1=1151574&r2=1151575&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/memory/AbstractMemoryCache.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/memory/AbstractMemoryCache.java Wed Jul 27 18:08:23 2011
@@ -26,6 +26,10 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -41,9 +45,6 @@ import org.apache.jcs.engine.memory.util
import org.apache.jcs.engine.stats.Stats;
import org.apache.jcs.engine.stats.behavior.IStats;
-import EDU.oswego.cs.dl.util.concurrent.ClockDaemon;
-import EDU.oswego.cs.dl.util.concurrent.ThreadFactory;
-
/**
* This base includes some common code for memory caches.
* <p>
@@ -63,7 +64,7 @@ public abstract class AbstractMemoryCach
protected String cacheName;
/** Map where items are stored by key. This is created by the concrete child class. */
- protected Map map;
+ protected Map<Serializable, MemoryElementDescriptor> map;
/** Region Elemental Attributes, used as a default and copied for each item. */
public IElementAttributes elementAttributes;
@@ -82,7 +83,7 @@ public abstract class AbstractMemoryCach
/** The background memory shrinker, one for all regions. */
// TODO fix for multi-instance JCS
- private static ClockDaemon shrinkerDaemon;
+ private static ScheduledExecutorService shrinkerDaemon;
/**
* For post reflection creation initialization
@@ -103,11 +104,10 @@ public abstract class AbstractMemoryCach
{
if ( shrinkerDaemon == null )
{
- shrinkerDaemon = new ClockDaemon();
- shrinkerDaemon.setThreadFactory( new MyThreadFactory() );
+ shrinkerDaemon = Executors.newScheduledThreadPool(1, new MyThreadFactory());
}
- shrinkerDaemon.executePeriodically( cacheAttributes.getShrinkerIntervalSeconds() * 1000, new ShrinkerThread( this ),
- false );
+
+ shrinkerDaemon.scheduleAtFixedRate(new ShrinkerThread(this), 0, cacheAttributes.getShrinkerIntervalSeconds(), TimeUnit.SECONDS);
}
}
@@ -117,7 +117,7 @@ public abstract class AbstractMemoryCach
* <p>
* @return a threadsafe Map
*/
- public abstract Map createMap();
+ public abstract Map<Serializable, MemoryElementDescriptor> createMap();
/**
* Removes an item from the cache
@@ -147,19 +147,15 @@ public abstract class AbstractMemoryCach
* data in cache for any of these keys
* @throws IOException
*/
- public Map getMultiple( Set keys )
+ public Map<Serializable, ICacheElement> getMultiple( Set<Serializable> keys )
throws IOException
{
- Map elements = new HashMap();
+ Map<Serializable, ICacheElement> elements = new HashMap<Serializable, ICacheElement>();
if ( keys != null && !keys.isEmpty() )
{
- Iterator iterator = keys.iterator();
-
- while ( iterator.hasNext() )
+ for (Serializable key : keys)
{
- Serializable key = (Serializable) iterator.next();
-
ICacheElement element = get( key );
if ( element != null )
@@ -185,7 +181,7 @@ public abstract class AbstractMemoryCach
{
ICacheElement ce = null;
- MemoryElementDescriptor me = (MemoryElementDescriptor) map.get( key );
+ MemoryElementDescriptor me = map.get( key );
if ( me != null )
{
if ( log.isDebugEnabled() )
@@ -201,7 +197,7 @@ public abstract class AbstractMemoryCach
}
return ce;
- };
+ }
/**
* Puts an item to the cache.
@@ -241,7 +237,7 @@ public abstract class AbstractMemoryCach
log.info( "Memory Cache dispose called. Shutting down shrinker thread if it is running." );
if ( shrinkerDaemon != null )
{
- shrinkerDaemon.shutDown();
+ shrinkerDaemon.shutdownNow();
}
}
@@ -302,11 +298,25 @@ public abstract class AbstractMemoryCach
* <p>
* @return The iterator value
*/
- public Iterator getIterator()
+ public Iterator<Map.Entry<Serializable, MemoryElementDescriptor>> getIterator()
{
return map.entrySet().iterator();
}
+ // ---------------------------------------------------------- debug method
+ /**
+ * Dump the cache map for debugging.
+ */
+ public void dumpMap()
+ {
+ log.debug( "dumpingMap" );
+ for (Map.Entry<Serializable, MemoryElementDescriptor> e : map.entrySet())
+ {
+ MemoryElementDescriptor me = e.getValue();
+ log.debug( "dumpMap> key=" + e.getKey() + ", val=" + me.ce.getVal() );
+ }
+ }
+
/**
* Returns the CacheAttributes.
* <p>
@@ -341,20 +351,19 @@ public abstract class AbstractMemoryCach
* @param groupName
* @return group keys
*/
- public Set getGroupKeys( String groupName )
+ public Set<Serializable> getGroupKeys( String groupName )
{
GroupId groupId = new GroupId( getCacheName(), groupName );
- HashSet keys = new HashSet();
+ HashSet<Serializable> keys = new HashSet<Serializable>();
synchronized ( map )
{
- for ( Iterator itr = map.entrySet().iterator(); itr.hasNext(); )
+ for (Map.Entry<Serializable, MemoryElementDescriptor> entry : map.entrySet())
{
- Map.Entry entry = (Map.Entry) itr.next();
Object k = entry.getKey();
if ( k instanceof GroupAttrName && ( (GroupAttrName) k ).groupId.equals( groupId ) )
{
- keys.add( ( (GroupAttrName) k ).attrName );
+ keys.add((Serializable) ( (GroupAttrName) k ).attrName );
}
}
}
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/memory/behavior/IMemoryCache.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/memory/behavior/IMemoryCache.java?rev=1151575&r1=1151574&r2=1151575&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/memory/behavior/IMemoryCache.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/engine/memory/behavior/IMemoryCache.java Wed Jul 27 18:08:23 2011
@@ -28,6 +28,7 @@ import java.util.Set;
import org.apache.jcs.engine.behavior.ICacheElement;
import org.apache.jcs.engine.behavior.ICompositeCacheAttributes;
import org.apache.jcs.engine.control.CompositeCache;
+import org.apache.jcs.engine.memory.util.MemoryElementDescriptor;
import org.apache.jcs.engine.stats.behavior.IStats;
/** For the framework. Insures methods a MemoryCache needs to access. */
@@ -69,7 +70,7 @@ public interface IMemoryCache
* <p>
* @return An iterator
*/
- Iterator getIterator();
+ Iterator<Map.Entry<Serializable, MemoryElementDescriptor>> getIterator();
/**
* Get an Array of the keys for all elements in the memory cache.
@@ -132,11 +133,11 @@ public interface IMemoryCache
* 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
+ * @return a map of Serializable key to ICacheElement element, or an empty map
* if there is no data in cache for any of these keys
- * @throws IOException
+ * @throws IOException
*/
- Map getMultiple( Set keys )
+ Map<Serializable, ICacheElement> getMultiple( Set<Serializable> keys )
throws IOException;
/**
@@ -202,5 +203,5 @@ public interface IMemoryCache
* @param group
* @return a Set of group keys.
*/
- Set getGroupKeys( String group );
+ Set<Serializable> getGroupKeys( String group );
}
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=1151575&r1=1151574&r2=1151575&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 Jul 27 18:08:23 2011
@@ -29,7 +29,6 @@ import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.jcs.engine.CacheConstants;
-import org.apache.jcs.engine.CacheElement;
import org.apache.jcs.engine.behavior.ICacheElement;
import org.apache.jcs.engine.control.CompositeCache;
import org.apache.jcs.engine.control.group.GroupAttrName;
@@ -51,7 +50,7 @@ public class LHMLRUMemoryCache
private static final long serialVersionUID = 6403738094136424101L;
/** The Logger. */
- private final static Log log = LogFactory.getLog( LRUMemoryCache.class );
+ protected final static Log log = LogFactory.getLog( LRUMemoryCache.class );
/** number of hits */
protected int hitCnt = 0;
@@ -67,6 +66,7 @@ public class LHMLRUMemoryCache
* <p>
* @param hub
*/
+ @Override
public synchronized void initialize( CompositeCache hub )
{
super.initialize( hub );
@@ -78,7 +78,8 @@ public class LHMLRUMemoryCache
* <p>
* @return Collections.synchronizedMap( new LHMSpooler() )
*/
- public Map createMap()
+ @Override
+ public Map<Serializable, MemoryElementDescriptor> createMap()
{
return Collections.synchronizedMap( new LHMSpooler() );
}
@@ -89,12 +90,13 @@ public class LHMLRUMemoryCache
* @param ce Description of the Parameter
* @exception IOException
*/
+ @Override
public void update( ICacheElement ce )
throws IOException
{
putCnt++;
ce.getElementAttributes().setLastAccessTimeNow();
- map.put( ce.getKey(), ce );
+ map.put( ce.getKey(), new MemoryElementDescriptor(ce) );
}
/**
@@ -105,10 +107,11 @@ public class LHMLRUMemoryCache
* @return Element matching key if found, or null
* @exception IOException
*/
+ @Override
public ICacheElement getQuiet( Serializable key )
throws IOException
{
- return (ICacheElement) map.get( key );
+ return map.get( key ).ce;
}
/**
@@ -118,6 +121,7 @@ public class LHMLRUMemoryCache
* @return ICacheElement if found, else null
* @exception IOException
*/
+ @Override
public synchronized ICacheElement get( Serializable key )
throws IOException
{
@@ -128,7 +132,7 @@ public class LHMLRUMemoryCache
log.debug( "getting item from cache " + cacheName + " for key " + key );
}
- ce = (ICacheElement) map.get( key );
+ ce = map.get( key ).ce;
if ( ce != null )
{
@@ -157,6 +161,7 @@ public class LHMLRUMemoryCache
* @return true if removed
* @exception IOException
*/
+ @Override
public synchronized boolean remove( Serializable key )
throws IOException
{
@@ -173,9 +178,9 @@ public class LHMLRUMemoryCache
// remove all keys of the same name hierarchy.
synchronized ( map )
{
- for ( Iterator itr = map.entrySet().iterator(); itr.hasNext(); )
+ for (Iterator<Map.Entry<Serializable, MemoryElementDescriptor>> itr = map.entrySet().iterator(); itr.hasNext(); )
{
- Map.Entry entry = (Map.Entry) itr.next();
+ Map.Entry<Serializable, MemoryElementDescriptor> entry = itr.next();
Object k = entry.getKey();
if ( k instanceof String && ( (String) k ).startsWith( key.toString() ) )
@@ -191,9 +196,9 @@ public class LHMLRUMemoryCache
// remove all keys of the same name hierarchy.
synchronized ( map )
{
- for ( Iterator itr = map.entrySet().iterator(); itr.hasNext(); )
+ for (Iterator<Map.Entry<Serializable, MemoryElementDescriptor>> itr = map.entrySet().iterator(); itr.hasNext(); )
{
- Map.Entry entry = (Map.Entry) itr.next();
+ Map.Entry<Serializable, MemoryElementDescriptor> entry = itr.next();
Object k = entry.getKey();
if ( k instanceof GroupAttrName && ( (GroupAttrName) k ).groupId.equals( key ) )
@@ -207,8 +212,8 @@ public class LHMLRUMemoryCache
else
{
// remove single item.
- ICacheElement ce = (ICacheElement) map.remove( key );
- if ( ce != null )
+ MemoryElementDescriptor me = map.remove( key );
+ if ( me != null )
{
removed = true;
}
@@ -222,6 +227,7 @@ public class LHMLRUMemoryCache
* <p>
* @return An Object[]
*/
+ @Override
public Object[] getKeyArray()
{
// need a better locking strategy here.
@@ -238,12 +244,13 @@ public class LHMLRUMemoryCache
* <p>
* @return IStats
*/
+ @Override
public synchronized IStats getStatistics()
{
IStats stats = new Stats();
stats.setTypeName( "LHMLRU Memory Cache" );
- ArrayList elems = new ArrayList();
+ ArrayList<IStatElement> elems = new ArrayList<IStatElement>();
IStatElement se = null;
@@ -268,7 +275,7 @@ public class LHMLRUMemoryCache
elems.add( se );
// get an array and put them in the Stats object
- IStatElement[] ses = (IStatElement[]) elems.toArray( new StatElement[0] );
+ IStatElement[] ses = elems.toArray( new StatElement[0] );
stats.setStatElements( ses );
// int rate = ((hitCnt + missCnt) * 100) / (hitCnt * 100) * 100;
@@ -280,24 +287,6 @@ public class LHMLRUMemoryCache
// ---------------------------------------------------------- debug methods
/**
- * Dump the cache map for debugging.
- */
- public void dumpMap()
- {
- if ( log.isDebugEnabled() )
- {
- log.debug( "dumpingMap" );
-
- for ( Iterator itr = map.entrySet().iterator(); itr.hasNext(); )
- {
- Map.Entry e = (Map.Entry) itr.next();
- MemoryElementDescriptor me = (MemoryElementDescriptor) e.getValue();
- log.debug( "dumpMap> key=" + e.getKey() + ", val=" + me.ce.getVal() );
- }
- }
- }
-
- /**
* Dump the cache entries from first to last for debugging.
*/
public void dumpCacheEntries()
@@ -308,9 +297,9 @@ public class LHMLRUMemoryCache
/**
* This can't be implemented.
* <p>
- * @param numberToFree
- * @return 0
- * @throws IOException
+ * @param numberToFree
+ * @return 0
+ * @throws IOException
*/
public int freeElements( int numberToFree )
throws IOException
@@ -325,7 +314,7 @@ public class LHMLRUMemoryCache
* Implementation of removeEldestEntry in LinkedHashMap
*/
public class LHMSpooler
- extends java.util.LinkedHashMap
+ extends java.util.LinkedHashMap<Serializable, MemoryElementDescriptor>
{
/** Don't change. */
private static final long serialVersionUID = -1255907868906762484L;
@@ -345,9 +334,10 @@ public class LHMLRUMemoryCache
* @param eldest
* @return true if removed
*/
- protected boolean removeEldestEntry( Map.Entry eldest )
+ @Override
+ protected boolean removeEldestEntry( Map.Entry<Serializable, MemoryElementDescriptor> eldest )
{
- CacheElement element = (CacheElement) eldest.getValue();
+ ICacheElement element = eldest.getValue().ce;
if ( size() <= cache.getCacheAttributes().getMaxObjects() )
{
@@ -376,7 +366,7 @@ public class LHMLRUMemoryCache
* <p>
* @param element The CacheElement
*/
- private void spoolToDisk( CacheElement element )
+ private void spoolToDisk( ICacheElement element )
{
cache.spoolToDisk( element );
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=1151575&r1=1151574&r2=1151575&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 Jul 27 18:08:23 2011
@@ -22,7 +22,6 @@ package org.apache.jcs.engine.memory.shr
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
-import java.util.Iterator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -52,7 +51,7 @@ public class ShrinkerThread
private final long maxMemoryIdleTime;
/** Maximum number of items to spool per run. Default is -1, or no limit. */
- private int maxSpoolPerRun;
+ private final int maxSpoolPerRun;
/** Should we limit the number spooled per run. If so, the maxSpoolPerRun will be used. */
private boolean spoolLimit = false;
@@ -288,7 +287,7 @@ public class ShrinkerThread
{
IElementAttributes attributes = cacheElement.getElementAttributes();
- ArrayList eventHandlers = attributes.getElementEventHandlers();
+ ArrayList<IElementEventHandler> eventHandlers = attributes.getElementEventHandlers();
if ( eventHandlers != null )
{
@@ -299,12 +298,8 @@ public class ShrinkerThread
IElementEvent event = new ElementEvent( cacheElement, eventType );
- Iterator handlerIter = eventHandlers.iterator();
-
- while ( handlerIter.hasNext() )
+ for (IElementEventHandler hand : eventHandlers)
{
- IElementEventHandler hand = (IElementEventHandler) handlerIter.next();
-
// extra safety
// TODO we shouldn't be operating on a variable of another class.
// we did this to get away from the singleton composite cache.
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=1151575&r1=1151574&r2=1151575&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 Jul 27 18:08:23 2011
@@ -26,7 +26,7 @@ import org.apache.jcs.utils.struct.Doubl
* This wrapper is needed for double linked lists.
*/
public class MemoryElementDescriptor
- extends DoubleLinkedListNode
+ extends DoubleLinkedListNode<ICacheElement>
{
/** Don't change */
private static final long serialVersionUID = -1905161209035522460L;
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=1151575&r1=1151574&r2=1151575&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 Jul 27 18:08:23 2011
@@ -101,12 +101,12 @@ public class JCSWorker
/**
* Map to hold who's doing work presently.
*/
- private static volatile Map map = new HashMap();
+ private static volatile Map<String, JCSWorkerHelper> map = new HashMap<String, JCSWorkerHelper>();
/**
* Region for the JCS cache.
*/
- private String region;
+ private final String region;
/**
* Constructor which takes a region for the JCS cache.
@@ -200,7 +200,7 @@ public class JCSWorker
private Object run( Serializable aKey, String aGroup, JCSWorkerHelper aHelper )
throws Exception
{
- Object result = null;
+ Serializable result = null;
// long start = 0;
// long dbTime = 0;
JCSWorkerHelper helper = null;
@@ -208,7 +208,7 @@ public class JCSWorker
synchronized ( map )
{
// Check to see if we allready have a thread doing this work.
- helper = (JCSWorkerHelper) map.get( getRegion() + aKey );
+ helper = map.get( getRegion() + aKey );
if ( helper == null )
{
// If not, add ourselves as the Worker so
@@ -222,7 +222,7 @@ public class JCSWorker
{
if ( logger.isDebugEnabled() )
{
- logger.debug( "Found a worker allready doing this work (" + getRegion() + ":" + aKey + ")." );
+ logger.debug( "Found a worker already doing this work (" + getRegion() + ":" + aKey + ")." );
}
if ( !helper.isFinished() )
{
@@ -230,7 +230,7 @@ public class JCSWorker
}
if ( logger.isDebugEnabled() )
{
- logger.debug( "Another thread finished our work for us. Using thoes results instead. ("
+ logger.debug( "Another thread finished our work for us. Using those results instead. ("
+ getRegion() + ":" + aKey + ")." );
}
}
@@ -242,7 +242,6 @@ public class JCSWorker
{
logger.debug( getRegion() + " is doing the work." );
}
- result = null;
// Try to get the item from the cache
if ( aGroup != null )
@@ -256,7 +255,7 @@ public class JCSWorker
// If the cache dosn't have it, do the work.
if ( result == null )
{
- result = aHelper.doWork();
+ result = (Serializable)aHelper.doWork();
if ( logger.isDebugEnabled() )
{
logger.debug( "Work Done, caching: key:" + aKey + ", group:" + aGroup + ", result:" + result + "." );
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/config/IUtilConstants.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/config/IUtilConstants.java?rev=1151575&r1=1151574&r2=1151575&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/config/IUtilConstants.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/config/IUtilConstants.java Wed Jul 27 18:08:23 2011
@@ -49,10 +49,10 @@ public interface IUtilConstants
private final static Log log = LogFactory.getLog( Config.class );
/** username */
- private final static String ADMIN_USERID;
+ protected final static String ADMIN_USERID;
/** password */
- private final static String ADMIN_PASSWORD;
+ protected final static String ADMIN_PASSWORD;
static
{
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/config/OptionConverter.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/config/OptionConverter.java?rev=1151575&r1=1151574&r2=1151575&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/config/OptionConverter.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/config/OptionConverter.java Wed Jul 27 18:08:23 2011
@@ -162,7 +162,7 @@ public class OptionConverter
* @param defaultValue
* @return Object that was created
*/
- public static Object instantiateByKey( Properties props, String key, Class superClass, Object defaultValue )
+ public static Object instantiateByKey( Properties props, String key, Class<?> superClass, Object defaultValue )
{
// Get the value of the property in string form
@@ -317,13 +317,13 @@ public class OptionConverter
* @return instantiated object
*/
- public static Object instantiateByClassName( String className, Class superClass, Object defaultValue )
+ public static Object instantiateByClassName( String className, Class<?> superClass, Object defaultValue )
{
if ( className != null )
{
try
{
- Class classObj = Class.forName( className );
+ Class<?> classObj = Class.forName( className );
if ( !superClass.isAssignableFrom( classObj ) )
{
log.error( "A \"" + className + "\" object is not assignable to a \"" + superClass.getName()
@@ -347,11 +347,11 @@ public class OptionConverter
* The variable substitution delimeters are <b>${ </b> and <b>} </b>.
* <p>
* For example, if the System properties contains "key=value", then the call
- *
+ *
* <pre>
* String s = OptionConverter.substituteVars( "Value of key is ${key}." );
* </pre>
- *
+ *
* will set the variable <code>s</code> to "Value of key is value.".
* <p>
* If no value could be found for the specified key, then the <code>props</code> parameter is
@@ -359,11 +359,11 @@ public class OptionConverter
* string.
* <p>
* For example, if system propeties contains no value for the key "inexistentKey", then the call
- *
+ *
* <pre>
* String s = OptionConverter.subsVars( "Value of inexistentKey is [${inexistentKey}]" );
* </pre>
- *
+ *
* will set <code>s</code> to "Value of inexistentKey is []"
* <p>
* An {@link java.lang.IllegalArgumentException}is thrown if <code>val</code> contains a start
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/config/PropertySetter.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/config/PropertySetter.java?rev=1151575&r1=1151574&r2=1151575&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/config/PropertySetter.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/config/PropertySetter.java Wed Jul 27 18:08:23 2011
@@ -40,14 +40,14 @@ import org.apache.commons.logging.LogFac
* reflection.
* <p>
* Usage:
- *
+ *
* <pre>
* PropertySetter ps = new PropertySetter( anObject );
* ps.set( "name", "Joe" );
* ps.set( "age", "32" );
* ps.set( "isMale", "true" );
* </pre>
- *
+ *
* will cause the invocations anObject.setName("Joe"), anObject.setAge(32), and setMale(true) if
* such methods exist with those signatures. Otherwise an {@link IntrospectionException}are thrown.
*/
@@ -112,7 +112,7 @@ public class PropertySetter
{
int len = prefix.length();
- for ( Enumeration e = properties.propertyNames(); e.hasMoreElements(); )
+ for ( Enumeration<?> e = properties.propertyNames(); e.hasMoreElements(); )
{
String key = (String) e.nextElement();
@@ -195,7 +195,7 @@ public class PropertySetter
{
throw new PropertySetterException( "No setter for property" );
}
- Class[] paramTypes = setter.getParameterTypes();
+ Class<?>[] paramTypes = setter.getParameterTypes();
if ( paramTypes.length != 1 )
{
throw new PropertySetterException( "#params for setter != 1" );
@@ -231,7 +231,7 @@ public class PropertySetter
* @param type
* @return Object
*/
- protected Object convertArg( String val, Class type )
+ protected Object convertArg( String val, Class<?> type )
{
if ( val == null )
{
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/discovery/DiscoveredService.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/discovery/DiscoveredService.java?rev=1151575&r1=1151574&r2=1151575&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/discovery/DiscoveredService.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/discovery/DiscoveredService.java Wed Jul 27 18:08:23 2011
@@ -38,7 +38,7 @@ public class DiscoveredService
private static final long serialVersionUID = -7810164772089509751L;
/** region names */
- private ArrayList cacheNames;
+ private ArrayList<String> cacheNames;
/** service address */
private String serviceAddress;
@@ -52,7 +52,7 @@ public class DiscoveredService
/**
* @param cacheNames the cacheNames to set
*/
- public void setCacheNames( ArrayList cacheNames )
+ public void setCacheNames( ArrayList<String> cacheNames )
{
this.cacheNames = cacheNames;
}
@@ -60,7 +60,7 @@ public class DiscoveredService
/**
* @return the cacheNames
*/
- public ArrayList getCacheNames()
+ public ArrayList<String> getCacheNames()
{
return cacheNames;
}
@@ -114,6 +114,7 @@ public class DiscoveredService
}
/** @return hashcode based on address/port */
+ @Override
public int hashCode()
{
HashCodeBuilder builder = new HashCodeBuilder();
@@ -133,6 +134,7 @@ public class DiscoveredService
* @param otherArg other
* @return equality based on the address/port
*/
+ @Override
public boolean equals( Object otherArg )
{
if ( otherArg instanceof DiscoveredService )
@@ -150,6 +152,7 @@ public class DiscoveredService
/**
* @return string for debugging purposes.
*/
+ @Override
public String toString()
{
StringBuffer buf = new StringBuffer();
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/discovery/UDPCleanupRunner.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/discovery/UDPCleanupRunner.java?rev=1151575&r1=1151574&r2=1151575&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/discovery/UDPCleanupRunner.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/discovery/UDPCleanupRunner.java Wed Jul 27 18:08:23 2011
@@ -20,7 +20,6 @@ package org.apache.jcs.utils.discovery;
*/
import java.util.HashSet;
-import java.util.Iterator;
import java.util.Set;
import org.apache.commons.logging.Log;
@@ -40,13 +39,13 @@ public class UDPCleanupRunner
private static final Log log = LogFactory.getLog( UDPCleanupRunner.class );
/** UDP discovery service */
- private UDPDiscoveryService discoveryService;
+ private final UDPDiscoveryService discoveryService;
/** default for max idle time, in seconds */
private static final long DEFAULT_MAX_IDLE_TIME_SECONDS = 180;
/** The configured max idle time, in seconds */
- private long maxIdleTimeSeconds = DEFAULT_MAX_IDLE_TIME_SECONDS;
+ private final long maxIdleTimeSeconds = DEFAULT_MAX_IDLE_TIME_SECONDS;
/**
* @param service UDPDiscoveryService
@@ -72,13 +71,10 @@ public class UDPCleanupRunner
// html
// TODO this should get a copy. you can't simply remove from this.
// the listeners need to be notified.
- Iterator it = discoveryService.getDiscoveredServices().iterator();
-
- Set toRemove = new HashSet();
+ Set<DiscoveredService> toRemove = new HashSet<DiscoveredService>();
// can't remove via the iterator. must remove directly
- while ( it.hasNext() )
+ for (DiscoveredService service : discoveryService.getDiscoveredServices())
{
- DiscoveredService service = (DiscoveredService) it.next();
if ( ( now - service.getLastHearFromTime() ) > ( maxIdleTimeSeconds * 1000 ) )
{
if ( log.isInfoEnabled() )
@@ -91,11 +87,10 @@ public class UDPCleanupRunner
}
// remove the bad ones
- Iterator toRemoveIt = toRemove.iterator();
- while ( toRemoveIt.hasNext() )
+ for (DiscoveredService service : toRemove)
{
// call this so the listeners get notified
- discoveryService.removeDiscoveredService( (DiscoveredService) toRemoveIt.next() );
+ discoveryService.removeDiscoveredService( service );
}
}
}
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/discovery/UDPDiscoveryManager.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/discovery/UDPDiscoveryManager.java?rev=1151575&r1=1151574&r2=1151575&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/discovery/UDPDiscoveryManager.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/discovery/UDPDiscoveryManager.java Wed Jul 27 18:08:23 2011
@@ -43,7 +43,7 @@ public class UDPDiscoveryManager
private static UDPDiscoveryManager INSTANCE = new UDPDiscoveryManager();
/** Known services */
- private Map services = new HashMap();
+ private final Map<String, UDPDiscoveryService> services = new HashMap<String, UDPDiscoveryService>();
/** private for singleton */
private UDPDiscoveryManager()
@@ -52,7 +52,7 @@ public class UDPDiscoveryManager
}
/**
- * Singelton
+ * Singleton
* <p>
* @return UDPDiscoveryManager
*/
@@ -65,7 +65,7 @@ public class UDPDiscoveryManager
* Creates a service for the address and port if one doesn't exist already.
* <p>
* We need to key this using the listener port too. TODO think of making one discovery service
- * work for mutliple types of clients.
+ * work for multiple types of clients.
* <p>
* @param discoveryAddress
* @param discoveryPort
@@ -80,7 +80,7 @@ public class UDPDiscoveryManager
{
String key = discoveryAddress + ":" + discoveryPort + ":" + servicePort;
- UDPDiscoveryService service = (UDPDiscoveryService) services.get( key );
+ UDPDiscoveryService service = services.get( key );
if ( service == null )
{
if ( log.isInfoEnabled() )
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/discovery/UDPDiscoveryMessage.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/discovery/UDPDiscoveryMessage.java?rev=1151575&r1=1151574&r2=1151575&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/discovery/UDPDiscoveryMessage.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/utils/discovery/UDPDiscoveryMessage.java Wed Jul 27 18:08:23 2011
@@ -21,7 +21,6 @@ package org.apache.jcs.utils.discovery;
import java.io.Serializable;
import java.util.ArrayList;
-import java.util.Iterator;
/**
* The message sent by the discovery mechanism.
@@ -42,11 +41,11 @@ public class UDPDiscoveryMessage
* This asks recipients to broadcast their location. This is used on startup.
*/
public static final int REQUEST_BROADCAST = 1;
-
+
/**
* This message instructs the receiver to remove this service from its list.
*/
- public static final int REMOVE_BROADCAST = 2;
+ public static final int REMOVE_BROADCAST = 2;
/** The message type */
private int messageType = PASSIVE_BROADCAST;
@@ -61,8 +60,8 @@ public class UDPDiscoveryMessage
private long requesterId;
/** Names of regions */
- private ArrayList cacheNames = new ArrayList();
-
+ private ArrayList<String> cacheNames = new ArrayList<String>();
+
/**
* @param port The port to set.
*/
@@ -130,7 +129,7 @@ public class UDPDiscoveryMessage
/**
* @param cacheNames The cacheNames to set.
*/
- public void setCacheNames( ArrayList cacheNames )
+ public void setCacheNames( ArrayList<String> cacheNames )
{
this.cacheNames = cacheNames;
}
@@ -138,14 +137,15 @@ public class UDPDiscoveryMessage
/**
* @return Returns the cacheNames.
*/
- public ArrayList getCacheNames()
+ public ArrayList<String> getCacheNames()
{
return cacheNames;
}
-
+
/**
* @return debugging string
*/
+ @Override
public String toString()
{
StringBuffer buf = new StringBuffer();
@@ -154,10 +154,8 @@ public class UDPDiscoveryMessage
buf.append( "\n requesterId = [" + requesterId + "]" );
buf.append( "\n messageType = [" + messageType + "]" );
buf.append( "\n Cache Names" );
- Iterator it = cacheNames.iterator();
- while ( it.hasNext() )
+ for (String name : cacheNames)
{
- String name = (String) it.next();
buf.append( " cacheName = [" + name + "]" );
}
return buf.toString();