You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jcs-dev@jakarta.apache.org by as...@apache.org on 2007/03/19 03:28:36 UTC

svn commit: r519799 - in /jakarta/jcs/trunk/src: java/org/apache/jcs/auxiliary/disk/block/ java/org/apache/jcs/auxiliary/disk/indexed/ java/org/apache/jcs/auxiliary/remote/ java/org/apache/jcs/engine/ java/org/apache/jcs/engine/memory/lru/ java/org/apa...

Author: asmuts
Date: Sun Mar 18 19:28:35 2007
New Revision: 519799

URL: http://svn.apache.org/viewvc?view=rev&rev=519799
Log:
FIXED JCS-21

Added additional synchonrization on a few methods on 4 classes.  Most of the changes were from a patch supplied by Michael Stevens.

I also improved some javadocs and formatting. 

Modified:
    jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskCache.java
    jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCache.java
    jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheMonitor.java
    jakarta/jcs/trunk/src/java/org/apache/jcs/engine/CacheEventQueue.java
    jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/lru/LRUMemoryCache.java
    jakarta/jcs/trunk/src/java/org/apache/jcs/utils/struct/DoubleLinkedList.java
    jakarta/jcs/trunk/src/java/org/apache/jcs/utils/struct/SortedPreferentialArray.java
    jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/block/BlockDiskCacheSameRegionConcurrentUnitTest.java
    jakarta/jcs/trunk/src/test/org/apache/jcs/utils/struct/LRUMapConcurrentUnitTest.java
    jakarta/jcs/trunk/src/test/org/apache/jcs/utils/struct/LRUMapPerformanceTest.java

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskCache.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskCache.java?view=diff&rev=519799&r1=519798&r2=519799
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskCache.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskCache.java Sun Mar 18 19:28:35 2007
@@ -55,6 +55,7 @@
 
     private File rootDirectory;
 
+    /** Store, loads, and persists the keys */
     private BlockDiskKeyStore keyStore;
 
     // public Object lock = new Object();
@@ -87,7 +88,7 @@
 
         if ( log.isInfoEnabled() )
         {
-            log.info( logCacheName + "Cache file root directory: " + rootDirName );
+            log.info( logCacheName + "Cache file root directory: [" + rootDirName + "]" );
         }
 
         try

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCache.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCache.java?view=diff&rev=519799&r1=519798&r2=519799
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCache.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCache.java Sun Mar 18 19:28:35 2007
@@ -551,7 +551,7 @@
      * Reads the item from disk.
      * <p>
      * @param key
-     * @return
+     * @return ICacheElement
      * @throws IOException
      */
     private ICacheElement readElement( Serializable key )
@@ -1207,7 +1207,7 @@
      * <p>
      * @return The number bytes free on the disk file.
      */
-    protected long getBytesFree()
+    protected synchronized long getBytesFree()
     {
         return this.bytesFree;
     }
@@ -1331,7 +1331,7 @@
      * (non-Javadoc)
      * @see org.apache.jcs.auxiliary.AuxiliaryCache#getStatistics()
      */
