You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jcs-dev@jakarta.apache.org by as...@apache.org on 2005/02/01 02:35:16 UTC

cvs commit: jakarta-turbine-jcs/src/java/org/apache/jcs/auxiliary/disk/indexed IndexedDiskCache.java

asmuts      2005/01/31 17:35:16

  Modified:    src/java/org/apache/jcs/auxiliary/disk
                        AbstractDiskCache.java
               src/java/org/apache/jcs/auxiliary/disk/indexed
                        IndexedDiskCache.java
  Log:
  changing rwlock to simple sunchronization around purgatory calls in abstractdiskcache.
  
  Revision  Changes    Path
  1.29      +38 -95    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.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- AbstractDiskCache.java	1 Feb 2005 00:01:57 -0000	1.28
  +++ AbstractDiskCache.java	1 Feb 2005 01:35:15 -0000	1.29
  @@ -29,6 +29,7 @@
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  +
   import org.apache.jcs.auxiliary.AuxiliaryCache;
   import org.apache.jcs.auxiliary.disk.behavior.IDiskCacheAttributes;
   import org.apache.jcs.engine.CacheConstants;
  @@ -42,8 +43,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 org.apache.jcs.utils.locking.ReadWriteLock;
  -import org.apache.jcs.utils.locking.ReadWriteLockManager;
   
   /**
    * Abstract class providing a base implementation of a disk cache, which can
  @@ -64,8 +63,7 @@
   public abstract class AbstractDiskCache implements AuxiliaryCache, Serializable
   {
       private static final Log log =
  -        LogFactory.getLog( AbstractDiskCache.class );
  -
  +        LogFactory.getLog( AbstractDiskCache.class );  
   
       /**  Generic disk cache attributes */
       private IDiskCacheAttributes dcattr = null;
  @@ -86,16 +84,8 @@
        * 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.
  -     */
  -    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.
  @@ -234,7 +224,12 @@
               return null;
           }
   
  -        PurgatoryElement pe = ( PurgatoryElement ) purgatory.get( key );
  +        PurgatoryElement pe = null;
  +        synchronized ( purgatory )
  +        {
  +            pe = ( PurgatoryElement ) purgatory.get( key );            
  +        }
  +
   
           // If the element was found in purgatory
   
  @@ -297,28 +292,25 @@
        */
       public final boolean remove( Serializable key )
       {
  -        String keyAsString = key.toString();
  +        //String keyAsString = key.toString();
   
  -        writeLock( keyAsString );
  -        try
  +        PurgatoryElement pe = null;
  +        synchronized ( purgatory )
           {
               // Remove element from purgatory if it is there
  -
  -            PurgatoryElement pe = ( PurgatoryElement )purgatory.remove( key );
  -            if ( pe != null ) {
  -              // no way to remove from queue, just make sure it doesn't get on disk
  -              // and then removed right afterwards
  -              pe.setSpoolable(false);
  -            }
  -            // Remove from persistent store immediately
  -
  -            doRemove( key );
  +            pe = ( PurgatoryElement )purgatory.remove( key );
           }
  -        finally
  -        {
  -            releaseLock( keyAsString );
  +        
  +
  +        if ( pe != null ) {
  +            // no way to remove from queue, just make sure it doesn't get on disk
  +            // and then removed right afterwards
  +            pe.setSpoolable(false);
           }
  +        // Remove from persistent store immediately
   
  +        doRemove( key );
  +        
           return false;
       }
   
  @@ -434,46 +426,6 @@
           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 ( Throwable e )
  -        {
  -
  -            log.error( e );
  -        }
  -    }
  -
  -    /**
  -     * Internally used write lock for purgatory item modification.
  -     *
  -     * @param id What name to lock on.
  -     */
  -    private void releaseLock( String id )
  -    {
  -        try
  -        {
  -            locker.done( id );
  -        }
  -        catch ( IllegalStateException e )
  -        {
  -            log.warn( "Problem releasing lock", e );
  -        }
  -    }
   
       /**
        * Cache that implements the CacheListener interface, and calls appropriate
  @@ -526,16 +478,14 @@
                   {
                       PurgatoryElement pe = ( PurgatoryElement ) element;
   
  -                    String keyAsString = element.getKey().toString();
  -
  -                    writeLock( keyAsString );
  +                    //String keyAsString = element.getKey().toString();
   
  -                    try
  +                    synchronized ( purgatory )
                       {
                           // If the element has already been removed from
                           // purgatory do nothing
   
  -                        if ( ! purgatory.containsKey( pe.getKey() ) )
  +                        if (!purgatory.containsKey( pe.getKey() ))
                           {
                               return;
                           }
  @@ -544,20 +494,18 @@
   
                           // If the element is still eligable, spool it.
   
  -                        if ( pe.isSpoolable() )
  -                        {
  -                            doUpdate( element );
  -                        }
  -
  +                    	if (pe.isSpoolable())
  +                    	{
  +                    	    doUpdate( element );
  +                    	}
  +                        
                           // After the update has completed, it is safe to remove
                           // the element from purgatory.
   
                           purgatory.remove( element.getKey() );
  -                    }
  -                    finally
  -                    {
  -                        releaseLock( keyAsString );
  -                    }
  +                        
  +                    }                    
  +
                   }
                   else
                   {
  @@ -573,18 +521,13 @@
                   // queue.  This block handles the case where the disk cache fails
                   // during normal opertations.
                   
  -                String keyAsString = element.getKey().toString();
  -
  -                writeLock( keyAsString );
  +                //String keyAsString = element.getKey().toString();
   
  -                try
  +                synchronized ( purgatory )
                   {
                       purgatory.remove( element.getKey() );
                   }
  -                finally
  -                {
  -                    releaseLock( keyAsString );
  -                }                              
  +                                        
               }
           }
   
  
  
  
  1.20      +1 -9      jakarta-turbine-jcs/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCache.java
  
  Index: IndexedDiskCache.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-jcs/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCache.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- IndexedDiskCache.java	29 Jan 2005 00:40:02 -0000	1.19
  +++ IndexedDiskCache.java	1 Feb 2005 01:35:16 -0000	1.20
  @@ -460,7 +460,6 @@
   
       try
       {
  -      //storageLock.readLock();
         storageLock.readLock().acquire();
         try {
           if (!alive)
  @@ -475,7 +474,6 @@
         }
         finally
         {
  -        //storageLock.done();
           storageLock.readLock().release();
         }
       }
  @@ -528,7 +526,6 @@
       HashSet keys = new HashSet();
       try
       {
  -      //storageLock.readLock();
         storageLock.readLock().acquire();
   
         for (Iterator itr = keyHash.keySet().iterator(); itr.hasNext(); )
  @@ -550,7 +547,6 @@
       }
       finally
       {
  -      //storageLock.done();
         storageLock.readLock().release();
       }
   
  @@ -731,7 +727,6 @@
   
       try
       {
  -      //storageLock.writeLock();
         storageLock.writeLock().acquire();
   
         dataFile.close();
  @@ -758,7 +753,6 @@
       }
       finally
       {
  -      //storageLock.done();
         storageLock.writeLock().release();
       }
     }
  @@ -963,7 +957,6 @@
   
       try
       {
  -      //storageLock.readLock();
         storageLock.readLock().acquire();
         try
         {
  @@ -971,7 +964,6 @@
         }
         finally
         {
  -        //storageLock.done();
           storageLock.readLock().release();
         }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-jcs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-jcs-dev-help@jakarta.apache.org