asmuts 02/05/14 13:21:43
Modified: src/java/org/apache/jcs/auxiliary/disk
AbstractDiskCache.java
Log:
first test fails, second works
manual testing works
Revision Changes Path
1.7 +59 -6
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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- AbstractDiskCache.java 14 May 2002 19:40:24 -0000 1.6
+++ AbstractDiskCache.java 14 May 2002 20:21:43 -0000 1.7
@@ -66,6 +66,7 @@
import org.apache.jcs.engine.behavior.ICacheListener;
import org.apache.jcs.auxiliary.AuxiliaryCache;
import org.apache.jcs.utils.locking.ReadWriteLock;
+import org.apache.jcs.utils.locking.ReadWriteLockManager;
import java.io.IOException;
import java.io.Serializable;
@@ -87,7 +88,7 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Aaron Smuts</a>
* @author <a href="mailto:[EMAIL PROTECTED]">James Taylor</a>
- * @version $Id: AbstractDiskCache.java,v 1.6 2002/05/14 19:40:24 jtaylor Exp $
+ * @version $Id: AbstractDiskCache.java,v 1.7 2002/05/14 20:21:43 asmuts Exp $
*/
public abstract class AbstractDiskCache implements AuxiliaryCache, Serializable
{
@@ -116,6 +117,9 @@
*/
protected ReadWriteLock lock = new ReadWriteLock();
+ /** 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.
@@ -256,11 +260,21 @@
{
// Remove element from purgatory if it is there
- purgatory.remove( key );
- // Remove from persistent store immediately
+ writeLock( this.cacheName + key.toString() );
+ try
+ {
+
+ purgatory.remove( key );
- doRemove( key );
+ doRemove( key );
+
+ }
+ finally
+ {
+ locker.done( this.cacheName + key.toString() );
+ }
+ // Remove from persistent store immediately
return false;
}
@@ -330,6 +344,32 @@
return DISK_CACHE;
}
+
+ /**
+ * Internally used write lock for purgatory item modification.
+ *
+ * @param id What name to lock on.
+ */
+ private void writeLock( String id )
+ {
+ try
+ {
+ locker.writeLock( id );
+ }
+ catch ( InterruptedException e )
+ {
+ // See note in readLock()
+
+ log.error( "Was interrupted while acquiring read lock", e );
+ }
+ catch ( Exception e )
+ {
+
+ log.error( e );
+ }
+ }
+
+
/**
* Cache that implements the CacheListener interface, and calls appropriate
* methods in its parent class.
@@ -379,9 +419,19 @@
// If the element has already been removed from purgatory
// do nothing
- if ( ! purgatory.contains( pe ) )
+ writeLock( getCacheName() + element.getKey().toString() );
+ try
+ {
+
+ if ( ! purgatory.contains( pe ) )
+ {
+ return;
+ }
+
+ }
+ finally
{
- return;
+ locker.done( getCacheName() + element.getKey().toString() );
}
element = pe.getCacheElement();
@@ -445,6 +495,7 @@
}
}
+
// ---------------------- subclasses should implement the following methods
/**
@@ -477,5 +528,7 @@
* 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]>