-    public IStats getStatistics()
+    public synchronized IStats getStatistics()
     {
         IStats stats = new Stats();
         stats.setTypeName( "Indexed Disk Cache" );

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheMonitor.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheMonitor.java?view=diff&rev=519799&r1=519798&r2=519799
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheMonitor.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheMonitor.java Sun Mar 18 19:28:35 2007
@@ -36,23 +36,29 @@
 public class RemoteCacheMonitor
     implements Runnable
 {
+    /** The logger */
     private final static Log log = LogFactory.getLog( RemoteCacheMonitor.class );
 
+    /** The remote cache that we are monitoring */
     private static RemoteCacheMonitor instance;
 
+    /** Time between checks */
     private static long idlePeriod = 30 * 1000;
 
     // minimum 30 seconds.
     //private static long idlePeriod = 3*1000; // for debugging.
 
-    // Must make sure RemoteCacheMonitor is started before any remote error can
-    // be detected!
+    /** Must make sure RemoteCacheMonitor is started before any remote error can
+    * be detected! */
     private boolean alright = true;
 
+    /** Time driven mode */
     final static int TIME = 0;
 
+    /** Error driven mode -- only check on health if there is an error */
     final static int ERROR = 1;
 
+    /** The mode to use */
     static int mode = ERROR;
 
     /**
@@ -118,35 +124,37 @@
         log.debug( "Monitoring daemon started" );
         do
         {
-
             if ( mode == ERROR )
             {
-                if ( alright )
+                synchronized ( this )
                 {
-                    synchronized ( this )
+                    if ( alright )
                     {
-                        if ( alright )
+                        // make this configurable, comment out wait to enter
+                        // time driven mode
+                        // Failure driven mode.
+                        try
                         {
-                            // make this configurable, comment out wait to enter
-                            // time driven mode
-                            // Failure driven mode.
-                            try
-                            {
-                                log.debug( "FAILURE DRIVEN MODE: cache monitor waiting for error" );
-                                wait();
-                                // wake up only if there is an error.
-                            }
-                            catch ( InterruptedException ignore )
+                            if ( log.isDebugEnabled() )
                             {
-                                // swallow
+                                log.debug( "FAILURE DRIVEN MODE: cache monitor waiting for error" );                                
                             }
+                            wait();
+                            // wake up only if there is an error.
+                        }
+                        catch ( InterruptedException ignore )
+                        {
+                            // swallow
                         }
                     }
                 }
             }
             else
             {
-                log.debug( "TIME DRIVEN MODE: cache monitor sleeping for " + idlePeriod );
+                if ( log.isDebugEnabled() )
+                {                
+                    log.debug( "TIME DRIVEN MODE: cache monitor sleeping for " + idlePeriod );
+                }
                 // Time driven mode: sleep between each round of recovery
                 // attempt.
                 // will need to test not just check status
@@ -216,14 +224,8 @@
     }
 
     /** Sets the "alright" flag to false in a critial section. */
-    private void bad()
+    private synchronized void bad()
     {
-        if ( alright )
-        {
-            synchronized ( this )
-            {
-                alright = false;
-            }
-        }
+        alright = false;
     }
 }

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/engine/CacheEventQueue.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/engine/CacheEventQueue.java?view=diff&rev=519799&r1=519798&r2=519799
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/engine/CacheEventQueue.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/engine/CacheEventQueue.java Sun Mar 18 19:28:35 2007
@@ -1,14 +1,12 @@
 package org.apache.jcs.engine;
 
 /*
- * Copyright 2001-2004 The Apache Software Foundation. Licensed under the Apache
- * License, Version 2.0 (the "License") you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
- * or agreed to in writing, software distributed under the License is
- * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the specific language
- * governing permissions and limitations under the License.
+ * Copyright 2001-2004 The Apache Software Foundation. Licensed under the Apache License, Version
+ * 2.0 (the "License") you may not use this file except in compliance with the License. You may
+ * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
+ * applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
+ * the License for the specific language governing permissions and limitations under the License.
  */
 
 import java.io.IOException;
@@ -26,62 +24,72 @@
 import org.apache.jcs.engine.stats.behavior.IStats;
 
 /**
- * An event queue is used to propagate ordered cache events to one and only one
- * target listener.
+ * An event queue is used to propagate ordered cache events to one and only one target listener.
  * <p>
- * This is a modified version of the experimental version. It should lazy
- * initilaize the processor thread, and kill the thread if the queue goes emtpy
- * for a specified period, now set to 1 minute. If something comes in after that
- * a new processor thread should be created.
+ * This is a modified version of the experimental version. It should lazy initilaize the processor
+ * thread, and kill the thread if the queue goes emtpy for a specified period, now set to 1 minute.
+ * If something comes in after that a new processor thread should be created.
  */
 public class CacheEventQueue
     implements ICacheEventQueue
 {
+    /** The logger. */
     private static final Log log = LogFactory.getLog( CacheEventQueue.class );
 
+    /** The type of queue -- there are pooled and single */
     private static final int queueType = SINGLE_QUEUE_TYPE;
 
+    /** default */
     private static final int DEFAULT_WAIT_TO_DIE_MILLIS = 10000;
 
-    // time to wait for an event before snuffing the background thread
-    // if the queue is empty.
-    // make configurable later
+    /**
+     * time to wait for an event before snuffing the background thread if the queue is empty. make
+     * configurable later
+     */
     private int waitToDieMillis = DEFAULT_WAIT_TO_DIE_MILLIS;
 
-    // When the events are pulled off the queue, the tell the listener to handle
-    // the specific event type. The work is done by the listener.
+    /**
+     * When the events are pulled off the queue, the tell the listener to handle the specific event
+     * type. The work is done by the listener.
+     */
     private ICacheListener listener;
 
+    /** Id of the listener registed with this queue */
     private long listenerId;
 
+    /** The cache region name, if applicable. */
     private String cacheName;
 
+    /** Maximum number of failures before we buy the farm. */
     private int maxFailure;
 
-    // in milliseconds
+    /** in milliseconds */
     private int waitBeforeRetry;
 
-    // this is true if there is no worker thread.
+    /** this is true if there is no worker thread. */
     private boolean destroyed = true;
 
-    // This means that the queue is functional.
-    // If we reached the max number of failures, the queue is marked as
-    // non functional and will never work again.
+    /**
+     * This means that the queue is functional. If we reached the max number of failures, the queue
+     * is marked as non functional and will never work again.
+     */
     private boolean working = true;
 
-    // the thread that works the queue.
+    /** the thread that works the queue. */
     private Thread processorThread;
 
+    /** sync */
     private Object queueLock = new Object();
 
-    // the head of the queue
+    /** the head of the queue */
     private Node head = new Node();
 
-    // the end of the queue
+    /** the end of the queue */
     private Node tail = head;
 
+    /** Number of items in the queue */
     private int size = 0;
-    
+
     /**
      * Constructs with the specified listener and the cache name.
      * <p>
@@ -104,7 +112,7 @@
      * @param waitBeforeRetry
      */
     public CacheEventQueue( ICacheListener listener, long listenerId, String cacheName, int maxFailure,
-                           int waitBeforeRetry )
+                            int waitBeforeRetry )
     {
         if ( listener == null )
         {
@@ -123,7 +131,9 @@
         }
     }
 
-    /*
+    /**
+     * What type of queue is this.
+     * <p>
      * (non-Javadoc)
      * @see org.apache.jcs.engine.behavior.ICacheEventQueue#getQueueType()
      */
@@ -133,8 +143,8 @@
     }
 
     /**
-     * Kill the processor thread and indicate that the queue is detroyed and no
-     * longer alive, but it can still be working.
+     * Kill the processor thread and indicate that the queue is detroyed and no longer alive, but it
+     * can still be working.
      */
     public synchronized void stopProcessing()
     {
@@ -154,8 +164,7 @@
     /**
      * Sets the time to wait for events before killing the background thread.
      * <p>
-     * @param wtdm
-     *            the ms for the q to sit idle.
+     * @param wtdm the ms for the q to sit idle.
      */
     public void setWaitToDieMillis( int wtdm )
     {
@@ -163,6 +172,8 @@
     }
 
     /**
+     * Creates a brief string identifying the listener and the region.
+     * <p>
      * @return String debugging info.
      */
     public String toString()
@@ -175,18 +186,17 @@
      * <p>
      * @return The alive value
      */
-    public boolean isAlive()
+    public synchronized boolean isAlive()
     {
         return ( !destroyed );
     }
 
     /**
-     * Sets whether the queue is actively processing -- if there are working
-     * threads.
+     * Sets whether the queue is actively processing -- if there are working threads.
      * <p>
      * @param aState
      */
-    public void setAlive( boolean aState )
+    public synchronized void setAlive( boolean aState )
     {
         destroyed = !aState;
     }
@@ -242,8 +252,10 @@
     }
 
     /**
-     * @param ce
-     *            The feature to be added to the PutEvent attribute
+     * This adds a put event ot the queue. When it is processed, the element will be put to the
+     * listener.
+     * <p>
+     * @param ce The feature to be added to the PutEvent attribute
      * @exception IOException
      */
     public synchronized void addPutEvent( ICacheElement ce )
