jakarta-jcs-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asm...@apache.org
Subject svn commit: r430809 [2/2] - in /jakarta/jcs/trunk/src: experimental/org/apache/jcs/engine/memory/arc/ java/org/apache/jcs/access/ java/org/apache/jcs/access/behavior/ java/org/apache/jcs/auxiliary/lateral/ java/org/apache/jcs/auxiliary/lateral/socket/t...
Date Fri, 11 Aug 2006 15:51:11 GMT
Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/AbstractMemoryCache.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/AbstractMemoryCache.java?rev=430809&r1=430808&r2=430809&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/AbstractMemoryCache.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/AbstractMemoryCache.java Fri Aug
11 08:51:10 2006
@@ -1,19 +1,14 @@
 package org.apache.jcs.engine.memory;
 
 /*
- * 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;
@@ -46,7 +41,6 @@
  * This keeps a static reference to a memory shrinker clock daemon. If this
  * region is configured to use the shrinker, the clock daemon will be setup to
  * run the shrinker on this region.
- * 
  * @version $Id$
  */
 public abstract class AbstractMemoryCache
@@ -101,7 +95,6 @@
 
     /**
      * For post reflection creation initialization
-     * 
      * @param hub
      */
     public synchronized void initialize( CompositeCache hub )
@@ -127,7 +120,6 @@
 
     /**
      * Removes an item from the cache
-     * 
      * @param key
      *            Identifies item to be removed
      * @return Description of the Return Value
@@ -139,7 +131,6 @@
 
     /**
      * Get an item from the cache
-     * 
      * @param key
      *            Description of the Parameter
      * @return Description of the Return Value
@@ -152,7 +143,6 @@
     /**
      * Get an item from the cache without effecting its order or last access
      * time
-     * 
      * @param key
      *            Description of the Parameter
      * @return The quiet value
@@ -164,7 +154,6 @@
 
     /**
      * Puts an item to the cache.
-     * 
      * @param ce
      *            Description of the Parameter
      * @exception IOException
@@ -175,14 +164,12 @@
 
     /**
      * Get an Array of the keys for all elements in the memory cache
-     * 
      * @return An Object[]
      */
     public abstract Object[] getKeyArray();
 
     /**
      * Removes all cached items from the cache.
-     * 
      * @exception IOException
      */
     public void removeAll()
@@ -193,7 +180,6 @@
 
     /**
      * Prepares for shutdown.
-     * 
      * @exception IOException
      */
     public void dispose()
@@ -208,7 +194,6 @@
 
     /*
      * (non-Javadoc)
-     * 
      * @see org.apache.jcs.engine.memory.MemoryCache#getStatistics()
      */
     public IStats getStatistics()
@@ -220,7 +205,6 @@
 
     /**
      * Returns the current cache size.
-     * 
      * @return The size value
      */
     public int getSize()
@@ -230,7 +214,6 @@
 
     /**
      * Returns the cache status.
-     * 
      * @return The status value
      */
     public int getStatus()
@@ -240,7 +223,6 @@
 
     /**
      * Returns the cache name.
-     * 
      * @return The cacheName value
      */
     public String getCacheName()
@@ -250,7 +232,6 @@
 
     /**
      * Puts an item to the cache.
-     * 
      * @param ce
      * @exception IOException
      */
@@ -262,7 +243,6 @@
 
     /**
      * Gets the iterator attribute of the LRUMemoryCache object
-     * 
      * @return The iterator value
      */
     public Iterator getIterator()
@@ -272,7 +252,6 @@
 
     /**
      * Returns the CacheAttributes.
-     * 
      * @return The CacheAttributes value
      */
     public ICompositeCacheAttributes getCacheAttributes()
@@ -282,7 +261,6 @@
 
     /**
      * Sets the CacheAttributes.
-     * 
      * @param cattr
      *            The new CacheAttributes value
      */
