Two questions: 1) Does this last commit contain anything but formatting changes? If so I want to back it out -- it was better before =] I can't find any difference, so I'll test it.
2) Do we need to include the cacheName when locking? Since each cache has its own lock manager and is specific to a given region, can we just use the key? Would save a string concatenation in a spot where it probably matters =] Looks like a good approach though. Better than what I was doing (locking the whole region). On Tue, 2002-05-14 at 16:41, [EMAIL PROTECTED] wrote: > asmuts 02/05/14 13:41:04 > > Modified: src/java/org/apache/jcs/auxiliary/disk > AbstractDiskCache.java > Log: > seems to work fine. > > Adjusting the default log level changes everything. > > Please look at this. > > Revision Changes Path > 1.9 +120 -91 >jakarta-turbine-jcs/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCache.java > > Index: AbstractDiskCache.java > =================================================================== > RCS file: >/home/cvs/jakarta-turbine-jcs/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCache.java,v > retrieving revision 1.8 > retrieving revision 1.9 > diff -u -r1.8 -r1.9 > --- AbstractDiskCache.java 14 May 2002 20:36:03 -0000 1.8 > +++ AbstractDiskCache.java 14 May 2002 20:41:04 -0000 1.9 > @@ -53,7 +53,6 @@ > * information on the Apache Software Foundation, please see > * <http://www.apache.org/>. > */ > - > import org.apache.commons.logging.Log; > import org.apache.commons.logging.LogFactory; > import org.apache.jcs.engine.CacheElement; > @@ -73,22 +72,20 @@ > import java.util.Hashtable; > > /** > - * Abstract class providing a base implementation of a disk cache, which can > - * be easily extended to implement a disk cache for a specific perstistence > - * mechanism. > - * > - * When implementing the abstract methods note that while this base class > - * handles most things, it does not acquire or release any locks. > - * Implementations should do so as neccesary. This is mainly done to minimize > - * the time speant in critical sections. > + * Abstract class providing a base implementation of a disk cache, which can be > + * easily extended to implement a disk cache for a specific perstistence > + * mechanism. When implementing the abstract methods note that while this base > + * class handles most things, it does not acquire or release any locks. > + * Implementations should do so as neccesary. This is mainly done to minimize > + * the time speant in critical sections. Error handling in this class needs to > + * be addressed. Currently if an exception is thrown by the persistence > + * mechanism, this class destroys the event queue. Should it also destory > + * purgatory? Should it dispose itself? > * > - * Error handling in this class needs to be addressed. Currently if an > - * exception is thrown by the persistence mechanism, this class destroys the > - * event queue. Should it also destory purgatory? Should it dispose itself? > - * > - * @author <a href="mailto:[EMAIL PROTECTED]">Aaron Smuts</a> > - * @author <a href="mailto:[EMAIL PROTECTED]">James Taylor</a> > - * @version $Id: AbstractDiskCache.java,v 1.8 2002/05/14 20:36:03 asmuts Exp $ > + *@author <a href="mailto:[EMAIL PROTECTED]">Aaron Smuts</a> > + *@author <a href="mailto:[EMAIL PROTECTED]">James Taylor</a> > + *@created May 13, 2002 > + *@version $Id: AbstractDiskCache.java,v 1.9 2002/05/14 20:41:04 asmuts Exp $ > */ > public abstract class AbstractDiskCache implements AuxiliaryCache, Serializable > { > @@ -96,66 +93,75 @@ > LogFactory.getLog( AbstractDiskCache.class ); > > /** > - * Map where elements are stored between being added to this cache and > - * actually spooled to disk. This allows puts to the disk cache to return > - * quickly, and the more expensive operation of serializing the elements > - * to persistent storage queued for later. If the elements are pulled into > - * the memory cache while the are still in purgatory, writing to disk can > - * be cancelled. > + * Map where elements are stored between being added to this cache and > + * actually spooled to disk. This allows puts to the disk cache to return > + * quickly, and the more expensive operation of serializing the elements to > + * persistent storage queued for later. If the elements are pulled into the > + * memory cache while the are still in purgatory, writing to disk can be > + * cancelled. > */ > protected Hashtable purgatory = new Hashtable(); > > /** > - * The CacheEventQueue where changes will be queued for asynchronous > - * updating of the persistent storage. > + * The CacheEventQueue where changes will be queued for asynchronous > + * updating of the persistent storage. > */ > protected ICacheEventQueue cacheEventQueue; > > /** > - * Each instance of a Disk cache should use this lock to synchronize reads > - * and writes to the underlying storage mechansism. > + * Each instance of a Disk cache should use this lock to synchronize reads > + * and writes to the underlying storage mechansism. > */ > protected ReadWriteLock lock = new ReadWriteLock(); > > - /** Manages locking for purgatory item manipulation. */ > + /** > + * Manages locking for purgatory item manipulation. > + */ > protected ReadWriteLockManager locker = new ReadWriteLockManager(); > > /** > - * Indicates whether the cache is 'alive', defined as having been > - * initialized, but not yet disposed. > + * Indicates whether the cache is 'alive', defined as having been > + * initialized, but not yet disposed. > */ > protected boolean alive = false; > > /** > - * Every cache will have a name, subclasses must set this when they are > - * initialized. > + * Every cache will have a name, subclasses must set this when they are > + * initialized. > */ > protected String cacheName; > > /** > - * DEBUG: Keeps a count of the number of purgatory hits for debug messages > + * DEBUG: Keeps a count of the number of purgatory hits for debug messages > */ > protected int purgHits = 0; > > // ----------------------------------------------------------- constructors > > + /** > + * Constructor for the AbstractDiskCache object > + * > + *@param cacheName Description of the Parameter > + */ > public AbstractDiskCache( String cacheName ) > { > this.cacheName = cacheName; > > this.cacheEventQueue = new CacheEventQueue( new MyCacheListener(), > - CacheInfo.listenerId, > - cacheName ); > + CacheInfo.listenerId, > + cacheName ); > } > > // ------------------------------------------------------- interface ICache > > /** > - * Adds the provided element to the cache. Element will be added to > - * purgatory, and then queued for later writing to the serialized storage > - * mechanism. > + * Adds the provided element to the cache. Element will be added to > + * purgatory, and then queued for later writing to the serialized storage > + * mechanism. > * > - * @see org.apache.jcs.engine.behavior.ICache#update > + *@param cacheElement Description of the Parameter > + *@exception IOException Description of the Exception > + *@see org.apache.jcs.engine.behavior.ICache#update > */ > public final void update( ICacheElement cacheElement ) > throws IOException > @@ -163,7 +169,7 @@ > if ( log.isDebugEnabled() ) > { > log.debug( "Putting element in purgatory, cacheName: " + cacheName + > - ", key: " + cacheElement.getKey() ); > + ", key: " + cacheElement.getKey() ); > } > > try > @@ -195,7 +201,9 @@ > } > > /** > - * @see AuxiliaryCache#get > + *@param key Description of the Parameter > + *@return Description of the Return Value > + *@see AuxiliaryCache#get > */ > public final ICacheElement get( Serializable key ) > { > @@ -229,7 +237,7 @@ > pe.setSpoolable( false ); > > log.debug( "Found element in purgatory, cacheName: " + cacheName + > - ", key: " + key ); > + ", key: " + key ); > > purgatory.remove( key ); > > @@ -254,7 +262,9 @@ > } > > /** > - * @see org.apache.jcs.engine.behavior.ICache#remove > + *@param key Description of the Parameter > + *@return Description of the Return Value > + *@see org.apache.jcs.engine.behavior.ICache#remove > */ > public final boolean remove( Serializable key ) > { > @@ -265,14 +275,14 @@ > try > { > > - purgatory.remove( key ); > + purgatory.remove( key ); > > - doRemove( key ); > + doRemove( key ); > > } > finally > { > - releaseLock( this.cacheName + key.toString() ); > + releaseLock( this.cacheName + key.toString() ); > } > // Remove from persistent store immediately > > @@ -280,7 +290,7 @@ > } > > /** > - * @see org.apache.jcs.engine.behavior.ICache#removeAll > + *@see org.apache.jcs.engine.behavior.ICache#removeAll > */ > public final void removeAll() > { > @@ -294,7 +304,7 @@ > } > > /** > - * Adds a dispose request to the disk cache. > + * Adds a dispose request to the disk cache. > */ > public final void dispose() > { > @@ -310,7 +320,8 @@ > } > > /** > - * @see ICache#getCacheName > + *@return The cacheName value > + *@see ICache#getCacheName > */ > public String getCacheName() > { > @@ -318,7 +329,8 @@ > } > > /** > - * @see ICache#getStatus > + *@return The status value > + *@see ICache#getStatus > */ > public int getStatus() > { > @@ -326,18 +338,18 @@ > } > > /** > - * Size cannot be determined without knowledge of the cache implementation, > - * so subclasses will need to implement this method. > + * Size cannot be determined without knowledge of the cache implementation, > + * so subclasses will need to implement this method. > * > - * @see ICache#getSize > + *@return The size value > + *@see ICache#getSize > */ > public abstract int getSize(); > > /** > - * @see org.apache.jcs.engine.behavior.ICacheType#getCacheType > - * > - * @return Always returns DISK_CACHE since subclasses should all be of > - * that type. > + *@return Always returns DISK_CACHE since subclasses should all be of > + * that type. > + *@see org.apache.jcs.engine.behavior.ICacheType#getCacheType > */ > public int getCacheType() > { > @@ -346,9 +358,9 @@ > > > /** > - * Internally used write lock for purgatory item modification. > + * Internally used write lock for purgatory item modification. > * > - * @param id What name to lock on. > + *@param id What name to lock on. > */ > private void writeLock( String id ) > { > @@ -365,15 +377,15 @@ > catch ( Throwable e ) > { > > - log.error( e ); > + log.error( e ); > } > } > > > /** > - * Internally used write lock for purgatory item modification. > + * Internally used write lock for purgatory item modification. > * > - * @param id What name to lock on. > + *@param id What name to lock on. > */ > private void releaseLock( String id ) > { > @@ -384,21 +396,26 @@ > catch ( Throwable e ) > { > > - log.error( e ); > + log.error( e ); > } > } > > > /** > - * Cache that implements the CacheListener interface, and calls appropriate > - * methods in its parent class. > + * Cache that implements the CacheListener interface, and calls appropriate > + * methods in its parent class. > + * > + *@author asmuts > + *@created May 13, 2002 > */ > private class MyCacheListener implements ICacheListener > { > private byte listenerId = 0; > > /** > - * @see org.apache.jcs.engine.CacheListener#getListenerId > + *@return The listenerId value > + *@exception IOException Description of the Exception > + *@see >org.apache.jcs.engine.CacheListener#getListenerId > */ > public byte getListenerId() > throws IOException > @@ -407,7 +424,9 @@ > } > > /** > - * @see ICacheListener#setListenerId > + *@param id The new listenerId value > + *@exception IOException Description of the Exception > + *@see ICacheListener#setListenerId > */ > public void setListenerId( byte id ) > throws IOException > @@ -416,12 +435,13 @@ > } > > /** > - * @see ICacheListener#handlePut > - * > - * NOTE: This checks if the element is a puratory element and behaves > - * differently depending. However since we have control over how > - * elements are added to the cache event queue, that may not be needed > - * ( they are always PurgatoryElements ). > + *@param element Description of the Parameter > + *@exception IOException Description of the Exception > + *@see ICacheListener#handlePut NOTE: This checks if > + * the element is a puratory element and behaves differently > + * depending. However since we have control over how elements are > + * added to the cache event queue, that may not be needed ( they > + * are always PurgatoryElements ). > */ > public void handlePut( ICacheElement element ) > throws IOException > @@ -438,20 +458,20 @@ > // If the element has already been removed from purgatory > // do nothing > > - String lK =element.getKey().toString(); > + String lK = element.getKey().toString(); > writeLock( getCacheName() + lK ); > try > { > > - if ( ! purgatory.contains( pe ) ) > - { > - return; > - } > + if ( !purgatory.contains( pe ) ) > + { > + return; > + } > > } > finally > { > - releaseLock( getCacheName() + lK ); > + releaseLock( getCacheName() + lK ); > } > > element = pe.getCacheElement(); > @@ -476,7 +496,10 @@ > } > > /** > - * @see org.apache.jcs.engine.CacheListener#handleRemove > + *@param cacheName Description of the Parameter > + *@param key Description of the Parameter > + *@exception IOException Description of the Exception > + *@see >org.apache.jcs.engine.CacheListener#handleRemove > */ > public void handleRemove( String cacheName, Serializable key ) > throws IOException > @@ -491,7 +514,9 @@ > } > > /** > - * @see org.apache.jcs.engine.CacheListener#handleRemoveAll > + *@param cacheName Description of the Parameter > + *@exception IOException Description of the Exception > + *@see >org.apache.jcs.engine.CacheListener#handleRemoveAll > */ > public void handleRemoveAll( String cacheName ) > throws IOException > @@ -503,7 +528,9 @@ > } > > /** > - * @see org.apache.jcs.engine.CacheListener#handleDispose > + *@param cacheName Description of the Parameter > + *@exception IOException Description of the Exception > + *@see >org.apache.jcs.engine.CacheListener#handleDispose > */ > public void handleDispose( String cacheName ) > throws IOException > @@ -519,36 +546,38 @@ > // ---------------------- subclasses should implement the following methods > > /** > - * Get a value from the persistent store. > + * Get a value from the persistent store. > * > - * @param key Key to locate value for. > - * @return An object matching key, or null. > + *@param key Key to locate value for. > + *@return An object matching key, or null. > */ > protected abstract ICacheElement doGet( Serializable key ); > > /** > - * Add a cache element to the persistent store. > + * Add a cache element to the persistent store. > + * > + *@param element Description of the Parameter > */ > protected abstract void doUpdate( ICacheElement element ); > > /** > - * Remove an object from the persistent store if found. > + * Remove an object from the persistent store if found. > * > - * @param key Key of object to remove. > + *@param key Key of object to remove. > + *@return Description of the Return Value > */ > protected abstract boolean doRemove( Serializable key ); > > /** > - * Remove all objects from the persistent store. > + * Remove all objects from the persistent store. > */ > protected abstract void doRemoveAll(); > > /** > - * Dispose of the persistent store. Note that disposal of purgatory and > - * setting alive to false does NOT need to be done by this method. > + * Dispose of the persistent store. Note that disposal of purgatory and > + * setting alive to false does NOT need to be done by this method. > */ > protected abstract void doDispose(); > - > > } > > > > > > -- > To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> > For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> > > -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