@@ -263,8 +275,10 @@
     }
 
     /**
-     * @param key
-     *            The feature to be added to the RemoveEvent attribute
+     * This adds a remove event to the queue. When processed the listener's remove method will be
+     * called for the key.
+     * <p>
+     * @param key The feature to be added to the RemoveEvent attribute
      * @exception IOException
      */
     public synchronized void addRemoveEvent( Serializable key )
@@ -284,8 +298,8 @@
     }
 
     /**
-     * This adds a remove all event to the queue. When it is processed, all
-     * elements will be removed from the cache.
+     * This adds a remove all event to the queue. When it is processed, all elements will be removed
+     * from the cache.
      * <p>
      * @exception IOException
      */
@@ -365,12 +379,10 @@
     }
 
     /**
-     * Returns the next cache event from the queue or null if there are no
-     * events in the queue.
+     * Returns the next cache event from the queue or null if there are no events in the queue.
      * <p>
-     * We have an empty node at the head and the tail. When we take an item from
-     * the queue we move the next node to the head and then clear the value from
-     * that node. This value is returned.
+     * We have an empty node at the head and the tail. When we take an item from the queue we move
+     * the next node to the head and then clear the value from that node. This value is returned.
      * <p>
      * When the queue is empty the head node is the same as the tail node.
      * <p>
@@ -406,7 +418,9 @@
         }
     }
 
-    /*
+    /**
+     * This method returns semi structured data on this queue.
+     * <p>
      * (non-Javadoc)
      * @see org.apache.jcs.engine.behavior.ICacheEventQueue#getStatistics()
      */