@@ -293,7 +271,6 @@
 
     /**
      * Gets the cache hub / region taht the MemoryCache is used by
-     * 
      * @return The cache value
      */
     public CompositeCache getCompositeCache()
@@ -323,9 +300,7 @@
 
     /**
      * Allows us to set the daemon status on the clockdaemon
-     * 
      * @author aaronsm
-     * 
      */
     class MyThreadFactory
         implements ThreadFactory
@@ -333,7 +308,6 @@
 
         /*
          * (non-Javadoc)
-         * 
          * @see EDU.oswego.cs.dl.util.concurrent.ThreadFactory#newThread(java.lang.Runnable)
          */
         public Thread newThread( Runnable runner )

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/MemoryCache.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/MemoryCache.java?rev=430809&r1=430808&r2=430809&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/MemoryCache.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/MemoryCache.java Fri Aug 11 08:51:10
2006
@@ -101,6 +101,20 @@
         throws IOException;
 
     /**
+     * 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.
+     * @throws IOException
+     */
+    public int freeElements( int numberToFree )
+        throws IOException;
+
+    /**
      * Get an item from the cache
      * <p>
      * @param key

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?rev=430809&r1=430808&r2=430809&view=diff
==============================================================================
--- 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 Fri Aug
11 08:51:10 2006
@@ -1,19 +1,14 @@
 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;
@@ -52,7 +47,7 @@
  * 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
@@ -73,7 +68,6 @@
 
     /**
      * For post reflection creation initialization.
-     * 
      * @param hub
      */
     public synchronized void initialize( CompositeCache hub )
@@ -88,7 +82,7 @@
      * 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
      * @exception IOException
@@ -144,59 +138,100 @@
 
         for ( int i = 0; i < chunkSizeCorrected; i++ )
         {
-            synchronized ( this )
+            spoolLastElement();
+        }
+
+        if ( log.isDebugEnabled() )
+        {
+            log.debug( "update: After spool map size: " + map.size() + " linked list size
= " + dumpCacheSize() );
+        }
+
+    }
+
+    /**
+     * This spools the last element in the LRU, if one exists.
+     * <p>
+     * @return ICacheElement if there was a last element, else null.
+     * @throws Error
+     */
+    protected ICacheElement spoolLastElement()
+        throws Error
+    {
+        ICacheElement toSpool = null;
+        synchronized ( this )
+        {
+            if ( list.getLast() != null )
             {
-                if ( list.getLast() != null )
+                toSpool = ( (MemoryElementDescriptor) list.getLast() ).ce;
+                if ( toSpool != null )
                 {
-                    if ( ( (MemoryElementDescriptor) list.getLast() ).ce != null )
+                    cache.spoolToDisk( ( (MemoryElementDescriptor) list.getLast() ).ce );
+                    if ( !map.containsKey( ( (MemoryElementDescriptor) list.getLast() ).ce.getKey()
) )
                     {
-                        cache.spoolToDisk( ( (MemoryElementDescriptor) list.getLast() ).ce
);
-                        if ( !map.containsKey( ( (MemoryElementDescriptor) list.getLast()
).ce.getKey() ) )
-                        {
-                            log.error( "update: map does not contain key: "
-                                + ( (MemoryElementDescriptor) list.getLast() ).ce.getKey()
);
-                            verifyCache();
-                        }
-                        if ( map.remove( ( (MemoryElementDescriptor) list.getLast() ).ce.getKey()
) == null )
-                        {
-                            log.warn( "update: remove failed for key: "
-                                + ( (MemoryElementDescriptor) list.getLast() ).ce.getKey()
);
-                            verifyCache();
-                        }
+                        log.error( "update: map does not contain key: "
+                            + ( (MemoryElementDescriptor) list.getLast() ).ce.getKey() );
+                        verifyCache();
                     }
-                    else
+                    if ( map.remove( ( (MemoryElementDescriptor) list.getLast() ).ce.getKey()
) == null )
                     {
-                        throw new Error( "update: last.ce is null!" );
+                        log.warn( "update: remove failed for key: "
+                            + ( (MemoryElementDescriptor) list.getLast() ).ce.getKey() );
+                        verifyCache();
                     }
-                    list.removeLast();
                 }
                 else
                 {
-                    verifyCache();
-                    throw new Error( "update: last is null!" );
+                    throw new Error( "update: last.ce is null!" );
                 }
+                list.removeLast();
+            }
+            else
+            {
+                verifyCache();
+                throw new Error( "update: last is null!" );
+            }
 
-                // If this is out of the sync block it can detect a mismatch
-                // where there is none.
-                if ( map.size() != dumpCacheSize() )
-                {
-                    log.warn( "update: After spool, size mismatch: map.size() = " + map.size()
-                        + ", linked list size = " + dumpCacheSize() );
-                }
+            // If this is out of the sync block it can detect a mismatch
+            // where there is none.
+            if ( map.size() != dumpCacheSize() )
+            {
+                log.warn( "update: After spool, size mismatch: map.size() = " + map.size()
+ ", linked list size = "
+                    + dumpCacheSize() );
             }
         }
+        return toSpool;
+    }
 
