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

cvs commit: jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/engine/memory/behavior IMemoryCache.java

asmuts      02/02/18 10:43:59

  Modified:    src/java/org/apache/stratum/jcs/engine/memory/shrinking
                        ShrinkingMemoryCache.java ShrinkerThread.java
               src/java/org/apache/stratum/jcs/engine/memory/mru
                        MRUMemoryCache.java
               src/java/org/apache/stratum/jcs/engine/memory/lru
                        LRUMemoryCache.java
               src/java/org/apache/stratum/jcs/engine/memory/behavior
                        IMemoryCache.java
  Log:
  making the shrinker available to all memory caches
  
  Revision  Changes    Path
  1.2       +30 -2     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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ShrinkingMemoryCache.java	18 Feb 2002 18:16:50 -0000	1.1
  +++ ShrinkingMemoryCache.java	18 Feb 2002 18:43:58 -0000	1.2
  @@ -369,10 +369,18 @@
        * Description of the Method
        *
        * @param me
  +     * @exception IOException
  +     */
  +    /**
  +     * Description of the Method
  +     *
  +     * Puts an item to the cache.
  +     *
        */
  -    protected void waterfal( MemoryElementDescriptor me )
  +    public void waterfal( MemoryElementDescriptor me )
  +        throws IOException
       {
  -        hub.spoolToDisk( me.ce );
  +        this.hub.spoolToDisk( me.ce );
       }
   
   
  @@ -444,6 +452,26 @@
           return map.entrySet().iterator();
       }
   
  +
  +    /**
  +     * Returns the CacheAttributes.
  +     *
  +     * @return The CacheAttributes value
  +     */
  +    public ICompositeCacheAttributes getCacheAttributes()
  +    {
  +        return this.cattr;
  +    }
  +
  +    /**
  +     * Sets the CacheAttributes.
  +     *
  +     * @param cattr The new CacheAttributes value
  +     */
  +    public void setCacheAttributes( ICompositeCacheAttributes cattr )
  +    {
  +        this.cattr = cattr;
  +    }
   
       /**
        * Dump the cache map for debugging.
  
  
  
  1.2       +34 -15    jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/engine/memory/shrinking/ShrinkerThread.java
  
  Index: ShrinkerThread.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/engine/memory/shrinking/ShrinkerThread.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ShrinkerThread.java	18 Feb 2002 18:16:50 -0000	1.1
  +++ ShrinkerThread.java	18 Feb 2002 18:43:58 -0000	1.2
  @@ -54,10 +54,16 @@
    * <http://www.apache.org/>.
    */
   
  +import java.util.Map.Entry;
  +import java.util.Iterator;
  +import java.util.Map;
  +import java.util.Set;
  +
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogSource;
   
   import org.apache.stratum.jcs.engine.memory.MemoryElementDescriptor;
  +import org.apache.stratum.jcs.engine.memory.behavior.IMemoryCache;
   
   /**
    * A background memory shrinker. Just started. Don't use.
  @@ -69,15 +75,19 @@
   public class ShrinkerThread extends Thread
   {
   
  -    private ShrinkingMemoryCache cache;
  +    private IMemoryCache cache;
       boolean alive = true;
   
  +    private final static Log log =
  +        LogSource.getInstance( ShrinkerThread.class );
  +
  +
       /**
        * Constructor for the ShrinkerThread object. Should take an IMemoryCache
        *
        * @param cache
        */
  -    public ShrinkerThread( ShrinkingMemoryCache cache )
  +    public ShrinkerThread( IMemoryCache cache )
       {
           super();
           this.cache = cache;
  @@ -102,10 +112,9 @@
   
               shrink();
   
  -            // should be in the CacheAttributes
               try
               {
  -                this.sleep( cache.cattr.getShrinkerIntervalSeconds() * 1000 );
  +                this.sleep( cache.getCacheAttributes().getShrinkerIntervalSeconds() * 1000 );
               }
               catch ( InterruptedException ie )
               {
  @@ -121,28 +130,36 @@
       protected void shrink()
       {
   
  +        if ( log.isDebugEnabled() )
  +        {
  +            log.debug( "Shrinking" );
  +        }
  +
           // not thread safe.  Copuld cause problems.  Only call remove directly
           // to the map.
           try
           {
  -            java.util.Set keySet = cache.map.keySet();
   
  -            java.util.Iterator keys = keySet.iterator();
  +            java.util.Iterator itr = cache.getIterator();
   
  -            while ( keys.hasNext() )
  +            while ( itr.hasNext() )
               {
  -                Object key = keys.next();
  -                long now = System.currentTimeMillis();
  +                Map.Entry e = ( Map.Entry ) itr.next();
  +                MemoryElementDescriptor me = ( MemoryElementDescriptor ) e.getValue();
   
  -                MemoryElementDescriptor me = ( MemoryElementDescriptor ) cache.map.get( key );
  +                long now = System.currentTimeMillis();
   
                   // Memory idle, to disk shrinkage
  -                if ( cache.cattr.getMaxMemoryIdleTimeSeconds() != -1 )
  +                if ( cache.getCacheAttributes().getMaxMemoryIdleTimeSeconds() != -1 )
                   {
  -                    long deadAt = me.ce.getElementAttributes().getLastAccessTime() + ( cache.cattr.getMaxMemoryIdleTimeSeconds() * 1000 );
  +                    long deadAt = me.ce.getElementAttributes().getLastAccessTime() + ( cache.getCacheAttributes().getMaxMemoryIdleTimeSeconds() * 1000 );
                       if ( ( deadAt - now ) < 0 )
                       {
  -                        cache.map.remove( key );
  +                        if ( log.isDebugEnabled() )
  +                        {
  +                            log.debug( "Pushing item to disk -- " + me.ce.getKey() );
  +                        }
  +                        itr.remove();
                           cache.waterfal( me );
                       }
                   }
  @@ -152,13 +169,15 @@
                       // Exceeded maxLifeSeconds
                       if ( ( me.ce.getElementAttributes().getMaxLifeSeconds() != -1 ) && ( now - me.ce.getElementAttributes().getCreateTime() ) > ( me.ce.getElementAttributes().getMaxLifeSeconds() * 1000 ) )
                       {
  -                        cache.map.remove( key );
  +                        itr.remove();
  +                        //cache.remove( me.ce.getKey() );
                       }
   
                       // Exceeded maxIdleTime, removal
                       if ( ( me.ce.getElementAttributes().getIdleTime() * 1000 != -1 ) && ( now - me.ce.getElementAttributes().getLastAccessTime() ) > ( me.ce.getElementAttributes().getIdleTime() * 1000 ) )
                       {
  -                        cache.map.remove( key );
  +                        itr.remove();
  +                        //cache.remove( me.ce.getKey() );
                       }
                   }
   
  
  
  
  1.5       +113 -17   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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- MRUMemoryCache.java	18 Feb 2002 17:14:23 -0000	1.4
  +++ MRUMemoryCache.java	18 Feb 2002 18:43:58 -0000	1.5
  @@ -45,21 +45,31 @@
       // MOVE TO MEMORYMANAGER
       String cacheName;
   
  -    /** Storage of cache items. */
  +    /**
  +     * Storage of cache items.
  +     */
       protected HashMap map = new HashMap();
   
  -    /** Description of the Field */
  +    /**
  +     * Description of the Field
  +     */
       protected int[] lockMe = new int[0];
   
  -    /** MRU list. */
  +    /**
  +     * MRU list.
  +     */
       protected LinkedList mrulist = new LinkedList();
   
       // Region Elemental Attributes
  -    /** Description of the Field */
  +    /**
  +     * Description of the Field
  +     */
       public IElementAttributes attr;
   
       // Cache Attributes
  -    /** Description of the Field */
  +    /**
  +     * Description of the Field
  +     */
       public ICompositeCacheAttributes cattr;
   
       private String source_id = "org.apache.stratum.jcs.engine.memory.mru.MRUMemoryCache";
  @@ -75,7 +85,9 @@
   
   
       // for reflection
  -    /** Constructor for the LRUMemoryCache object */
  +    /**
  +     * Constructor for the LRUMemoryCache object
  +     */
       public MRUMemoryCache()
       {
           // might want to consider this an error state
  @@ -97,7 +109,13 @@
   
   
       // for post reflection creation initialization
  -    /** Description of the Method */
  +    /**
  +     * Description of the Method
  +     *
  +     * @param cacheName
  +     * @param cattr
  +     * @param hub
  +     */
       public void initialize( String cacheName, ICompositeCacheAttributes cattr, ICacheHub hub )
       {
           this.cacheName = cacheName;
  @@ -129,7 +147,12 @@
       }
   
   
  -    /** Puts an item to the cache. */
  +    /**
  +     * Puts an item to the cache.
  +     *
  +     * @param ce
  +     * @exception IOException
  +     */
       public void update( ICacheElement ce )
           throws IOException
       {
  @@ -217,7 +240,13 @@
   
       // TODO: Implement or modify interface, just implement
       // may need insert if we want to distinguish b/wn put and replace
  -    /** Description of the Method */
  +    /**
  +     * Description of the Method
  +     *
  +     * @param key
  +     * @param val
  +     * @exception IOException
  +     */
       public void put( Serializable key, Serializable val )
           throws IOException
       {
  @@ -225,7 +254,14 @@
       }
   
   
  -    /** Description of the Method */
  +    /**
  +     * Description of the Method
  +     *
  +     * @param key
  +     * @param val
  +     * @param attr
  +     * @exception IOException
  +     */
       public void put( Serializable key, Serializable val, IElementAttributes attr )
           throws IOException
       {
  @@ -233,7 +269,13 @@
       }
   
   
  -    /** Gets an item from the cache. */
  +    /**
  +     * Gets an item from the cache.
  +     *
  +     * @return
  +     * @param key
  +     * @exception IOException
  +     */
       public Serializable get( Serializable key )
           throws IOException
       {
  @@ -241,7 +283,14 @@
       }
   
   
  -    /** Description of the Method */
  +    /**
  +     * Description of the Method
  +     *
  +     * @return
  +     * @param key
  +     * @param container
  +     * @exception IOException
  +     */
       public Serializable get( Serializable key, boolean container )
           throws IOException
       {
  @@ -332,7 +381,13 @@
       }
       // end get
   
  -    /** Removes an item from the cache. */
  +    /**
  +     * Removes an item from the cache.
  +     *
  +     * @return
  +     * @param key
  +     * @exception IOException
  +     */
       public boolean remove( Serializable key )
           throws IOException
       {
  @@ -386,7 +441,11 @@
       }
   
   
  -    /** Removes all cached items from the cache. */
  +    /**
  +     * Removes all cached items from the cache.
  +     *
  +     * @exception IOException
  +     */
       public void removeAll()
           throws IOException
       {
  @@ -394,7 +453,11 @@
       }
   
   
  -    /** Prepares for shutdown. */
  +    /**
  +     * Prepares for shutdown.
  +     *
  +     * @exception IOException
  +     */
       public void dispose()
           throws IOException
       {
  @@ -446,6 +509,15 @@
       }
   
   
  +    /** Puts an item to the cache. */
  +    public void waterfal( MemoryElementDescriptor me )
  +        throws IOException
  +    {
  +        this.hub.spoolToDisk(me.ce);
  +    }
  +
  +
  +
       /**
        * Gets the iterator attribute of the LRUMemoryCache object
        *
  @@ -457,8 +529,30 @@
           return map.entrySet().iterator();
       }
   
  +    /**
  +     * Returns the CacheAttributes.
  +     *
  +     * @return The CacheAttributes value
  +     */
  +    public ICompositeCacheAttributes getCacheAttributes()
  +    {
  +        return this.cattr;
  +    }
   
  -    /** Dump the cache map for debugging. */
  +    /**
  +     * Sets the CacheAttributes.
  +     *
  +     * @param cattr The new CacheAttributes value
  +     */
  +    public void setCacheAttributes( ICompositeCacheAttributes cattr )
  +    {
  +        this.cattr = cattr;
  +    }
  +
  +
  +    /**
  +     * Dump the cache map for debugging.
  +     */
       public void dumpMap()
       {
           log.debug( "dumpingMap" );
  @@ -472,7 +566,9 @@
       }
   
   
  -    /** Dump the cache entries from first to list for debugging. */
  +    /**
  +     * Dump the cache entries from first to list for debugging.
  +     */
       public void dumpCacheEntries()
       {
           log.debug( "dumpingCacheEntries" );
  
  
  
  1.11      +121 -18   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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- LRUMemoryCache.java	18 Feb 2002 17:14:23 -0000	1.10
  +++ LRUMemoryCache.java	18 Feb 2002 18:43:59 -0000	1.11
  @@ -47,7 +47,9 @@
   
       // MOVE TO MEMORYMANAGER
       String cacheName;
  -    /** Description of the Field */
  +    /**
  +     * Description of the Field
  +     */
       protected Map map = new Hashtable();
   
       // LRU double linked list
  @@ -56,11 +58,15 @@
       private int max;
   
       // Region Elemental Attributes
  -    /** Description of the Field */
  +    /**
  +     * Description of the Field
  +     */
       public IElementAttributes attr;
   
       // Cache Attributes
  -    /** Description of the Field */
  +    /**
  +     * Description of the Field
  +     */
       public ICompositeCacheAttributes cattr;
   
       private String source_id = "org.apache.stratum.jcs.engine.memory.lru.LRUMemoryCache";
  @@ -76,7 +82,9 @@
   
   
       // for reflection
  -    /** Constructor for the LRUMemoryCache object */
  +    /**
  +     * Constructor for the LRUMemoryCache object
  +     */
       public LRUMemoryCache()
       {
           // might want to consider this an error state
  @@ -99,7 +107,13 @@
   
   
       // for post reflection creation initialization
  -    /** Description of the Method */
  +    /**
  +     * Description of the Method
  +     *
  +     * @param cacheName
  +     * @param cattr
  +     * @param hub
  +     */
       public void initialize( String cacheName, ICompositeCacheAttributes cattr, ICacheHub hub )
       {
           this.cacheName = cacheName;
  @@ -133,7 +147,12 @@
       }
   
   
  -    /** Puts an item to the cache. */
  +    /**
  +     * Puts an item to the cache.
  +     *
  +     * @param ce
  +     * @exception IOException
  +     */
       public void update( ICacheElement ce )
           throws IOException
       {
  @@ -205,7 +224,13 @@
   
       // TODO: Implement or modify interface, just implement
       // may need insert if we want to distinguish b/wn put and replace
  -    /** Description of the Method */
  +    /**
  +     * Description of the Method
  +     *
  +     * @param key
  +     * @param val
  +     * @exception IOException
  +     */
       public void put( Serializable key, Serializable val )
           throws IOException
       {
  @@ -213,7 +238,14 @@
       }
   
   
  -    /** Description of the Method */
  +    /**
  +     * Description of the Method
  +     *
  +     * @param key
  +     * @param val
  +     * @param attr
  +     * @exception IOException
  +     */
       public void put( Serializable key, Serializable val, IElementAttributes attr )
           throws IOException
       {
  @@ -221,7 +253,13 @@
       }
   
   
  -    /** Gets an item from the cache. */
  +    /**
  +     * Gets an item from the cache.
  +     *
  +     * @return
  +     * @param key
  +     * @exception IOException
  +     */
       public Serializable get( Serializable key )
           throws IOException
       {
  @@ -229,7 +267,14 @@
       }
   
   
  -    /** Description of the Method */
  +    /**
  +     * Description of the Method
  +     *
  +     * @return
  +     * @param key
  +     * @param container
  +     * @exception IOException
  +     */
       public Serializable get( Serializable key, boolean container )
           throws IOException
       {
  @@ -314,7 +359,13 @@
       }
       // end get
   
  -    /** Removes an item from the cache. */
  +    /**
  +     * Removes an item from the cache.
  +     *
  +     * @return
  +     * @param key
  +     * @exception IOException
  +     */
       public boolean remove( Serializable key )
           throws IOException
       {
  @@ -362,7 +413,11 @@
       }
   
   
  -    /** Removes all cached items from the cache. */
  +    /**
  +     * Removes all cached items from the cache.
  +     *
  +     * @exception IOException
  +     */
       public void removeAll()
           throws IOException
       {
  @@ -370,7 +425,11 @@
       }
   
   
  -    /** Prepares for shutdown. */
  +    /**
  +     * Prepares for shutdown.
  +     *
  +     * @exception IOException
  +     */
       public void dispose()
           throws IOException
       {
  @@ -467,7 +526,11 @@
   
   
       // internal mehods
  -    /** Removes the specified node from the link list. */
  +    /**
  +     * Removes the specified node from the link list.
  +     *
  +     * @param me
  +     */
       private void removeNode( MemoryElementDescriptor me )
       {
           if ( log.isDebugEnabled() )
  @@ -557,14 +620,22 @@
       }
   
   
  -    /** Moves an existing node to the start of the link list. */
  +    /**
  +     * Moves an existing node to the start of the link list.
  +     *
  +     * @param ce
  +     */
       public synchronized void makeFirst( ICacheElement ce )
       {
           makeFirst( new MemoryElementDescriptor( ce ) );
       }
   
   
  -    /** Moves an existing node to the start of the link list. */
  +    /**
  +     * Moves an existing node to the start of the link list.
  +     *
  +     * @param me
  +     */
       public synchronized void makeFirst( MemoryElementDescriptor me )
       {
   
  @@ -602,8 +673,38 @@
           return;
       }
   
  +    /** Puts an item to the cache. */
  +    public void waterfal( MemoryElementDescriptor me )
  +        throws IOException
  +    {
  +        this.hub.spoolToDisk(me.ce);
  +    }
  +
   
  -    /** Dump the cache map for debugging. */
  +    /**
  +     * Returns the CacheAttributes.
  +     *
  +     * @return The CacheAttributes value
  +     */
  +    public ICompositeCacheAttributes getCacheAttributes()
  +    {
  +        return this.cattr;
  +    }
  +
  +    /**
  +     * Sets the CacheAttributes.
  +     *
  +     * @param cattr The new CacheAttributes value
  +     */
  +    public void setCacheAttributes( ICompositeCacheAttributes cattr )
  +    {
  +        this.cattr = cattr;
  +    }
  +
  +
  +    /**
  +     * Dump the cache map for debugging.
  +     */
       public void dumpMap()
       {
           log.debug( "dumpingMap" );
  @@ -617,7 +718,9 @@
       }
   
   
  -    /** Dump the cache entries from first to list for debugging. */
  +    /**
  +     * Dump the cache entries from first to list for debugging.
  +     */
       public void dumpCacheEntries()
       {
           log.debug( "dumpingCacheEntries" );
  
  
  
  1.7       +11 -0     jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/engine/memory/behavior/IMemoryCache.java
  
  Index: IMemoryCache.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/engine/memory/behavior/IMemoryCache.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- IMemoryCache.java	16 Feb 2002 02:37:23 -0000	1.6
  +++ IMemoryCache.java	18 Feb 2002 18:43:59 -0000	1.7
  @@ -71,7 +71,18 @@
   
   
       /** Puts an item to the cache. */
  +    public void waterfal( MemoryElementDescriptor me )
  +        throws IOException;
  +
  +
  +    /** Puts an item to the cache. */
       public void update( ICacheElement ce )
           throws IOException;
  +
  +
  +    /** Returns the CacheAttributes. */
  +    public ICompositeCacheAttributes getCacheAttributes( );
  +    /** Sets the CacheAttributes. */
  +    public void setCacheAttributes( ICompositeCacheAttributes cattr );
   
   }
  
  
  

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