@@ -467,10 +481,13 @@
 
     // /////////////////////////// Inner classes /////////////////////////////
 
+    /** The queue is composed of nodes. */
     private static class Node
     {
+        /** Next node in the singly linked list. */
         Node next = null;
 
+        /** The payload. */
         CacheEventQueue.AbstractCacheEvent event = null;
     }
 
@@ -483,12 +500,13 @@
     private class QProcessor
         extends Thread
     {
+        /** The queue to work */
         CacheEventQueue queue;
 
         /**
          * Constructor for the QProcessor object
-         * @param aQueue
-         *            the event queue to take items from.
+         * <p>
+         * @param aQueue the event queue to take items from.
          */
         QProcessor( CacheEventQueue aQueue )
         {
@@ -501,9 +519,8 @@
         /**
          * Main processing method for the QProcessor object.
          * <p>
-         * Waits for a specified time (waitToDieMillis) for something to come in
-         * and if no new events come in during that period the run method can
-         * exit and the thread is dereferenced.
+         * Waits for a specified time (waitToDieMillis) for something to come in and if no new
+         * events come in during that period the run method can exit and the thread is dereferenced.
          */
         public void run()
         {
@@ -564,8 +581,10 @@
     private abstract class AbstractCacheEvent
         implements Runnable
     {
+        /** Number of failures encountered processing this event. */
         int failures = 0;
 
+        /** Have we finished the job */
         boolean done = false;
 
         /**
@@ -633,10 +652,12 @@
     private class PutEvent
         extends AbstractCacheEvent
     {
+        /** The element to put to the listener */
         private ICacheElement ice;
 
         /**
-         * Constructor for the PutEvent object
+         * Constructor for the PutEvent object.
+         * <p>
          * @param ice
          * @exception IOException
          */
@@ -647,7 +668,8 @@
         }
 
         /**
-         * Description of the Method
+         * Call put on the listener.
+         * <p>
          * @exception IOException
          */
         protected void doRun()
@@ -658,6 +680,8 @@
 
         /**
          * For debugging.
+         * <p>
+         * @return Info on the key and value.
          */
         public String toString()
         {
@@ -676,10 +700,12 @@
     private class RemoveEvent
         extends AbstractCacheEvent
     {
+        /** The key to remove from the listener */
         private Serializable key;
 
         /**
          * Constructor for the RemoveEvent object
+         * <p>
          * @param key
          * @exception IOException
          */
@@ -690,7 +716,7 @@
         }
 
         /**
-         * Description of the Method
+         * Call remove on the listener.
          * <p>
          * @exception IOException
          */
@@ -700,9 +726,10 @@
             listener.handleRemove( cacheName, key );
         }
 
-        /*
-         * (non-Javadoc)
-         * @see java.lang.Object#toString()
+        /**
+         * For debugging.
+         * <p>
+         * @return Info on the key to remove.
          */
         public String toString()
         {
@@ -712,8 +739,7 @@
     }
 
     /**
-     * All elements should be removed from the cache when this event is
-     * processed.
+     * All elements should be removed from the cache when this event is processed.
      * <p>
      * @author asmuts
      * @created January 15, 2002
@@ -722,7 +748,8 @@
         extends AbstractCacheEvent
     {
         /**
-         * Description of the Method
+         * Call removeAll on the listener.
+         * <p>
          * @exception IOException
          */
         protected void doRun()
@@ -731,9 +758,10 @@
             listener.handleRemoveAll( cacheName );
         }
 
-        /*
-         * (non-Javadoc)
-         * @see java.lang.Object#toString()
+        /**
+         * For debugging.
+         * <p>
+         * @return The name of the event.
          */
         public String toString()
         {
@@ -762,6 +790,11 @@
             listener.handleDispose( cacheName );
         }
 
+        /**
+         * For debugging.
+         * <p>
+         * @return The name of the event.
+         */
         public String toString()
         {
             return "DisposeEvent";
@@ -777,9 +810,8 @@
     }
 
     /**
-     * This means that the queue is functional. If we reached the max number of
-     * failures, the queue is marked as non functional and will never work
-     * again.
+     * This means that the queue is functional. If we reached the max number of failures, the queue
+     * is marked as non functional and will never work again.
      * <p>
      * @param b
      */
@@ -797,7 +829,7 @@
     }
 
     /**
-     * Returns the number of elements in the queue. 
+     * Returns the number of elements in the queue.
      * <p>
      * @return number of items in the queue.
      */

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/lru/LRUMemoryCache.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/lru/LRUMemoryCache.java?view=diff&rev=519799&r1=519798&r2=519799
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/lru/LRUMemoryCache.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/lru/LRUMemoryCache.java Sun Mar 18 19:28:35 2007
@@ -1,14 +1,12 @@
 package org.apache.jcs.engine.memory.lru;
 
 /*
- * Copyright 2001-2004 The Apache Software Foundation. Licensed under the Apache
- * License, Version 2.0 (the "License") you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
- * or agreed to in writing, software distributed under the License is
- * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the specific language
- * governing permissions and limitations under the License.
+ * Copyright 2001-2004 The Apache Software Foundation. Licensed under the Apache License, Version
+ * 2.0 (the "License") you may not use this file except in compliance with the License. You may
+ * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
+ * applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
+ * the License for the specific language governing permissions and limitations under the License.
  */
 
 import java.io.IOException;
@@ -35,39 +33,42 @@
 import org.apache.jcs.utils.struct.DoubleLinkedList;
 
 /**
- * A fast reference management system. The least recently used items move to the
- * end of the list and get spooled to disk if the cache hub is configured to use
- * a disk cache. Most of the cache bottelnecks are in IO. There are no io
- * bottlenecks here, it's all about processing power.
+ * A fast reference management system. The least recently used items move to the end of the list and
+ * get spooled to disk if the cache hub is configured to use a disk cache. Most of the cache
+ * bottelnecks are in IO. There are no io bottlenecks here, it's all about processing power.
  * <p>
- * Even though there are only a few adjustments necessary to maintain the double
- * linked list, we might want to find a more efficient memory manager for large
- * cache regions.
+ * Even though there are only a few adjustments necessary to maintain the double linked list, we
+ * might want to find a more efficient memory manager for large cache regions.
  * <p>
- * The LRUMemoryCache is most efficient when the first element is selected. The
- * smaller the region, the better the chance that this will be the case. < .04
- * ms per put, p3 866, 1/10 of that per get
+ * The LRUMemoryCache is most efficient when the first element is selected. The smaller the region,
+ * the better the chance that this will be the case. < .04 ms per put, p3 866, 1/10 of that per get
  * <p>
  * @version $Id$
  */
 public class LRUMemoryCache
     extends AbstractMemoryCache
 {
+    /** Don't change */
     private static final long serialVersionUID = 6403738094136424201L;
 
+    /** The logger. */
     private final static Log log = LogFactory.getLog( LRUMemoryCache.class );
 
-    // double linked list for lru
+    /** thread-safe double linked list for lru */
     private DoubleLinkedList list;
 
+    /** number of hits */
     private int hitCnt = 0;
 
+    /** number of misses */
     private int missCnt = 0;
 
+    /** number of puts */
     private int putCnt = 0;
 
     /**
      * For post reflection creation initialization.
+     * <p>
      * @param hub
      */
     public synchronized void initialize( CompositeCache hub )
@@ -78,13 +79,12 @@
     }
 
     /**
-     * Puts an item to the cache. Removes any pre-existing entries of the same
-     * key from the linked list and adds this one first.
+     * Puts an item to the cache. Removes any pre-existing entries of the same key from the linked
+     * list and adds this one first.
      * <p>
      * If the max size is reached, an element will be put to disk.
      * <p>
-     * @param ce
-     *            The cache element, or entry wrapper
+     * @param ce The cache element, or entry wrapper
      * @exception IOException
      */
     public void update( ICacheElement ce )
@@ -203,14 +203,13 @@
     }
 
     /**
-     * This instructs the memory cache to remove the <i>numberToFree</i>
-     * according to its eviction policy. For example, the LRUMemoryCache will
-     * remove the <i>numberToFree</i> least recently used items. These will be
-     * spooled to disk if a disk auxiliary is available.
+     * This instructs the memory cache to remove the <i>numberToFree</i> according to its eviction
+     * policy. For example, the LRUMemoryCache will remove the <i>numberToFree</i> least recently
+     * used items. These will be spooled to disk if a disk auxiliary is available.
      * <p>
      * @param numberToFree
-     * @return the number that were removed. if you ask to free 5, but there are
-     *         only 3, you will get 3.
+     * @return the number that were removed. if you ask to free 5, but there are only 3, you will
+     *         get 3.
      * @throws IOException
      */
     public int freeElements( int numberToFree )