-        if ( log.isDebugEnabled() )
+    /**
+     * 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.
+     * @throws IOException
+     */
+    public int freeElements( int numberToFree )
+        throws IOException
+    {
+        int freed = 0;
+        for ( ; freed < numberToFree; freed++ )
         {
-            log.debug( "update: After spool map size: " + map.size() + " linked list size
= " + dumpCacheSize() );
+            ICacheElement element = spoolLastElement();
+            if ( element == null )
+            {
+                break;
+            }
         }
-
+        return freed;
     }
-
+    
     /**
      * Get an item from the cache without affecting its last access time or
      * position.
-     * 
+     * <p>
      * @param key
      *            Identifies item to find
      * @return Element mathinh key if found, or null
@@ -227,7 +262,7 @@
 
     /**
      * Get an item from the cache
-     * 
+     * <p>
      * @param key
      *            Identifies item to find
      * @return ICacheElement if found, else null
@@ -276,7 +311,7 @@
      * 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
      * @exception IOException
@@ -352,7 +387,7 @@
     /**
      * Remove all of the elements from both the Map and the linked list
      * implementation. Overrides base class.
-     * 
+     * <p>
      * @throws IOException
      */
     public synchronized void removeAll()
@@ -364,9 +399,7 @@
 
     // --------------------------- iteration mehods (iteration helpers)
     /**
-     * 
      * iteration aid
-     * 
      */
     public class IteratorWrapper
         implements Iterator
@@ -407,10 +440,7 @@
     }
 
     /**
-     * 
-     * 
      * @author Aaron Smuts
-     * 
      */
     public class MapEntryWrapper
         implements Map.Entry
@@ -451,7 +481,7 @@
 
     /**
      * Gets the iterator attribute of the LRUMemoryCache object
-     * 
+     * <p>
      * @return The iterator value
      */
     public Iterator getIterator()
@@ -461,7 +491,6 @@
 
     /**
      * Get an Array of the keys for all elements in the memory cache
-     * 
      * @return An Object[]
      */
     public Object[] getKeyArray()
@@ -477,7 +506,7 @@
     // --------------------------- internal mehods (linked list implementation)
     /**
      * 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
      */
@@ -490,7 +519,7 @@
 
     /**
      * Adds a new node to the start of the link list.
-     * 
+     * <p>
      * @param ce
      *            The feature to be added to the First
      */
@@ -532,7 +561,6 @@
 
     /**
      * Returns the size of the list.
-     * 
      * @return
      */
     private int dumpCacheSize()
