You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by jt...@apache.org on 2002/02/24 20:18:06 UTC

cvs commit: jakarta-turbine-stratum/src/test/org/apache/stratum/jcs TestDiskCache.java

jtaylor     02/02/24 11:18:05

  Modified:    src/java/org/apache/stratum/jcs/auxiliary/disk/hsql
                        HSQLCache.java HSQLCacheNoWaitBuffer.java
               src/java/org/apache/stratum/jcs/auxiliary/disk/indexed
                        IndexedDiskCache.java IndexedDiskCacheManager.java
               src/java/org/apache/stratum/jcs/auxiliary/disk/jisp
                        JISPCache.java JISPCacheNoWaitBuffer.java
               src/java/org/apache/stratum/jcs/auxiliary/lateral
                        LateralCache.java LateralCacheNoWait.java
                        LateralCacheNoWaitFacade.java
               src/java/org/apache/stratum/jcs/auxiliary/remote
                        RemoteCache.java RemoteCacheNoWait.java
                        RemoteCacheNoWaitFacade.java
               src/java/org/apache/stratum/jcs/engine/behavior ICache.java
               src/java/org/apache/stratum/jcs/engine/control Cache.java
               src/java/org/apache/stratum/jcs/engine/memory/lru
                        LRUMemoryCache.java
               src/java/org/apache/stratum/jcs/engine/memory/mru
                        MRUMemoryCache.java
               src/java/org/apache/stratum/jcs/engine/memory/shrinking
                        ShrinkingMemoryCache.java
               src/java/org/apache/stratum/jcs/utils/locking
                        ReadWriteLock.java
               src/test/org/apache/stratum/jcs TestDiskCache.java
  Added:       src/java/org/apache/stratum/jcs/auxiliary/disk
                        AbstractDiskCache.java PurgatoryElement.java
  Removed:     src/java/org/apache/stratum/jcs/auxiliary/disk/indexed
                        IndexedDiskCacheNoWaitBuffer.java
                        IndexedDiskLockManager.java PurgatoryElement.java
  Log:
  Initial pass at refactoring disk cache. Added 'AbstractDiskCache' which
  contains most of the code that was duplicated between different disk cache
  implementations. IndexedDiskCache now extends this class. The other
  implementations have not yet been changed to extend it, mainly since neither
  of them work currently and I didn't want to get bogged down.
  
  Also, removed ICache.getSourceID() which really wasn't used anywhere important.
  
  I decided to extract an abstract superclass for consistency with the current
  code, however my feeling now is that composition rather than inheritence, ie
  some kind of plugin architecture, would be better for disk caches, more along
  the lines of the way lateral caches work. More on that later.
  
  Revision  Changes    Path
  1.1                  jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/disk/AbstractDiskCache.java
  
  Index: AbstractDiskCache.java
  ===================================================================
  package org.apache.stratum.jcs.auxiliary.disk;
  
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   * notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   * notice, this list of conditions and the following disclaimer in
   * the documentation and/or other materials provided with the
   * distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   * any, must include the following acknowlegement:
   * "This product includes software developed by the
   * Apache Software Foundation (http://www.apache.org/)."
   * Alternately, this acknowlegement may appear in the software itself,
   * if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Velocity", and "Apache Software
   * Foundation" must not be used to endorse or promote products derived
   * from this software without prior written permission. For written
   * permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   * nor may "Apache" appear in their names without prior written
   * permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogSource;
  import org.apache.stratum.jcs.engine.CacheElement;
  import org.apache.stratum.jcs.engine.CacheEventQueue;
  import org.apache.stratum.jcs.engine.CacheInfo;
  import org.apache.stratum.jcs.engine.behavior.ICache;
  import org.apache.stratum.jcs.engine.behavior.ICacheElement;
  import org.apache.stratum.jcs.engine.behavior.ICacheEventQueue;
  import org.apache.stratum.jcs.engine.behavior.ICacheListener;
  import org.apache.stratum.jcs.engine.behavior.IElementAttributes;
  import org.apache.stratum.jcs.auxiliary.behavior.IAuxiliaryCacheAttributes;
  import org.apache.stratum.jcs.utils.locking.ReadWriteLock;
  
  import java.io.IOException;
  import java.io.Serializable;
  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.
   *
   * 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:asmuts@yahoo.com">Aaron Smuts</a>
   * @author <a href="mailto:james@jamestaylor.org">James Taylor</a>
   * @version $Id: AbstractDiskCache.java,v 1.1 2002/02/24 19:18:04 jtaylor Exp $
   */
  public abstract class AbstractDiskCache implements ICache, Serializable
  {
      private final static Log log =
          LogSource.getInstance( 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.
       */
      protected Hashtable purgatory = new Hashtable();
  
      /**
       * 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.
       */
      protected ReadWriteLock lock = new ReadWriteLock();
  
      /**
       * 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.
       */
      protected String cacheName;
  
      /**
       * DEBUG: Keeps a count of the number of purgatory hits for debug messages
       */
      protected int purgHits = 0;
  
      // ----------------------------------------------------------- constructors
  
      public AbstractDiskCache( String cacheName )
      {
          this.cacheName = cacheName;
  
          this.cacheEventQueue = new CacheEventQueue( new MyCacheListener(),
                                                      CacheInfo.listenerId,
                                                      cacheName );
      }
  
      // ------------------------------------------------------- interface ICache
  
      /**
       * @see org.apache.stratum.jcs.engine.behavior.ICache#put
       */
      public final void put( Serializable key, Serializable value )
          throws IOException
      {
          put( key, value, null );
      }
  
      /**
       * @see org.apache.stratum.jcs.engine.behavior.ICache#put
       */
      public final void put( Serializable key, Serializable value,
                       IElementAttributes attributes )
          throws IOException
      {
          CacheElement ce = new CacheElement( cacheName, key, value );
  
          ce.setElementAttributes( attributes );
  
          update( ce );
      }
  
      /**
       * 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.stratum.jcs.engine.behavior.ICache#update
       */
      public final void update( ICacheElement cacheElement )
          throws IOException
      {
          try
          {
              // Wrap the CacheElement in a PurgatoryElement
  
              PurgatoryElement pe = new PurgatoryElement( cacheElement );
  
              // Indicates the the element is eligable to be spooled to disk,
              // this will remain true unless the item is pulled back into
              // memory.
  
              pe.setSpoolable( true );
  
              // Add the element to purgatory
  
              purgatory.put( pe.getKey(), pe );
  
              // Queue element for serialization
  
              cacheEventQueue.addPutEvent( pe );
          }
          catch ( IOException ex )
          {
              log.error( ex );
  
              cacheEventQueue.destroy();
          }
      }
  
      /**
       * @see org.apache.stratum.jcs.engine.behavior.ICache#get
       */
      public final Serializable get( Serializable key )
      {
          return get( key, true );
      }
  
      /**
       * @see org.apache.stratum.jcs.engine.behavior.ICache#get
       */
      public final Serializable get( Serializable key, boolean container )
      {
          // If not alive, always return null.
  
          if ( !alive )
          {
              return null;
          }
  
          PurgatoryElement pe = ( PurgatoryElement ) purgatory.get( key );
  
          // If the element was found in purgatory
  
          if ( pe != null )
          {
              purgHits++;
  
              if ( log.isDebugEnabled() )
              {
                  if ( purgHits % 100 == 0 )
                  {
                      log.debug( "Purgatory hits = " + purgHits );
                  }
              }
  
              // The element will go back to the memory cache, so set spoolable
              // to false, which will prevent the queue listener from serializing
              // the element.
  
              pe.setSpoolable( false );
  
              log.debug( "Found in purgatory" );
  
              if ( container )
              {
                  purgatory.remove( key );
  
                  return pe.cacheElement;
              }
              else
              {
                  purgatory.remove( key );
  
                  return ( Serializable ) pe.cacheElement.getVal();
              }
          }
  
          // If we reach this point, element was not found in purgatory, so get
          // it from the cache.
  
          try
          {
              return doGet( key );
          }
          catch ( Exception e )
          {
              log.error( e );
  
              cacheEventQueue.destroy();
          }
  
          return null;
      }
  
      /**
       * @see org.apache.stratum.jcs.engine.behavior.ICache#remove
       */
      public final boolean remove( Serializable key )
      {
          // Remove element from purgatory if it is there
  
          purgatory.remove( key );
  
          // Queue removal for persistent store
  
          try
          {
              cacheEventQueue.addRemoveEvent( key );
          }
          catch ( IOException e )
          {
              log.error( e );
  
              cacheEventQueue.destroy();
          }
  
          return false;
      }
  
      /**
       * @see org.apache.stratum.jcs.engine.behavior.ICache#removeAll
       */
      public final void removeAll()
      {
          // Replace purgatory with a new empty hashtable
  
          purgatory = new Hashtable();
  
          // Queue a remove all for the persistent store
  
          try
          {
              cacheEventQueue.addRemoveAllEvent();
          }
          catch ( IOException e )
          {
              log.error( e );
  
              cacheEventQueue.destroy();
          }
      }
  
      /**
       * Adds a dispose request to the disk cache.
       */
      public final void dispose()
      {
          alive = false;
  
          // Invoke any implementation specific disposal code
  
          doDispose();
  
          // FIXME: May lose the end of the queue, need to be more graceful
  
          cacheEventQueue.destroy();
      }
  
      /**
       * @see ICache#getCacheName
       */
      public String getCacheName()
      {
          return cacheName;
      }
  
      /**
       * Subclasses will want to override this to provide more information most
       * likely.
       *
       * @see ICache#getStats
       */
      public String getStats()
      {
          return "cacheName = " + cacheName;
      }
  
      /**
       * @see ICache#getStatus
       */
      public int getStatus()
      {
          return ( alive ? STATUS_ALIVE : STATUS_DISPOSED );
      }
  
      /**
       * Size cannot be determined without knowledge of the cache implementation,
       * so subclasses will need to implement this method.
       *
       * @see ICache#getSize
       */
      public abstract int getSize();
  
      /**
       * @see ICache#getType
       *
       * @return Always returns DISK_CACHE since subclasses should all be of
       *         that type.
       */
      public int getCacheType()
      {
          return DISK_CACHE;
      }
  
      /**
       * Cache that implements the CacheListener interface, and calls appropriate
       * methods in its parent class.
       */
      private class MyCacheListener implements ICacheListener
      {
          private byte listenerId = 0;
  
          /**
           * @see ICacheListener#getListenerID
           */
          public byte getListenerId()
              throws IOException
          {
              return this.listenerId;
          }
  
          /**
           * @see ICacheListener#setListenerID
           */
          public void setListenerId( byte id )
              throws IOException
          {
              this.listenerId = id;
          }
  
          /**
           * @see ICacheListener#handlePut
           */
          public void handlePut( ICacheElement element )
              throws IOException
          {
              if ( alive )
              {
                  // If the element is a PurgatoryElement we must check to see
                  // if it is still spoolable, and remove it from purgatory.
  
                  if ( element instanceof PurgatoryElement )
                  {
                      PurgatoryElement pe = ( PurgatoryElement ) element;
  
                      element = pe.getCacheElement();
  
                      purgatory.remove( element.getKey() );
  
                      if ( ! pe.isSpoolable() )
                      {
                          // It has returned to memory from puratory, so do not
                          // spool it to disk.
                          return;
                      }
                  }
  
                  doUpdate( element );
              }
          }
  
          /**
           * @see ICacheListener#handleRemove
           */
          public void handleRemove( String cacheName, Serializable key )
              throws IOException
          {
              if ( alive )
              {
                  if ( doRemove( key ) )
                  {
                      log.debug( "Element removed, key: " + key );
                  }
              }
          }
  
          /**
           * @see ICacheListener#handleRemoveAll
           */
          public void handleRemoveAll( String cacheName )
              throws IOException
          {
              if ( alive )
              {
                  doRemoveAll();
              }
          }
  
          /**
           * @see ICacheListener#handleDispose
           */
          public void handleDispose( String cacheName )
              throws IOException
          {
              if ( alive )
              {
                  doDispose();
              }
          }
      }
  
      // ---------------------- subclasses should implement the following methods
  
      /**
       * Get a value from the persistent store.
       *
       * @param key Key to locate value for.
       * @return An object matching key, or null.
       */
      protected abstract Serializable doGet( Serializable key );
  
      /**
       * Add a cache element to the persistent store.
       */
      protected abstract void doUpdate( ICacheElement element );
  
      /**
       * Remove an object from the persistent store if found.
       *
       * @param key Key of object to remove.
       */
      protected abstract boolean doRemove( Serializable key );
  
      /**
       * 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.
       */
      protected abstract void doDispose();
  }
  
  
  
  
  1.7       +66 -78    jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/disk/PurgatoryElement.java
  
  
  
  
  1.10      +3 -17     jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/disk/hsql/HSQLCache.java
  
  Index: HSQLCache.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/disk/hsql/HSQLCache.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- HSQLCache.java	23 Feb 2002 20:39:11 -0000	1.9
  +++ HSQLCache.java	24 Feb 2002 19:18:04 -0000	1.10
  @@ -73,6 +73,7 @@
   import java.util.Properties;
   
   import org.apache.stratum.jcs.auxiliary.disk.hsql.behavior.IHSQLCacheAttributes;
  +import org.apache.stratum.jcs.auxiliary.disk.PurgatoryElement;
   
   import org.apache.stratum.jcs.engine.behavior.IElementAttributes;
   import org.apache.stratum.jcs.engine.CacheElement;
  @@ -103,9 +104,6 @@
       /** Description of the Field */
       public boolean isAlive = false;
   
  -    // not used
  -    private String source_id = "org.apache.stratum.jcs.auxiliary.hsql.HSQLCache";
  -
       IHSQLCacheAttributes cattr;
   
       // disk cache buffer, need to remove key from buffer on update, if its there
  @@ -122,18 +120,6 @@
       //PreparedStatement psUpdate;
       //PreparedStatement psSelect;
   
  -
  -    /**
  -     * Gets the sourceId attribute of the HSQLCache object
  -     *
  -     * @return The sourceId value
  -     */
  -    public Serializable getSourceId()
  -    {
  -        return this.source_id;
  -    }
  -
  -
       // should use this method
       /**
        * Constructor for the HSQLCache object
  @@ -342,8 +328,8 @@
           if ( ce instanceof PurgatoryElement )
           {
               PurgatoryElement pe = ( PurgatoryElement ) ce;
  -            ce = pe.ice;
  -            if ( !pe.isSpoolable )
  +            ce = pe.getCacheElement();
  +            if ( ! pe.isSpoolable() )
               {
                   log.debug( "pe is not spoolable" );
   
  
  
  
  1.8       +7 -21     jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/disk/hsql/HSQLCacheNoWaitBuffer.java
  
  Index: HSQLCacheNoWaitBuffer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/disk/hsql/HSQLCacheNoWaitBuffer.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- HSQLCacheNoWaitBuffer.java	18 Feb 2002 17:14:23 -0000	1.7
  +++ HSQLCacheNoWaitBuffer.java	24 Feb 2002 19:18:04 -0000	1.8
  @@ -60,6 +60,7 @@
   
   import org.apache.stratum.jcs.auxiliary.disk.hsql.behavior.IHSQLCacheAttributes;
   import org.apache.stratum.jcs.auxiliary.disk.hsql.behavior.IHSQLCacheService;
  +import org.apache.stratum.jcs.auxiliary.disk.PurgatoryElement;
   
   import org.apache.stratum.jcs.engine.behavior.IElementAttributes;
   import org.apache.stratum.jcs.engine.CacheAdaptor;
  @@ -104,20 +105,6 @@
       private HSQLCache cache;
       private ICacheEventQueue q;
   
  -    private String source_id = "org.apache.stratum.jcs.auxiliary.disk.HSQLCacheNoWaitBuffer";
  -
  -
  -    /**
  -     * Gets the sourceId attribute of the HSQLCacheNoWaitBuffer object
  -     *
  -     * @return The sourceId value
  -     */
  -    public Serializable getSourceId()
  -    {
  -        return this.source_id;
  -    }
  -
  -
       /**
        * Constructs with the given disk cache, and fires up an event queue for
        * aysnchronous processing.
  @@ -177,7 +164,7 @@
               log.debug( "putting in purgatory" );
   
               PurgatoryElement pe = new PurgatoryElement( ce );
  -            pe.isSpoolable = true;
  +            pe.setSpoolable( true );
               q.addPutEvent( ( ICacheElement ) pe );
   
               //q.addPutEvent( ce );
  @@ -227,22 +214,21 @@
                   }
               }
   
  -            //ide.setIsSpoolable( false );
  -            pe.isSpoolable = false;
  +            pe.setSpoolable( false );
   
               log.debug( "found in purgatory" );
   
               if ( container )
               {
                   purgatory.remove( key );
  -                //return (ICacheElement)ide;
  -                return pe.ice;
  +
  +                return pe.getCacheElement();
               }
               else
               {
                   purgatory.remove( key );
  -                //return (Serializable)ide.getVal();
  -                return ( Serializable ) pe.ice.getVal();
  +
  +                return ( Serializable ) pe.getCacheElement().getVal();
               }
           }
           try
  
  
  
  1.4       +217 -404  jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/disk/indexed/IndexedDiskCache.java
  
  Index: IndexedDiskCache.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/disk/indexed/IndexedDiskCache.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- IndexedDiskCache.java	22 Feb 2002 06:05:22 -0000	1.3
  +++ IndexedDiskCache.java	24 Feb 2002 19:18:05 -0000	1.4
  @@ -53,111 +53,57 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    */
  +
  +import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogSource;
  +import org.apache.stratum.jcs.auxiliary.disk.AbstractDiskCache;
  +import org.apache.stratum.jcs.auxiliary.disk.indexed.behavior.IIndexedDiskCacheAttributes;
  +import org.apache.stratum.jcs.engine.CacheElement;
  +import org.apache.stratum.jcs.engine.behavior.ICacheElement;
  +
   import java.io.File;
  -import java.io.FileNotFoundException;
   import java.io.IOException;
   import java.io.Serializable;
  -
   import java.util.ConcurrentModificationException;
   import java.util.HashMap;
   import java.util.Iterator;
   import java.util.Map;
  -import java.util.Set;
  -
  -import java.util.Map.Entry;
  -
  -import org.apache.stratum.jcs.auxiliary.disk.indexed.behavior.IIndexedDiskCacheAttributes;
  -import org.apache.stratum.jcs.auxiliary.disk.indexed.IndexedDiskCacheNoWaitBuffer;
  -import org.apache.stratum.jcs.auxiliary.disk.indexed.PurgatoryElement;
  -
  -import org.apache.stratum.jcs.engine.behavior.IElementAttributes;
  -import org.apache.stratum.jcs.engine.CacheElement;
  -
  -import org.apache.stratum.jcs.engine.behavior.ICache;
  -import org.apache.stratum.jcs.engine.behavior.ICacheElement;
  -
  -import org.apache.stratum.jcs.utils.data.PropertyGroups;
  -
  -import org.apache.commons.logging.Log;
  -import org.apache.commons.logging.LogSource;
   
   /**
  - * @author Aaron Smuts
  - * @author Hanson Char
  - * @author Aaron Smuts
  - * @created January 15, 2002
  - * @version 1.0
  - * @version 1.1 <br>
  - *      <br>
  - *      Changes in version 1.1:
  - *      <ol>
  - *        <li> replace synchronization mechanism with read/write lock manager;
  + * Disk cache that uses a RandomAccessFile with keys stored in memory
    *
  - *        <li> replace the use of DiskIO with Disk;
  - *        <li> avoid disk write if no change to data value;
  - *        <li> reduce disk fragmentation by re-using disk locations when
  - *        possible;
  - *      </ol>
  - *
  - * @version 1.2 Made the disk cache attribute driven. Uses common ICache
  - *      interface and ICacheAttributes.
  + * @author <a href="mailto:asmuts@yahoo.com">Aaron Smuts</a>
  + * @author <a href="mailto:james@jamestaylor.org">James Taylor</a>
  + * @version $Id: IndexedDiskCache.java,v 1.4 2002/02/24 19:18:05 jtaylor Exp $
    */
  -public class IndexedDiskCache implements ICache, Serializable
  +public class IndexedDiskCache extends AbstractDiskCache
   {
       private final static Log log =
           LogSource.getInstance( IndexedDiskCache.class );
   
  -    private static int numCreated = 0;
  -    private int numInstances = 0;
  -
  -    private final static IndexedDiskLockManager locker = IndexedDiskLockManager.getInstance();
       private String fileName;
       private String cacheName;
       private IndexedDisk dataFile;
       private IndexedDisk keyFile;
       private HashMap keyHash;
   
  -    /**
  -     * Description of the Field
  -     */
  -    public boolean isAlive = false;
       private File rafDir;
   
       IIndexedDiskCacheAttributes cattr;
   
  -    // not used
  -    private String source_id = "org.apache.stratum.jcs.auxiliary.disk.DiskCache";
  -
  -    // disk cache buffer, need to remove key from buffer on update, if its there
  -    IndexedDiskCacheNoWaitBuffer buffer;
  -
  -
  -    /**
  -     * Gets the sourceId attribute of the DiskCache object
  -     *
  -     * @return The sourceId value
  -     */
  -    public Serializable getSourceId()
  -    {
  -        return this.source_id;
  -    }
  -
  -
  -    // should use this method
       /**
        * Constructor for the DiskCache object
        *
        * @param buffer
        * @param cattr
        */
  -    public IndexedDiskCache( IndexedDiskCacheNoWaitBuffer buffer, IIndexedDiskCacheAttributes cattr )
  +    public IndexedDiskCache( IIndexedDiskCacheAttributes cattr )
       {
           this( cattr.getCacheName(), cattr.getDiskPath() );
  +
           this.cattr = cattr;
  -        this.buffer = buffer;
       }
   
  -
       /**
        * Constructor for the DiskCache object
        *
  @@ -168,94 +114,90 @@
           this( cacheName, null );
       }
   
  -
       /**
        * Constructor for the DiskCache object
        *
        * @param cacheName
        * @param rafroot
        */
  -    protected IndexedDiskCache( String cacheName, String rafroot )
  +    protected IndexedDiskCache( String cacheName, String rootDirName )
       {
  -        numInstances++;
  +        super( cacheName );
  +
           this.fileName = cacheName;
           this.cacheName = cacheName;
   
  -        //String rafroot = cattr.getDiskPath();
  -        if ( rafroot == null )
  -        {
  -            try
  -            {
  -                PropertyGroups pg = new PropertyGroups( "/cache.properties" );
  -                rafroot = pg.getProperty( "diskPath" );
  -            }
  -            catch ( Exception e )
  -            {
  -                log.error( e );
  -            }
  -        }
  -        rafDir = new File( rafroot );
  +        rafDir = new File( rootDirName );
           rafDir.mkdirs();
   
  -        log.info( "rafroot=" + rafroot );
  +        log.info( "Cache file root directory: " + rootDirName );
   
           try
           {
  -            try
  +            dataFile = new IndexedDisk(
  +                new File( rafDir, fileName + ".data" ) );
  +
  +            keyFile = new IndexedDisk(
  +                new File( rafDir, fileName + ".key" ) );
  +
  +            // If the key file has contents, try to initialize the keys
  +            // from it. In no keys are loaded reset the data file.
  +
  +            if ( keyFile.length() > 0 )
               {
  -                dataFile = new IndexedDisk( new File( rafDir, fileName + ".data" ) );
  -                keyFile = new IndexedDisk( new File( rafDir, fileName + ".key" ) );
  -                if ( keyFile.length() > 0 )
  -                {
  -                    loadKeys();
  -                    if ( keyHash.size() == 0 )
  -                    {
  -                        dataFile.reset();
  -                    }
  -                }
  -                else
  +                loadKeys();
  +
  +                if ( keyHash.size() == 0 )
                   {
  -                    keyHash = new HashMap();
  -                    if ( dataFile.length() > 0 )
  -                    {
  -                        dataFile.reset();
  -                    }
  +                    dataFile.reset();
                   }
  -                isAlive = true;
  -            }
  -            catch ( FileNotFoundException e )
  -            {
  -                log.error( e );
               }
  -            catch ( Exception e )
  +
  +            // Otherwise start with a new empty map for the keys, and reset
  +            // the data file if it has contents.
  +
  +            else
               {
  -                log.error( fileName, e );
  +                keyHash = new HashMap();
  +
  +                if ( dataFile.length() > 0 )
  +                {
  +                    dataFile.reset();
  +                }
               }
  +
  +            // Initialization finished successfully, so set alive to true.
  +
  +            alive = true;
           }
           catch ( Exception e )
           {
  -            log.error( e );
  -
  +            log.error( "Failure initializing for fileName: " + fileName
  +                + " and root directory: " + rootDirName, e );
           }
       }
  -    // end constructor
   
       /**
        * Description of the Method
        */
  -    public void loadKeys()
  +    private void loadKeys()
  +        throws InterruptedException
       {
  -        locker.writeLock();
  +        lock.writeLock();
  +
           try
           {
               keyHash = ( HashMap ) keyFile.readObject( 0 );
  +
               if ( keyHash == null )
               {
                   keyHash = new HashMap();
               }
  +
               if ( log.isDebugEnabled() )
               {
  -                log.debug( "LOADKEYS " + fileName + " -- keyHash.size() = " + keyHash.size() );
  +                log.debug( "Loaded keys from: " + fileName +
  +                    ", key count: " + keyHash.size() );
               }
           }
           catch ( Exception e )
  @@ -264,27 +206,29 @@
           }
           finally
           {
  -            locker.done();
  -            // release read lock.
  +            lock.done();
           }
       }
  -    // end loadKeys
   
       /**
        * Saves key file to disk
        */
  -    public void saveKeys()
  +    private void saveKeys()
       {
           try
           {
               if ( log.isDebugEnabled() )
               {
  -                log.debug( "SAVEKEYS " + fileName + " -- keyHash.size() = " + keyHash.size() );
  +                log.debug( "Saving keys to: " + fileName +
  +                    ", key count: " + keyHash.size() );
               }
  -            locker.writeLock();
  +
  +            lock.writeLock();
  +
               try
               {
                   keyFile.reset();
  +
                   if ( keyHash.size() > 0 )
                   {
                       keyFile.writeObject( keyHash, 0 );
  @@ -292,8 +236,7 @@
               }
               finally
               {
  -                locker.done();
  -                // release write lock.
  +                lock.done();
               }
           }
           catch ( Exception e )
  @@ -301,69 +244,6 @@
               log.error( e );
           }
       }
  -    // end saveKeys
  -
  -    /**
  -     * Description of the Method
  -     *
  -     * @param key
  -     * @param value
  -     * @exception IOException
  -     */
  -    public void add( Serializable key, Serializable value )
  -        throws IOException
  -    {
  -        put( key, value );
  -    }
  -
  -
  -    // ignore the multicast field.
  -    /**
  -     * Description of the Method
  -     *
  -     * @param key
  -     * @param value
  -     * @param multicast
  -     * @exception IOException
  -     */
  -    public void put( Serializable key, Serializable value, boolean multicast )
  -        throws IOException
  -    {
  -        put( key, value );
  -    }
  -
  -
  -    /**
  -     * Description of the Method
  -     *
  -     * @param key
  -     * @param value
  -     * @exception IOException
  -     */
  -    public void put( Serializable key, Serializable value )
  -        throws IOException
  -    {
  -        put( key, value, null );
  -    }
  -
  -
  -    /**
  -     * Description of the Method
  -     *
  -     * @param key
  -     * @param value
  -     * @param attr
  -     * @exception IOException
  -     */
  -    public void put( Serializable key, Serializable value, IElementAttributes attr )
  -        throws IOException
  -    {
  -        CacheElement ce = null;
  -        ce = new CacheElement( cacheName, key, value );
  -        ce.setElementAttributes( attr );
  -        update( ce );
  -    }
  -
   
       /**
        * Update the disk cache. Called from the Queue. Makes sure the Item has not
  @@ -373,58 +253,34 @@
        * @param ce
        * @exception IOException
        */
  -    public void update( ICacheElement ce )
  -        throws IOException
  +    public void doUpdate( ICacheElement ce )
       {
  -        log.debug( "update" );
  -
  -        if ( !isAlive )
  -        {
  -            return;
  -        }
  -
  -        if ( ce instanceof PurgatoryElement )
  -        {
  -            PurgatoryElement pe = ( PurgatoryElement ) ce;
  -            ce = pe.ice;
  -            if ( !pe.isSpoolable )
  -            {
  -                log.debug( "pe is not spoolable" );
  -
  -                // it has been plucked from purgatory
  -                return;
  -            }
  -        }
  -
  -        // remove item from purgatory since we are putting it on disk
  -        // assume that the disk cache will never break
  -        // disk breakage is akin to an out of memory exception
  -        buffer.purgatory.remove( ce.getKey() );
  -
           if ( log.isDebugEnabled() )
           {
  -            log.debug( "putting " + ce.getKey() + " on disk, removing from purgatory" );
  +            log.debug( "Storing element on disk, key: " + ce.getKey() );
           }
   
           IndexedDiskElementDescriptor ded = null;
  +
           try
           {
  -
               ded = new IndexedDiskElementDescriptor();
               byte[] data = IndexedDisk.serialize( ce );
               ded.init( dataFile.length(), data );
   
               // make sure this only locks for one particular cache region
  -            locker.writeLock();
  +            lock.writeLock();
   
               try
               {
  -                if ( !isAlive )
  +                if ( !alive )
                   {
                       return;
                   }
   
  -                IndexedDiskElementDescriptor old = ( IndexedDiskElementDescriptor ) keyHash.put( ce.getKey(), ded );
  +                IndexedDiskElementDescriptor old =
  +                    ( IndexedDiskElementDescriptor )
  +                        keyHash.put( ce.getKey(), ded );
   
                   // Item with the same key already exists in file.
                   // Try to reuse the location if possible.
  @@ -432,16 +288,19 @@
                   {
                       ded.pos = old.pos;
                   }
  +
                   dataFile.write( data, ded.pos );
               }
               finally
               {
  -                locker.done();
  -                // release write lock.
  +                lock.done();
               }
               if ( log.isDebugEnabled() )
               {
  -                log.debug( fileName + " -- put " + ce.getKey() + " on disk at pos " + ded.pos + " size = " + ded.len );
  +                log.debug( "Put to file: " + fileName +
  +                           ", key: " + ce.getKey() +
  +                           ", position: " + ded.pos +
  +                           ", size: " + ded.len );
               }
           }
           catch ( ConcurrentModificationException cme )
  @@ -450,38 +309,12 @@
           }
           catch ( Exception e )
           {
  -            log.error( "cacheName = " + cacheName + ", ce.getKey() = " + ce.getKey(), e );
  -            //reset();
  +            log.error( "Failure updating element, cacheName: " + cacheName +
  +                       ", key: " + ce.getKey(), e );
           }
           return;
       }
   
  -
  -    /**
  -     * Description of the Method
  -     *
  -     * @return
  -     * @param key
  -     */
  -    public Serializable get( Serializable key )
  -    {
  -        return get( key, true, true );
  -    }
  -
  -
  -    /**
  -     * Description of the Method
  -     *
  -     * @return
  -     * @param key
  -     * @param container
  -     */
  -    public Serializable get( Serializable key, boolean container )
  -    {
  -        return get( key, true, true );
  -    }
  -
  -
       /**
        * Description of the Method
        *
  @@ -490,62 +323,60 @@
        * @param container
        * @param lock
        */
  -    private Serializable get( Serializable key, boolean container, final boolean lock )
  +    protected Serializable doGet( Serializable key )
       {
  -
           if ( log.isDebugEnabled() )
           {
  -            log.debug( "getting " + key + " from disk" );
  +            log.debug( "Trying to get from disk: " + key );
           }
   
  -        if ( !isAlive )
  -        {
  -            return null;
  -        }
  +        Serializable object = null;
   
  -        Serializable obj = null;
  -        if ( lock )
  -        {
  -            locker.readLock();
  -        }
           try
           {
  -            if ( !isAlive )
  +            lock.readLock();
  +
  +            if ( !alive )
               {
                   return null;
               }
  -            IndexedDiskElementDescriptor ded = ( IndexedDiskElementDescriptor ) keyHash.get( key );
  -            if ( ded != null )
  -            {
  -                if ( log.isDebugEnabled() )
  -                {
  -                    log.debug( "found " + key + " on disk" );
  -                }
   
  -                obj = dataFile.readObject( ded.pos );
  -            }
  +            object = readElement( key );
   
           }
  -        catch ( NullPointerException e )
  -        {
  -            log.error( "cacheName = " + cacheName + ", key = " + key, e );
  -        }
           catch ( Exception e )
           {
               log.error( "cacheName = " + cacheName + ", key = " + key, e );
           }
           finally
           {
  -            if ( lock )
  +            lock.done();
  +        }
  +
  +        return object;
  +    }
  +
  +    private Serializable readElement( Serializable key )
  +        throws Exception
  +    {
  +        Serializable object = null;
  +
  +        IndexedDiskElementDescriptor ded =
  +            ( IndexedDiskElementDescriptor ) keyHash.get( key );
  +
  +        if ( ded != null )
  +        {
  +            if ( log.isDebugEnabled() )
               {
  -                locker.done();
  +                log.debug( "Found on disk, key: " + key );
               }
  +
  +            object = dataFile.readObject( ded.pos );
           }
   
  -        return obj;
  +        return object;
       }
   
  -
       /**
        * Returns true if the removal was succesful; or false if there is nothing
        * to remove. Current implementation always result in a disk orphan.
  @@ -553,30 +384,40 @@
        * @return
        * @param key
        */
  -    public boolean remove( Serializable key )
  +    public boolean doRemove( Serializable key )
       {
  -        locker.writeLock();
           try
           {
  +            lock.writeLock();
   
  -            if ( key instanceof String && key.toString().endsWith( NAME_COMPONENT_DELIMITER ) )
  +            if ( key instanceof String
  +                 && key.toString().endsWith( NAME_COMPONENT_DELIMITER ) )
               {
                   // remove all keys of the same name group.
                   boolean removed = false;
  -                for ( Iterator itr = keyHash.entrySet().iterator(); itr.hasNext();  )
  +
  +                Iterator iter = keyHash.entrySet().iterator();
  +
  +                while ( iter.hasNext() )
                   {
  -                    Map.Entry entry = ( Map.Entry ) itr.next();
  +                    Map.Entry entry = ( Map.Entry ) iter.next();
  +
                       Object k = entry.getKey();
  -                    if ( k instanceof String && k.toString().startsWith( key.toString() ) )
  +
  +                    if ( k instanceof String
  +                         && k.toString().startsWith( key.toString() ) )
                       {
  -                        itr.remove();
  +                        iter.remove();
                           removed = true;
                       }
                   }
                   return removed;
               }
  -            // remove single item.
  -            return keyHash.remove( key ) != null;
  +            else
  +            {
  +                // remove single item.
  +                return keyHash.remove( key ) != null;
  +            }
           }
           catch ( Exception e )
           {
  @@ -585,17 +426,16 @@
           }
           finally
           {
  -            locker.done();
  -            // release write lock.
  +            lock.done();
           }
  +
           return false;
       }
   
  -
       /**
        * Description of the Method
        */
  -    public void removeAll()
  +    public void doRemoveAll()
       {
           try
           {
  @@ -615,47 +455,39 @@
       /**
        * handle error by last resort, force content update, or removeall
        */
  -    public void reset()
  +    private void reset()
       {
           log.debug( "Reseting cache" );
  -        locker.writeLock();
  +
           try
           {
  -            try
  -            {
  -                dataFile.close();
  -                File file = new File( rafDir, fileName + ".data" );
  -                file.delete();
  -                keyFile.close();
  -                File file2 = new File( rafDir, fileName + ".key" );
  -                file2.delete();
  -            }
  -            catch ( Exception e )
  -            {
  -                log.error( e );
  -            }
  -            try
  -            {
  -                dataFile = new IndexedDisk( new File( rafDir, fileName + ".data" ) );
  -                keyFile = new IndexedDisk( new File( rafDir, fileName + ".key" ) );
  -                keyHash = new HashMap();
  -            }
  -            catch ( IOException e )
  -            {
  -                log.error( "IN RESET", e );
  -            }
  -            catch ( Exception e )
  -            {
  -                log.error( "IN RESET", e );
  -            }
  +            lock.writeLock();
  +
  +            dataFile.close();
  +            File file = new File( rafDir, fileName + ".data" );
  +            file.delete();
  +
  +            keyFile.close();
  +            File file2 = new File( rafDir, fileName + ".key" );
  +            file2.delete();
  +
  +            dataFile =
  +                new IndexedDisk( new File( rafDir, fileName + ".data" ) );
  +
  +            keyFile =
  +                new IndexedDisk( new File( rafDir, fileName + ".key" ) );
  +
  +            keyHash = new HashMap();
  +        }
  +        catch ( Exception e )
  +        {
  +            log.error( "Failure reseting state", e );
           }
           finally
           {
  -            locker.done();
  -            // release write lock.
  +            lock.done();
           }
       }
  -    // end reset
   
       /**
        * Gets the stats attribute of the DiskCache object
  @@ -664,30 +496,25 @@
        */
       public String getStats()
       {
  -        return "fileName = " + fileName + ", numInstances = " + numInstances;
  +        return "fileName = " + fileName;
       }
   
  -
  -    // shold be called by cachemanager, since it knows how
  -    // many are checked out
       /**
        * Description of the Method
        */
  -    public void dispose()
  +    public void doDispose()
       {
  -        if ( !isAlive )
  -        {
  -            log.debug( "is not alive and close() was called -- " + fileName );
  -            return;
  -        }
  -        locker.writeLock();
           try
           {
  -            if ( !isAlive )
  +            lock.writeLock();
  +
  +            if ( !alive )
               {
  -                log.debug( "is not alive and close() was called -- " + fileName );
  +                log.debug( "Not alive and dispose was called, filename: " +
  +                    fileName );
                   return;
               }
  +
               try
               {
                   optimizeFile();
  @@ -698,29 +525,28 @@
               }
               try
               {
  -                numInstances--;
  -                if ( numInstances == 0 )
  -                {
  -                    log.warn( "dispose -- Closing files -- in close -- " + fileName );
  -                    dataFile.close();
  -                    dataFile = null;
  -                    keyFile.close();
  -                    keyFile = null;
  -                }
  +                log.warn( "Closing files, base filename: " + fileName );
  +                dataFile.close();
  +                dataFile = null;
  +                keyFile.close();
  +                keyFile = null;
               }
               catch ( Exception e )
               {
  -                log.error( "-- " + fileName, e );
  +                log.error( "Failure closing files in dispose, filename: " +
  +                    fileName, e );
               }
           }
  +        catch ( Exception e )
  +        {
  +            log.error( "Failure in dispose", e );
  +        }
           finally
           {
  -            isAlive = false;
  -            locker.done();
  -            // release write lock;
  +            alive = false;
  +            lock.done();
           }
       }
  -    // end dispose
   
       /**
        * Note: synchronization currently managed by the only caller method -
  @@ -733,39 +559,49 @@
               // Migrate from keyHash to keyHshTemp in memory,
               // and from dataFile to dataFileTemp on disk.
               HashMap keyHashTemp = new HashMap();
  -            IndexedDisk dataFileTemp = new IndexedDisk( new File( rafDir, fileName + "Temp.data" ) );
  +
  +            IndexedDisk dataFileTemp =
  +                new IndexedDisk( new File( rafDir, fileName + "Temp.data" ) );
  +
               if ( log.isDebugEnabled() )
               {
                   log.info( "optomizing file keyHash.size()=" + keyHash.size() );
               }
  +
               Iterator itr = keyHash.keySet().iterator();
  +
               while ( itr.hasNext() )
               {
                   Serializable key = ( Serializable ) itr.next();
   
  -                // Must not have a read-lock;  Else results in deadlock.
  -                CacheElement tempDe = ( CacheElement ) get( key, true, false );
  +                CacheElement tempDe = ( CacheElement ) readElement( key );
                   try
                   {
  -                    IndexedDiskElementDescriptor de = dataFileTemp.appendObject( tempDe );
  +                    IndexedDiskElementDescriptor de =
  +                        dataFileTemp.appendObject( tempDe );
  +
                       if ( log.isDebugEnabled() )
                       {
  -                        log.debug( fileName + " -- Put " + key + " on temp disk cache" );
  +                        log.debug( "Put to temp disk cache: " + fileName +
  +                                   ", key: " + key );
                       }
  +
                       keyHashTemp.put( key, de );
                   }
                   catch ( Exception e )
                   {
  -                    log.error( fileName + " -- cacheName = "
  -                         + cacheName + ", key = " + key, e );
  +                    log.error( "Failed to put to temp disk cache: " + fileName
  +                               + ", key: " + key, e );
                   }
               }
  -            // end while
  +
               if ( log.isDebugEnabled() )
               {
  -                log.debug( fileName + " -- keyHashTemp.size() =  " + keyHashTemp.size()
  -                     + " / keyHash.size() =  " + keyHash.size() );
  +                log.debug( fileName
  +                    + " -- keyHashTemp.size(): " + keyHashTemp.size()
  +                    + ", keyHash.size(): " + keyHash.size() );
               }
  +
               // Make dataFileTemp to become dataFile on disk.
               dataFileTemp.close();
               dataFile.close();
  @@ -774,7 +610,8 @@
               {
                   if ( log.isDebugEnabled() )
                   {
  -                    log.debug( fileName + " -- oldData.length() = " + oldData.length() );
  +                    log.debug( fileName + " -- oldData.length() = " +
  +                        oldData.length() );
                   }
                   oldData.delete();
               }
  @@ -784,7 +621,8 @@
               {
                   if ( log.isDebugEnabled() )
                   {
  -                    log.debug( fileName + " -- newData.length() = " + newData.length() );
  +                    log.debug( fileName + " -- newData.length() = " +
  +                        newData.length() );
                   }
                   newData.renameTo( newFileName );
               }
  @@ -797,18 +635,6 @@
               log.error( fileName, e );
           }
       }
  -    // end optimizeFile
  -
  -    /**
  -     * Returns the cache status.
  -     *
  -     * @return The status value
  -     */
  -    public int getStatus()
  -    {
  -        return isAlive ? STATUS_ALIVE : STATUS_DISPOSED;
  -    }
  -
   
       /**
        * Returns the current cache size.
  @@ -820,43 +646,30 @@
           return keyHash.size();
       }
   
  -
  -    /**
  -     * Gets the cacheType attribute of the DiskCache object
  -     *
  -     * @return The cacheType value
  -     */
  -    public int getCacheType()
  -    {
  -        return DISK_CACHE;
  -    }
  -
  -
       /**
        * For debugging.
        */
       public void dump()
       {
  -        log.debug( "keyHash.size()=" + keyHash.size() );
  -        for ( Iterator itr = keyHash.entrySet().iterator(); itr.hasNext();  )
  +        log.debug( "Number of keys: " + keyHash.size() );
  +
  +        Iterator itr = keyHash.entrySet().iterator();
  +
  +        while ( itr.hasNext() )
           {
               Map.Entry e = ( Map.Entry ) itr.next();
  +
               Serializable key = ( Serializable ) e.getKey();
  -            IndexedDiskElementDescriptor ded = ( IndexedDiskElementDescriptor ) e.getValue();
  -            Serializable val = get( key );
  -            log.debug( "disk dump> key=" + key + ", val=" + val + ", pos=" + ded.pos );
  -        }
  -    }
   
  +            IndexedDiskElementDescriptor ded =
  +                ( IndexedDiskElementDescriptor ) e.getValue();
   
  -    /**
  -     * Returns cache name, ha
  -     *
  -     * @return The cacheName value
  -     */
  -    public String getCacheName()
  -    {
  -        return cacheName;
  +            Serializable val = get( key );
  +
  +            log.debug( "Disk element, key: " + key +
  +                       ", val: " + val +
  +                       ", pos: " + ded.pos );
  +        }
       }
   }
   
  
  
  
  1.2       +100 -71   jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/disk/indexed/IndexedDiskCacheManager.java
  
  Index: IndexedDiskCacheManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/disk/indexed/IndexedDiskCacheManager.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- IndexedDiskCacheManager.java	17 Feb 2002 06:59:19 -0000	1.1
  +++ IndexedDiskCacheManager.java	24 Feb 2002 19:18:05 -0000	1.2
  @@ -53,22 +53,22 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    */
  -import java.util.Enumeration;
  -import java.util.Hashtable;
   
  +import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogSource;
   import org.apache.stratum.jcs.auxiliary.disk.indexed.behavior.IIndexedDiskCacheAttributes;
  -
   import org.apache.stratum.jcs.engine.behavior.ICache;
   import org.apache.stratum.jcs.engine.behavior.ICacheManager;
   
  -import org.apache.commons.logging.Log;
  -import org.apache.commons.logging.LogSource;
  +import java.util.Enumeration;
  +import java.util.Hashtable;
   
   /**
  - * Description of the Class
  + * Cache manager for IndexedDiskCaches.
    *
  - * @author asmuts
  - * @created January 15, 2002
  + * @author <a href="mailto:asmuts@yahoo.com">Aaron Smuts</a>
  + * @author <a href="mailto:james@jamestaylor.org">James Taylor</a>
  + * @version $Id: IndexedDiskCacheManager.java,v 1.2 2002/02/24 19:18:05 jtaylor Exp $
    */
   public class IndexedDiskCacheManager implements ICacheManager
   {
  @@ -77,42 +77,34 @@
   
       private static int clients;
   
  -    private static Hashtable caches = new Hashtable();
  -
       private static IndexedDiskCacheManager instance;
   
  -    private static IIndexedDiskCacheAttributes defaultCattr;
  -
  -
  -    /**
  -     * Constructor for the DiskCacheManager object
  -     *
  -     * @param cattr
  -     */
  -    private IndexedDiskCacheManager( IIndexedDiskCacheAttributes cattr )
  -    {
  -        this.defaultCattr = cattr;
  -    }
  +    private Hashtable caches = new Hashtable();
   
  +    private IIndexedDiskCacheAttributes defaultCacheAttributes;
   
       /**
  -     * Gets the defaultCattr attribute of the DiskCacheManager object
  +     * Constructor for the IndexedDiskCacheManager object
        *
  -     * @return The defaultCattr value
  +     * @param defaultCacheAttributes Default attributes for caches managed by
  +     *                               the instance.
        */
  -    public IIndexedDiskCacheAttributes getDefaultCattr()
  +    private IndexedDiskCacheManager(
  +        IIndexedDiskCacheAttributes defaultCacheAttributes )
       {
  -        return this.defaultCattr;
  +        this.defaultCacheAttributes = defaultCacheAttributes;
       }
   
  -
       /**
  -     * Gets the instance attribute of the DiskCacheManager class
  +     * Gets the singleton instance of the manager
        *
  +     * @param defaultCacheAttributes If the instance has not yet been created,
  +     *                               it will be initialized with this set of
  +     *                               default attributes.
        * @return The instance value
  -     * @param cattr
        */
  -    public static IndexedDiskCacheManager getInstance( IIndexedDiskCacheAttributes cattr )
  +    public static IndexedDiskCacheManager getInstance(
  +        IIndexedDiskCacheAttributes defaultCacheAttributes )
       {
           if ( instance == null )
           {
  @@ -120,85 +112,111 @@
               {
                   if ( instance == null )
                   {
  -                    instance = new IndexedDiskCacheManager( cattr );
  +                    instance =
  +                        new IndexedDiskCacheManager( defaultCacheAttributes );
                   }
               }
           }
  +
           if ( log.isDebugEnabled() )
           {
  -            log.debug( "Manager stats : " + instance.getStats() + "-- in getInstance()" );
  +            log.debug( "Get instance, manager stats: " + instance.getStats() );
           }
  +
           clients++;
  +
           return instance;
       }
   
  -
       /**
  -     * Gets the cache attribute of the DiskCacheManager object
  +     * Gets an IndexedDiskCache for the supplied name using the default
  +     * attributes.
        *
  -     * @return The cache value
  -     * @param cacheName
  +     * @see getCache( IIndexedDiskCacheAttributes }
  +     *
  +     * @param cacheName Name that will be used when creating attributes.
  +     * @return A cache.
        */
       public ICache getCache( String cacheName )
       {
  -        IIndexedDiskCacheAttributes cattr = ( IIndexedDiskCacheAttributes ) defaultCattr.copy();
  -        cattr.setCacheName( cacheName );
  -        return getCache( cattr );
  -    }
  +        IIndexedDiskCacheAttributes cacheAttributes =
  +            ( IIndexedDiskCacheAttributes ) defaultCacheAttributes.copy();
  +
  +        cacheAttributes.setCacheName( cacheName );
   
  +        return getCache( cacheAttributes );
  +    }
   
       /**
  -     * Gets the cache attribute of the DiskCacheManager object
  +     * Get an IndexedDiskCache for the supplied attributes. Will provide an
  +     * existing cache for the name attribute if one has been created, or will
  +     * create a new cache.
  +     *
  +     * @param cattr Attributes the cache should have.
  +     * @return A cache, either from the existing set or newly created.
        *
  -     * @return The cache value
  -     * @param cattr
        */
  -    public ICache getCache( IIndexedDiskCacheAttributes cattr )
  +    public ICache getCache( IIndexedDiskCacheAttributes cacheAttributes )
       {
  -        ICache raf = null;
  +        ICache cache = null;
  +
  +        String cacheName = cacheAttributes.getCacheName();
   
  -        log.debug( "cacheName = " + cattr.getCacheName() );
  +        log.debug( "Getting cache named: " + cacheName );
   
           synchronized ( caches )
           {
  -            raf = ( ICache ) caches.get( cattr.getCacheName() );
  +            // Try to load the cache from the set that have already been
  +            // created. This only looks at the name attribute.
   
  -            if ( raf == null )
  +            cache = ( ICache ) caches.get( cacheName );
  +
  +            // If it was not found, create a new one using the supplied
  +            // attributes
  +
  +            if ( cache == null )
               {
  -                // make use cattr
  -                //raf = new DiskCache( cattr.getCacheName(), cattr.getDiskPath() );
  -                raf = new IndexedDiskCacheNoWaitBuffer( cattr );
  -                caches.put( cattr.getCacheName(), raf );
  +                cache = new IndexedDiskCache( cacheAttributes );
  +
  +                caches.put( cacheName, cache );
               }
           }
  +
           if ( log.isDebugEnabled() )
           {
  -            log.debug( "Manager stats : " + instance.getStats() );
  +            log.debug( "After getCache, manager stats: " + instance.getStats() );
           }
  -        return raf;
  -    }
   
  +        return cache;
  +    }
   
       /**
  -     * Description of the Method
  +     * Disposes the cache with the given name, if found in the set of managed
  +     * caches.
        *
  -     * @param name
  +     * @param cacheName Name of cache to dispose.
        */
  -    public void freeCache( String name )
  +    public void freeCache( String cacheName )
       {
  -        IndexedDiskCache raf = ( IndexedDiskCache ) caches.get( name );
  -        if ( raf != null )
  +        ICache cache = ( ICache ) caches.get( cacheName );
  +
  +        if ( cache != null )
           {
  -            raf.dispose();
  +            try
  +            {
  +                cache.dispose();
  +            }
  +            catch ( Exception e )
  +            {
  +                log.error( "Failure disposing cache: " + cacheName, e );
  +            }
           }
       }
   
  -
  -    // Don't care if there is a concurrency failure ?
       /**
  -     * Gets the stats attribute of the DiskCacheManager object
  +     * Returns the stats of all the managed caches.
        *
  -     * @return The stats value
  +     * @return String of stats from each managed cache, seperated by commas.
        */
       public String getStats()
       {
  @@ -230,27 +248,38 @@
           return DISK_CACHE;
       }
   
  -
       /**
  -     * Description of the Method
  +     * Releases the cache manager instance. When all clients have released the
  +     * cache manager, all contained caches will be disposed.
        */
       public void release()
       {
  -        // Wait until called by the last client
  +        clients--;
  +
           if ( --clients != 0 )
           {
               return;
           }
  +
           synchronized ( caches )
           {
               Enumeration allCaches = caches.elements();
   
               while ( allCaches.hasMoreElements() )
               {
  -                IndexedDiskCache raf = ( IndexedDiskCache ) allCaches.nextElement();
  -                if ( raf != null )
  +                ICache cache = ( ICache ) allCaches.nextElement();
  +
  +                if ( cache != null )
                   {
  -                    raf.dispose();
  +                    try
  +                    {
  +                        cache.dispose();
  +                    }
  +                    catch ( Exception e )
  +                    {
  +                        log.error( "Failure disposing cache: " +
  +                            cache.getCacheName(), e );
  +                    }
                   }
               }
           }
  
  
  
  1.15      +3 -17     jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/disk/jisp/JISPCache.java
  
  Index: JISPCache.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/disk/jisp/JISPCache.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- JISPCache.java	18 Feb 2002 17:14:23 -0000	1.14
  +++ JISPCache.java	24 Feb 2002 19:18:05 -0000	1.15
  @@ -65,6 +65,7 @@
   import java.io.Serializable;
   
   import org.apache.stratum.jcs.auxiliary.disk.jisp.behavior.IJISPCacheAttributes;
  +import org.apache.stratum.jcs.auxiliary.disk.PurgatoryElement;
   
   import org.apache.stratum.jcs.engine.behavior.IElementAttributes;
   import org.apache.stratum.jcs.engine.CacheElement;
  @@ -95,9 +96,6 @@
       /** Description of the Field */
       public boolean isAlive = false;
   
  -    // not used
  -    private String source_id = "org.apache.stratum.jcs.auxiliary.disk.jisp.HSQLCache";
  -
       IJISPCacheAttributes cattr;
   
       // disk cache buffer, need to remove key from buffer on update, if its there
  @@ -113,18 +111,6 @@
   
       private final static JISPLockManager locker = JISPLockManager.getInstance();
   
  -
  -    /**
  -     * Gets the sourceId attribute of the JISPCache object
  -     *
  -     * @return The sourceId value
  -     */
  -    public Serializable getSourceId()
  -    {
  -        return this.source_id;
  -    }
  -
  -
       // should use this method
       /**
        * Constructor for the JISPCache object
  @@ -304,8 +290,8 @@
           if ( ce instanceof PurgatoryElement )
           {
               PurgatoryElement pe = ( PurgatoryElement ) ce;
  -            ce = pe.ice;
  -            if ( !pe.isSpoolable )
  +            ce = pe.getCacheElement();
  +            if ( ! pe.isSpoolable() )
               {
                   log.debug( "pe is not spoolable" );
   
  
  
  
  1.7       +7 -7      jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/disk/jisp/JISPCacheNoWaitBuffer.java
  
  Index: JISPCacheNoWaitBuffer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/disk/jisp/JISPCacheNoWaitBuffer.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- JISPCacheNoWaitBuffer.java	18 Feb 2002 17:14:23 -0000	1.6
  +++ JISPCacheNoWaitBuffer.java	24 Feb 2002 19:18:05 -0000	1.7
  @@ -14,6 +14,7 @@
   
   import org.apache.stratum.jcs.auxiliary.disk.jisp.behavior.IJISPCacheAttributes;
   import org.apache.stratum.jcs.auxiliary.disk.jisp.behavior.IJISPCacheService;
  +import org.apache.stratum.jcs.auxiliary.disk.PurgatoryElement;
   
   import org.apache.stratum.jcs.engine.behavior.IElementAttributes;
   import org.apache.stratum.jcs.engine.CacheAdaptor;
  @@ -131,7 +132,7 @@
               log.debug( "putting in purgatory" );
   
               PurgatoryElement pe = new PurgatoryElement( ce );
  -            pe.isSpoolable = true;
  +            pe.setSpoolable( true );
               q.addPutEvent( ( ICacheElement ) pe );
   
               //q.addPutEvent( ce );
  @@ -180,22 +181,21 @@
                   }
               }
   
  -            //ide.setIsSpoolable( false );
  -            pe.isSpoolable = false;
  +            pe.setSpoolable( false );
   
               log.debug( "found in purgatory" );
   
               if ( container )
               {
                   purgatory.remove( key );
  -                //return (ICacheElement)ide;
  -                return pe.ice;
  +
  +                return pe.getCacheElement();
               }
               else
               {
                   purgatory.remove( key );
  -                //return (Serializable)ide.getVal();
  -                return ( Serializable ) pe.ice.getVal();
  +
  +                return ( Serializable ) pe.getCacheElement().getVal();
               }
           }
           try
  
  
  
  1.11      +0 -6      jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/lateral/LateralCache.java
  
  Index: LateralCache.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/lateral/LateralCache.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- LateralCache.java	18 Feb 2002 17:14:24 -0000	1.10
  +++ LateralCache.java	24 Feb 2002 19:18:05 -0000	1.11
  @@ -329,10 +329,4 @@
           this.lateral = lateral;
           return;
       }
  -
  -    /** Gets the sourceId attribute of the LateralCache object */
  -    public Serializable getSourceId()
  -    {
  -        return LateralCache.class.getName();
  -    }
   }
  
  
  
  1.7       +0 -6      jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/lateral/LateralCacheNoWait.java
  
  Index: LateralCacheNoWait.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/lateral/LateralCacheNoWait.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- LateralCacheNoWait.java	18 Feb 2002 17:14:24 -0000	1.6
  +++ LateralCacheNoWait.java	24 Feb 2002 19:18:05 -0000	1.7
  @@ -269,10 +269,4 @@
       {
           return "LateralCacheNoWait: " + cache.toString();
       }
  -
  -    /** Gets the sourceId attribute of the LateralCacheNoWait object */
  -    public Serializable getSourceId()
  -    {
  -        return LateralCache.class.getName();
  -    }
   }
  
  
  
  1.9       +0 -14     jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/lateral/LateralCacheNoWaitFacade.java
  
  Index: LateralCacheNoWaitFacade.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/lateral/LateralCacheNoWaitFacade.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- LateralCacheNoWaitFacade.java	18 Feb 2002 17:14:24 -0000	1.8
  +++ LateralCacheNoWaitFacade.java	24 Feb 2002 19:18:05 -0000	1.9
  @@ -32,21 +32,7 @@
       /** Description of the Field */
       public LateralCacheNoWait[] noWaits;
   
  -    private String source_id = "org.apache.stratum.jcs.auxiliary.lateral.LateralCacheNoWaitFacade";
  -
       private String cacheName;
  -
  -
  -    /**
  -     * Gets the sourceId attribute of the LateralCacheNoWaitFacade object
  -     *
  -     * @return The sourceId value
  -     */
  -    public Serializable getSourceId()
  -    {
  -        return this.source_id;
  -    }
  -
   
       /**
        * Constructs with the given lateral cache, and fires events to any
  
  
  
  1.11      +0 -13     jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/remote/RemoteCache.java
  
  Index: RemoteCache.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/remote/RemoteCache.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- RemoteCache.java	18 Feb 2002 17:14:23 -0000	1.10
  +++ RemoteCache.java	24 Feb 2002 19:18:05 -0000	1.11
  @@ -43,19 +43,6 @@
       private HashMap keyHash;
       // not synchronized to maximize concurrency.
   
  -    private String source_id = "org.apache.stratum.jcs.auxiliary.remote.RemoteCache";
  -
  -
  -    /**
  -     * Gets the sourceId attribute of the RemoteCache object
  -     *
  -     * @return The sourceId value
  -     */
  -    public Serializable getSourceId()
  -    {
  -        return this.source_id;
  -    }
  -
   
       /** Description of the Method */
       public String toString()
  
  
  
  1.7       +0 -14     jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/remote/RemoteCacheNoWait.java
  
  Index: RemoteCacheNoWait.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/remote/RemoteCacheNoWait.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- RemoteCacheNoWait.java	18 Feb 2002 17:14:23 -0000	1.6
  +++ RemoteCacheNoWait.java	24 Feb 2002 19:18:05 -0000	1.7
  @@ -35,20 +35,6 @@
       private final RemoteCache cache;
       private ICacheEventQueue q;
   
  -    private String source_id = "org.apache.stratum.jcs.auxiliary.remote.RemoteCacheNoWait";
  -
  -
  -    /**
  -     * Gets the sourceId attribute of the RemoteCacheNoWait object
  -     *
  -     * @return The sourceId value
  -     */
  -    public Serializable getSourceId()
  -    {
  -        return this.source_id;
  -    }
  -
  -
       /**
        * Constructs with the given remote cache, and fires up an event queue for
        * aysnchronous processing.
  
  
  
  1.7       +0 -14     jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/remote/RemoteCacheNoWaitFacade.java
  
  Index: RemoteCacheNoWaitFacade.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/remote/RemoteCacheNoWaitFacade.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- RemoteCacheNoWaitFacade.java	18 Feb 2002 17:14:23 -0000	1.6
  +++ RemoteCacheNoWaitFacade.java	24 Feb 2002 19:18:05 -0000	1.7
  @@ -29,8 +29,6 @@
       /** Description of the Field */
       public RemoteCacheNoWait[] noWaits;
   
  -    private String source_id = "org.apache.stratum.jcs.auxiliary.remote.RemoteCacheNoWaitFacade";
  -
       private String cacheName;
   
       // holds failover and cluster information
  @@ -59,18 +57,6 @@
       {
           this.rca = rca;
       }
  -
  -
  -    /**
  -     * Gets the sourceId attribute of the RemoteCacheNoWaitFacade object
  -     *
  -     * @return The sourceId value
  -     */
  -    public Serializable getSourceId()
  -    {
  -        return this.source_id;
  -    }
  -
   
       /**
        * Constructs with the given remote cache, and fires events to any
  
  
  
  1.7       +0 -10     jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/engine/behavior/ICache.java
  
  Index: ICache.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/engine/behavior/ICache.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ICache.java	18 Feb 2002 17:14:24 -0000	1.6
  +++ ICache.java	24 Feb 2002 19:18:05 -0000	1.7
  @@ -13,7 +13,6 @@
    */
   public interface ICache extends ICacheType
   {
  -
       /**
        * Where the current activity came from. This effects whether the remote
        * will be included. Prevents remote-local loops.
  @@ -48,15 +47,6 @@
   
       /** Delimiter of a cache name component. */
       public final static String NAME_COMPONENT_DELIMITER = ":";
  -
  -
  -    /**
  -     * used to identify the source of cache modifications, should be unique
  -     *
  -     * @return The sourceId value
  -     */
  -    public Serializable getSourceId();
  -
   
       /** Puts an item to the cache. */
       public void update( ICacheElement ce )
  
  
  
  1.20      +3 -15     jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/engine/control/Cache.java
  
  Index: Cache.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/engine/control/Cache.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- Cache.java	22 Feb 2002 06:05:22 -0000	1.19
  +++ Cache.java	24 Feb 2002 19:18:05 -0000	1.20
  @@ -118,8 +118,6 @@
        */
       public ICompositeCacheAttributes cacheAttr;
   
  -    private String source_id = "org.apache.stratum.jcs.engine.control.Cache";
  -
       // statistics
       private static int numInstances;
       private int ramHit;
  @@ -133,18 +131,6 @@
       // IMemoryCache
       IMemoryCache memCache;
   
  -
  -    /**
  -     * Gets the sourceId attribute of the Cache object
  -     *
  -     * @return The sourceId value
  -     */
  -    public Serializable getSourceId()
  -    {
  -        return this.source_id;
  -    }
  -
  -
       /**
        * Constructor for the Cache object
        *
  @@ -1014,6 +1000,8 @@
       /**
        * Gets the stats attribute of the Cache object
        *
  +     * FIXME: Remove HTML!
  +     *
        * @return The stats value
        */
       public String getStats()
  @@ -1024,7 +1012,7 @@
   
           for ( int i = 0; i < auxHit.length; i++ )
           {
  -            stats.append( "/n<br> auxHit[" + i + "] = " + auxHit[i] + ", " + this.auxCaches[i].getSourceId() + "" );
  +            stats.append( "/n<br> auxHit[" + i + "] = " + auxHit[i] + ", " + this.auxCaches[i].getClass().getName() + "" );
           }
           stats.append( "/n<br> miss = " + miss );
           stats.append( "/n<br> cacheAttr = " + cacheAttr.toString() );
  
  
  
  1.13      +0 -14     jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/engine/memory/lru/LRUMemoryCache.java
  
  Index: LRUMemoryCache.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/engine/memory/lru/LRUMemoryCache.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- LRUMemoryCache.java	19 Feb 2002 04:46:54 -0000	1.12
  +++ LRUMemoryCache.java	24 Feb 2002 19:18:05 -0000	1.13
  @@ -71,8 +71,6 @@
        */
       public ICompositeCacheAttributes cattr;
   
  -    private String source_id = "org.apache.stratum.jcs.engine.memory.lru.LRUMemoryCache";
  -
       // The HUB
       ICacheHub hub;
   
  @@ -147,18 +145,6 @@
           }
   
       }
  -
  -
  -    /**
  -     * Gets the sourceId attribute of the LRUMemoryCache object
  -     *
  -     * @return The sourceId value
  -     */
  -    public Serializable getSourceId()
  -    {
  -        return this.source_id;
  -    }
  -
   
       /**
        * Gets the cacheType attribute of the LRUMemoryCache object
  
  
  
  1.7       +0 -14     jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/engine/memory/mru/MRUMemoryCache.java
  
  Index: MRUMemoryCache.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/engine/memory/mru/MRUMemoryCache.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- MRUMemoryCache.java	19 Feb 2002 04:46:54 -0000	1.6
  +++ MRUMemoryCache.java	24 Feb 2002 19:18:05 -0000	1.7
  @@ -73,8 +73,6 @@
        */
       public ICompositeCacheAttributes cattr;
   
  -    private String source_id = "org.apache.stratum.jcs.engine.memory.mru.MRUMemoryCache";
  -
       // The HUB
       ICacheHub hub;
   
  @@ -146,18 +144,6 @@
           }
   
       }
  -
  -
  -    /**
  -     * Gets the sourceId attribute of the LRUMemoryCache object
  -     *
  -     * @return The sourceId value
  -     */
  -    public Serializable getSourceId()
  -    {
  -        return this.source_id;
  -    }
  -
   
       /**
        * Gets the cacheType attribute of the LRUMemoryCache object
  
  
  
  1.4       +0 -14     jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/engine/memory/shrinking/ShrinkingMemoryCache.java
  
  Index: ShrinkingMemoryCache.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/engine/memory/shrinking/ShrinkingMemoryCache.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ShrinkingMemoryCache.java	19 Feb 2002 04:46:54 -0000	1.3
  +++ ShrinkingMemoryCache.java	24 Feb 2002 19:18:05 -0000	1.4
  @@ -55,8 +55,6 @@
        */
       public ICompositeCacheAttributes cattr;
   
  -    private String source_id = "org.apache.stratum.jcs.engine.memory.shrinking.ShrinkingMemoryCache";
  -
       // The HUB
       ICacheHub hub;
   
  @@ -114,18 +112,6 @@
   
           log.info( "initialized ShrinkingMemoryCache for " + cacheName );
       }
  -
  -
  -    /**
  -     * Gets the sourceId attribute of the ShrinkingMemoryCache object
  -     *
  -     * @return The sourceId value
  -     */
  -    public Serializable getSourceId()
  -    {
  -        return this.source_id;
  -    }
  -
   
       /**
        * Gets the cacheType attribute of the ShrinkingMemoryCache object
  
  
  
  1.3       +5 -5      jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/utils/locking/ReadWriteLock.java
  
  Index: ReadWriteLock.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/utils/locking/ReadWriteLock.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ReadWriteLock.java	16 Feb 2002 22:26:08 -0000	1.2
  +++ ReadWriteLock.java	24 Feb 2002 19:18:05 -0000	1.3
  @@ -21,7 +21,7 @@
    * @author asmuts
    * @created January 15, 2002
    */
  -class ReadWriteLock
  +public class ReadWriteLock
   {
       private final static Log log =
           LogSource.getInstance( ReadWriteLockManager.class );
  @@ -49,7 +49,7 @@
   
   
       /** Default constructor. */
  -    ReadWriteLock() { }
  +    public ReadWriteLock() { }
   
   
       /**
  @@ -57,7 +57,7 @@
        * waiting to get a write lock. Caller of this method must be careful to
        * avoid synchronizing the calling code so as to avoid deadlock.
        */
  -    synchronized void readLock()
  +    public synchronized void readLock()
           throws InterruptedException
       {
           waitingForReadLock++;
  @@ -80,7 +80,7 @@
        * Caller of this method must be careful to avoid synchronizing the calling
        * code so as to avoid deadlock.
        */
  -    void writeLock()
  +    public void writeLock()
           throws InterruptedException
       {
           Thread thisThread = Thread.currentThread();
  @@ -129,7 +129,7 @@
        * @throws IllegalStateException if called when there are no outstanding
        *      locks or there is a write lock issued to a different thread.
        */
  -    synchronized void done()
  +    public synchronized void done()
       {
           if ( outstandingReadLocks > 0 )
           {
  
  
  
  1.3       +6 -6      jakarta-turbine-stratum/src/test/org/apache/stratum/jcs/TestDiskCache.java
  
  Index: TestDiskCache.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-stratum/src/test/org/apache/stratum/jcs/TestDiskCache.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestDiskCache.java	23 Feb 2002 20:39:11 -0000	1.2
  +++ TestDiskCache.java	24 Feb 2002 19:18:05 -0000	1.3
  @@ -66,7 +66,7 @@
    * Test which excercises the disk caches (Indexed, JISP, and HSQL).
    *
    * @author <a href="mailto:james@jamestaylor.org">James Taylor</a>
  - * @version $Id: TestDiskCache.java,v 1.2 2002/02/23 20:39:11 jtaylor Exp $
  + * @version $Id: TestDiskCache.java,v 1.3 2002/02/24 19:18:05 jtaylor Exp $
    */
   public class TestDiskCache extends TestCase
   {
  @@ -114,8 +114,8 @@
           runTestForRegion( "indexedRegion" );
       }
   
  -    /** 
  -     * Tests the region which uses the JISP disk cache 
  +    /**
  +     * Tests the region which uses the JISP disk cache
        */
       public void testJISPDiskCache()
           throws Exception
  @@ -123,8 +123,8 @@
           runTestForRegion( "jispRegion" );
       }
   
  -    /** 
  -     * Tests the region which uses the HSQL disk cache 
  +    /**
  +     * Tests the region which uses the HSQL disk cache
        */
       public void testHSQLDiskCache()
           throws Exception
  @@ -157,7 +157,7 @@
           for ( int i = 0; i <= items; i++ )
           {
               String value = ( String ) jcs.get( i + ":key" );
  -            
  +
               this.assertEquals( "data" + i, value );
           }
   
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: cvs commit:jakarta-turbine-stratum/src/test/org/apache/stratum/jcs TestDiskCache.java

Posted by Aaron Smuts <aa...@verizon.net>.
Sounds like what I want to do for the lateral, but the lateral has
another part.  The disk is just a service.

The lateral needs both a listener and a service.  The listener recives
and the service handles broadcasts.  There are interfaces for both.
There will be a core LateralCacheAttributes and the specific lateral
implementations can have both.  Instead of having multiple server types
in the config there will be one servers list and one local listening
port.  The factory will create a service for each server.

I'll do it this week.

Aaron

> -----Original Message-----
> From: James Taylor [mailto:jtaylor@4lane.com]
> Sent: Sunday, February 24, 2002 3:01 PM
> To: Turbine Developers List
> Subject: Re: cvs commit:jakarta-turbine-
> stratum/src/test/org/apache/stratum/jcs TestDiskCache.java
> 
> >   I decided to extract an abstract superclass for consistency with
the
> current
> >   code, however my feeling now is that composition rather than
> inheritence, ie
> >   some kind of plugin architecture, would be better for disk caches,
> more along
> >   the lines of the way lateral caches work. More on that later.
> 
> With the AbstractDiskCache all one needs to do to implement a
DiskCache
> is extend it and implement the methods that actually modify the
> underlying persistent store. This works well, but there is actually
> quite a bit more work involved since you need to implement a factory
and
> manager, and possibly even a CacheAttributes, for each subclass.
> 
> I think a better model would be to implement a concrete DiskCache,
with
> a manager and factory, which uses a plugin for access to the
underlying
> store. At configuration time you would configure what plugin to use by
> providing a class name. I think the lateral cache could be refactored
> similarly (rather than providing a token that the code maps to a
class,
> you can just provide the class name, which reduces compile time
> coupling).
> 
> I could see a cache configuration like this (just the disk
auxiliaries):
> 
>     <disk name="indexedDiskCache>
>       <driver
>
className="org.apache.stratum.jcs.auxiliary.disk.indexed.IndexedDiskCach
eD
> river"/>
>       <attributeSet>
>         <diskPath>bin/test/indexed-disk-cache</diskPath>
>       </attributeSet>
>     </disk>
> 
>     <disk name="hsqlDiskCache>
>       <driver
>
className="org.apache.stratum.jcs.auxiliary.disk.hsql.HSQLDiskCacheDrive
r"
> />
>       <attributeSet>
>         <diskPath>bin/test/jisp-disk-cache</diskPath>
>         <clearOnStart>false</clearOnStart>
>       </attributeSet>
>     </disk>
> 
>     <disk name="jispDiskCache>
>       <driver
>
className="org.apache.stratum.jcs.auxiliary.disk.jisp.JISPDiskCacheDrive
r"
> />
>       <attributeSet>
>         <diskPath>bin/test/hsql-disk-cache</diskPath>
>       </attributeSet>
>     </disk>
> 
> Where the manager would store the plugin and attributes for each named
> disk auxiliary, and use them when caches are requested. This reduces
the
> number of classes to implement multiple disk caches quite a bit.
> 
> Thoughts?
> 
> Thanks,
> James
> 
> 
> --
> To unsubscribe, e-mail:   <mailto:turbine-dev-
> unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:turbine-dev-
> help@jakarta.apache.org>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: cvs commit: jakarta-turbine-stratum/src/test/org/apache/stratum/jcs TestDiskCache.java

Posted by James Taylor <jt...@4lane.com>.
>   I decided to extract an abstract superclass for consistency with the current
>   code, however my feeling now is that composition rather than inheritence, ie
>   some kind of plugin architecture, would be better for disk caches, more along
>   the lines of the way lateral caches work. More on that later.

With the AbstractDiskCache all one needs to do to implement a DiskCache
is extend it and implement the methods that actually modify the
underlying persistent store. This works well, but there is actually
quite a bit more work involved since you need to implement a factory and
manager, and possibly even a CacheAttributes, for each subclass.

I think a better model would be to implement a concrete DiskCache, with
a manager and factory, which uses a plugin for access to the underlying
store. At configuration time you would configure what plugin to use by
providing a class name. I think the lateral cache could be refactored
similarly (rather than providing a token that the code maps to a class,
you can just provide the class name, which reduces compile time
coupling).

I could see a cache configuration like this (just the disk auxiliaries):

    <disk name="indexedDiskCache>
      <driver className="org.apache.stratum.jcs.auxiliary.disk.indexed.IndexedDiskCacheDriver"/>
      <attributeSet>
        <diskPath>bin/test/indexed-disk-cache</diskPath>
      </attributeSet>
    </disk>
    
    <disk name="hsqlDiskCache>
      <driver className="org.apache.stratum.jcs.auxiliary.disk.hsql.HSQLDiskCacheDriver"/>
      <attributeSet>
        <diskPath>bin/test/jisp-disk-cache</diskPath>
        <clearOnStart>false</clearOnStart>
      </attributeSet>
    </disk>
    
    <disk name="jispDiskCache>
      <driver className="org.apache.stratum.jcs.auxiliary.disk.jisp.JISPDiskCacheDriver"/>
      <attributeSet>
        <diskPath>bin/test/hsql-disk-cache</diskPath>
      </attributeSet>
    </disk>

Where the manager would store the plugin and attributes for each named
disk auxiliary, and use them when caches are requested. This reduces the
number of classes to implement multiple disk caches quite a bit.

Thoughts? 

Thanks,
James


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>