@@ -227,13 +226,11 @@
         }
         return freed;
     }
-    
+
     /**
-     * Get an item from the cache without affecting its last access time or
-     * position.
+     * Get an item from the cache without affecting its last access time or position.
      * <p>
-     * @param key
-     *            Identifies item to find
+     * @param key Identifies item to find
      * @return Element matching key if found, or null
      * @exception IOException
      */
@@ -263,8 +260,7 @@
     /**
      * Get an item from the cache
      * <p>
-     * @param key
-     *            Identifies item to find
+     * @param key Identifies item to find
      * @return ICacheElement if found, else null
      * @exception IOException
      */
@@ -307,13 +303,12 @@
     }
 
     /**
-     * Removes an item from the cache. This method handles hierarchical removal.
-     * If the key is a String and ends with the
-     * CacheConstants.NAME_COMPONENT_DELIMITER, then all items with keys
+     * Removes an item from the cache. This method handles hierarchical removal. If the key is a
+     * String and ends with the CacheConstants.NAME_COMPONENT_DELIMITER, then all items with keys
      * starting with the argument String will be removed.
      * <p>
      * @param key
-     * @return
+     * @return true if the removal was successful
      * @exception IOException
      */
     public synchronized boolean remove( Serializable key )
@@ -385,8 +380,8 @@
     }
 
     /**
-     * Remove all of the elements from both the Map and the linked list
-     * implementation. Overrides base class.
+     * Remove all of the elements from both the Map and the linked list implementation. Overrides
+     * base class.
      * <p>
      * @throws IOException
      */