@@ -543,7 +571,6 @@
     /**
      * Checks to see if all the items that should be in the cache are. Checks
      * consistency between List and map.
-     * 
      */
     private void verifyCache()
     {
@@ -633,7 +660,7 @@
 
     /**
      * Logs an error is an element that should be in the cache is not.
-     * 
+     * <p>
      * @param key
      */
     private void verifyCache( Serializable key )
@@ -663,7 +690,6 @@
 
     /*
      * (non-Javadoc)
-     * 
      * @see org.apache.jcs.engine.memory.MemoryCache#getStatistics()
      */
     public IStats getStatistics()

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/mru/MRUMemoryCache.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/mru/MRUMemoryCache.java?rev=430809&r1=430808&r2=430809&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/mru/MRUMemoryCache.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/mru/MRUMemoryCache.java Fri Aug
11 08:51:10 2006
@@ -1,19 +1,14 @@
 package org.apache.jcs.engine.memory.mru;
 
 /*
- * 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;
@@ -38,13 +33,12 @@
 import org.apache.jcs.engine.stats.behavior.IStats;
 
 /**
- * A SLOW reference management system. The most recently used items move
- * to the front of the list and get spooled to disk if the cache hub is
- * configured to use a disk cache.
+ * A SLOW reference management system. The most recently used items move to the
+ * front of the list and get spooled to disk if the cache hub is configured to
+ * use a disk cache.
  * <p>
  * This class is mainly for testing the hub. It also shows that use the
  * Collection LinkedList is far slower than JCS' own double linked list.
- * 
  */
 public class MRUMemoryCache
     extends AbstractMemoryCache
@@ -71,7 +65,6 @@
 
     /**
      * For post reflection creation initialization
-     * 
      * @param hub
      */
     public synchronized void initialize( CompositeCache hub )
@@ -82,7 +75,6 @@
 
     /**
      * Puts an item to the cache.
-     * 
      * @param ce
      * @exception IOException
      */
@@ -144,19 +136,8 @@
             // and wouldn't save much time in this synchronous call.
             for ( int i = 0; i < chunkSizeCorrected; i++ )
             {
-
-                ICacheElement toSpool = null;
-                
-                // need a more fine grained locking here
-                synchronized ( lockMe )
-                {
-                    Serializable last = (Serializable) mrulist.removeLast();
-                    toSpool = (ICacheElement) map.get( last );
-                    map.remove( last );
-                }
-                // Might want to rename this "overflow" incase the hub
-                // wants to do something else.
-                cache.spoolToDisk( toSpool );
+                // remove the last
+                spoolLastElement();
             }
 
             if ( log.isDebugEnabled() )
@@ -175,9 +156,63 @@
     }
 
     /**
+     * This removes the last elemement in the list.
+     * <p>
+     * @return ICacheElement if there was a last element, else null.
+     */
+    protected ICacheElement spoolLastElement()
+    {
+        ICacheElement toSpool = null;
+
+        // need a more fine grained locking here
+        synchronized ( lockMe )
+        {
+            Serializable last = (Serializable) mrulist.removeLast();
+            if ( last != null )
+            {
+                toSpool = (ICacheElement) map.get( last );
+                map.remove( last );
+            }
+        }
+        // Might want to rename this "overflow" incase the hub
+        // wants to do something else.
+        if ( toSpool != null )
+        {
+            cache.spoolToDisk( toSpool );
+        }
+
+        return toSpool;
+    }
+
+    /**
+     * 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.
+     * @throws IOException
+     */
+    public int freeElements( int numberToFree )
+        throws IOException
+    {
+        int freed = 0;
+        for ( ; freed < numberToFree; freed++ )
+        {
+            ICacheElement element = spoolLastElement();
+            if ( element == null )
+            {
+                break;
+            }
+        }
+        return freed;
+    }
+
+    /**
      * Get an item from the cache without affecting its last access time or
      * position.
-     * 
      * @return Element mathinh key if found, or null
      * @param key
      *            Identifies item to find
@@ -211,11 +246,9 @@
         return ce;
     }
 
-       
     /**
      * Gets an item out of the map. If it finds an item, it is removed from the
      * list and then added to the first position in the linked list.
-     * 
      * @return
      * @param key
      * @exception IOException
@@ -294,7 +327,6 @@
 
     /**
      * Removes an item from the cache.
-     * 
      * @return
      * @param key
      * @exception IOException
@@ -323,7 +355,7 @@
                     {
                         itr.remove();
                         Serializable keyR = (Serializable) entry.getKey();
-                        //map.remove( keyR );
+                        // map.remove( keyR );
                         mrulist.remove( keyR );
                         removed = true;
                     }
@@ -368,7 +400,6 @@
 
     /**
      * Get an Array of the keys for all elements in the memory cache
-     * 
      * @return Object[]
      */
     public Object[] getKeyArray()
