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 [2/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/auxiliary/disk/block/BlockDiskCache.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskCache.java?rev=1151575&r1=1151574&r2=1151575&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskCache.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskCache.java Wed Jul 27 18:08:23 2011
@@ -30,6 +30,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -45,8 +46,6 @@ import org.apache.jcs.engine.stats.Stats
import org.apache.jcs.engine.stats.behavior.IStatElement;
import org.apache.jcs.engine.stats.behavior.IStats;
-import EDU.oswego.cs.dl.util.concurrent.WriterPreferenceReadWriteLock;
-
/**
* There is one BlockDiskCache per region. It manages the key and data store.
* <p>
@@ -59,22 +58,22 @@ public class BlockDiskCache
private static final long serialVersionUID = 1L;
/** The logger. */
- private static final Log log = LogFactory.getLog( BlockDiskCache.class );
+ protected static final Log log = LogFactory.getLog( BlockDiskCache.class );
/** The name to prefix all log messages with. */
private final String logCacheName;
/** The name of the file to store data. */
- private String fileName;
+ private final String fileName;
/** The data access object */
private BlockDisk dataFile;
/** Attributes governing the behavior of the block disk cache. */
- private BlockDiskCacheAttributes blockDiskCacheAttributes;
+ private final BlockDiskCacheAttributes blockDiskCacheAttributes;
/** The root directory for keys and data. */
- private File rootDirectory;
+ private final File rootDirectory;
/** Store, loads, and persists the keys */
private BlockDiskKeyStore keyStore;
@@ -83,7 +82,7 @@ public class BlockDiskCache
* Use this lock to synchronize reads and writes to the underlying storage mechansism. We don't
* need a reentrant lock, since we only lock one level.
*/
- private WriterPreferenceReadWriteLock storageLock = new WriterPreferenceReadWriteLock();
+ private final ReentrantReadWriteLock storageLock = new ReentrantReadWriteLock();
/**
* Constructs the BlockDisk after setting up the root directory.
@@ -174,13 +173,12 @@ public class BlockDiskCache
{
int maxToTest = 100;
int count = 0;
- Set keySet = this.keyStore.entrySet();
- Iterator it = keySet.iterator();
+ Iterator<Map.Entry<Serializable, int[]>> it = this.keyStore.entrySet().iterator();
while ( it.hasNext() && count < maxToTest )
{
count++;
- Map.Entry entry = (Map.Entry) it.next();
- Object data = this.dataFile.read( (int[]) entry.getValue() );
+ Map.Entry<Serializable, int[]> entry = it.next();
+ Object data = this.dataFile.read( entry.getValue() );
if ( data == null )
{
throw new Exception( logCacheName + "Couldn't find data for key [" + entry.getKey() + "]" );
@@ -202,20 +200,20 @@ public class BlockDiskCache
* (non-Javadoc)
* @see org.apache.jcs.auxiliary.disk.AbstractDiskCache#getGroupKeys(java.lang.String)
*/
- public Set getGroupKeys( String groupName )
+ @Override
+ public Set<Serializable> getGroupKeys( String groupName )
{
GroupId groupId = new GroupId( cacheName, groupName );
- HashSet keys = new HashSet();
+ HashSet<Serializable> keys = new HashSet<Serializable>();
try
{
- storageLock.readLock().acquire();
+ storageLock.readLock().lock();
- for ( Iterator itr = this.keyStore.keySet().iterator(); itr.hasNext(); )
+ for ( Serializable key : this.keyStore.keySet())
{
- Object k = itr.next();
- if ( k instanceof GroupAttrName && ( (GroupAttrName) k ).groupId.equals( groupId ) )
+ if ( key instanceof GroupAttrName && ( (GroupAttrName) key ).groupId.equals( groupId ) )
{
- keys.add( ( (GroupAttrName) k ).attrName );
+ keys.add( (Serializable)( (GroupAttrName) key ).attrName );
}
}
}
@@ -225,7 +223,7 @@ public class BlockDiskCache
}
finally
{
- storageLock.readLock().release();
+ storageLock.readLock().unlock();
}
return keys;
@@ -238,28 +236,27 @@ public class BlockDiskCache
* @return a map of Serializable key to ICacheElement element, or an empty map if there is no
* data in cache matching keys
*/
- public Map processGetMatching( String pattern )
+ @Override
+ public Map<Serializable, ICacheElement> processGetMatching( String pattern )
{
- Map elements = new HashMap();
+ Map<Serializable, ICacheElement> elements = new HashMap<Serializable, ICacheElement>();
try
{
Object[] keyArray = null;
- storageLock.readLock().acquire();
+ storageLock.readLock().lock();
try
{
keyArray = this.keyStore.keySet().toArray();
}
finally
{
- storageLock.readLock().release();
+ storageLock.readLock().unlock();
}
- Set matchingKeys = getKeyMatcher().getMatchingKeysFromArray( pattern, keyArray );
+ Set<Serializable> matchingKeys = getKeyMatcher().getMatchingKeysFromArray( pattern, keyArray );
- Iterator keyIterator = matchingKeys.iterator();
- while ( keyIterator.hasNext() )
+ for (Serializable key : matchingKeys)
{
- String key = (String) keyIterator.next();
ICacheElement element = processGet( key );
if ( element != null )
{
@@ -280,6 +277,7 @@ public class BlockDiskCache
* (non-Javadoc)
* @see org.apache.jcs.auxiliary.disk.AbstractDiskCache#getSize()
*/
+ @Override
public int getSize()
{
return this.keyStore.size();
@@ -297,6 +295,7 @@ public class BlockDiskCache
* @return ICacheElement
* @see org.apache.jcs.auxiliary.disk.AbstractDiskCache#doGet(java.io.Serializable)
*/
+ @Override
protected ICacheElement processGet( Serializable key )
{
if ( !alive )
@@ -316,7 +315,7 @@ public class BlockDiskCache
ICacheElement object = null;
try
{
- storageLock.readLock().acquire();
+ storageLock.readLock().lock();
try
{
int[] ded = this.keyStore.get( key );
@@ -327,7 +326,7 @@ public class BlockDiskCache
}
finally
{
- storageLock.readLock().release();
+ storageLock.readLock().unlock();
}
}
catch ( IOException ioe )
@@ -355,6 +354,7 @@ public class BlockDiskCache
* @param element
* @see org.apache.jcs.auxiliary.disk.AbstractDiskCache#doUpdate(org.apache.jcs.engine.behavior.ICacheElement)
*/
+ @Override
protected void processUpdate( ICacheElement element )
{
if ( !alive )
@@ -370,7 +370,7 @@ public class BlockDiskCache
try
{
// make sure this only locks for one particular cache region
- storageLock.writeLock().acquire();
+ storageLock.writeLock().lock();
try
{
old = this.keyStore.get( element.getKey() );
@@ -386,7 +386,7 @@ public class BlockDiskCache
}
finally
{
- storageLock.writeLock().release();
+ storageLock.writeLock().unlock();
}
if ( log.isDebugEnabled() )
@@ -405,7 +405,7 @@ public class BlockDiskCache
}
/**
- * Returns true if the removal was succesful; or false if there is nothing to remove. Current
+ * Returns true if the removal was successful; or false if there is nothing to remove. Current
* implementation always result in a disk orphan.
* <p>
* (non-Javadoc)
@@ -413,6 +413,7 @@ public class BlockDiskCache
* @return true if removed anything
* @see org.apache.jcs.auxiliary.disk.AbstractDiskCache#doRemove(java.io.Serializable)
*/
+ @Override
protected boolean processRemove( Serializable key )
{
if ( !alive )
@@ -428,18 +429,17 @@ public class BlockDiskCache
boolean removed = false;
try
{
- storageLock.writeLock().acquire();
+ storageLock.writeLock().lock();
if ( key instanceof String && key.toString().endsWith( CacheConstants.NAME_COMPONENT_DELIMITER ) )
{
// remove all keys of the same name group.
- Iterator iter = this.keyStore.entrySet().iterator();
+ Iterator<Map.Entry<Serializable, int[]>> iter = this.keyStore.entrySet().iterator();
while ( iter.hasNext() )
{
- Map.Entry entry = (Map.Entry) iter.next();
-
+ Map.Entry<Serializable, int[]> entry = iter.next();
Object k = entry.getKey();
if ( k instanceof String && k.toString().startsWith( key.toString() ) )
@@ -448,17 +448,17 @@ public class BlockDiskCache
this.dataFile.freeBlocks( ded );
iter.remove();
removed = true;
- // TODO this needs to update the rmove count separately
+ // TODO this needs to update the remove count separately
}
}
}
else if ( key instanceof GroupId )
{
// remove all keys of the same name hierarchy.
- Iterator iter = this.keyStore.entrySet().iterator();
+ Iterator<Map.Entry<Serializable, int[]>> iter = this.keyStore.entrySet().iterator();
while ( iter.hasNext() )
{
- Map.Entry entry = (Map.Entry) iter.next();
+ Map.Entry<Serializable, int[]> entry = iter.next();
Object k = entry.getKey();
if ( k instanceof GroupAttrName && ( (GroupAttrName) k ).groupId.equals( key ) )
@@ -494,7 +494,7 @@ public class BlockDiskCache
}
finally
{
- storageLock.writeLock().release();
+ storageLock.writeLock().unlock();
}
if ( reset )
@@ -511,6 +511,7 @@ public class BlockDiskCache
* (non-Javadoc)
* @see org.apache.jcs.auxiliary.disk.AbstractDiskCache#doRemoveAll()
*/
+ @Override
protected void processRemoveAll()
{
try
@@ -530,6 +531,7 @@ public class BlockDiskCache
* <p>
* TODO make dispose window configurable.
*/
+ @Override
public void processDispose()
{
Runnable disR = new Runnable()
@@ -563,7 +565,7 @@ public class BlockDiskCache
* Internal method that handles the disposal.
* @throws InterruptedException
*/
- private void disposeInternal()
+ protected void disposeInternal()
throws InterruptedException
{
if ( !alive )
@@ -571,7 +573,7 @@ public class BlockDiskCache
log.error( logCacheName + "Not alive and dispose was called, filename: " + fileName );
return;
}
- storageLock.writeLock().acquire();
+ storageLock.writeLock().lock();
try
{
// Prevents any interaction with the cache while we're shutting down.
@@ -599,7 +601,7 @@ public class BlockDiskCache
}
finally
{
- storageLock.writeLock().release();
+ storageLock.writeLock().unlock();
}
if ( log.isInfoEnabled() )
@@ -633,7 +635,7 @@ public class BlockDiskCache
try
{
- storageLock.writeLock().acquire();
+ storageLock.writeLock().lock();
if ( dataFile != null )
{
@@ -661,7 +663,7 @@ public class BlockDiskCache
}
finally
{
- storageLock.writeLock().release();
+ storageLock.writeLock().unlock();
}
}
@@ -680,6 +682,7 @@ public class BlockDiskCache
* <p>
* @return String
*/
+ @Override
public String getStats()
{
return getStatistics().toString();
@@ -691,12 +694,13 @@ public class BlockDiskCache
* (non-Javadoc)
* @see org.apache.jcs.auxiliary.AuxiliaryCache#getStatistics()
*/
+ @Override
public IStats getStatistics()
{
IStats stats = new Stats();
stats.setTypeName( "Block Disk Cache" );
- ArrayList elems = new ArrayList();
+ ArrayList<IStatElement> elems = new ArrayList<IStatElement>();
IStatElement se = null;
@@ -753,11 +757,11 @@ public class BlockDiskCache
// get as array, convert to list, add list to our outer list
IStats sStats = super.getStatistics();
IStatElement[] sSEs = sStats.getStatElements();
- List sL = Arrays.asList( sSEs );
+ List<IStatElement> sL = Arrays.asList( sSEs );
elems.addAll( sL );
// 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;
@@ -768,6 +772,7 @@ public class BlockDiskCache
* <p>
* @return the location of the disk, either path or ip.
*/
+ @Override
protected String getDiskLocation()
{
return dataFile.getFilePath();
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskCacheManager.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskCacheManager.java?rev=1151575&r1=1151574&r2=1151575&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskCacheManager.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskCacheManager.java Wed Jul 27 18:08:23 2011
@@ -44,10 +44,10 @@ public class BlockDiskCacheManager
private static BlockDiskCacheManager instance;
/** block disks for a region. */
- private Hashtable caches = new Hashtable();
+ private final Hashtable<String, AuxiliaryCache> caches = new Hashtable<String, AuxiliaryCache>();
/** Attributes. */
- private BlockDiskCacheAttributes defaultCacheAttributes;
+ private final BlockDiskCacheAttributes defaultCacheAttributes;
/**
* Constructor for the BlockDiskCacheManager object
@@ -122,7 +122,7 @@ public class BlockDiskCacheManager
// Try to load the cache from the set that have already been
// created. This only looks at the name attribute.
- cache = (AuxiliaryCache) caches.get( cacheName );
+ cache = caches.get( cacheName );
// If it was not found, create a new one using the supplied
// attributes
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskKeyStore.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskKeyStore.java?rev=1151575&r1=1151574&r2=1151575&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskKeyStore.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskKeyStore.java Wed Jul 27 18:08:23 2011
@@ -29,18 +29,18 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.HashMap;
-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;
import org.apache.jcs.auxiliary.disk.LRUMapJCS;
import org.apache.jcs.utils.timing.ElapsedTimer;
-import EDU.oswego.cs.dl.util.concurrent.ClockDaemon;
-import EDU.oswego.cs.dl.util.concurrent.ThreadFactory;
-
/**
* This is responsible for storing the keys.
* <p>
@@ -49,36 +49,36 @@ import EDU.oswego.cs.dl.util.concurrent.
public class BlockDiskKeyStore
{
/** The logger */
- private static final Log log = LogFactory.getLog( BlockDiskKeyStore.class );
+ protected static final Log log = LogFactory.getLog( BlockDiskKeyStore.class );
/** Attributes governing the behavior of the block disk cache. */
- private BlockDiskCacheAttributes blockDiskCacheAttributes;
+ private final BlockDiskCacheAttributes blockDiskCacheAttributes;
/** The key to block map */
- private Map keyHash;
+ private Map<Serializable, int[]> keyHash;
/** The file where we persist the keys */
private File keyFile;
/** The name to prefix log messages with. */
- private final String logCacheName;
+ protected final String logCacheName;
/** Name of the file where we persist the keys */
- private String fileName;
+ private final String fileName;
/** The maximum number of keys to store in memory */
- private int maxKeySize;
+ private final int maxKeySize;
/** we need this so we can communicate free blocks to the data store when keys fall off the LRU */
- private BlockDiskCache blockDiskCache;
+ protected final BlockDiskCache blockDiskCache;
/** The root directory in which the keyFile lives */
- private File rootDirectory;
+ private final File rootDirectory;
/**
* The background key persister, one for all regions.
*/
- private static ClockDaemon persistenceDaemon;
+ private static ScheduledExecutorService persistenceDaemon;
/**
* Set the configuration options.
@@ -128,18 +128,20 @@ public class BlockDiskKeyStore
{
if ( persistenceDaemon == null )
{
- persistenceDaemon = new ClockDaemon();
- persistenceDaemon.setThreadFactory( new MyThreadFactory() );
+ persistenceDaemon = Executors.newScheduledThreadPool(1, new MyThreadFactory());
}
+
persistenceDaemon
- .executePeriodically( this.blockDiskCacheAttributes.getKeyPersistenceIntervalSeconds() * 1000,
- new Runnable()
- {
- public void run()
- {
- saveKeys();
- }
- }, false );
+ .scheduleAtFixedRate(new Runnable()
+ {
+ public void run()
+ {
+ saveKeys();
+ }
+ },
+ 0,
+ this.blockDiskCacheAttributes.getKeyPersistenceIntervalSeconds(),
+ TimeUnit.SECONDS);
}
}
@@ -168,13 +170,11 @@ public class BlockDiskKeyStore
try
{
// don't need to synchronize, since the underlying collection makes a copy
- Iterator keyIt = keyHash.entrySet().iterator();
- while ( keyIt.hasNext() )
+ for (Map.Entry<Serializable, int[]> entry : keyHash.entrySet())
{
- Map.Entry entry = (Map.Entry) keyIt.next();
BlockDiskElementDescriptor descriptor = new BlockDiskElementDescriptor();
- descriptor.setKey( (Serializable) entry.getKey() );
- descriptor.setBlocks( (int[]) entry.getValue() );
+ descriptor.setKey( entry.getKey() );
+ descriptor.setBlocks( entry.getValue() );
// stream these out in the loop.
oos.writeObject( descriptor );
}
@@ -235,7 +235,7 @@ public class BlockDiskKeyStore
else
{
// If no max size, use a plain map for memory and processing efficiency.
- keyHash = new HashMap();
+ keyHash = new HashMap<Serializable, int[]>();
// keyHash = Collections.synchronizedMap( new HashMap() );
if ( log.isInfoEnabled() )
{
@@ -263,7 +263,7 @@ public class BlockDiskKeyStore
// create a key map to use.
initKeyMap();
- HashMap keys = new HashMap();
+ HashMap<Serializable, int[]> keys = new HashMap<Serializable, int[]>();
FileInputStream fis = new FileInputStream( keyFile );
BufferedInputStream bis = new BufferedInputStream( fis );
@@ -315,7 +315,7 @@ public class BlockDiskKeyStore
* <p>
* @return entry set.
*/
- public Set entrySet()
+ public Set<Map.Entry<Serializable, int[]>> entrySet()
{
return this.keyHash.entrySet();
}
@@ -325,7 +325,7 @@ public class BlockDiskKeyStore
* <p>
* @return key set.
*/
- public Set keySet()
+ public Set<Serializable> keySet()
{
return this.keyHash.keySet();
}
@@ -348,7 +348,7 @@ public class BlockDiskKeyStore
*/
public int[] get( Object key )
{
- return (int[]) this.keyHash.get( key );
+ return this.keyHash.get( key );
}
/**
@@ -357,7 +357,7 @@ public class BlockDiskKeyStore
* @param key
* @param value
*/
- public void put( Object key, int[] value )
+ public void put( Serializable key, int[] value )
{
this.keyHash.put( key, value );
}
@@ -370,7 +370,7 @@ public class BlockDiskKeyStore
*/
public int[] remove( Object key )
{
- return (int[]) this.keyHash.remove( key );
+ return this.keyHash.remove( key );
}
/**
@@ -378,7 +378,7 @@ public class BlockDiskKeyStore
* blocks as free.
*/
public class LRUMap
- extends LRUMapJCS
+ extends LRUMapJCS<Serializable, int[]>
{
/** Don't change */
private static final long serialVersionUID = 4955079991472142198L;
@@ -411,9 +411,10 @@ public class BlockDiskKeyStore
* @param key
* @param value
*/
- protected void processRemovedLRU( Object key, Object value )
+ @Override
+ protected void processRemovedLRU( Serializable key, int[] value )
{
- blockDiskCache.freeBlocks( (int[]) value );
+ blockDiskCache.freeBlocks( value );
if ( log.isDebugEnabled() )
{
log.debug( logCacheName + "Removing key: [" + key + "] from key store." );
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/file/FileDiskCache.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/file/FileDiskCache.java?rev=1151575&r1=1151574&r2=1151575&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/file/FileDiskCache.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/file/FileDiskCache.java Wed Jul 27 18:08:23 2011
@@ -41,7 +41,7 @@ public class FileDiskCache
private final String logCacheName;
/** The config values. */
- private FileDiskCacheAttributes diskFileCacheAttributes;
+ private final FileDiskCacheAttributes diskFileCacheAttributes;
/** The directory where the files are stored */
private File directory;
@@ -69,7 +69,7 @@ public class FileDiskCache
setElementSerializer( elementSerializer );
this.diskFileCacheAttributes = cattr;
this.logCacheName = "Region [" + getCacheName() + "] ";
- alive = initializeFileSystem( cattr );;
+ alive = initializeFileSystem( cattr );
}
/**
@@ -138,7 +138,8 @@ public class FileDiskCache
* @param groupName
* @return Set
*/
- public Set getGroupKeys( String groupName )
+ @Override
+ public Set<Serializable> getGroupKeys(String groupName)
{
throw new UnsupportedOperationException();
}
@@ -146,6 +147,7 @@ public class FileDiskCache
/**
* @return dir.list().length
*/
+ @Override
public int getSize()
{
if ( getDirectory().exists() )
@@ -166,6 +168,7 @@ public class FileDiskCache
/**
* @return String the path to the directory
*/
+ @Override
protected String getDiskLocation()
{
return getDirectory().getAbsolutePath();
@@ -176,6 +179,7 @@ public class FileDiskCache
* <p>
* @throws IOException
*/
+ @Override
protected synchronized void processDispose()
throws IOException
{
@@ -210,6 +214,7 @@ public class FileDiskCache
* @return ICacheElement
* @throws IOException
*/
+ @Override
protected ICacheElement processGet( Serializable key )
throws IOException
{
@@ -287,7 +292,8 @@ public class FileDiskCache
* @return Map
* @throws IOException
*/
- protected Map processGetMatching( String pattern )
+ @Override
+ protected Map<Serializable, ICacheElement> processGetMatching( String pattern )
throws IOException
{
// TODO get a list of file and return those with matching keys.
@@ -302,6 +308,7 @@ public class FileDiskCache
* @return true if the item was removed
* @throws IOException
*/
+ @Override
protected boolean processRemove( Serializable key )
throws IOException
{
@@ -321,6 +328,7 @@ public class FileDiskCache
* <p>
* @throws IOException
*/
+ @Override
protected void processRemoveAll()
throws IOException
{
@@ -338,6 +346,7 @@ public class FileDiskCache
* @param element
* @throws IOException
*/
+ @Override
protected void processUpdate( ICacheElement element )
throws IOException
{
@@ -459,7 +468,7 @@ public class FileDiskCache
}
return success;
}
-
+
/**
* Tries to set the last access time to now.
* <p>
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/file/FileDiskCacheManager.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/file/FileDiskCacheManager.java?rev=1151575&r1=1151574&r2=1151575&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/file/FileDiskCacheManager.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/file/FileDiskCacheManager.java Wed Jul 27 18:08:23 2011
@@ -22,10 +22,10 @@ public class FileDiskCacheManager
private final static Log log = LogFactory.getLog( FileDiskCacheManager.class );
/** Each region has an entry here. */
- private Hashtable caches = new Hashtable();
+ private final Hashtable<String, AuxiliaryCache> caches = new Hashtable<String, AuxiliaryCache>();
/** User configurable attributes */
- private FileDiskCacheAttributes defaultCacheAttributes;
+ private final FileDiskCacheAttributes defaultCacheAttributes;
/**
* Constructor for the DiskFileCacheManager object
@@ -77,7 +77,7 @@ public class FileDiskCacheManager
// Try to load the cache from the set that have already been
// created. This only looks at the name attribute.
- cache = (AuxiliaryCache) caches.get( cacheName );
+ cache = caches.get( cacheName );
// If it was not found, create a new one using the supplied
// attributes
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCache.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCache.java?rev=1151575&r1=1151574&r2=1151575&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCache.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCache.java Wed Jul 27 18:08:23 2011
@@ -34,6 +34,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -54,8 +55,6 @@ import org.apache.jcs.engine.stats.behav
import org.apache.jcs.utils.struct.SortedPreferentialArray;
import org.apache.jcs.utils.timing.ElapsedTimer;
-import EDU.oswego.cs.dl.util.concurrent.ReentrantWriterPreferenceReadWriteLock;
-
/**
* Disk cache that uses a RandomAccessFile with keys stored in memory. The maximum number of keys
* stored in memory is configurable. The disk cache tries to recycle spots on disk to limit file
@@ -68,13 +67,13 @@ public class IndexedDiskCache
private static final long serialVersionUID = -265035607729729629L;
/** The logger */
- private static final Log log = LogFactory.getLog( IndexedDiskCache.class );
+ protected static final Log log = LogFactory.getLog( IndexedDiskCache.class );
/** Cache name used in log messages */
- private final String logCacheName;
+ protected final String logCacheName;
/** The name of the file where the data is stored */
- private String fileName;
+ private final String fileName;
/** The IndexedDisk manages reads and writes to the data file. */
private IndexedDisk dataFile;
@@ -83,10 +82,10 @@ public class IndexedDiskCache
private IndexedDisk keyFile;
/** Map containing the keys and disk offsets. */
- private Map keyHash;
+ private Map<Serializable, IndexedDiskElementDescriptor> keyHash;
/** The maximum number of keys that we will keep in memory. */
- private int maxKeySize;
+ private final int maxKeySize;
/** A handle on the data file. */
private File rafDir;
@@ -103,11 +102,11 @@ public class IndexedDiskCache
/** are we currently optimizing the files */
boolean isOptimizing = false;
- /** The numer of times the file has been optimized. */
+ /** The number of times the file has been optimized. */
private int timesOptimized = 0;
/** The thread optimizing the file. */
- private volatile Thread currentOptimizationThread;
+ protected volatile Thread currentOptimizationThread;
/** used for counting the number of requests */
private int removeCount = 0;
@@ -116,13 +115,14 @@ public class IndexedDiskCache
private boolean queueInput = false;
/** list where puts made during optimization are made */
- private LinkedList queuedPutList = new LinkedList();
+ private final LinkedList<IndexedDiskElementDescriptor> queuedPutList =
+ new LinkedList<IndexedDiskElementDescriptor>();
/** RECYLCE BIN -- array of empty spots */
- private SortedPreferentialArray recycle;
+ private SortedPreferentialArray<IndexedDiskElementDescriptor> recycle;
/** User configurable parameters */
- private IndexedDiskCacheAttributes cattr;
+ private final IndexedDiskCacheAttributes cattr;
/** How many slots have we recycled. */
private int recycleCnt = 0;
@@ -139,7 +139,7 @@ public class IndexedDiskCache
/**
* Use this lock to synchronize reads and writes to the underlying storage mechansism.
*/
- protected ReentrantWriterPreferenceReadWriteLock storageLock = new ReentrantWriterPreferenceReadWriteLock();
+ protected ReentrantReadWriteLock storageLock = new ReentrantReadWriteLock();
/**
* Constructor for the DiskCache object.
@@ -313,7 +313,7 @@ public class IndexedDiskCache
protected void loadKeys()
throws InterruptedException
{
- storageLock.writeLock().acquire();
+ storageLock.writeLock().lock();
if ( log.isDebugEnabled() )
{
@@ -325,7 +325,8 @@ public class IndexedDiskCache
// create a key map to use.
initializeKeyMap();
- HashMap keys = (HashMap) keyFile.readObject( new IndexedDiskElementDescriptor( 0, (int) keyFile.length()
+ HashMap<Serializable, IndexedDiskElementDescriptor> keys =
+ (HashMap<Serializable, IndexedDiskElementDescriptor>) keyFile.readObject( new IndexedDiskElementDescriptor( 0, (int) keyFile.length()
- IndexedDisk.RECORD_HEADER ) );
if ( keys != null )
@@ -355,7 +356,7 @@ public class IndexedDiskCache
}
finally
{
- storageLock.writeLock().release();
+ storageLock.writeLock().unlock();
}
}
@@ -379,11 +380,9 @@ public class IndexedDiskCache
{
fileLength = dataFile.length();
- Iterator itr = keyHash.entrySet().iterator();
- while ( itr.hasNext() )
+ for (Map.Entry<Serializable, IndexedDiskElementDescriptor> e : keyHash.entrySet())
{
- Map.Entry e = (Map.Entry) itr.next();
- IndexedDiskElementDescriptor ded = (IndexedDiskElementDescriptor) e.getValue();
+ IndexedDiskElementDescriptor ded = e.getValue();
isOk = ( ded.pos + IndexedDisk.RECORD_HEADER + ded.len <= fileLength );
@@ -452,7 +451,7 @@ public class IndexedDiskCache
}
/**
- * Saves key file to disk. This converts the LRUMap to a HashMap for deserialzation.
+ * Saves key file to disk. This converts the LRUMap to a HashMap for deserialization.
*/
protected void saveKeys()
{
@@ -465,7 +464,8 @@ public class IndexedDiskCache
keyFile.reset();
- HashMap keys = new HashMap();
+ HashMap<Serializable, IndexedDiskElementDescriptor> keys =
+ new HashMap<Serializable, IndexedDiskElementDescriptor>();
keys.putAll( keyHash );
if ( keys.size() > 0 )
@@ -490,6 +490,7 @@ public class IndexedDiskCache
* <p>
* @param ce The ICacheElement to put to disk.
*/
+ @Override
protected void processUpdate( ICacheElement ce )
{
if ( !alive )
@@ -513,10 +514,10 @@ public class IndexedDiskCache
byte[] data = getElementSerializer().serialize( ce );
// make sure this only locks for one particular cache region
- storageLock.writeLock().acquire();
+ storageLock.writeLock().lock();
try
{
- old = (IndexedDiskElementDescriptor) keyHash.get( ce.getKey() );
+ old = keyHash.get( ce.getKey() );
// Item with the same key already exists in file.
// Try to reuse the location if possible.
@@ -534,7 +535,7 @@ public class IndexedDiskCache
if ( doRecycle )
{
- IndexedDiskElementDescriptor rep = (IndexedDiskElementDescriptor) recycle
+ IndexedDiskElementDescriptor rep = recycle
.takeNearestLargerOrEqual( ded );
if ( rep != null )
{
@@ -573,7 +574,7 @@ public class IndexedDiskCache
}
finally
{
- storageLock.writeLock().release();
+ storageLock.writeLock().unlock();
}
if ( log.isDebugEnabled() )
@@ -605,6 +606,7 @@ public class IndexedDiskCache
* @return ICacheElement or null
* @see AbstractDiskCache#doGet
*/
+ @Override
protected ICacheElement processGet( Serializable key )
{
if ( !alive )
@@ -621,14 +623,14 @@ public class IndexedDiskCache
ICacheElement object = null;
try
{
- storageLock.readLock().acquire();
+ storageLock.readLock().lock();
try
{
object = readElement( key );
}
finally
{
- storageLock.readLock().release();
+ storageLock.readLock().unlock();
}
if ( object != null )
@@ -655,28 +657,27 @@ public class IndexedDiskCache
* @return a map of Serializable key to ICacheElement element, or an empty map if there is no
* data in cache matching keys
*/
- public Map processGetMatching( String pattern )
+ @Override
+ public Map<Serializable, ICacheElement> processGetMatching( String pattern )
{
- Map elements = new HashMap();
+ Map<Serializable, ICacheElement> elements = new HashMap<Serializable, ICacheElement>();
try
{
Object[] keyArray = null;
- storageLock.readLock().acquire();
+ storageLock.readLock().lock();
try
{
keyArray = keyHash.keySet().toArray();
}
finally
{
- storageLock.readLock().release();
+ storageLock.readLock().unlock();
}
- Set matchingKeys = getKeyMatcher().getMatchingKeysFromArray( pattern, keyArray );
+ Set<Serializable> matchingKeys = getKeyMatcher().getMatchingKeysFromArray( pattern, keyArray );
- Iterator keyIterator = matchingKeys.iterator();
- while ( keyIterator.hasNext() )
+ for (Serializable key : matchingKeys)
{
- String key = (String) keyIterator.next();
ICacheElement element = processGet( key );
if ( element != null )
{
@@ -703,7 +704,7 @@ public class IndexedDiskCache
{
ICacheElement object = null;
- IndexedDiskElementDescriptor ded = (IndexedDiskElementDescriptor) keyHash.get( key );
+ IndexedDiskElementDescriptor ded = keyHash.get( key );
if ( ded != null )
{
@@ -736,22 +737,20 @@ public class IndexedDiskCache
* <p>
* @see org.apache.jcs.auxiliary.AuxiliaryCache#getGroupKeys(java.lang.String)
*/
- public Set getGroupKeys( String groupName )
+ @Override
+ public Set<Serializable> getGroupKeys( String groupName )
{
GroupId groupId = new GroupId( cacheName, groupName );
- HashSet keys = new HashSet();
+ HashSet<Serializable> keys = new HashSet<Serializable>();
try
{
- storageLock.readLock().acquire();
+ storageLock.readLock().lock();
- for ( Iterator itr = keyHash.keySet().iterator(); itr.hasNext(); )
+ for (Serializable k : keyHash.keySet())
{
- // Map.Entry entry = (Map.Entry) itr.next();
- // Object k = entry.getKey();
- Object k = itr.next();
if ( k instanceof GroupAttrName && ( (GroupAttrName) k ).groupId.equals( groupId ) )
{
- keys.add( ( (GroupAttrName) k ).attrName );
+ keys.add( (Serializable) ( (GroupAttrName) k ).attrName );
}
}
}
@@ -761,7 +760,7 @@ public class IndexedDiskCache
}
finally
{
- storageLock.readLock().release();
+ storageLock.readLock().unlock();
}
return keys;
@@ -774,6 +773,7 @@ public class IndexedDiskCache
* @return true if at least one item was removed.
* @param key
*/
+ @Override
protected boolean processRemove( Serializable key )
{
if ( !alive )
@@ -791,7 +791,7 @@ public class IndexedDiskCache
boolean removed = false;
try
{
- storageLock.writeLock().acquire();
+ storageLock.writeLock().lock();
if ( key instanceof String && key.toString().endsWith( CacheConstants.NAME_COMPONENT_DELIMITER ) )
{
@@ -813,7 +813,7 @@ public class IndexedDiskCache
}
finally
{
- storageLock.writeLock().release();
+ storageLock.writeLock().unlock();
}
if ( reset )
@@ -845,13 +845,10 @@ public class IndexedDiskCache
boolean removed = false;
// remove all keys of the same name hierarchy.
- List itemsToRemove = new LinkedList();
+ List<Serializable> itemsToRemove = new LinkedList<Serializable>();
- Iterator iter = keyHash.entrySet().iterator();
- while ( iter.hasNext() )
+ for (Serializable k : keyHash.keySet())
{
- Map.Entry entry = (Map.Entry) iter.next();
- Object k = entry.getKey();
if ( k instanceof String && k.toString().startsWith( key.toString() ) )
{
itemsToRemove.add( k );
@@ -859,10 +856,8 @@ public class IndexedDiskCache
}
// remove matches.
- Iterator itToRemove = itemsToRemove.iterator();
- while ( itToRemove.hasNext() )
+ for (Serializable fullKey : itemsToRemove)
{
- String fullKey = (String) itToRemove.next();
// Don't add to recycle bin here
// https://issues.apache.org/jira/browse/JCS-67
performSingleKeyRemoval( fullKey );
@@ -875,7 +870,7 @@ public class IndexedDiskCache
/**
* Remove all elements from the group. This does not use the iterator to remove. It builds a
- * list of group elemetns and then removes them one by one.
+ * list of group elements and then removes them one by one.
* <p>
* This operates under a lock obtained in doRemove().
* <p>
@@ -887,15 +882,11 @@ public class IndexedDiskCache
boolean removed = false;
// remove all keys of the same name group.
- List itemsToRemove = new LinkedList();
+ List<Serializable> itemsToRemove = new LinkedList<Serializable>();
// remove all keys of the same name hierarchy.
- Iterator iter = keyHash.entrySet().iterator();
- while ( iter.hasNext() )
+ for (Serializable k : keyHash.keySet())
{
- Map.Entry entry = (Map.Entry) iter.next();
- Object k = entry.getKey();
-
if ( k instanceof GroupAttrName && ( (GroupAttrName) k ).groupId.equals( key ) )
{
itemsToRemove.add( k );
@@ -903,15 +894,15 @@ public class IndexedDiskCache
}
// remove matches.
- Iterator itToRemove = itemsToRemove.iterator();
- while ( itToRemove.hasNext() )
+ for (Serializable fullKey : itemsToRemove)
{
- GroupAttrName keyToRemove = (GroupAttrName) itToRemove.next();
// Don't add to recycle bin here
- // https://issues.apache.org/jira/browse/JCS-67
- performSingleKeyRemoval( keyToRemove );
+ // https://issues.apache.org/jira/browse/JCS-67
+ performSingleKeyRemoval( fullKey );
removed = true;
+ // TODO this needs to update the remove count separately
}
+
return removed;
}
@@ -927,7 +918,7 @@ public class IndexedDiskCache
{
boolean removed;
// remove single item.
- IndexedDiskElementDescriptor ded = (IndexedDiskElementDescriptor) keyHash.remove( key );
+ IndexedDiskElementDescriptor ded = keyHash.remove( key );
removed = ( ded != null );
addToRecycleBin( ded );
@@ -941,6 +932,7 @@ public class IndexedDiskCache
/**
* Remove all the items from the disk cache by reseting everything.
*/
+ @Override
public void processRemoveAll()
{
ICacheEvent cacheEvent = createICacheEvent( cacheName, "all", ICacheEventLogger.REMOVEALL_EVENT );
@@ -973,7 +965,7 @@ public class IndexedDiskCache
try
{
- storageLock.writeLock().acquire();
+ storageLock.writeLock().lock();
if ( dataFile != null )
{
@@ -1003,7 +995,7 @@ public class IndexedDiskCache
}
finally
{
- storageLock.writeLock().release();
+ storageLock.writeLock().unlock();
}
}
@@ -1014,7 +1006,7 @@ public class IndexedDiskCache
private void initializeRecycleBin()
{
int recycleBinSize = cattr.getMaxRecycleBinSize() >= 0 ? cattr.getMaxRecycleBinSize() : 0;
- recycle = new SortedPreferentialArray( recycleBinSize );
+ recycle = new SortedPreferentialArray<IndexedDiskElementDescriptor>( recycleBinSize );
if ( log.isDebugEnabled() )
{
log.debug( logCacheName + "Set recycle max Size to MaxRecycleBinSize: '" + recycleBinSize + "'" );
@@ -1038,7 +1030,7 @@ public class IndexedDiskCache
else
{
// If no max size, use a plain map for memory and processing efficiency.
- keyHash = new HashMap();
+ keyHash = new HashMap<Serializable, IndexedDiskElementDescriptor>();
// keyHash = Collections.synchronizedMap( new HashMap() );
if ( log.isInfoEnabled() )
{
@@ -1053,6 +1045,7 @@ public class IndexedDiskCache
* <p>
* TODO make dispose window configurable.
*/
+ @Override
public void processDispose()
{
ICacheEvent cacheEvent = createICacheEvent( cacheName, "none", ICacheEventLogger.DISPOSE_EVENT );
@@ -1086,7 +1079,7 @@ public class IndexedDiskCache
/**
* Internal method that handles the disposal.
*/
- private void disposeInternal()
+ protected void disposeInternal()
{
if ( !alive )
{
@@ -1156,7 +1149,7 @@ public class IndexedDiskCache
* <p>
* @param ded
*/
- private void addToRecycleBin( IndexedDiskElementDescriptor ded )
+ protected void addToRecycleBin( IndexedDiskElementDescriptor ded )
{
// reuse the spot
if ( ded != null )
@@ -1178,7 +1171,7 @@ public class IndexedDiskCache
/**
* Performs the check for optimization, and if it is required, do it.
*/
- private void doOptimizeRealTime()
+ protected void doOptimizeRealTime()
{
if ( isRealTimeOptimizationEnabled && !isOptimizing && ( removeCount++ >= cattr.getOptimizeAtRemoveCount() ) )
{
@@ -1192,31 +1185,22 @@ public class IndexedDiskCache
if ( currentOptimizationThread == null )
{
- try
+ storageLock.writeLock().lock();
+ if ( currentOptimizationThread == null )
{
- storageLock.writeLock().acquire();
- if ( currentOptimizationThread == null )
+ currentOptimizationThread = new Thread( new Runnable()
{
- currentOptimizationThread = new Thread( new Runnable()
+ public void run()
{
- public void run()
- {
- optimizeFile();
+ optimizeFile();
- currentOptimizationThread = null;
- }
- }, "IndexedDiskCache-OptimizationThread" );
- }
- }
- catch ( InterruptedException e )
- {
- log.error( logCacheName + "Unable to aquire storage write lock.", e );
- }
- finally
- {
- storageLock.writeLock().release();
+ currentOptimizationThread = null;
+ }
+ }, "IndexedDiskCache-OptimizationThread" );
}
+ storageLock.writeLock().unlock();
+
if ( currentOptimizationThread != null )
{
currentOptimizationThread.start();
@@ -1252,21 +1236,14 @@ public class IndexedDiskCache
// CREATE SNAPSHOT
IndexedDiskElementDescriptor[] defragList = null;
- try
- {
- storageLock.writeLock().acquire();
- queueInput = true;
- // shut off recycle while we're optimizing,
- doRecycle = false;
- defragList = createPositionSortedDescriptorList();
- // Release iff I aquired.
- storageLock.writeLock().release();
- }
- catch ( InterruptedException e )
- {
- log.error( logCacheName + "Error setting up optimization.", e );
- return;
- }
+
+ storageLock.writeLock().lock();
+ queueInput = true;
+ // shut off recycle while we're optimizing,
+ doRecycle = false;
+ defragList = createPositionSortedDescriptorList();
+ // Release if I acquired.
+ storageLock.writeLock().unlock();
// Defrag the file outside of the write lock. This allows a move to be made,
// and yet have the element still accessible for reading or writing.
@@ -1275,11 +1252,11 @@ public class IndexedDiskCache
// ADD THE QUEUED ITEMS to the end and then truncate
try
{
- storageLock.writeLock().acquire();
+ storageLock.writeLock().lock();
if ( !queuedPutList.isEmpty() )
{
- // This is perhaps unecessary, but the list might not be as sorted as we think.
+ // This is perhaps unnecessary, but the list might not be as sorted as we think.
defragList = new IndexedDiskElementDescriptor[queuedPutList.size()];
queuedPutList.toArray( defragList );
Arrays.sort( defragList, new PositionComparator() );
@@ -1306,7 +1283,7 @@ public class IndexedDiskCache
doRecycle = true;
isOptimizing = false;
- storageLock.writeLock().release();
+ storageLock.writeLock().unlock();
}
if ( log.isInfoEnabled() )
@@ -1338,7 +1315,7 @@ public class IndexedDiskCache
expectedNextPos = startingPos;
for ( int i = 0; i < defragList.length; i++ )
{
- storageLock.writeLock().acquire();
+ storageLock.writeLock().lock();
try
{
if ( expectedNextPos != defragList[i].pos )
@@ -1349,7 +1326,7 @@ public class IndexedDiskCache
}
finally
{
- storageLock.writeLock().release();
+ storageLock.writeLock().unlock();
}
}
@@ -1362,10 +1339,6 @@ public class IndexedDiskCache
{
log.error( logCacheName + "Error occurred during defragmentation.", e );
}
- catch ( InterruptedException e )
- {
- log.error( logCacheName + "Threading problem", e );
- }
finally
{
if ( log.isInfoEnabled() )
@@ -1390,11 +1363,11 @@ public class IndexedDiskCache
private IndexedDiskElementDescriptor[] createPositionSortedDescriptorList()
{
IndexedDiskElementDescriptor[] defragList = new IndexedDiskElementDescriptor[keyHash.size()];
- Iterator iterator = keyHash.entrySet().iterator();
+ Iterator<Map.Entry<Serializable, IndexedDiskElementDescriptor>> iterator = keyHash.entrySet().iterator();
for ( int i = 0; iterator.hasNext(); i++ )
{
- Object next = iterator.next();
- defragList[i] = (IndexedDiskElementDescriptor) ( (Map.Entry) next ).getValue();
+ Map.Entry<Serializable, IndexedDiskElementDescriptor> next = iterator.next();
+ defragList[i] = next.getValue();
}
Arrays.sort( defragList, new PositionComparator() );
@@ -1407,6 +1380,7 @@ public class IndexedDiskCache
* <p>
* @return The size value
*/
+ @Override
public int getSize()
{
return keyHash.size();
@@ -1477,22 +1451,13 @@ public class IndexedDiskCache
{
long size = 0;
- try
- {
- storageLock.readLock().acquire();
- if ( dataFile != null )
- {
- size = dataFile.length();
- }
- }
- catch ( InterruptedException e )
+ storageLock.readLock().lock();
+ if ( dataFile != null )
{
- // nothing
- }
- finally
- {
- storageLock.readLock().release();
+ size = dataFile.length();
}
+ storageLock.readLock().unlock();
+
return size;
}
@@ -1515,13 +1480,10 @@ public class IndexedDiskCache
{
log.debug( logCacheName + "[dump] Number of keys: " + keyHash.size() );
- Iterator itr = keyHash.entrySet().iterator();
-
- while ( itr.hasNext() )
+ for (Map.Entry<Serializable, IndexedDiskElementDescriptor> e : keyHash.entrySet())
{
- Map.Entry e = (Map.Entry) itr.next();
- Serializable key = (Serializable) e.getKey();
- IndexedDiskElementDescriptor ded = (IndexedDiskElementDescriptor) e.getValue();
+ Serializable key = e.getKey();
+ IndexedDiskElementDescriptor ded = e.getValue();
log.debug( logCacheName + "[dump] Disk element, key: " + key + ", pos: " + ded.pos + ", ded.len"
+ ded.len + ( ( dumpValues ) ? ( ", val: " + get( key ) ) : "" ) );
@@ -1550,6 +1512,7 @@ public class IndexedDiskCache
* <p>
* @return String
*/
+ @Override
public String getStats()
{
return getStatistics().toString();
@@ -1561,12 +1524,13 @@ public class IndexedDiskCache
* (non-Javadoc)
* @see org.apache.jcs.auxiliary.AuxiliaryCache#getStatistics()
*/
+ @Override
public synchronized IStats getStatistics()
{
IStats stats = new Stats();
stats.setTypeName( "Indexed Disk Cache" );
- ArrayList elems = new ArrayList();
+ ArrayList<IStatElement> elems = new ArrayList<IStatElement>();
IStatElement se = null;
@@ -1645,11 +1609,11 @@ public class IndexedDiskCache
// get as array, convert to list, add list to our outer list
IStats sStats = super.getStatistics();
IStatElement[] sSEs = sStats.getStatElements();
- List sL = Arrays.asList( sSEs );
+ List<IStatElement> sL = Arrays.asList( sSEs );
elems.addAll( sL );
// 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;
@@ -1670,6 +1634,7 @@ public class IndexedDiskCache
* <p>
* @return the location of the disk, either path or ip.
*/
+ @Override
protected String getDiskLocation()
{
return dataFile.getFilePath();
@@ -1679,18 +1644,18 @@ public class IndexedDiskCache
* Compares IndexedDiskElementDescriptor based on their position.
* <p>
*/
- private static final class PositionComparator
- implements Comparator
+ protected static final class PositionComparator
+ implements Comparator<IndexedDiskElementDescriptor>
{
/**
* Compares two descriptors based on position.
* <p>
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
*/
- public int compare( Object o1, Object o2 )
+ public int compare( IndexedDiskElementDescriptor o1, IndexedDiskElementDescriptor o2 )
{
- IndexedDiskElementDescriptor ded1 = (IndexedDiskElementDescriptor) o1;
- IndexedDiskElementDescriptor ded2 = (IndexedDiskElementDescriptor) o2;
+ IndexedDiskElementDescriptor ded1 = o1;
+ IndexedDiskElementDescriptor ded2 = o2;
if ( ded1.pos < ded2.pos )
{
@@ -1708,11 +1673,11 @@ public class IndexedDiskCache
}
/**
- * Class for recylcing and lru. This implements the LRU overflow callback, so we can add items
+ * Class for recycling and lru. This implements the LRU overflow callback, so we can add items
* to the recycle bin.
*/
public class LRUMap
- extends LRUMapJCS
+ extends LRUMapJCS<Serializable, IndexedDiskElementDescriptor>
{
/** Don't change */
private static final long serialVersionUID = 4955079991472142198L;
@@ -1745,9 +1710,10 @@ public class IndexedDiskCache
* @param key
* @param value
*/
- protected void processRemovedLRU( Object key, Object value )
+ @Override
+ protected void processRemovedLRU(Serializable key, IndexedDiskElementDescriptor value )
{
- addToRecycleBin( (IndexedDiskElementDescriptor) value );
+ addToRecycleBin( value );
if ( log.isDebugEnabled() )
{
log.debug( logCacheName + "Removing key: [" + key + "] from key store." );
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheManager.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheManager.java?rev=1151575&r1=1151574&r2=1151575&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheManager.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheManager.java Wed Jul 27 18:08:23 2011
@@ -44,10 +44,10 @@ public class IndexedDiskCacheManager
private static IndexedDiskCacheManager instance;
/** Each region has an entry here. */
- private Hashtable caches = new Hashtable();
+ private final Hashtable<String, AuxiliaryCache> caches = new Hashtable<String, AuxiliaryCache>();
/** User configurable attributes */
- private IndexedDiskCacheAttributes defaultCacheAttributes;
+ private final IndexedDiskCacheAttributes defaultCacheAttributes;
/**
* Constructor for the IndexedDiskCacheManager object
@@ -122,7 +122,7 @@ public class IndexedDiskCacheManager
// Try to load the cache from the set that have already been
// created. This only looks at the name attribute.
- cache = (AuxiliaryCache) caches.get( cacheName );
+ cache = caches.get( cacheName );
// If it was not found, create a new one using the supplied
// attributes
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskElementDescriptor.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskElementDescriptor.java?rev=1151575&r1=1151574&r2=1151575&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskElementDescriptor.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskElementDescriptor.java Wed Jul 27 18:08:23 2011
@@ -26,7 +26,7 @@ import java.io.Serializable;
* memory on startup.
*/
public class IndexedDiskElementDescriptor
- implements Serializable, Comparable
+ implements Serializable, Comparable<IndexedDiskElementDescriptor>
{
/** Don't change */
private static final long serialVersionUID = -3029163572847659450L;
@@ -52,6 +52,7 @@ public class IndexedDiskElementDescripto
/**
* @return debug string
*/
+ @Override
public String toString()
{
StringBuffer buf = new StringBuffer();
@@ -68,14 +69,14 @@ public class IndexedDiskElementDescripto
* @param o Object
* @return int
*/
- public int compareTo( Object o )
+ public int compareTo( IndexedDiskElementDescriptor o )
{
if ( o == null )
{
return 1;
}
- int oLen = ( (IndexedDiskElementDescriptor) o ).len;
+ int oLen = o.len;
if ( oLen == len )
{
return 0;
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCache.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCache.java?rev=1151575&r1=1151574&r2=1151575&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCache.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCache.java Wed Jul 27 18:08:23 2011
@@ -54,7 +54,7 @@ import org.apache.jcs.utils.serializatio
* <p>
* It expects a table created by the following script. The table name is configurable.
* <p>
- *
+ *
* <pre>
* drop TABLE JCS_STORE;
* CREATE TABLE JCS_STORE
@@ -181,6 +181,7 @@ public class JDBCDiskCache
* <p>
* @param ce
*/
+ @Override
protected void processUpdate( ICacheElement ce )
{
incrementUpdateCount();
@@ -219,7 +220,10 @@ public class JDBCDiskCache
{
try
{
- sStatement.close();
+ if (sStatement != null)
+ {
+ sStatement.close();
+ }
}
catch ( SQLException e )
{
@@ -355,8 +359,8 @@ public class JDBCDiskCache
catch ( SQLException e )
{
if ( e.toString().indexOf( "Violation of unique index" ) != -1
- || e.getMessage().indexOf( "Duplicate entry" ) != -1
- || e.getMessage().indexOf( "duplicate key" ) != -1
+ || e.getMessage().indexOf( "Duplicate entry" ) != -1
+ || e.getMessage().indexOf( "duplicate key" ) != -1
|| e.getMessage().indexOf( "primary key constraint" ) != -1 )
{
exists = true;
@@ -502,6 +506,7 @@ public class JDBCDiskCache
* @return ICacheElement
* @see org.apache.jcs.auxiliary.disk.AbstractDiskCache#doGet(java.io.Serializable)
*/
+ @Override
protected ICacheElement processGet( Serializable key )
{
incrementGetCount();
@@ -565,7 +570,6 @@ public class JDBCDiskCache
{
rs.close();
}
- rs.close();
}
}
finally
@@ -574,7 +578,6 @@ public class JDBCDiskCache
{
psSelect.close();
}
- psSelect.close();
}
}
finally
@@ -608,7 +611,8 @@ public class JDBCDiskCache
* @param pattern
* @return key,value map
*/
- protected Map processGetMatching( String pattern )
+ @Override
+ protected Map<Serializable, ICacheElement> processGetMatching( String pattern )
{
incrementGetMatchingCount();
@@ -622,7 +626,7 @@ public class JDBCDiskCache
return null;
}
- Map results = new HashMap();
+ Map<Serializable, ICacheElement> results = new HashMap<Serializable, ICacheElement>();
try
{
@@ -672,7 +676,6 @@ public class JDBCDiskCache
{
rs.close();
}
- rs.close();
}
}
finally
@@ -681,7 +684,6 @@ public class JDBCDiskCache
{
psSelect.close();
}
- psSelect.close();
}
}
finally
@@ -732,6 +734,7 @@ public class JDBCDiskCache
* @param key
* @return boolean
*/
+ @Override
protected boolean processRemove( Serializable key )
{
// remove single item.
@@ -800,6 +803,7 @@ public class JDBCDiskCache
* This should remove all elements. The auxiliary can be configured to forbid this behavior. If
* remove all is not allowed, the method balks.
*/
+ @Override
protected void processRemoveAll()
{
// it should never get here formt he abstract dis cache.
@@ -937,6 +941,7 @@ public class JDBCDiskCache
}
/** Shuts down the pool */
+ @Override
public void processDispose()
{
ICacheEvent cacheEvent = createICacheEvent( cacheName, "none", ICacheEventLogger.DISPOSE_EVENT );
@@ -962,6 +967,7 @@ public class JDBCDiskCache
* <p>
* @return The size value
*/
+ @Override
public int getSize()
{
int size = 0;
@@ -1003,7 +1009,6 @@ public class JDBCDiskCache
{
rs.close();
}
- rs.close();
}
}
finally
@@ -1012,7 +1017,6 @@ public class JDBCDiskCache
{
psSelect.close();
}
- psSelect.close();
}
}
catch ( SQLException e )
@@ -1050,7 +1054,8 @@ public class JDBCDiskCache
* @param groupName
* @return Set
*/
- public Set getGroupKeys( String groupName )
+ @Override
+ public Set<Serializable> getGroupKeys( String groupName )
{
if ( true )
{
@@ -1062,6 +1067,7 @@ public class JDBCDiskCache
/**
* @param elementSerializer The elementSerializer to set.
*/
+ @Override
public void setElementSerializer( IElementSerializer elementSerializer )
{
this.elementSerializer = elementSerializer;
@@ -1070,6 +1076,7 @@ public class JDBCDiskCache
/**
* @return Returns the elementSerializer.
*/
+ @Override
public IElementSerializer getElementSerializer()
{
return elementSerializer;
@@ -1122,13 +1129,14 @@ public class JDBCDiskCache
* <p>
* @return IStats
*/
+ @Override
public IStats getStatistics()
{
IStats stats = super.getStatistics();
stats.setTypeName( "JDBC/Abstract Disk Cache" );
stats.getStatElements();
- ArrayList elems = new ArrayList();
+ ArrayList<IStatElement> elems = new ArrayList<IStatElement>();
IStatElement se = null;
@@ -1177,11 +1185,11 @@ public class JDBCDiskCache
// get the stats from the event queue too
// get as array, convert to list, add list to our outer list
IStatElement[] eqSEs = stats.getStatElements();
- List eqL = Arrays.asList( eqSEs );
+ List<IStatElement> eqL = Arrays.asList( eqSEs );
elems.addAll( eqL );
// 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;
@@ -1223,6 +1231,7 @@ public class JDBCDiskCache
* <p>
* @return the location of the disk, either path or ip.
*/
+ @Override
protected String getDiskLocation()
{
return this.jdbcDiskCacheAttributes.getUrl();
@@ -1250,6 +1259,7 @@ public class JDBCDiskCache
* <p>
* @return this.getStats();
*/
+ @Override
public String toString()
{
return this.getStats();
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheManagerAbstractTemplate.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheManagerAbstractTemplate.java?rev=1151575&r1=1151574&r2=1151575&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheManagerAbstractTemplate.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheManagerAbstractTemplate.java Wed Jul 27 18:08:23 2011
@@ -23,15 +23,16 @@ import java.io.IOException;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Map;
+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;
import org.apache.jcs.auxiliary.AuxiliaryCache;
import org.apache.jcs.auxiliary.disk.AbstractDiskCacheManager;
-import EDU.oswego.cs.dl.util.concurrent.ClockDaemon;
-import EDU.oswego.cs.dl.util.concurrent.ThreadFactory;
-
/**
* This class serves as an abstract template for JDBCDiskCache Manager. The MySQL JDBC Disk Cache
* needs many of the same features as the generic manager.
@@ -51,22 +52,22 @@ public abstract class JDBCDiskCacheManag
protected static int clients;
/** A map of JDBCDiskCache objects to region names. */
- protected static Hashtable caches = new Hashtable();
+ protected static Hashtable<String, AuxiliaryCache> caches = new Hashtable<String, AuxiliaryCache>();
/**
* A map of TableState objects to table names. Each cache has a table state object, which is
* used to determine if any long processes such as deletes or optimizations are running.
*/
- protected static Hashtable tableStates = new Hashtable();
+ protected static Hashtable<String, TableState> tableStates = new Hashtable<String, TableState>();
/** The background disk shrinker, one for all regions. */
- private ClockDaemon shrinkerDaemon;
+ private ScheduledExecutorService shrinkerDaemon;
/**
* A map of table name to shrinker threads. This allows each table to have a different setting.
* It assumes that there is only one jdbc disk cache auxiliary defined per table.
*/
- private Map shrinkerThreadMap = new Hashtable();
+ private final Map<String, ShrinkerThread> shrinkerThreadMap = new Hashtable<String, ShrinkerThread>();
/**
* Children must implement this method.
@@ -78,7 +79,7 @@ public abstract class JDBCDiskCacheManag
protected abstract AuxiliaryCache createJDBCDiskCache( JDBCDiskCacheAttributes cattr, TableState tableState );
/**
- * Creates a JDBCDiskCache for the region if one doesn't exist, else it returns the precreated
+ * Creates a JDBCDiskCache for the region if one doesn't exist, else it returns the pre-created
* instance. It also adds the region to the shrinker thread if needed.
* <p>
* @param cattr
@@ -92,11 +93,11 @@ public abstract class JDBCDiskCacheManag
synchronized ( caches )
{
- diskCache = (AuxiliaryCache) caches.get( cattr.getCacheName() );
+ diskCache = caches.get( cattr.getCacheName() );
if ( diskCache == null )
{
- TableState tableState = (TableState) tableStates.get( cattr.getTableName() );
+ TableState tableState = tableStates.get( cattr.getTableName() );
if ( tableState == null )
{
@@ -134,11 +135,10 @@ public abstract class JDBCDiskCacheManag
{
if ( shrinkerDaemon == null )
{
- shrinkerDaemon = new ClockDaemon();
- shrinkerDaemon.setThreadFactory( new MyThreadFactory() );
+ shrinkerDaemon = Executors.newScheduledThreadPool(2, new MyThreadFactory());
}
- ShrinkerThread shrinkerThread = (ShrinkerThread) shrinkerThreadMap.get( cattr.getTableName() );
+ ShrinkerThread shrinkerThread = shrinkerThreadMap.get( cattr.getTableName() );
if ( shrinkerThread == null )
{
shrinkerThread = new ShrinkerThread();
@@ -150,7 +150,7 @@ public abstract class JDBCDiskCacheManag
log.info( "Setting the shrinker to run every [" + intervalMillis + "] ms. for table ["
+ cattr.getTableName() + "]" );
}
- shrinkerDaemon.executePeriodically( intervalMillis, shrinkerThread, false );
+ shrinkerDaemon.scheduleAtFixedRate(shrinkerThread, 0, intervalMillis, TimeUnit.MILLISECONDS);
}
shrinkerThread.addDiskCacheToShrinkList( (JDBCDiskCache) raf );
}
@@ -195,7 +195,7 @@ public abstract class JDBCDiskCacheManag
}
synchronized ( caches )
{
- Enumeration allCaches = caches.elements();
+ Enumeration<AuxiliaryCache> allCaches = caches.elements();
while ( allCaches.hasMoreElements() )
{
@@ -231,7 +231,7 @@ public abstract class JDBCDiskCacheManag
{
Thread t = new Thread( runner );
String oldName = t.getName();
- t.setName( "JCS-JDBCDiskCacheManager-" + oldName );
+ t.setName( "JCS-JDBCDiskCacheManager-" + oldName );
t.setDaemon( true );
t.setPriority( Thread.MIN_PRIORITY );
return t;
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCachePoolAccessManager.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCachePoolAccessManager.java?rev=1151575&r1=1151574&r2=1151575&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCachePoolAccessManager.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCachePoolAccessManager.java Wed Jul 27 18:08:23 2011
@@ -11,7 +11,7 @@ import org.apache.jcs.utils.config.Prope
/**
* Manages JDBCDiskCachePoolAccess instances. If a connectionPoolName value is supplied, the JDBC
* disk cache will try to use this manager to create a pool. Assuming the name is "MyPool":
- *
+ *
* <pre>
* jcs.jdbcconnectionpool.MyPool.attributes.userName=MyUserName
* jcs.jdbcconnectionpool.MyPool.attributes.password=MyPassword
@@ -26,7 +26,7 @@ public class JDBCDiskCachePoolAccessMana
private static JDBCDiskCachePoolAccessManager instance;
/** Pool name to JDBCDiskCachePoolAccess */
- private Map pools = new HashMap();
+ private final Map<String, JDBCDiskCachePoolAccess> pools = new HashMap<String, JDBCDiskCachePoolAccess>();
/** props prefix */
public static final String POOL_CONFIGURATION_PREFIX = "jcs.jdbcconnectionpool.";
@@ -76,7 +76,7 @@ public class JDBCDiskCachePoolAccessMana
*/
public synchronized JDBCDiskCachePoolAccess getJDBCDiskCachePoolAccess( String poolName )
{
- JDBCDiskCachePoolAccess poolAccess = (JDBCDiskCachePoolAccess) pools.get( poolName );
+ JDBCDiskCachePoolAccess poolAccess = pools.get( poolName );
if ( poolAccess == null )
{
@@ -84,7 +84,7 @@ public class JDBCDiskCachePoolAccessMana
try
{
poolAccess = JDBCDiskCachePoolAccessFactory.createPoolAccess( poolAttributes );
-
+
if ( log.isInfoEnabled() )
{
log.info( "Created shared pooled access for pool name [" + poolName + "]." );
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/ShrinkerThread.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/ShrinkerThread.java?rev=1151575&r1=1151574&r2=1151575&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/ShrinkerThread.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/ShrinkerThread.java Wed Jul 27 18:08:23 2011
@@ -39,7 +39,7 @@ public class ShrinkerThread
private final static Log log = LogFactory.getLog( ShrinkerThread.class );
/** A set of JDBCDiskCache objects to call deleteExpired on. */
- private Set shrinkSet = Collections.synchronizedSet( new HashSet() );
+ private final Set<JDBCDiskCache> shrinkSet = Collections.synchronizedSet( new HashSet<JDBCDiskCache>() );
/** Default time period to use. */
private static final long DEFAULT_PAUSE_BETWEEN_REGION_CALLS_MILLIS = 5000;
@@ -67,7 +67,7 @@ public class ShrinkerThread
public void addDiskCacheToShrinkList( JDBCDiskCache diskCache )
{
// the set will prevent dupes.
- // we could also just add these to a hasmap by region name
+ // we could also just add these to a hashmap by region name
// but that might cause a problem if you wanted to use two different
// jbdc disk caches for the same region.
shrinkSet.add( diskCache );
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/hsql/HSQLDiskCacheFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/hsql/HSQLDiskCacheFactory.java?rev=1151575&r1=1151574&r2=1151575&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/hsql/HSQLDiskCacheFactory.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/hsql/HSQLDiskCacheFactory.java Wed Jul 27 18:08:23 2011
@@ -54,10 +54,10 @@ public class HSQLDiskCacheFactory
private String name = "HSQLDiskCacheFactory";
/** The databases. */
- private Set databases = Collections.synchronizedSet( new HashSet() );
+ private final Set<String> databases = Collections.synchronizedSet( new HashSet<String>() );
/**
- * This factory method should create an instance of the mysqlcache.
+ * This factory method should create an instance of the hsqlcache.
* <p>
* @param rawAttr
* @param arg1
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCache.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCache.java?rev=1151575&r1=1151574&r2=1151575&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCache.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCache.java Wed Jul 27 18:08:23 2011
@@ -47,7 +47,7 @@ public class MySQLDiskCache
private final static Log log = LogFactory.getLog( MySQLDiskCache.class );
/** config attributes */
- private MySQLDiskCacheAttributes mySQLDiskCacheAttributes;
+ private final MySQLDiskCacheAttributes mySQLDiskCacheAttributes;
/**
* Delegates to the super and makes use of the MySQL specific parameters used for scheduled
@@ -55,7 +55,7 @@ public class MySQLDiskCache
* <p>
* @param attributes
* @param tableState
- * @param compositeCacheManager
+ * @param compositeCacheManager
*/
public MySQLDiskCache( MySQLDiskCacheAttributes attributes, TableState tableState, ICompositeCacheManager compositeCacheManager )
{
@@ -76,6 +76,7 @@ public class MySQLDiskCache
* @param key Key to locate value for.
* @return An object matching key, or null.
*/
+ @Override
protected ICacheElement processGet( Serializable key )
{
if ( this.getTableState().getState() == TableState.OPTIMIZATION_RUNNING )
@@ -95,7 +96,8 @@ public class MySQLDiskCache
* @param pattern used for like query.
* @return An object matching key, or null.
*/
- protected Map processGetMatching( String pattern )
+ @Override
+ protected Map<Serializable, ICacheElement> processGetMatching( String pattern )
{
if ( this.getTableState().getState() == TableState.OPTIMIZATION_RUNNING )
{
@@ -106,30 +108,32 @@ public class MySQLDiskCache
}
return super.processGetMatching( pattern );
}
-
+
/**
* @param pattern
* @return String to use in the like query.
*/
+ @Override
public String constructLikeParameterFromPattern( String pattern )
{
pattern = pattern.replaceAll( "\\.\\+", "%" );
pattern = pattern.replaceAll( "\\.", "_" );
-
+
if ( log.isDebugEnabled() )
{
log.debug( "pattern = [" + pattern + "]" );
}
-
+
return pattern;
}
-
+
/**
* This delegates to the generic JDBC disk cache. If we are currently optimizing, then this
* method will balk and do nothing.
* <p>
* @param element
*/
+ @Override
protected void processUpdate( ICacheElement element )
{
if ( this.getTableState().getState() == TableState.OPTIMIZATION_RUNNING )
@@ -151,6 +155,7 @@ public class MySQLDiskCache
* <p>
* @return the number deleted
*/
+ @Override
protected int deleteExpired()
{
if ( this.getTableState().getState() == TableState.OPTIMIZATION_RUNNING )
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheManager.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheManager.java?rev=1151575&r1=1151574&r2=1151575&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheManager.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheManager.java Wed Jul 27 18:08:23 2011
@@ -50,28 +50,28 @@ public class MySQLDiskCacheManager
private static final long serialVersionUID = -8258856770927857896L;
/** The logger */
- private static final Log log = LogFactory.getLog( MySQLDiskCacheManager.class );
+ protected static final Log log = LogFactory.getLog( MySQLDiskCacheManager.class );
/** The singleton instance. */
private static MySQLDiskCacheManager instance;
- /** User configurable atributes. */
- private MySQLDiskCacheAttributes defaultJDBCDiskCacheAttributes;
+ /** User configurable attributes. */
+ private final MySQLDiskCacheAttributes defaultJDBCDiskCacheAttributes;
/** ms in a day */
private static final int DAILY_INTERVAL = 60 * 60 * 24 * 1000;
/** for schedule optimizations */
private Timer daemon = null;
-
+
/** The cache manager instance */
- private ICompositeCacheManager compositeCacheManager;
+ private ICompositeCacheManager compositeCacheManager;
/**
* Constructor for the HSQLCacheManager object
* <p>
* @param cattr
- * @param compositeCacheManager
+ * @param compositeCacheManager
* @param cacheEventLogger
* @param elementSerializer
*/
@@ -84,8 +84,8 @@ public class MySQLDiskCacheManager
}
defaultJDBCDiskCacheAttributes = cattr;
setElementSerializer( elementSerializer );
- setCacheEventLogger( cacheEventLogger );
- setCompositeCacheManager( compositeCacheManager );
+ setCacheEventLogger( cacheEventLogger );
+ setCompositeCacheManager( compositeCacheManager );
}
/**
@@ -102,7 +102,7 @@ public class MySQLDiskCacheManager
* Gets the instance attribute of the HSQLCacheManager class
* <p>
* @param cattr
- * @param compositeCacheManager
+ * @param compositeCacheManager
* @param cacheEventLogger
* @param elementSerializer
* @return The instance value
@@ -142,6 +142,7 @@ public class MySQLDiskCacheManager
* @param tableState
* @return AuxiliaryCache
*/
+ @Override
protected AuxiliaryCache createJDBCDiskCache( JDBCDiskCacheAttributes cattr, TableState tableState )
{
MySQLDiskCache diskCache = new MySQLDiskCache( (MySQLDiskCacheAttributes) cattr, tableState, getCompositeCacheManager() );
@@ -273,6 +274,7 @@ public class MySQLDiskCacheManager
* <p>
* @see java.lang.Runnable#run()
*/
+ @Override
public void run()
{
if ( optimizer != null )