@@ -507,8 +502,7 @@
     /**
      * Adds a new node to the end of the link list. Currently not used.
      * <p>
-     * @param ce
-     *            The feature to be added to the Last
+     * @param ce The feature to be added to the Last
      */
     protected void addLast( CacheElement ce )
     {
@@ -520,8 +514,7 @@
     /**
      * Adds a new node to the start of the link list.
      * <p>
-     * @param ce
-     *            The feature to be added to the First
+     * @param ce The feature to be added to the First
      */
     private synchronized void addFirst( ICacheElement ce )
     {
@@ -561,7 +554,8 @@
 
     /**
      * Returns the size of the list.
-     * @return
+     * <p>
+     * @return the number of items in the map.
      */
     private int dumpCacheSize()
     {
@@ -569,8 +563,8 @@
     }
 
     /**
-     * Checks to see if all the items that should be in the cache are. Checks
-     * consistency between List and map.
+     * Checks to see if all the items that should be in the cache are. Checks consistency between
+     * List and map.
      */
     private void verifyCache()
     {
@@ -688,11 +682,13 @@
         }
     }
 
-    /*
-     * (non-Javadoc)
+    /**
+     * This returns semi-structured information on the memory cache, such as the size, put count,
+     * hit count, and miss count.
+     * <p>
      * @see org.apache.jcs.engine.memory.MemoryCache#getStatistics()
      */
-    public IStats getStatistics()
+    public synchronized IStats getStatistics()
     {
         IStats stats = new Stats();
         stats.setTypeName( "LRU Memory Cache" );
@@ -735,5 +731,4 @@
 
         return stats;
     }
-
 }

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/utils/struct/DoubleLinkedList.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/utils/struct/DoubleLinkedList.java?view=diff&rev=519799&r1=519798&r2=519799
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/utils/struct/DoubleLinkedList.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/utils/struct/DoubleLinkedList.java Sun Mar 18 19:28:35 2007
@@ -10,14 +10,16 @@
  */
 public class DoubleLinkedList
 {
-    // record size to avoid having to iterate
+    /** record size to avoid having to iterate */
     private int size = 0;
 
+    /** The logger */
     private final static Log log = LogFactory.getLog( DoubleLinkedList.class );
 
-    // LRU double linked list head/tail nodes
+    /** LRU double linked list head node */
     private DoubleLinkedListNode first;
 
+    /** LRU double linked list tail node */
     private DoubleLinkedListNode last;
 
     /**
@@ -34,7 +36,7 @@
      * @param me
      *            The feature to be added to the Last
      */
-    public void addLast( DoubleLinkedListNode me )
+    public synchronized void addLast( DoubleLinkedListNode me )
     {
         if ( first == null )
         {
@@ -78,7 +80,7 @@
      * <p>
      * @return The last node.
      */
-    public DoubleLinkedListNode getLast()
+    public synchronized DoubleLinkedListNode getLast()
     {
         if ( log.isDebugEnabled() )
         {
@@ -90,9 +92,9 @@
     /**
      * Removes the specified node from the link list.
      * <p>
-     * @return
+     * @return DoubleLinkedListNode, the first node.
      */
-    public DoubleLinkedListNode getFirst()
+    public synchronized DoubleLinkedListNode getFirst()
     {
         if ( log.isDebugEnabled() )
         {
@@ -105,7 +107,7 @@
      * Moves an existing node to the start of the link list.
      * <p>
      * @param ln
-     *            Description of the Parameter
+     *            The node to set as the head.
      */
     public synchronized void makeFirst( DoubleLinkedListNode ln )
     {
@@ -212,7 +214,7 @@
      * <p>
      * @return The last node if there was one to remove.
      */
-    public DoubleLinkedListNode removeLast()
+    public synchronized DoubleLinkedListNode removeLast()
     {
         if ( log.isDebugEnabled() )
         {
@@ -231,7 +233,7 @@
      * <p>
      * @return int
      */
-    public int size()
+    public synchronized int size()
     {
         return size;
     }
@@ -240,7 +242,7 @@
     /**
      * Dump the cache entries from first to list for debugging.
      */
-    public void debugDumpEntries()
+    public synchronized void debugDumpEntries()
     {
         log.debug( "dumping Entries" );
         for ( DoubleLinkedListNode me = first; me != null; me = me.next )
@@ -248,5 +250,4 @@
             log.debug( "dump Entries> payload= '" + me.getPayload() + "'" );
         }
     }
-
 }

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/utils/struct/SortedPreferentialArray.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/utils/struct/SortedPreferentialArray.java?view=diff&rev=519799&r1=519798&r2=519799
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/utils/struct/SortedPreferentialArray.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/utils/struct/SortedPreferentialArray.java Sun Mar 18 19:28:35 2007
@@ -22,17 +22,22 @@
  */
 public class SortedPreferentialArray
 {
+    /** The logger */
     private static final Log log = LogFactory.getLog( SortedPreferentialArray.class );
 
-    // prefer large means that the smallest will be removed when full.
+    /** prefer large means that the smallest will be removed when full. */
     private boolean preferLarge = true;
 
+    /** maximum number allowed */
     private int maxSize = 0;
 
+    /** The currency number */
     private int curSize = 0;
 
+    /** The primary array */
     private Comparable[] array;
 
+    /** the number that have been inserted. */
     private int insertCnt = 0;
 
     /**
@@ -297,7 +302,7 @@
      * <p>
      * @return int
      */
-    public int size()
+    public synchronized int size()
     {
         return this.curSize;
     }
@@ -578,9 +583,9 @@
     /**
      * Debugging method to return a human readable display of array data.
      * <p>
-     * @return
+     * @return String representation of the contents.  
      */
-    protected String dumpArray()
+    protected synchronized String dumpArray()
     {
         StringBuffer buf = new StringBuffer();
         buf.append( "\n ---------------------------" );

Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/block/BlockDiskCacheSameRegionConcurrentUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/block/BlockDiskCacheSameRegionConcurrentUnitTest.java?view=diff&rev=519799&r1=519798&r2=519799
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/block/BlockDiskCacheSameRegionConcurrentUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/block/BlockDiskCacheSameRegionConcurrentUnitTest.java Sun Mar 18 19:28:35 2007
@@ -128,9 +128,10 @@
 
         for ( int i = start; i <= end; i++ )
         {
-            String value = (String) jcs.get( i + ":key" );
+            String key = i + ":key";
+            String value = (String) jcs.get( key );
 
-            assertEquals( region + " data " + i, value );
+            assertEquals( "Wrong value for key [" + key + "]", region + " data " + i, value );
         }
     }
 }

Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/utils/struct/LRUMapConcurrentUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/utils/struct/LRUMapConcurrentUnitTest.java?view=diff&rev=519799&r1=519798&r2=519799
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/utils/struct/LRUMapConcurrentUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/utils/struct/LRUMapConcurrentUnitTest.java Sun Mar 18 19:28:35 2007
@@ -10,19 +10,19 @@
 
 /**
  * Tests the LRUMap
- * 
- * @author aaronsm
+ * <p>
+ * @author aaron smuts
  *  
  */
 public class LRUMapConcurrentUnitTest
     extends TestCase
 {
-
+    /** number to test with */
     private static int items = 20000;
 
     /**
      * Constructor for the TestSimpleLoad object
-     * 
+     * <p>
      * @param testName
      *            Description of the Parameter
      */
@@ -32,20 +32,8 @@
     }
 
     /**
-     * Description of the Method
-     * 
-     * @param args
-     *            Description of the Parameter
-     */
-    public static void main( String args[] )
-    {
-        String[] testCaseName = { LRUMapConcurrentUnitTest.class.getName() };
-        junit.textui.TestRunner.main( testCaseName );
-    }
-
-    /**
      * A unit test suite for JUnit
-     * 
+     * <p>
      * @return The test suite
      */
     public static Test suite()
@@ -105,7 +93,7 @@
 
     /**
      * Just test that we can put, get and remove as expected.
-     * 
+     * <p>
      * @exception Exception
      *                Description of the Exception
      */
@@ -245,7 +233,7 @@
     /**
      * Put, get, and remove from a range. This should occur at a range that is
      * not touched by other tests.
-     * 
+     * <p>
      * @param map
      * @param start
      * @param end
@@ -271,7 +259,5 @@
         // test removal
         map.remove( start + ":key" );
         assertNull( map.get( start + ":key" ) );
-
     }
-
 }

Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/utils/struct/LRUMapPerformanceTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/utils/struct/LRUMapPerformanceTest.java?view=diff&rev=519799&r1=519798&r2=519799
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/utils/struct/LRUMapPerformanceTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/utils/struct/LRUMapPerformanceTest.java Sun Mar 18 19:28:35 2007
@@ -12,22 +12,29 @@
 /**
  * This ensures that the jcs version of the LRU map is as fast as the commons
  * version. It has been testing at .6 to .7 times the commons LRU.
- * 
+ * <p>
  * @author aaronsm
  *  
  */
 public class LRUMapPerformanceTest
     extends TestCase
 {
-
+    /** The put put ration after the test */
     float ratioPut = 0;
 
+    /** The ratio after the test */
     float ratioGet = 0;
 
-    float target = 1.0f;
+    /** put jcs / commons ratio */
+    float targetPut = 1.2f;
+
+    /** get jcs / commons ratio */
+    float targetGet = .5f;
 
+    /** Time to loop */
     int loops = 20;
 
+    /** items to put and get per loop */
     int tries = 50000;
 
     /**
@@ -40,7 +47,7 @@
 
     /**
      * A unit test suite for JUnit
-     * 
+     * <p>
      * @return The test suite
      */
     public static Test suite()
@@ -58,8 +65,8 @@
         throws Exception
     {
         doWork();
-        assertTrue( this.ratioPut < target );
-        assertTrue( this.ratioGet < target );
+        assertTrue( this.ratioPut < targetPut );
+        assertTrue( this.ratioGet < targetGet );
     }
 
     /**
@@ -67,7 +74,6 @@
      */
     public void doWork()
     {
-
         long start = 0;
         long end = 0;
         long time = 0;
@@ -83,12 +89,10 @@
 
         try
         {
-
             Map cache = new LRUMap( tries );
 
             for ( int j = 0; j < loops; j++ )
             {
-
                 name = "JCS      ";
                 start = System.currentTimeMillis();
                 for ( int i = 0; i < tries; i++ )
@@ -142,7 +146,6 @@
 
                 System.out.println( "\n" );
             }
-
         }
         catch ( Exception e )
         {
@@ -161,16 +164,15 @@
         System.out.println( "Put average for LRUMap       = " + putAvJCS );
         System.out.println( "Put average for " + cache2Name + " = " + putAvHashtable );
         ratioPut = Float.intBitsToFloat( (int) putAvJCS ) / Float.intBitsToFloat( (int) putAvHashtable );
-        System.out.println( name + " puts took " + ratioPut + " times the " + cache2Name + ", the goal is <" + target
+        System.out.println( name + " puts took " + ratioPut + " times the " + cache2Name + ", the goal is <" + targetPut
             + "x" );
 
         System.out.println( "\n" );
         System.out.println( "Get average for LRUMap       = " + getAvJCS );
         System.out.println( "Get average for " + cache2Name + " = " + getAvHashtable );
         ratioGet = Float.intBitsToFloat( (int) getAvJCS ) / Float.intBitsToFloat( (int) getAvHashtable );
-        System.out.println( name + " gets took " + ratioGet + " times the " + cache2Name + ", the goal is <" + target
+        System.out.println( name + " gets took " + ratioGet + " times the " + cache2Name + ", the goal is <" + targetGet
             + "x" );
-
     }
 
     /**



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