@@ -411,7 +442,6 @@
 
     /*
      * (non-Javadoc)
-     * 
      * @see org.apache.jcs.engine.memory.MemoryCache#getStatistics()
      */
     public IStats getStatistics()

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/utils/serialization/StandardSerializer.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/utils/serialization/StandardSerializer.java?rev=430809&r1=430808&r2=430809&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/utils/serialization/StandardSerializer.java
(original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/utils/serialization/StandardSerializer.java
Fri Aug 11 08:51:10 2006
@@ -18,7 +18,6 @@
 public class StandardSerializer
     implements IElementSerializer
 {
-
     /**
      * Serializes an object using default serilaization.
      */

Added: jakarta/jcs/trunk/src/test-conf/TestARCCache.ccf
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test-conf/TestARCCache.ccf?rev=430809&view=auto
==============================================================================
--- jakarta/jcs/trunk/src/test-conf/TestARCCache.ccf (added)
+++ jakarta/jcs/trunk/src/test-conf/TestARCCache.ccf Fri Aug 11 08:51:10 2006
@@ -0,0 +1,17 @@
+# JCS Config for unit testing, just a simple memory only cache, with 10 max size
+# with the memory shrinker on.
+
+jcs.default=
+jcs.default.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
+jcs.default.cacheattributes.MaxObjects=10
+jcs.default.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.arc.ARCMemoryCache
+jcs.default.cacheattributes.UseMemoryShrinker=false
+jcs.default.cacheattributes.MaxMemoryIdleTimeSeconds=3600
+jcs.default.cacheattributes.ShrinkerIntervalSeconds=1
+jcs.default.elementattributes=org.apache.jcs.engine.ElementAttributes
+jcs.default.elementattributes.IsEternal=true
+jcs.default.elementattributes.MaxLifeSeconds=600
+jcs.default.elementattributes.IdleTime=1800
+jcs.default.elementattributes.IsSpool=true
+jcs.default.elementattributes.IsRemote=true
+jcs.default.elementattributes.IsLateral=true

Modified: jakarta/jcs/trunk/src/test-conf/TestTCPLateralCacheConcurrent.ccf
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test-conf/TestTCPLateralCacheConcurrent.ccf?rev=430809&r1=430808&r2=430809&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test-conf/TestTCPLateralCacheConcurrent.ccf (original)
+++ jakarta/jcs/trunk/src/test-conf/TestTCPLateralCacheConcurrent.ccf Fri Aug 11 08:51:10
2006
@@ -10,6 +10,6 @@
 jcs.auxiliary.LTCP.attributes.TransmissionTypeName=TCP
 #jcs.auxiliary.LTCP.attributes.TcpServers=
 jcs.auxiliary.LTCP.attributes.TcpListenerPort=1102
-jcs.auxiliary.LTCP.attributes.AllowGet=false
+jcs.auxiliary.LTCP.attributes.AllowGet=true
 
 

Modified: jakarta/jcs/trunk/src/test-conf/log4j.properties
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test-conf/log4j.properties?rev=430809&r1=430808&r2=430809&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test-conf/log4j.properties (original)
+++ jakarta/jcs/trunk/src/test-conf/log4j.properties Fri Aug 11 08:51:10 2006
@@ -17,7 +17,7 @@
 
 log4j.appender.logfile=org.apache.log4j.RollingFileAppender
 log4j.appender.logfile.File=target/test-sandbox/logs/jcs.log
-log4j.appender.logfile.MaxFileSize=2MB
+log4j.appender.logfile.MaxFileSize=5MB
 # Keep three backup files
 log4j.appender.logfile.MaxBackupIndex=3
 log4j.appender.logfile.layout=org.apache.log4j.PatternLayout

Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPConcurrentRandomTestUtil.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPConcurrentRandomTestUtil.java?rev=430809&r1=430808&r2=430809&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPConcurrentRandomTestUtil.java
(original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPConcurrentRandomTestUtil.java
Fri Aug 11 08:51:10 2006
@@ -16,7 +16,6 @@
 {
 
     private static boolean isSysOut = false;
-
     //private static boolean isSysOut = true;
 
     /**
@@ -41,7 +40,7 @@
      * Randomly adds items to cache, gets them, and removes them. The range
      * count is more than the size of the memory cache, so items should spool to
      * disk.
-     * 
+     * <p>
      * @param region
      *            Name of the region to access
      * @param range
@@ -54,13 +53,12 @@
     public void runTestForRegion( String region, int range, int numOps, int testNum )
         throws Exception
     {
-
         boolean show = true;//false;
 
         JCS cache = JCS.getInstance( region );
 
         TCPLateralCacheAttributes lattr2 = new TCPLateralCacheAttributes();
-        lattr2.setTcpListenerPort( 1102 );
+        lattr2.setTcpListenerPort( 1103 );
         lattr2.setTransmissionTypeName( "TCP" );
         lattr2.setTcpServer( "localhost:1102" );
 

Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPNoDeadLockConcurrentTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPNoDeadLockConcurrentTest.java?rev=430809&r1=430808&r2=430809&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPNoDeadLockConcurrentTest.java
(original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPNoDeadLockConcurrentTest.java
Fri Aug 11 08:51:10 2006
@@ -26,7 +26,6 @@
 /**
  * Test which exercises the tcp lateral cache. Runs two threads against the
  * same region and two against other regions.
- * 
  */
 public class LateralTCPNoDeadLockConcurrentTest
     extends TestCase
@@ -135,5 +134,4 @@
             e.printStackTrace();
         }
     }
-
 }

Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/TestTCPLateral.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/TestTCPLateral.java?rev=430809&r1=430808&r2=430809&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/TestTCPLateral.java
(original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/TestTCPLateral.java
Fri Aug 11 08:51:10 2006
@@ -33,7 +33,7 @@
      * Make sure we can send a bunch to the listener. This would be better if we
      * could plugin a Mock CacheManger. The listener will instantiate on on its
      * own. We have to configure one before that.
-     * 
+     * <p>
      * @throws Exception
      */
     public void testSimpleSend()
@@ -129,9 +129,9 @@
     public void testSameKeyDifferentObject()
         throws Exception
     {
+        // setup a listener
         TCPLateralCacheAttributes lattr = new TCPLateralCacheAttributes();
-        lattr.setTcpListenerPort( 1101 );
-        lattr.setTransmissionTypeName( "TCP" );
+        lattr.setTcpListenerPort( 1103 );
         CompositeCacheManagerMockImpl cacheMgr = new CompositeCacheManagerMockImpl();
         System.out.println( "mock cache = " + cacheMgr.getCache( "test" ) );
 
@@ -140,10 +140,10 @@
         //LateralTCPListener listener = (LateralTCPListener) 
         LateralTCPListener.getInstance( lattr, cacheMgr );
 
+        // setup a service to talk to the listener started above.
         TCPLateralCacheAttributes lattr2 = new TCPLateralCacheAttributes();
-        lattr2.setTcpListenerPort( 1102 );
-        lattr2.setTransmissionTypeName( "TCP" );
-        lattr2.setTcpServer( "localhost:1101" );
+        lattr2.setTcpListenerPort( 1104 );
+        lattr2.setTcpServer( "localhost:1103" );
 
         LateralTCPService service = new LateralTCPService( lattr2 );
         service.setListenerId( 123456 );
@@ -172,7 +172,7 @@
         throws Exception
     {
         TCPLateralCacheAttributes lattr = new TCPLateralCacheAttributes();
-        lattr.setTcpListenerPort( 1101 );
+        lattr.setTcpListenerPort( 1105 );
         lattr.setTransmissionTypeName( "TCP" );
         CompositeCacheManagerMockImpl cacheMgr = new CompositeCacheManagerMockImpl();
         System.out.println( "mock cache = " + cacheMgr.getCache( "test" ) );
@@ -183,9 +183,9 @@
         LateralTCPListener.getInstance( lattr, cacheMgr );
 
         TCPLateralCacheAttributes lattr2 = new TCPLateralCacheAttributes();
-        lattr2.setTcpListenerPort( 1102 );
+        lattr2.setTcpListenerPort( 1106);
         lattr2.setTransmissionTypeName( "TCP" );
-        lattr2.setTcpServer( "localhost:1101" );
+        lattr2.setTcpServer( "localhost:1105" );
 
         LateralTCPService service = new LateralTCPService( lattr2 );
         service.setListenerId( 123456 );
@@ -205,4 +205,45 @@
         System.out.println( "cacheElement = " + cacheElement );
         assertEquals( "Didn't get the correct object", element2.getVal(), cacheElement.getVal()
);
     }
+    
+    /**
+     * Create a listener.  Add an element to the listeners cache.  Setup a service.  Try
to get from the service.
+     * <p>
+     * @throws Exception
+     */
+    public void testSendAndReceived()
+        throws Exception
+    {
+        // setup a listener
+        TCPLateralCacheAttributes lattr = new TCPLateralCacheAttributes();
+        lattr.setTcpListenerPort( 1107 );
+        CompositeCacheManagerMockImpl cacheMgr = new CompositeCacheManagerMockImpl();
+        System.out.println( "mock cache = " + cacheMgr.getCache( "test" ) );
+
+        // get the listener started
+        // give it our mock cache manager
+        //LateralTCPListener listener = (LateralTCPListener) 
+        LateralTCPListener.getInstance( lattr, cacheMgr );
+
+        // add the item to the listeners cache
+        ICacheElement element = new CacheElement( "test", "key", "value1" );
+        cacheMgr.getCache().update( element );
+                
+        // setup a service to talk to the listener started above.
+        TCPLateralCacheAttributes lattr2 = new TCPLateralCacheAttributes();
+        lattr2.setTcpListenerPort( 1108 );
+        lattr2.setTcpServer( "localhost:1107" );
+
+        LateralTCPService service = new LateralTCPService( lattr2 );
+        service.setListenerId( 123456 );
+
+        Thread.sleep( 300 );
+
+        // DO WORK
+        ICacheElement result = service.get( "test", "key" );
+
+        System.out.println( "testSendAndReceived, result = " + result );
+        assertNotNull( "Result should not be null.", result );
+        assertEquals( "Didn't get the correct object", element.getVal(), result.getVal()
);
+    }    
 }

Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/engine/memory/MemoryCacheMockImpl.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/engine/memory/MemoryCacheMockImpl.java?rev=430809&r1=430808&r2=430809&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/engine/memory/MemoryCacheMockImpl.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/engine/memory/MemoryCacheMockImpl.java Fri Aug
11 08:51:10 2006
@@ -37,7 +37,6 @@
 public class MemoryCacheMockImpl
     implements MemoryCache
 {
-
     private ICompositeCacheAttributes cacheAttr;
 
     private HashMap map = new HashMap();
@@ -152,4 +151,13 @@
         return null;
     }
 
+    /* (non-Javadoc)
+     * @see org.apache.jcs.engine.memory.MemoryCache#freeElements(int)
+     */
+    public int freeElements( int numberToFree )
+        throws IOException
+    {
+        // TODO Auto-generated method stub
+        return 0;
+    }
 }



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


Mime
View raw message