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/01/12 02:21:58 UTC

cvs commit: jakarta-turbine-jcs/src/java/org/apache/jcs/auxiliary/disk/jisp JISPCache.java JISPCacheAttributes.java

asmuts      2005/01/11 17:21:58

  Modified:    src/java/org/apache/jcs/auxiliary/disk
                        AbstractDiskCache.java
               src/java/org/apache/jcs/engine/memory
                        AbstractMemoryCache.java
               src/conf cache.ccf
               src/java/org/apache/jcs/auxiliary/disk/hsql HSQLCache.java
                        HSQLCacheAttributes.java
               src/java/org/apache/jcs/auxiliary/disk/indexed
                        IndexedDiskCache.java
                        IndexedDiskCacheAttributes.java
               src/java/org/apache/jcs/auxiliary/disk/jisp JISPCache.java
                        JISPCacheAttributes.java
  Added:       src/java/org/apache/jcs/auxiliary/disk
                        AbstractDiskCacheAttributes.java
               src/java/org/apache/jcs/auxiliary/disk/behavior
                        IDiskCacheAttributes.java
  Log:
  Optional, configurable thread pools can be set for all auxiliaries.  By default
  the single queue is used. (Will document later.)
  Shrinkers for all regions now share one thread and are executed by a Doug Lea
  Clock Daemon.
  The disk cache now has more configuration options exposed.  You can set the purgatory size,
  recycle bin size, etc.  Alos, you can set a bound on the purgatory.  This solves the possibility
  or an ever growing purgatory with a bounded queue.
  Uped version to 1.2-dev to mark the changes.
  Updated some documentation.  I need to rebuild the site.  I published the new
  disk cache config page already.
  The disk cache options are described on the web site.
  
  jcs.auxiliary.DC.attributes.MaxPurgatorySize=10000
  jcs.auxiliary.DC.attributes.MaxKeySize=10000
  jcs.auxiliary.DC.attributes.MaxRecycleBinSize=5000
  jcs.auxiliary.DC.attributes.OptimizeAtRemoveCount=300000
  
  Revision  Changes    Path
  1.25      +44 -9     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.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- AbstractDiskCache.java	7 Jan 2005 22:27:14 -0000	1.24
  +++ AbstractDiskCache.java	12 Jan 2005 01:21:54 -0000	1.25
  @@ -22,14 +22,15 @@
   import java.io.Serializable;
   import java.util.ArrayList;
   import java.util.Arrays;
  -import java.util.Hashtable;
  +import java.util.HashMap;
   import java.util.List;
  +import java.util.Map;
   import java.util.Set;
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   import org.apache.jcs.auxiliary.AuxiliaryCache;
  -import org.apache.jcs.auxiliary.AuxiliaryCacheAttributes;
  +import org.apache.jcs.auxiliary.disk.behavior.IDiskCacheAttributes;
   import org.apache.jcs.engine.CacheConstants;
   import org.apache.jcs.engine.CacheEventQueueFactory;
   import org.apache.jcs.engine.CacheInfo;
  @@ -65,6 +66,10 @@
       private static final Log log =
           LogFactory.getLog( AbstractDiskCache.class );
   
  +    
  +    /**  Generic disk cache attributes */
  +    private IDiskCacheAttributes dcattr = null;
  +    
       /**
        * 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
  @@ -73,7 +78,8 @@
        * the memory cache while the are still in purgatory, writing to disk can
        * be cancelled.
        */
  -    protected Hashtable purgatory = new Hashtable();
  +    //protected Hashtable purgatory = new Hashtable();
  +    protected Map purgatory = new HashMap();
   
       /**
        * The CacheEventQueue where changes will be queued for asynchronous
  @@ -109,18 +115,47 @@
   
       // ----------------------------------------------------------- constructors
   
  -    public AbstractDiskCache( AuxiliaryCacheAttributes attr )
  +    public AbstractDiskCache( IDiskCacheAttributes attr )
       {
  +      	this.dcattr = attr;
  +      
           this.cacheName = attr.getCacheName();
   
           CacheEventQueueFactory fact = new CacheEventQueueFactory();
           this.cacheEventQueue = fact.createCacheEventQueue( new MyCacheListener(),
                                                       CacheInfo.listenerId,
                                                       cacheName, 
  -                                                    attr.getEventQueuePoolName(), 
  -                                                    attr.getEventQueueTypeFactoryCode() );
  +                                                    dcattr.getEventQueuePoolName(), 
  +                                                    dcattr.getEventQueueTypeFactoryCode() );
  +        
  +        initPurgatory();
       }
   
  +    
  +    /**
  +     * Purgatory size of -1 means to use a HashMap with no size limit.
  +     * Anything greater will use an LRU map of some sort.
  +     * 
  +     * @TODO Currently setting this to 0 will cause nothing to be put to disk, since it
  +     * will assume that if an item is not in purgatory, then it must have been plucked.  
  +     * We should make 0 work, a way to not use purgatory.
  +     * 
  +     *
  +     */
  +    private void initPurgatory()
  +    {
  +      purgatory = null;
  +      
  +      if ( dcattr.getMaxPurgatorySize() >= 0 )
  +      {
  +        purgatory = new LRUMapJCS( dcattr.getMaxPurgatorySize() );              
  +      }
  +      else 
  +      {
  +        purgatory = new HashMap();
  +      }
  +    }
  +    
       // ------------------------------------------------------- interface ICache
   
       /**
  @@ -269,7 +304,7 @@
       {
           // Replace purgatory with a new empty hashtable
   
  -        purgatory = new Hashtable();
  +        initPurgatory();
   
           // Remove all from persistent store immediately
   
  @@ -470,7 +505,7 @@
                           // If the element has already been removed from
                           // purgatory do nothing
   
  -                        if ( ! purgatory.contains( pe ) )
  +                        if ( ! purgatory.containsKey( pe.getKey() ) )
                           {
                               return;
                           }
  
  
  
  1.1                  jakarta-turbine-jcs/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCacheAttributes.java
  
  Index: AbstractDiskCacheAttributes.java
  ===================================================================
  package org.apache.jcs.auxiliary.disk;
  
  /*
   * Copyright 2001-2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License") you may not
   * use this file except in compliance with the License. You may obtain a copy of
   * the License at
   * 
   * http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   * License for the specific language governing permissions and limitations under
   * the License.
   */
  
  import org.apache.jcs.auxiliary.AbstractAuxiliaryCacheAttributes;
  import org.apache.jcs.auxiliary.AuxiliaryCacheAttributes;
  import org.apache.jcs.auxiliary.disk.behavior.IDiskCacheAttributes;
  
  public abstract class AbstractDiskCacheAttributes extends
      AbstractAuxiliaryCacheAttributes implements IDiskCacheAttributes
  {
  
    /** path to disk */
    protected String diskPath;
  
    /** default to 5000 */
    protected int    maxPurgatorySize = MAX_PURGATORY_SIZE_DEFUALT;
  
    /*
     * (non-Javadoc)
     * 
     * @see org.apache.jcs.auxiliary.disk.behavior.IDiskCacheAttributes#setDiskPath(java.lang.String)
     */
    public void setDiskPath( String path )
    {
      this.diskPath = path.trim();
    }
  
    /*
     * (non-Javadoc)
     * 
     * @see org.apache.jcs.auxiliary.disk.behavior.IDiskCacheAttributes#getDiskPath()
     */
    public String getDiskPath()
    {
      return this.diskPath;
    }
  
    /*
     * (non-Javadoc)
     * 
     * @see org.apache.jcs.auxiliary.disk.behavior.IDiskCacheAttributes#getMaxPurgatorySize()
     */
    public int getMaxPurgatorySize()
    {
      return maxPurgatorySize;
    }
  
    /*
     * (non-Javadoc)
     * 
     * @see org.apache.jcs.auxiliary.disk.behavior.IDiskCacheAttributes#setMaxPurgatorySize(int)
     */
    public void setMaxPurgatorySize( int maxPurgatorySize )
    {
      this.maxPurgatorySize = maxPurgatorySize;
    }
  
    /**
     * Description of the Method
     * 
     * @return
     */
    public AuxiliaryCacheAttributes copy()
    {
      try
      {
        return (AuxiliaryCacheAttributes) this.clone();
      }
      catch (Exception e)
      {
      }
      return this;
    }
    
    /**
     * Description of the Method
     *
     * @return
     */
    public String toString()
    {
        StringBuffer str = new StringBuffer();
        str.append( "AbstractDiskCacheAttributes " );
        str.append( "\n diskPath = " + diskPath );
        str.append( "\n maxPurgatorySize   = " + maxPurgatorySize );
        return str.toString();
    }  
  
  }
  
  
  1.11      +41 -11    jakarta-turbine-jcs/src/java/org/apache/jcs/engine/memory/AbstractMemoryCache.java
  
  Index: AbstractMemoryCache.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-jcs/src/java/org/apache/jcs/engine/memory/AbstractMemoryCache.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- AbstractMemoryCache.java	6 Jan 2005 01:17:55 -0000	1.10
  +++ AbstractMemoryCache.java	12 Jan 2005 01:21:56 -0000	1.11
  @@ -30,6 +30,9 @@
   import org.apache.jcs.engine.stats.Stats;
   import org.apache.jcs.engine.stats.behavior.IStats;
   
  +import EDU.oswego.cs.dl.util.concurrent.ClockDaemon;
  +import EDU.oswego.cs.dl.util.concurrent.ThreadFactory;
  +
   /**
    *  Some common code for the LRU and MRU caches.
    *
  @@ -70,10 +73,9 @@
       protected int chunkSize = 2;
   
       /**
  -     *  The background memory shrinker
  +     *  The background memory shrinker, one for all regions.
        */
  -    private ShrinkerThread shrinker;
  -
  +    private static ClockDaemon shrinkerDaemon;
   
       /**
        *  Constructor for the LRUMemoryCache object
  @@ -97,12 +99,15 @@
   
           status = CacheConstants.STATUS_ALIVE;
   
  -        if ( cattr.getUseMemoryShrinker() && shrinker == null )
  +        if ( cattr.getUseMemoryShrinker() )          
           {
  -            shrinker = new ShrinkerThread( this );
  -            shrinker.setDaemon(true);
  -            shrinker.setPriority( ShrinkerThread.MIN_PRIORITY );
  -            shrinker.start();
  +            if ( shrinkerDaemon == null )
  +            {
  +              shrinkerDaemon = new ClockDaemon();
  +              shrinkerDaemon.setThreadFactory( new MyThreadFactory() );              
  +            }
  +            shrinkerDaemon.executePeriodically( cattr.getShrinkerIntervalSeconds() * 1000, new ShrinkerThread( this ), false );
  +            
           }
       }
   
  @@ -174,8 +179,8 @@
       public void dispose()
           throws IOException
       {
  -      if ( shrinker != null ) {
  -        shrinker.kill();
  +      if ( shrinkerDaemon != null ) {
  +        shrinkerDaemon.shutDown();
         }
       }
   
  @@ -293,4 +298,29 @@
           }
           return keys;
       }
  +
  +    /**
  +     * Allows us to set the daemon status on the clockdaemon
  +     * 
  +     * @author aaronsm
  +     *
  +     */
  +    class MyThreadFactory implements ThreadFactory 
  +    {
  +
  +      /* (non-Javadoc)
  +       * @see EDU.oswego.cs.dl.util.concurrent.ThreadFactory#newThread(java.lang.Runnable)
  +       */
  +      public Thread newThread( Runnable runner )
  +      {
  +        Thread t = new Thread( runner );
  +        t.setDaemon( true );
  +        t.setPriority( Thread.MIN_PRIORITY );
  +        return t;
  +      }
  +      
  +    }
  +
  +    
   }
  +
  
  
  
  1.13      +16 -18    jakarta-turbine-jcs/src/conf/cache.ccf
  
  Index: cache.ccf
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-jcs/src/conf/cache.ccf,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- cache.ccf	7 Jan 2005 22:27:14 -0000	1.12
  +++ cache.ccf	12 Jan 2005 01:21:58 -0000	1.13
  @@ -8,7 +8,6 @@
   jcs.default.cacheattributes.UseMemoryShrinker=true
   jcs.default.cacheattributes.MaxMemoryIdleTimeSeconds=3600
   jcs.default.cacheattributes.ShrinkerIntervalSeconds=60
  -jcs.default.cacheattributes.ShrinkerIntervalSeconds=60
   jcs.default.elementattributes=org.apache.jcs.engine.ElementAttributes
   jcs.default.elementattributes.IsEternal=false
   jcs.default.elementattributes.MaxLifeSeconds=7
  @@ -25,10 +24,10 @@
   jcs.region.testCache1.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
   jcs.region.testCache1.cacheattributes.MaxObjects=1000
   jcs.region.testCache1.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
  -jcs.region.testCache1.cacheattributes.UseMemoryShrinker=false
  -jcs.region.testCache1.cacheattributes.MaxMemoryIdleTimeSeconds=5000
  -jcs.region.testCache1.cacheattributes.MaxSpoolPerRun=100
  +jcs.region.testCache1.cacheattributes.UseMemoryShrinker=true
   jcs.region.testCache1.cacheattributes.ShrinkerIntervalSeconds=30
  +jcs.region.testCache1.cacheattributes.MaxMemoryIdleTimeSeconds=300
  +jcs.region.testCache1.cacheattributes.MaxSpoolPerRun=100
   jcs.region.testCache1.elementattributes=org.apache.jcs.engine.ElementAttributes
   jcs.region.testCache1.elementattributes.IsEternal=false
   jcs.region.testCache1.elementattributes.MaxLifeSeconds=60000
  @@ -39,9 +38,9 @@
   jcs.region.testCache2.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
   jcs.region.testCache2.cacheattributes.MaxObjects=100
   jcs.region.testCache2.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
  -jcs.region.testCache2.cacheattributes.UseMemoryShrinker=false
  -jcs.region.testCache2.cacheattributes.MaxMemoryIdleTimeSeconds=10
  -jcs.region.testCache2.cacheattributes.ShrinkerIntervalSeconds=6
  +jcs.region.testCache2.cacheattributes.UseMemoryShrinker=true
  +jcs.region.testCache2.cacheattributes.MaxMemoryIdleTimeSeconds=1000
  +jcs.region.testCache2.cacheattributes.ShrinkerIntervalSeconds=40
   jcs.region.testCache2.elementattributes=org.apache.jcs.engine.ElementAttributes
   jcs.region.testCache2.elementattributes.IsEternal=false
   jcs.region.testCache2.elementattributes.MaxLifeSeconds=600
  @@ -86,10 +85,10 @@
   jcs.auxiliary.DC=org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheFactory
   jcs.auxiliary.DC.attributes=org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheAttributes
   jcs.auxiliary.DC.attributes.DiskPath=target/test-sandbox/raf
  -#new disk cache parameter.
  -jcs.auxiliary.DC.attributes.maxKeySize=100000
  -jcs.auxiliary.DC.attributes.optimizeAtRemoveCount=300
  -
  +jcs.auxiliary.DC.attributes.MaxPurgatorySize=10000
  +jcs.auxiliary.DC.attributes.MaxKeySize=10000
  +jcs.auxiliary.DC.attributes.MaxRecycleBinSize=5000
  +jcs.auxiliary.DC.attributes.OptimizeAtRemoveCount=300000
   
   # Disk Cache Using a Pooled Event Queue -- this allows you
   # to control the maximum number of threads it will use.
  @@ -101,9 +100,10 @@
   jcs.auxiliary.DC2=org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheFactory
   jcs.auxiliary.DC2.attributes=org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheAttributes
   jcs.auxiliary.DC2.attributes.DiskPath=target/test-sandbox/raf
  -#new disk cache parameter.
  -jcs.auxiliary.DC2.attributes.maxKeySize=100000
  -jcs.auxiliary.DC2.attributes.optimizeAtRemoveCount=300
  +jcs.auxiliary.DC2.attributes.MaxPurgatorySize=10000
  +jcs.auxiliary.DC2.attributes.MaxKeySize=10000
  +jcs.auxiliary.DC2.attributes.MaxRecycleBinSize=5000
  +jcs.auxiliary.DC2.attributes.OptimizeAtRemoveCount=300000
   jcs.auxiliary.DC2.attributes.EventQueueType=POOLED
   jcs.auxiliary.DC2.attributes.EventQueuePoolName=disk_cache_event_queue
   
  @@ -196,7 +196,7 @@
   
   
   ##############################################################
  -################## THREAD POOL CONFIGURATION ###################
  +################## OPTIONAL THREAD POOL CONFIGURATION ###################
   # Default thread pool config
   thread_pool.default.boundarySize=2000
   thread_pool.default.maximumPoolSize=150
  @@ -207,12 +207,10 @@
   thread_pool.default.startUpSize=4
   
   # Default Cache Event Queue thread pool config, used by auxiliaries
  +# since it doesn't use a boundary, some of the options are unnecessary
   thread_pool.cache_event_queue.useBoundary=false
  -#thread_pool.cache_event_queue.boundarySize=2000
  -#thread_pool.cache_event_queue.maximumPoolSize=10
   thread_pool.cache_event_queue.minimumPoolSize=5
   thread_pool.cache_event_queue.keepAliveTime=3500
  -#thread_pool.cache_event_queue.whenBlockedPolicy=RUN
   thread_pool.cache_event_queue.startUpSize=5
   
   # Disk Cache pool
  
  
  
  1.8       +2 -2      jakarta-turbine-jcs/src/java/org/apache/jcs/auxiliary/disk/hsql/HSQLCache.java
  
  Index: HSQLCache.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-jcs/src/java/org/apache/jcs/auxiliary/disk/hsql/HSQLCache.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- HSQLCache.java	7 Jan 2005 22:27:15 -0000	1.7
  +++ HSQLCache.java	12 Jan 2005 01:21:58 -0000	1.8
  @@ -36,8 +36,8 @@
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  -import org.apache.jcs.auxiliary.AuxiliaryCacheAttributes;
   import org.apache.jcs.auxiliary.disk.AbstractDiskCache;
  +import org.apache.jcs.auxiliary.disk.behavior.IDiskCacheAttributes;
   import org.apache.jcs.engine.CacheConstants;
   import org.apache.jcs.engine.behavior.ICacheElement;
   import org.apache.jcs.utils.data.PropertyGroups;
  @@ -74,7 +74,7 @@
        */
       public HSQLCache( HSQLCacheAttributes cattr )
       {
  -        super( (AuxiliaryCacheAttributes)cattr );
  +        super( (IDiskCacheAttributes)cattr );
   
           this.cattr = cattr;
   
  
  
  
  1.7       +2 -3      jakarta-turbine-jcs/src/java/org/apache/jcs/auxiliary/disk/hsql/HSQLCacheAttributes.java
  
  Index: HSQLCacheAttributes.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-jcs/src/java/org/apache/jcs/auxiliary/disk/hsql/HSQLCacheAttributes.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- HSQLCacheAttributes.java	7 Jan 2005 22:27:15 -0000	1.6
  +++ HSQLCacheAttributes.java	12 Jan 2005 01:21:58 -0000	1.7
  @@ -18,15 +18,14 @@
    */
   
   
  -import org.apache.jcs.auxiliary.AbstractAuxiliaryCacheAttributes;
   import org.apache.jcs.auxiliary.AuxiliaryCacheAttributes;
  +import org.apache.jcs.auxiliary.disk.AbstractDiskCacheAttributes;
   
   /**
    * Description of the Class
    *
    */
  -public class HSQLCacheAttributes extends AbstractAuxiliaryCacheAttributes 
  -	implements AuxiliaryCacheAttributes
  +public class HSQLCacheAttributes extends AbstractDiskCacheAttributes
   {
   
       private String diskPath;
  
  
  
  1.1                  jakarta-turbine-jcs/src/java/org/apache/jcs/auxiliary/disk/behavior/IDiskCacheAttributes.java
  
  Index: IDiskCacheAttributes.java
  ===================================================================
  package org.apache.jcs.auxiliary.disk.behavior;
  
  /*
   * Copyright 2001-2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License")
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  import org.apache.jcs.auxiliary.AuxiliaryCacheAttributes;
  
  /**
   * Common disk cache attributes.
   *  
   */
  public interface IDiskCacheAttributes extends AuxiliaryCacheAttributes
  {
    
    public static final int MAX_PURGATORY_SIZE_DEFUALT = 5000;
  
    /**
     * Sets the diskPath attribute of the IJISPCacheAttributes object
     * 
     * @param path
     *          The new diskPath value
     */
    public void setDiskPath( String path );
  
    /**
     * Gets the diskPath attribute of the IJISPCacheAttributes object
     * 
     * @return The diskPath value
     */
    public String getDiskPath();
  
  
    
    /**
     * Gets the maxKeySize attribute of the DiskCacheAttributes object
     *
     * @return The maxPurgatorySize value
     */
    public int getMaxPurgatorySize();
  
  
    /**
     * Sets the maxPurgatorySize attribute of the DiskCacheAttributes object
     *
     * @param name The new maxPurgatorySize value
     */
    public void setMaxPurgatorySize( int maxPurgatorySize );
  
  }
  //   end interface
  
  
  
  1.18      +66 -21    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.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- IndexedDiskCache.java	7 Jan 2005 22:27:54 -0000	1.17
  +++ IndexedDiskCache.java	12 Jan 2005 01:21:58 -0000	1.18
  @@ -32,9 +32,9 @@
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  -import org.apache.jcs.auxiliary.AuxiliaryCacheAttributes;
   import org.apache.jcs.auxiliary.disk.AbstractDiskCache;
   import org.apache.jcs.auxiliary.disk.LRUMapJCS;
  +import org.apache.jcs.auxiliary.disk.behavior.IDiskCacheAttributes;
   import org.apache.jcs.engine.CacheConstants;
   import org.apache.jcs.engine.CacheElement;
   import org.apache.jcs.engine.behavior.ICacheElement;
  @@ -66,7 +66,7 @@
     private String fileName;
     private IndexedDisk dataFile;
     private IndexedDisk keyFile;
  -  private LRUMap keyHash;
  +  private Map keyHash;
     private int maxKeySize;
   
     private File rafDir;
  @@ -105,7 +105,7 @@
      */
     public IndexedDiskCache(IndexedDiskCacheAttributes cattr)
     {
  -    super((AuxiliaryCacheAttributes)cattr);
  +    super((IDiskCacheAttributes)cattr);
   
       String cacheName = cattr.getCacheName();
       String rootDirName = cattr.getDiskPath();
  @@ -155,7 +155,7 @@
   
         else
         {
  -        keyHash = new LRUMap(maxKeySize);
  +        initKeyMap();
   
           if (dataFile.length() > 0)
           {
  @@ -163,11 +163,10 @@
           }
         }
   
  -      // TODO, make a new size parameter for this.
  -      recycle = new SortedPreferentialArray(maxKeySize);
  +      // create the recyclebin
  +      initRecycleBin();
   
         // Initialization finished successfully, so set alive to true.
  -
         alive = true;
       }
       catch (Exception e)
  @@ -177,6 +176,7 @@
       }
     }
   
  +  
     /**
      * Loads the keys from the .key file.  The keys are stored in a HashMap on
      * disk.  This is converted into a LRUMap.
  @@ -194,7 +194,9 @@
       try
       {
   
  -      keyHash = new LRUMap(maxKeySize);
  +      // create a key map to use.
  +      initKeyMap();
  +      
         HashMap keys = (HashMap) keyFile.readObject(0);
   
         if (keys != null)
  @@ -204,13 +206,8 @@
           if (log.isInfoEnabled())
           {
             log.info("Loaded keys from: " + fileName +
  -                   ", key count: " + keyHash.size());
  -        }
  -
  -        keyHash.setMaximumSize(maxKeySize);
  -        if (log.isInfoEnabled())
  -        {
  -          log.info("Reset maxKeySize to: '" + maxKeySize + "'");
  +                   ", key count: " + keyHash.size() +
  +                   "; upto " + maxKeySize + " will be available." );
           }
   
         }
  @@ -759,11 +756,9 @@
         keyFile =
             new IndexedDisk(new File(rafDir, fileName + ".key"));
   
  -      recycle = null;
  -      recycle = new SortedPreferentialArray(maxKeySize);
  +      initRecycleBin();
   
  -      keyHash = null;
  -      keyHash = new LRUMap(this.maxKeySize);
  +      initKeyMap();
       }
       catch (Exception e)
       {
  @@ -777,6 +772,56 @@
     }
   
     /**
  +   * If the maxKeySize is < 0, use 5000, no way to have an unlimted
  +   * recycle bin right now, or one less than the mazKeySize.
  +   * 
  +   * @TODO make separate config.  
  +   *
  +   */
  +  private void initRecycleBin()
  +  {
  +    recycle = null;
  +    if ( cattr.getMaxRecycleBinSize() >= 0 )
  +    {
  +      recycle = new SortedPreferentialArray( cattr.getMaxRecycleBinSize() );   
  +      if (log.isInfoEnabled())
  +      {
  +        log.info("Set recycle max Size to MaxRecycleBinSize: '" + cattr.getMaxRecycleBinSize() + "'");
  +      }
  +    }
  +    else 
  +    {
  +      // this is a fail safetly.  Will no
  +      recycle = new SortedPreferentialArray(0);
  +      if (log.isInfoEnabled())
  +      {
  +        log.warn("Set recycle maxSize to 0, will not try to recycle, MaxRecycleBinSize was less than 0");
  +      }
  +    }       
  +  }  
  +  
  +  
  +  private void initKeyMap()
  +  {
  +    keyHash = null;
  +    if ( maxKeySize >= 0 )
  +    {
  +      keyHash = new LRUMapJCS(maxKeySize);      
  +      if (log.isInfoEnabled())
  +      {
  +        log.info("Set maxKeySize to: '" + maxKeySize + "'");
  +      }
  +    }
  +    else 
  +    {
  +      keyHash = new HashMap();// Hashtable();//HashMap();
  +      if (log.isInfoEnabled())
  +      {
  +        log.info("Set maxKeySize to unlimited'");
  +      }
  +    }       
  +  }    
  +  /**
      * Dispose of the disk cache in a background thread.  Joins against this
      * thread to put a cap on the disposal time.
      */
  @@ -1097,7 +1142,7 @@
       catch (IOException e)
       {
         log.error("Failed to get orinigal off disk cache: " + fileName
  -                + ", key: " + key + "; keyHash.tag = " + keyHash.tag);
  +                + ", key: " + key + "" );//; keyHash.tag = " + keyHash.tag);
         //reset();
         throw e;
       }
  
  
  
  1.12      +54 -33    jakarta-turbine-jcs/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheAttributes.java
  
  Index: IndexedDiskCacheAttributes.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-jcs/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheAttributes.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- IndexedDiskCacheAttributes.java	7 Jan 2005 22:27:54 -0000	1.11
  +++ IndexedDiskCacheAttributes.java	12 Jan 2005 01:21:58 -0000	1.12
  @@ -18,22 +18,25 @@
    */
   
   
  -import org.apache.jcs.auxiliary.AbstractAuxiliaryCacheAttributes;
   import org.apache.jcs.auxiliary.AuxiliaryCacheAttributes;
  +import org.apache.jcs.auxiliary.disk.AbstractDiskCacheAttributes;
   
   /**
    * Configuration class for the Indexed Disk Cache
    *
    */
  -public class IndexedDiskCacheAttributes extends AbstractAuxiliaryCacheAttributes 
  -	implements AuxiliaryCacheAttributes
  -{
  -
  -    private String diskPath;
  -
  -    // default to 5000
  -    private int maxKeySize = 5000;
  +public class IndexedDiskCacheAttributes extends AbstractDiskCacheAttributes 
  +{   
  +  
  +    private static final int DEFAULT_maxKeySize = 5000;
  +    private static final int DEFAULT_maxRecycleBinSize = 5000;
  +  
  +    /** -1 mean no limit. */
  +    private int maxKeySize = DEFAULT_maxKeySize;
   
  +    /** Cannot be larger than the max size.  If max is less than 0, this will be 5000 */
  +    private int maxRecycleBinSize = DEFAULT_maxRecycleBinSize;
  +    
       // default to -1, i.e., don't optimize until shutdown
       private int optimizeAtRemoveCount = -1;
   
  @@ -42,29 +45,7 @@
        */
       public IndexedDiskCacheAttributes()
       {
  -    }
  -
  -
  -    /**
  -     * Sets the diskPath attribute of theputm 2000 DiskCacheAttributes object
  -     *
  -     * @param path The new diskPath value
  -     */
  -    public void setDiskPath( String path )
  -    {
  -        this.diskPath = path.trim();
  -    }
  -
  -
  -    /**
  -     * Gets the diskPath attribute of the DiskCacheAttributes object
  -     *
  -     * @return The diskPath value
  -     */
  -    public String getDiskPath()
  -    {
  -        return this.diskPath;
  -    }
  +    } 
   
       
       /**
  @@ -86,6 +67,9 @@
       public void setMaxKeySize( int maxKeySize )
       {
           this.maxKeySize = maxKeySize;
  +        
  +        // make sure the sizes are in accord with our rule.
  +        setMaxRecycleBinSize( maxRecycleBinSize );
       }
   
       /**
  @@ -113,6 +97,38 @@
   
   
       /**
  +     * This cannot be larger than the maxKeySize.  It wouldn't hurt
  +     * anything, but it makes the config necessary.  The recycle bin
  +     * entry willbe at least as large as a key.
  +     * 
  +     * If the maxKeySize
  +     * is -1 this will be set tot he default, which is 5000.
  +     * 
  +     * @param maxRecycleBinSize The maxRecycleBinSize to set.
  +     */
  +    public void setMaxRecycleBinSize( int maxRecycleBinSize )
  +    {
  +      if ( maxKeySize >= 0 )
  +      {
  +        this.maxRecycleBinSize = Math.min( maxRecycleBinSize, maxKeySize );
  +      }
  +      else
  +      {
  +        this.maxRecycleBinSize = DEFAULT_maxRecycleBinSize;        
  +      }
  +    }
  +
  +
  +    /**
  +     * @return Returns the maxRecycleBinSize.
  +     */
  +    public int getMaxRecycleBinSize()
  +    {
  +      return maxRecycleBinSize;
  +    }
  +
  +    
  +    /**
        * Description of the Method
        *
        * @return
  @@ -138,7 +154,12 @@
       public String toString()
       {
           StringBuffer str = new StringBuffer();
  -        str.append( "diskPath = " + diskPath );
  +        str.append( "IndexedDiskCacheAttributes " );
  +        str.append( "\n diskPath = " + diskPath );
  +        str.append( "\n maxPurgatorySize   = " + maxPurgatorySize );
  +        str.append( "\n maxKeySize  = " + maxKeySize );
  +        str.append( "\n maxRecycleBinSize  = " + maxRecycleBinSize );
  +        str.append( "\n optimizeAtRemoveCount  = " + optimizeAtRemoveCount );
           return str.toString();
       }
   
  
  
  
  1.11      +6 -5      jakarta-turbine-jcs/src/java/org/apache/jcs/auxiliary/disk/jisp/JISPCache.java
  
  Index: JISPCache.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-jcs/src/java/org/apache/jcs/auxiliary/disk/jisp/JISPCache.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- JISPCache.java	7 Jan 2005 22:27:54 -0000	1.10
  +++ JISPCache.java	12 Jan 2005 01:21:58 -0000	1.11
  @@ -22,16 +22,17 @@
   import java.io.Serializable;
   import java.util.Set;
   
  -import com.coyotegulch.jisp.BTreeIndex;
  -import com.coyotegulch.jisp.IndexedObjectDatabase;
  -import com.coyotegulch.jisp.KeyObject;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  -import org.apache.jcs.auxiliary.AuxiliaryCacheAttributes;
   import org.apache.jcs.auxiliary.disk.AbstractDiskCache;
  +import org.apache.jcs.auxiliary.disk.behavior.IDiskCacheAttributes;
   import org.apache.jcs.engine.CacheElement;
   import org.apache.jcs.engine.behavior.ICacheElement;
   
  +import com.coyotegulch.jisp.BTreeIndex;
  +import com.coyotegulch.jisp.IndexedObjectDatabase;
  +import com.coyotegulch.jisp.KeyObject;
  +
   /**
    * JISP disk cache implementation. Slow as hell with this type of key.
    *
  @@ -67,7 +68,7 @@
        */
       public JISPCache( JISPCacheAttributes cattr )
       {
  -        super( (AuxiliaryCacheAttributes)cattr);
  +        super( (IDiskCacheAttributes)cattr);
   
           numInstances++;
   
  
  
  
  1.7       +2 -25     jakarta-turbine-jcs/src/java/org/apache/jcs/auxiliary/disk/jisp/JISPCacheAttributes.java
  
  Index: JISPCacheAttributes.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-jcs/src/java/org/apache/jcs/auxiliary/disk/jisp/JISPCacheAttributes.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- JISPCacheAttributes.java	7 Jan 2005 22:27:54 -0000	1.6
  +++ JISPCacheAttributes.java	12 Jan 2005 01:21:58 -0000	1.7
  @@ -18,45 +18,22 @@
    */
   
   
  -import org.apache.jcs.auxiliary.AbstractAuxiliaryCacheAttributes;
   import org.apache.jcs.auxiliary.AuxiliaryCacheAttributes;
  +import org.apache.jcs.auxiliary.disk.AbstractDiskCacheAttributes;
   
   /**
    * Description of the Class
    *
    */
  -public class JISPCacheAttributes extends AbstractAuxiliaryCacheAttributes
  -	implements AuxiliaryCacheAttributes
  +public class JISPCacheAttributes extends AbstractDiskCacheAttributes
   {
   
  -    private String diskPath;
  -
       private boolean clearOnStart;
   
       /** Constructor for the JISPCacheAttributes object */
       public JISPCacheAttributes()
       {
           clearOnStart = false;
  -    }
  -
  -    /**
  -     * Sets the diskPath attribute of the JISPCacheAttributes object
  -     *
  -     * @param path The new diskPath value
  -     */
  -    public void setDiskPath( String path )
  -    {
  -        this.diskPath = path;
  -    }
  -
  -    /**
  -     * Gets the diskPath attribute of the JISPCacheAttributes object
  -     *
  -     * @return The diskPath value
  -     */
  -    public String getDiskPath()
  -    {
  -        return this.diskPath;
       }
   
   
  
  
  

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