svn commit: r707758 [1/2] - in /jakarta/jcs/trunk/src: java/org/apache/jcs/access/ java/org/apache/jcs/access/behavior/ java/org/apache/jcs/auxiliary/ java/org/apache/jcs/auxiliary/disk/ java/org/apache/jcs/auxiliary/disk/block/ java/org/apache/jcs/aux...
[email protected] Fri, 24 Oct 2008 21:56:07 -0000
| Newsgroups | gmane.comp.jakarta.turbine.jcs.devel |
|---|---|
| Message-ID | <[email protected]> |
Author: asmuts
Date: Fri Oct 24 14:56:06 2008
New Revision: 707758
URL: http://svn.apache.org/viewvc?rev=707758&view=rev
Log:
This is a partial check in. Not all of the new features are fully implmented. I just wanted to get this part of the getMatching API into the repository.
Added:
jakarta/jcs/trunk/src/java/org/apache/jcs/utils/match/
jakarta/jcs/trunk/src/java/org/apache/jcs/utils/match/KeyMatcherUtil.java
jakarta/jcs/trunk/src/test/org/apache/jcs/JCSUnitTest.java (contents, props changed)
- copied, changed from r682483, jakarta/jcs/trunk/src/test/org/apache/jcs/JCSUniTest.java
jakarta/jcs/trunk/src/test/org/apache/jcs/utils/match/
jakarta/jcs/trunk/src/test/org/apache/jcs/utils/match/KeyMatcherUtilUnitTest.java
Removed:
jakarta/jcs/trunk/src/test/org/apache/jcs/JCSUniTest.java
Modified:
jakarta/jcs/trunk/src/java/org/apache/jcs/access/CacheAccess.java
jakarta/jcs/trunk/src/java/org/apache/jcs/access/behavior/ICacheAccess.java
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/AbstractAuxiliaryCacheEventLogging.java
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCache.java
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/disk/jdbc/JDBCDiskCache.java
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCache.java
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralCache.java
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheNoWait.java
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheNoWaitFacade.java
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCache.java
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheNoWait.java
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheNoWaitFacade.java
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/ZombieRemoteCacheService.java
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/behavior/IRemoteCacheService.java
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServer.java
jakarta/jcs/trunk/src/java/org/apache/jcs/engine/behavior/ICache.java
jakarta/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCache.java
jakarta/jcs/trunk/src/java/org/apache/jcs/engine/logging/behavior/ICacheEventLogger.java
jakarta/jcs/trunk/src/test-conf/TestMySQLDiskCache.ccf
jakarta/jcs/trunk/src/test/org/apache/jcs/JCSLightLoadUnitTest.java
jakarta/jcs/trunk/src/test/org/apache/jcs/JCSRemovalSimpleConcurrentTest.java
jakarta/jcs/trunk/src/test/org/apache/jcs/JCSThrashTest.java
jakarta/jcs/trunk/src/test/org/apache/jcs/JCSvsHashtablePerformanceTest.java
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/MockAuxiliaryCache.java
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/HsqlSetupTableUtil.java
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheUnitTest.java
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheHsqlBackedUnitTest.java
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheUnitTest.java
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/MockRemoteCacheClient.java
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/MockRemoteCacheService.java
jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/CompositeCacheDiskUsageUnitTest.java
jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/CompositeCacheUnitTest.java
jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/event/ElementEventHandlerMockImpl.java
jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/event/SimpleEventHandlingUnitTest.java
jakarta/jcs/trunk/src/test/org/apache/jcs/engine/memory/MockMemoryCache.java
jakarta/jcs/trunk/src/test/org/apache/jcs/utils/struct/JCSvsCommonsLRUMapPerformanceTest.java
Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/access/CacheAccess.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/access/CacheAccess.java?rev=707758&r1=707757&r2=707758&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/access/CacheAccess.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/access/CacheAccess.java Fri Oct 24 14:56:06 2008
@@ -45,10 +45,10 @@
* An instance of this class is tied to a specific cache region. Static methods are provided to get
* such instances.
* <p>
- * Using this class you can retrieve an item, the items wrapper, the element configuration, put an
+ * Using this class you can retrieve an item, the item's wrapper, the element configuration, put an
* item in the cache, remove an item, and clear a region.
* <p>
- * The JCS class is the prefered way to access these methods.
+ * The JCS class is the preferred way to access these methods.
*/
public class CacheAccess
implements ICacheAccess
@@ -64,7 +64,7 @@
/**
* The cache that a given instance of this class provides access to.
* <p>
- * @TODO Should this be the inteface?
+ * @TODO Should this be the interface?
*/
protected CompositeCache cacheControl;
@@ -82,7 +82,7 @@
/**
* Define a new cache region with the given name. In the oracle specification, these attributes
- * are global and not region specific, regional overirdes is a value add each region should be
+ * are global and not region specific, regional overrides is a value add each region should be
* able to house both cache and element attribute sets. It is more efficient to define a cache
* in the props file and then strictly use the get access method. Use of the define region
* outside of an initialization block should be avoided.
@@ -237,6 +237,28 @@
}
/**
+ * Get multiple elements from the cache based on a set of cache keys.
+ * <p>
+ * This method returns the ICacheElement wrapper which provides access to element info and other
+ * attributes.
+ * <p>
+ * This returns a reference to the wrapper. Any modifications will be reflected in the cache. No
+ * defensive copy is made.
+ * <p>
+ * This method is most useful if you want to determine things such as the how long the element
+ * has been in the cache.
+ * <p>
+ * The last access time in the ElementAttributes should be current.
+ * <p>
+ * @param pattern key search patern
+ * @return a map of Object key to ICacheElement element, or empty map if no keys match the pattern
+ */
+ public Map getMatchingCacheElements( String pattern )
+ {
+ return this.cacheControl.getMatching( pattern );
+ }
+
+ /**
* Place a new object in the cache, associated with key name. If there is currently an object
* associated with name in the region an ObjectExistsException is thrown. Names are scoped to a
* region so they must be unique within the region they are placed.
Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/access/behavior/ICacheAccess.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/access/behavior/ICacheAccess.java?rev=707758&r1=707757&r2=707758&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/access/behavior/ICacheAccess.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/access/behavior/ICacheAccess.java Fri Oct 24 14:56:06 2008
@@ -108,6 +108,25 @@
Map getCacheElements( Set names );
/**
+ * Get multiple elements from the cache based on a set of cache keys.
+ * <p>
+ * This method returns the ICacheElement wrapper which provides access to element info and other
+ * attributes.
+ * <p>
+ * This returns a reference to the wrapper. Any modifications will be reflected in the cache. No
+ * defensive copy is made.
+ * <p>
+ * This method is most useful if you want to determine things such as the how long the element
+ * has been in the cache.
+ * <p>
+ * The last access time in the ElementAttributes should be current.
+ * <p>
+ * @param pattern key search patern
+ * @return a map of Object key to ICacheElement element, or empty map if no keys match the pattern
+ */
+ Map getMatchingCacheElements( String pattern );
+
+ /**
* Removes an item or all items. Should be called remove.
* <p>
* @throws CacheException
Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/AbstractAuxiliaryCacheEventLogging.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/AbstractAuxiliaryCacheEventLogging.java?rev=707758&r1=707757&r2=707758&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/AbstractAuxiliaryCacheEventLogging.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/AbstractAuxiliaryCacheEventLogging.java Fri Oct 24 14:56:06 2008
@@ -2,6 +2,7 @@
import java.io.IOException;
import java.io.Serializable;
+import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@@ -95,7 +96,7 @@
logICacheEvent( cacheEvent );
}
}
-
+
/**
* Implementation of get.
* <p>
@@ -142,19 +143,74 @@
logICacheEvent( cacheEvent );
}
}
-
+
/**
* Implementation of getMultiple.
* <p>
* @param keys
* @return a map of Serializable key to ICacheElement element, or an empty map if there is no
* data in cache for any of these keys
- * @throws IOException
+ * @throws IOException
*/
protected abstract Map processGetMultiple( Set keys )
- throws IOException;
+ throws IOException;
+
+ /**
+ * Gets items from the cache matching the given pattern. Items from memory will replace those
+ * from remote sources.
+ * <p>
+ * This only works with string keys. It's too expensive to do a toString on every key.
+ * <p>
+ * Auxiliaries will do their best to handle simple expressions. For instance, the JDBC disk
+ * cache will convert * to % and . to _
+ * <p>
+ * @param pattern
+ * @return a map of Serializable key to ICacheElement element, or an empty map if there is no
+ * data matching the pattern.
+ * @throws IOException
+ */
+ public Map getMatching( String pattern )
+ throws IOException
+ {
+ // do nothing
+ return new HashMap();
+ }
/**
+ * Gets mmatching items from the cache based on the given pattern.
+ * <p>
+ * @param pattern
+ * @return a map of Serializable key to ICacheElement element, or an empty map if there is no
+ * data matching the pattern.
+ * @throws IOException
+ */
+ protected final Map getMatchingWithEventLogging( String pattern )
+ throws IOException
+ {
+ ICacheEvent cacheEvent = createICacheEvent( getCacheName(), pattern,
+ ICacheEventLogger.GETMATCHING_EVENT );
+ try
+ {
+ return processGetMatching( pattern );
+ }
+ finally
+ {
+ logICacheEvent( cacheEvent );
+ }
+ }
+
+ /**
+ * Implementation of getMatching.
+ * <p>
+ * @param pattern
+ * @return a map of Serializable key to ICacheElement element, or an empty map if there is no
+ * data matching the pattern.
+ * @throws IOException
+ */
+ protected abstract Map processGetMatching( String pattern )
+ throws IOException;
+
+ /**
* Removes the item from the cache. Wraps the remove in event logs.
* <p>
* @param key
@@ -187,7 +243,7 @@
logICacheEvent( cacheEvent );
}
}
-
+
/**
* Specific implementation of remove.
* <p>
@@ -196,7 +252,7 @@
* @throws IOException
*/
protected abstract boolean processRemove( Serializable key )
- throws IOException;
+ throws IOException;
/**
* Removes all from the region. Wraps the removeAll in event logs.
@@ -227,14 +283,14 @@
logICacheEvent( cacheEvent );
}
}
-
+
/**
* Specific implementation of removeAll.
* <p>
- * @throws IOException
+ * @throws IOException
*/
protected abstract void processRemoveAll()
- throws IOException;
+ throws IOException;
/**
* Synchronously dispose the remote cache; if failed, replace the remote handle with a zombie.
Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCache.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCache.java?rev=707758&r1=707757&r2=707758&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCache.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCache.java Fri Oct 24 14:56:06 2008
@@ -45,6 +45,7 @@
import org.apache.jcs.engine.stats.Stats;
import org.apache.jcs.engine.stats.behavior.IStatElement;
import org.apache.jcs.engine.stats.behavior.IStats;
+import org.apache.jcs.utils.match.KeyMatcherUtil;
import EDU.oswego.cs.dl.util.concurrent.WriterPreferenceReadWriteLock;
@@ -120,8 +121,7 @@
// create queue
CacheEventQueueFactory fact = new CacheEventQueueFactory();
this.cacheEventQueue = fact.createCacheEventQueue( new MyCacheListener(), CacheInfo.listenerId, cacheName,
- dcattr.getEventQueuePoolName(), dcattr
- .getEventQueueType() );
+ dcattr.getEventQueuePoolName(), dcattr.getEventQueueType() );
// create purgatory
initPurgatory();
@@ -301,6 +301,47 @@
}
/**
+ * Gets items from the cache matching the given pattern. Items from memory will replace those
+ * from remote sources.
+ * <p>
+ * This only works with string keys. It's too expensive to do a toString on every key.
+ * <p>
+ * Auxiliaries will do their best to handle simple expressions. For instance, the JDBC disk
+ * cache will convert * to % and . to _
+ * <p>
+ * @param pattern
+ * @return a map of Serializable key to ICacheElement element, or an empty map if there is no
+ * data matching the pattern.
+ * @throws IOException
+ */
+ public Map getMatching( String pattern )
+ throws IOException
+ {
+ // TODO finish.
+
+ // Get the keys from purgatory
+ Object[] keyArray = null;
+
+ // this avoids locking purgatory, but it uses more memory
+ synchronized ( purgatory )
+ {
+ keyArray = purgatory.keySet().toArray();
+ }
+
+ Set matchingKeys = KeyMatcherUtil.getMatchingKeysFromArray( pattern, keyArray );
+
+ // call getMultiple with the set
+ Map result = processGetMultiple( matchingKeys );
+
+ // Get the keys from disk
+ Map diskMatches = doGetMatching( pattern );
+
+ result.putAll( diskMatches );
+
+ return result;
+ }
+
+ /**
* Gets multiple items from the cache based on the given set of keys.
* <p>
* @param keys
@@ -344,10 +385,11 @@
* <p>
* @param key
* @return whether the item was present to be removed.
- * @throws IOException
+ * @throws IOException
* @see org.apache.jcs.engine.behavior.ICache#remove
*/
- public final boolean remove( Serializable key ) throws IOException
+ public final boolean remove( Serializable key )
+ throws IOException
{
PurgatoryElement pe = null;
@@ -385,10 +427,11 @@
}
/**
- * @throws IOException
+ * @throws IOException
* @see org.apache.jcs.engine.behavior.ICache#removeAll
*/
- public final void removeAll() throws IOException
+ public final void removeAll()
+ throws IOException
{
if ( this.dcattr.isAllowRemoveAll() )
{
@@ -418,9 +461,10 @@
* reached.
* <li>Call doDispose on the concrete impl.
* </ol>
- * @throws IOException
+ * @throws IOException
*/
- public final void dispose() throws IOException
+ public final void dispose()
+ throws IOException
{
Runnable disR = new Runnable()
{
@@ -746,6 +790,23 @@
}
/**
+ * Get a value from the persistent store.
+ * <p>
+ * Before the event logging layer, the subclasses implemented the do* methods. Now the do*
+ * methods call the *EventLogging method on the super. The *WithEventLogging methods call the
+ * abstract process* methods. The children implement the process methods.
+ * <p>
+ * @param pattern Used to match keys.
+ * @return A map of matches..
+ * @throws IOException
+ */
+ protected final Map doGetMatching( String pattern )
+ throws IOException
+ {
+ return super.getMatchingWithEventLogging( pattern );
+ }
+
+ /**
* Add a cache element to the persistent store.
* <p>
* Before the event logging layer, the subclasses implemented the do* methods. Now the do*
@@ -803,7 +864,8 @@
* <p>
* @throws IOException
*/
- protected final void doDispose() throws IOException
+ protected final void doDispose()
+ throws IOException
{
super.disposeWithEventLogging();
}
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?rev=707758&r1=707757&r2=707758&view=diff
==============================================================================
--- 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 Fri Oct 24 14:56:06 2008
@@ -24,6 +24,7 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -220,6 +221,22 @@
}
/**
+ * Gets matching items from the cache.
+ * <p>
+ * @param pattern
+ * @return a map of Serializable key to ICacheElement element, or an empty map if there is no
+ * data in cache matching keys
+ */
+ public Map processGetMatching( String pattern )
+ {
+ Map elements = new HashMap();
+
+ // implement
+
+ return elements;
+ }
+
+ /**
* Returns the number of keys.
* <p>
* (non-Javadoc)
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?rev=707758&r1=707757&r2=707758&view=diff
==============================================================================
--- 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 Fri Oct 24 14:56:06 2008
@@ -419,7 +419,7 @@
}
/**
- * Update the disk cache. Called from the Queue. Makes sure the Item has not been retireved from
+ * Update the disk cache. Called from the Queue. Makes sure the Item has not been retrieved from
* purgatory while in queue for disk. Remove items from purgatory when they go to disk.
* <p>
* @param ce The ICacheElement to put to disk.
@@ -577,6 +577,22 @@
}
/**
+ * Gets matching items from the cache.
+ * <p>
+ * @param pattern
+ * @return a map of Serializable key to ICacheElement element, or an empty map if there is no
+ * data in cache matching keys
+ */
+ public Map processGetMatching( String pattern )
+ {
+ Map elements = new HashMap();
+
+ // implement
+
+ return elements;
+ }
+
+ /**
* Reads the item from disk.
* <p>
* @param key
Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCache.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCache.java?rev=707758&r1=707757&r2=707758&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCache.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCache.java Fri Oct 24 14:56:06 2008
@@ -29,7 +29,9 @@
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import org.apache.commons.logging.Log;
@@ -98,6 +100,9 @@
/** # of times get was called */
private int getCount = 0;
+ /** # of times getMatching was called */
+ private int getMatchingCount = 0;
+
/** if count % interval == 0 then log */
private static final int LOG_INTERVAL = 100;
@@ -143,7 +148,8 @@
* @param compositeCacheManager
* @return JDBCDiskCachePoolAccess for testing
*/
- protected JDBCDiskCachePoolAccess initializePoolAccess( JDBCDiskCacheAttributes cattr, ICompositeCacheManager compositeCacheManager )
+ protected JDBCDiskCachePoolAccess initializePoolAccess( JDBCDiskCacheAttributes cattr,
+ ICompositeCacheManager compositeCacheManager )
{
if ( cattr.getConnectionPoolName() != null )
{
@@ -407,7 +413,7 @@
}
catch ( SQLException e2 )
{
- log.error( "e2 sql [" + sqlU + "] Exception: ", e2 );
+ log.error( "e2 sql [" + sqlU + "] Exception: ", e2 );
}
}
@@ -596,6 +602,130 @@
}
/**
+ * This will run a like query. It will try to construct a usable query but different
+ * implementations will be needed to adjust the syntax.
+ * <p>
+ * @param pattern
+ * @return key,value map
+ */
+ protected Map processGetMatching( String pattern )
+ {
+ incrementGetMatchingCount();
+
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( "Getting [" + pattern + "] from disk" );
+ }
+
+ if ( !alive )
+ {
+ return null;
+ }
+
+ Map results = new HashMap();
+
+ try
+ {
+ // region, key
+ String selectString = "select CACHE_KEY, ELEMENT from " + getJdbcDiskCacheAttributes().getTableName()
+ + " where REGION = ? and CACHE_KEY like ?";
+
+ Connection con = poolAccess.getConnection();
+ try
+ {
+ PreparedStatement psSelect = null;
+ try
+ {
+ psSelect = con.prepareStatement( selectString );
+ psSelect.setString( 1, this.getCacheName() );
+ psSelect.setString( 2, constructLikeParameterFromPattern( pattern ) );
+
+ ResultSet rs = psSelect.executeQuery();
+ try
+ {
+ while ( rs.next() )
+ {
+ String key = rs.getString( 1 );
+ byte[] data = rs.getBytes( 2 );
+ if ( data != null )
+ {
+ try
+ {
+ // USE THE SERIALIZER
+ ICacheElement value = (ICacheElement) getElementSerializer().deSerialize( data );
+ results.put( key, value );
+ }
+ catch ( IOException ioe )
+ {
+ log.error( "Problem getting items for pattern [" + pattern + "]", ioe );
+ }
+ catch ( Exception e )
+ {
+ log.error( "Problem getting items for pattern [" + pattern + "]", e );
+ }
+ }
+ }
+ }
+ finally
+ {
+ if ( rs != null )
+ {
+ rs.close();
+ }
+ rs.close();
+ }
+ }
+ finally
+ {
+ if ( psSelect != null )
+ {
+ psSelect.close();
+ }
+ psSelect.close();
+ }
+ }
+ finally
+ {
+ if ( con != null )
+ {
+ con.close();
+ }
+ }
+ }
+ catch ( SQLException sqle )
+ {
+ log.error( "Caught a SQL exception trying to get items for pattern [" + pattern + "]", sqle );
+ }
+
+ if ( log.isInfoEnabled() )
+ {
+ if ( getMatchingCount % LOG_INTERVAL == 0 )
+ {
+ // TODO make a log stats method
+ log.info( "Get Matching Count [" + getMatchingCount + "]" );
+ }
+ }
+ return results;
+ }
+
+ /**
+ * @param pattern
+ * @return String to use in the like query.
+ */
+ public String constructLikeParameterFromPattern( String pattern )
+ {
+ pattern = pattern.replaceAll( "\\.\\+", "%" );
+ pattern = pattern.replaceAll( "\\.", "_" );
+
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( "pattern = [" + pattern + "]" );
+ }
+
+ return pattern;
+ }
+
+ /**
* Returns true if the removal was successful; or false if there is nothing to remove. Current
* implementation always results in a disk orphan.
* <p>
@@ -639,7 +769,7 @@
}
catch ( SQLException e )
{
- log.error( "Problem creating statement. sql [" + sql + "]", e );
+ log.error( "Problem creating statement. sql [" + sql+ "]", e );
alive = false;
}
finally
@@ -958,6 +1088,12 @@
getCount++;
}
+ /** safely increment */
+ private synchronized void incrementGetMatchingCount()
+ {
+ getMatchingCount++;
+ }
+
/**
* @param jdbcDiskCacheAttributes The jdbcDiskCacheAttributes to set.
*/
@@ -1008,6 +1144,11 @@
elems.add( se );
se = new StatElement();
+ se.setName( "Get Matching Count" );
+ se.setData( "" + getMatchingCount );
+ elems.add( se );
+
+ se = new StatElement();
se.setName( "Size" );
se.setData( "" + getSize() );
elems.add( se );
@@ -1080,7 +1221,7 @@
{
return this.jdbcDiskCacheAttributes.getUrl();
}
-
+
/**
* For debugging.
* <p>
Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCache.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCache.java?rev=707758&r1=707757&r2=707758&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCache.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCache.java Fri Oct 24 14:56:06 2008
@@ -20,6 +20,7 @@
*/
import java.io.Serializable;
+import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -89,6 +90,42 @@
/**
* This delegates to the generic JDBC disk cache. If we are currently optimizing, then this
+ * method will balk and return null.
+ * <p>
+ * @param pattern used for like query.
+ * @return An object matching key, or null.
+ */
+ protected Map processGetMatching( String pattern )
+ {
+ if ( this.getTableState().getState() == TableState.OPTIMIZATION_RUNNING )
+ {
+ if ( this.mySQLDiskCacheAttributes.isBalkDuringOptimization() )
+ {
+ return null;
+ }
+ }
+ return super.processGetMatching( pattern );
+ }
+
+ /**
+ * @param pattern
+ * @return String to use in the like query.
+ */
+ public String constructLikeParameterFromPattern( String pattern )
+ {
+ pattern = pattern.replaceAll( "\\.\\+", "%" );
+ pattern = pattern.replaceAll( "\\.", "_" );
+
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( "pattern = [" + pattern + "]" );
+ }
+
+ return pattern;
+ }
+
+ /**
+ * This delegates to the generic JDBC disk cache. If we are currently optimizing, then this
* method will balk and do nothing.
* <p>
* @param element
Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralCache.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralCache.java?rev=707758&r1=707757&r2=707758&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralCache.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralCache.java Fri Oct 24 14:56:06 2008
@@ -147,6 +147,14 @@
return obj;
}
+ /** TODO finish */
+ protected Map processGetMatching( String pattern )
+ throws IOException
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
/**
* Gets multiple items from the cache based on the given set of keys.
* <p>
Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheNoWait.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheNoWait.java?rev=707758&r1=707757&r2=707758&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheNoWait.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheNoWait.java Fri Oct 24 14:56:06 2008
@@ -60,14 +60,19 @@
/** The logger. */
private final static Log log = LogFactory.getLog( LateralCacheNoWait.class );
+ /** The cache */
private final LateralCache cache;
- private ICacheEventQueue q;
+ /** The event queue */
+ private ICacheEventQueue eventQueue;
+ /** times get called */
private int getCount = 0;
+ /** times remove called */
private int removeCount = 0;
+ /** times put called */
private int putCount = 0;
/** An optional event logger */
@@ -92,7 +97,7 @@
}
CacheEventQueueFactory fact = new CacheEventQueueFactory();
- this.q = fact.createCacheEventQueue( new CacheAdaptor( cache ), LateralCacheInfo.listenerId, cache
+ this.eventQueue = fact.createCacheEventQueue( new CacheAdaptor( cache ), LateralCacheInfo.listenerId, cache
.getCacheName(), cache.getAuxiliaryCacheAttributes().getEventQueuePoolName(), cache
.getAuxiliaryCacheAttributes().getEventQueueType() );
@@ -104,7 +109,7 @@
// LateralCacheInfo.listenerId, cache.getCacheName());
if ( cache.getStatus() == CacheConstants.STATUS_ERROR )
{
- q.destroy();
+ eventQueue.destroy();
}
}
@@ -118,12 +123,12 @@
putCount++;
try
{
- q.addPutEvent( ce );
+ eventQueue.addPutEvent( ce );
}
catch ( IOException ex )
{
log.error( ex );
- q.destroy();
+ eventQueue.destroy();
}
}
@@ -152,12 +157,12 @@
catch ( IOException ex )
{
log.error( "Failed in retrying the get for the second time." );
- q.destroy();
+ eventQueue.destroy();
}
}
catch ( IOException ex )
{
- q.destroy();
+ eventQueue.destroy();
}
}
return null;
@@ -195,6 +200,42 @@
}
/**
+ * Synchronously reads from the lateral cache.
+ * <p>
+ * @param pattern
+ * @return ICacheElement if found, else null
+ */
+ public Map getMatching( String pattern )
+ {
+ getCount++;
+ if ( this.getStatus() != CacheConstants.STATUS_ERROR )
+ {
+ try
+ {
+ return cache.getMatching( pattern );
+ }
+ catch ( UnmarshalException ue )
+ {
+ log.debug( "Retrying the get owing to UnmarshalException." );
+ try
+ {
+ return cache.getMatching( pattern );
+ }
+ catch ( IOException ex )
+ {
+ log.error( "Failed in retrying the get for the second time." );
+ eventQueue.destroy();
+ }
+ }
+ catch ( IOException ex )
+ {
+ eventQueue.destroy();
+ }
+ }
+ return null;
+ }
+
+ /**
* @param groupName
* @return Set
*/
@@ -214,12 +255,12 @@
removeCount++;
try
{
- q.addRemoveEvent( key );
+ eventQueue.addRemoveEvent( key );
}
catch ( IOException ex )
{
log.error( ex );
- q.destroy();
+ eventQueue.destroy();
}
return false;
}
@@ -229,12 +270,12 @@
{
try
{
- q.addRemoveAllEvent();
+ eventQueue.addRemoveAllEvent();
}
catch ( IOException ex )
{
log.error( ex );
- q.destroy();
+ eventQueue.destroy();
}
}
@@ -243,12 +284,12 @@
{
try
{
- q.addDisposeEvent();
+ eventQueue.addDisposeEvent();
}
catch ( IOException ex )
{
log.error( ex );
- q.destroy();
+ eventQueue.destroy();
}
}
@@ -280,7 +321,7 @@
*/
public int getStatus()
{
- return q.isWorking() ? cache.getStatus() : CacheConstants.STATUS_ERROR;
+ return eventQueue.isWorking() ? cache.getStatus() : CacheConstants.STATUS_ERROR;
}
/**
@@ -311,12 +352,12 @@
*/
public void resetEventQ()
{
- if ( q.isWorking() )
+ if ( eventQueue.isWorking() )
{
- q.destroy();
+ eventQueue.destroy();
}
CacheEventQueueFactory fact = new CacheEventQueueFactory();
- this.q = fact.createCacheEventQueue( new CacheAdaptor( cache ), LateralCacheInfo.listenerId, cache
+ this.eventQueue = fact.createCacheEventQueue( new CacheAdaptor( cache ), LateralCacheInfo.listenerId, cache
.getCacheName(), cache.getAuxiliaryCacheAttributes().getEventQueuePoolName(), cache
.getAuxiliaryCacheAttributes().getEventQueueType() );
}
@@ -375,7 +416,7 @@
// get the stats from the event queue too
// get as array, convert to list, add list to our outer list
- IStats eqStats = this.q.getStatistics();
+ IStats eqStats = this.eventQueue.getStatistics();
IStatElement[] eqSEs = eqStats.getStatElements();
List eqL = Arrays.asList( eqSEs );
Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheNoWaitFacade.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheNoWaitFacade.java?rev=707758&r1=707757&r2=707758&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheNoWaitFacade.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheNoWaitFacade.java Fri Oct 24 14:56:06 2008
@@ -220,6 +220,30 @@
}
/**
+ * Synchronously reads from the lateral cache. Get a response from each! This will be slow.
+ * Merge them.
+ * <p>
+ * @param pattern
+ * @return ICacheElement
+ */
+ public Map getMatching( String pattern )
+ {
+ Map elements = new HashMap();
+ for ( int i = 0; i < noWaits.length; i++ )
+ {
+ try
+ {
+ elements.putAll( noWaits[i].getMatching( pattern ) );
+ }
+ catch ( Exception ex )
+ {
+ log.error( "Failed to get", ex );
+ }
+ }
+ return elements;
+ }
+
+ /**
* @param group
* @return Set
*/
Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCache.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCache.java?rev=707758&r1=707757&r2=707758&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCache.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCache.java Fri Oct 24 14:56:06 2008
@@ -252,6 +252,14 @@
return retVal;
}
+ /** TODO finish */
+ public Map processGetMatching( String pattern )
+ throws IOException
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
/**
* Gets multiple items from the cache based on the given set of keys.
* <p>
Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheNoWait.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheNoWait.java?rev=707758&r1=707757&r2=707758&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheNoWait.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheNoWait.java Fri Oct 24 14:56:06 2008
@@ -183,6 +183,14 @@
return null;
}
+ /** TODO fix this */
+ public Map getMatching( String pattern )
+ throws IOException
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
/**
* Gets multiple items from the cache based on the given set of keys. Sends the getMultiple
* request on to the server rather than looping through the requested keys.
Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheNoWaitFacade.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheNoWaitFacade.java?rev=707758&r1=707757&r2=707758&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheNoWaitFacade.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheNoWaitFacade.java Fri Oct 24 14:56:06 2008
@@ -206,6 +206,15 @@
}
return null;
}
+
+ /** TODO fix this */
+ public Map getMatching( String pattern )
+ throws IOException
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
/**
* Gets multiple items from the cache based on the given set of keys.
Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/ZombieRemoteCacheService.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/ZombieRemoteCacheService.java?rev=707758&r1=707757&r2=707758&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/ZombieRemoteCacheService.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/ZombieRemoteCacheService.java Fri Oct 24 14:56:06 2008
@@ -155,6 +155,14 @@
return null;
}
+ /** TODO finish */
+ public Map getMatching( String cacheName, String pattern, long requesterId )
+ throws IOException
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
/**
* @param cacheName
* @param keys
Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/behavior/IRemoteCacheService.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/behavior/IRemoteCacheService.java?rev=707758&r1=707757&r2=707758&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/behavior/IRemoteCacheService.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/behavior/IRemoteCacheService.java Fri Oct 24 14:56:06 2008
@@ -68,11 +68,9 @@
throws IOException;
/**
- * Returns a cache bean from the specified cache; or null if the key does
- * not exist.
+ * Returns a cache bean from the specified cache; or null if the key does not exist.
* <p>
- * Adding the requestor id, allows the cache to determine the sournce of the
- * get.
+ * Adding the requestor id, allows the cache to determine the sournce of the get.
* <p>
* @param cacheName
* @param key
@@ -86,16 +84,30 @@
/**
* Gets multiple items from the cache based on the given set of keys.
* <p>
- * @param cacheName
+ * @param cacheName
* @param keys
- * @param requesterId
- * @return a map of Serializable key to ICacheElement element, or an empty map if there is no data in cache for any of these keys
- * @throws IOException
+ * @param requesterId
+ * @return a map of Serializable key to ICacheElement element, or an empty map if there is no
+ * data in cache for any of these keys
+ * @throws IOException
*/
Map getMultiple( String cacheName, Set keys, long requesterId )
throws IOException;
/**
+ * Gets multiple items from the cache matching the pattern.
+ * <p>
+ * @param cacheName
+ * @param pattern
+ * @param requesterId
+ * @return a map of Serializable key to ICacheElement element, or an empty map if there is no
+ * data in cache matching the pattern.
+ * @throws IOException
+ */
+ Map getMatching( String cacheName, String pattern, long requesterId )
+ throws IOException;
+
+ /**
* @param cacheName
* @param groupName
* @return A Set of keys
Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServer.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServer.java?rev=707758&r1=707757&r2=707758&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServer.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServer.java Fri Oct 24 14:56:06 2008
@@ -495,6 +495,14 @@
return element;
}
+ /** TODO finish */
+ public Map getMatching( String cacheName, String pattern, long requesterId )
+ throws IOException
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
/**
* Gets the item from the associated cache listeners.
* <p>
Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/engine/behavior/ICache.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/engine/behavior/ICache.java?rev=707758&r1=707757&r2=707758&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/engine/behavior/ICache.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/engine/behavior/ICache.java Fri Oct 24 14:56:06 2008
@@ -64,6 +64,20 @@
throws IOException;
/**
+ * Gets items from the cache matching the given pattern. Items from memory will replace those from remote sources.
+ * <p>
+ * This only works with string keys. It's too expensive to do a toString on every key.
+ * <p>
+ * Auxiliaries will do their best to handle simple expressions. For instance, the JDBC disk cache will convert * to % and . to _
+ * <p>
+ * @param pattern
+ * @return a map of Serializable key to ICacheElement element, or an empty map if there is no data matching the pattern.
+ * @throws IOException
+ */
+ Map getMatching( String pattern )
+ throws IOException;
+
+ /**
* Removes an item from the cache.
* <p>
* @param key
Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCache.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCache.java?rev=707758&r1=707757&r2=707758&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCache.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCache.java Fri Oct 24 14:56:06 2008
@@ -55,6 +55,7 @@
import org.apache.jcs.engine.stats.behavior.ICacheStats;
import org.apache.jcs.engine.stats.behavior.IStatElement;
import org.apache.jcs.engine.stats.behavior.IStats;
+import org.apache.jcs.utils.match.KeyMatcherUtil;
/**
* This is the primary hub for a single cache/region. It controls the flow of items through the
@@ -608,8 +609,8 @@
* Gets multiple items from the cache based on the given set of keys.
* <p>
* @param keys
- * @return a map of Serializable key to ICacheElement element, or an empty map
- * if there is no data in cache for any of these keys
+ * @return a map of Serializable key to ICacheElement element, or an empty map if there is no
+ * data in cache for any of these keys
*/
public Map getMultiple( Set keys )
{
@@ -617,12 +618,12 @@
}
/**
- * Gets multiple items from the cache based on the given set of keys.
- * Do not try to go remote or laterally for this data.
+ * Gets multiple items from the cache based on the given set of keys. Do not try to go remote or
+ * laterally for this data.
* <p>
* @param keys
- * @return a map of Serializable key to ICacheElement element, or an empty map
- * if there is no data in cache for any of these keys
+ * @return a map of Serializable key to ICacheElement element, or an empty map if there is no
+ * data in cache for any of these keys
*/
public Map localGetMultiple( Set keys )
{
@@ -630,9 +631,9 @@
}
/**
- * Look in memory, then disk, remote, or laterally for these items. The order is dependent on the
- * order in the cache.ccf file. Keep looking in each cache location until either the element is found,
- * or the method runs out of places to look.
+ * Look in memory, then disk, remote, or laterally for these items. The order is dependent on
+ * the order in the cache.ccf file. Keep looking in each cache location until either the element
+ * is found, or the method runs out of places to look.
* <p>
* Do not try to go remote or laterally for this get if it is localOnly. Otherwise try to go
* remote or lateral if such an auxiliary is configured for this region.
@@ -682,7 +683,8 @@
}
/**
- * Gets items for the keys in the set. Returns a map: key -> result.
+ * Gets items for the keys in the set. Returns a map: key -> result.
+ * <p>
* @param keys
* @return the elements found in the memory cache
* @throws IOException
@@ -847,12 +849,209 @@
}
/**
+ *Build a map of all the matching elements in all of the auxiliaries and memory.
+ * <p>
+ * @param pattern
+ * @return a map of Serializable key to ICacheElement element, or an empty map if there is no
+ * data in cache for any matching keys
+ */
+ public Map getMatching( String pattern )
+ {
+ return getMatching( pattern, false );
+ }
+
+ /**
+ * Build a map of all the matching elements in all of the auxiliaries and memory. Do not try to
+ * go remote or laterally for this data.
+ * <p>
+ * @param pattern
+ * @return a map of Serializable key to ICacheElement element, or an empty map if there is no
+ * data in cache for any matching keys
+ */
+ public Map localGetMatching( String pattern )
+ {
+ return getMatching( pattern, true );
+ }
+
+ /**
+ * Build a map of all the matching elements in all of the auxiliaries and memory. Items in
+ * memory will replace from the auxiliaries in the returned map. The auxiliaries are accessed in
+ * opposite order. It's assumed that those closer to home are better.
+ * <p>
+ * Do not try to go remote or laterally for this get if it is localOnly. Otherwise try to go
+ * remote or lateral if such an auxiliary is configured for this region.
+ * <p>
+ * @param pattern
+ * @param localOnly
+ * @return a map of Serializable key to ICacheElement element, or an empty map if there is no
+ * data in cache for any matching keys
+ */
+ protected Map getMatching( String pattern, boolean localOnly )
+ {
+ Map elements = new HashMap();
+
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( "get: pattern [" + pattern + "], localOnly = " + localOnly );
+ }
+
+ try
+ {
+ // First look in auxiliaries
+ elements.putAll( getMatchingFromAuxiliaryCaches( pattern, localOnly ) );
+
+ // then look in memory, override aux with newer memory items.
+ elements.putAll( getMatchingFromMemory( pattern ) );
+ }
+ catch ( Exception e )
+ {
+ log.error( "Problem encountered getting elements.", e );
+ }
+
+ return elements;
+ }
+
+ /**
+ * Gets the key array from the memcache. Builds a set of matches. Calls getMultiple with the
+ * set. Returns a map: key -> result.
+ * <p>
+ * @param pattern
+ * @return a map of Serializable key to ICacheElement element, or an empty map if there is no
+ * data in cache for any matching keys
+ * @throws IOException
+ */
+ protected Map getMatchingFromMemory( String pattern )
+ throws IOException
+ {
+ // find matches in key array
+ // this avoids locking the memory cache, but it uses more memory
+ Object[] keyArray = memCache.getKeyArray();
+
+ Set matchingKeys = KeyMatcherUtil.getMatchingKeysFromArray( pattern, keyArray );
+
+ // call get multiple
+ return getMultipleFromMemory( matchingKeys );
+ }
+
+ /**
+ * If local invocation look in aux caches, even if not local look in disk auxiliaries.
+ * <p>
+ * Moves in reverse order of definition. This will allow you to override those that are fromthe
+ * remote with those on disk.
+ * <p>
+ * @param pattern
+ * @param localOnly
+ * @return a map of Serializable key to ICacheElement element, or an empty map if there is no
+ * data in cache for any matching keys
+ * @throws IOException
+ */
+ private Map getMatchingFromAuxiliaryCaches( String pattern, boolean localOnly )
+ throws IOException
+ {
+ Map elements = new HashMap();
+
+ for ( int i = auxCaches.length - 1; i >= 0; i-- )
+ {
+ AuxiliaryCache aux = auxCaches[i];
+
+ if ( aux != null )
+ {
+ Map elementsFromAuxiliary = new HashMap();
+
+ long cacheType = aux.getCacheType();
+
+ if ( !localOnly || cacheType == AuxiliaryCache.DISK_CACHE )
+ {
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( "Attempting to get from aux [" + aux.getCacheName() + "] which is of type: "
+ + cacheType );
+ }
+ }
+
+ try
+ {
+ elementsFromAuxiliary.putAll( aux.getMatching( pattern ) );
+ }
+ catch ( IOException e )
+ {
+ log.error( "Error getting from aux", e );
+ }
+
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( "Got CacheElements: " + elementsFromAuxiliary );
+ }
+
+ Iterator elementFromAuxiliaryIterator = new HashMap( elementsFromAuxiliary ).values().iterator();
+
+ while ( elementFromAuxiliaryIterator.hasNext() )
+ {
+ ICacheElement element = (ICacheElement) elementFromAuxiliaryIterator.next();
+
+ // Item found in one of the auxiliary caches.
+ if ( element != null )
+ {
+ if ( isExpired( element ) )
+ {
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( cacheName + " - Aux cache[" + i + "] hit, but element expired." );
+ }
+
+ missCountExpired++;
+
+ // This will tell the remotes to remove the item
+ // based on the element's expiration policy. The elements attributes
+ // associated with the item when it created govern its behavior
+ // everywhere.
+ remove( element.getKey() );
+ elementsFromAuxiliary.remove( element.getKey() );
+ }
+ else
+ {
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( cacheName + " - Aux cache[" + i + "] hit" );
+ }
+
+ // Update counters
+ hitCountAux++;
+ auxHitCountByIndex[i]++;
+
+ // Spool the item back into memory
+ // only spool if the mem cache size is greater
+ // than 0, else the item will immediately get put
+ // into purgatory
+ if ( memCache.getCacheAttributes().getMaxObjects() > 0 )
+ {
+ memCache.update( element );
+ }
+ else
+ {
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( "Skipping memory update since no items are allowed in memory" );
+ }
+ }
+ }
+ }
+ }
+
+ elements.putAll( elementsFromAuxiliary );
+ }
+ }
+
+ return elements;
+ }
+
+ /**
* Returns a set of keys that were not found.
* <p>
* @param keys
* @param foundElements
- * @return the original set of cache keys, minus any cache keys
- * present in the map keys of the foundElements map
+ * @return the original set of cache keys, minus any cache keys present in the map keys of the
+ * foundElements map
*/
private Set pruneKeysFound( Set keys, Map foundElements )
{
@@ -896,7 +1095,7 @@
{
log.debug( "Exceeded maxLife: " + element.getKey() );
}
-
+
handleElementEvent( element, IElementEventConstants.ELEMENT_EVENT_EXCEEDED_MAXLIFE_ONREQUEST );
return true;
@@ -1140,9 +1339,9 @@
}
/**
- * Invoked only by CacheManager. This method disposes of the auxiliaries one by one. For the disk cache, the items in memory
- * are freed, meaning that they will be sent through the overflow channel to disk. After the
- * auxiliaries are disposed, the memory cache is disposed.
+ * Invoked only by CacheManager. This method disposes of the auxiliaries one by one. For the
+ * disk cache, the items in memory are freed, meaning that they will be sent through the
+ * overflow channel to disk. After the auxiliaries are disposed, the memory cache is disposed.
* <p>
* @param fromRemote
*/
Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/engine/logging/behavior/ICacheEventLogger.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/engine/logging/behavior/ICacheEventLogger.java?rev=707758&r1=707757&r2=707758&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/engine/logging/behavior/ICacheEventLogger.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/engine/logging/behavior/ICacheEventLogger.java Fri Oct 24 14:56:06 2008
@@ -20,6 +20,9 @@
/** ICache getMultiple */
static final String GETMULTIPLE_EVENT = "getMultiple";
+ /** ICache getMatching */
+ static final String GETMATCHING_EVENT = "getMatching";
+
/** ICache remove */
static final String REMOVE_EVENT = "remove";
Added: jakarta/jcs/trunk/src/java/org/apache/jcs/utils/match/KeyMatcherUtil.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/utils/match/KeyMatcherUtil.java?rev=707758&view=auto
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/utils/match/KeyMatcherUtil.java (added)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/utils/match/KeyMatcherUtil.java Fri Oct 24 14:56:06 2008
@@ -0,0 +1,41 @@
+package org.apache.jcs.utils.match;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * We'll probably want to make an interface for this so new implementations can be plugged in.
+ */
+public class KeyMatcherUtil
+{
+ /**
+ * Creates a pattern and find matches on the array.
+ * <p>
+ * @param pattern
+ * @param keyArray
+ * @return Set of the matching keys
+ */
+ public static Set getMatchingKeysFromArray( String pattern, Object[] keyArray )
+ {
+ Pattern compiledPattern = Pattern.compile( pattern );
+
+ Set matchingKeys = new HashSet();
+
+ // Look for matches
+ for ( int i = 0; i < keyArray.length; i++ )
+ {
+ Object key = keyArray[i];
+ if ( key instanceof String )
+ {
+ Matcher matcher = compiledPattern.matcher( (String) key );
+ if ( matcher.matches() )
+ {
+ matchingKeys.add( key );
+ }
+ }
+ }
+ return matchingKeys;
+ }
+}
Modified: jakarta/jcs/trunk/src/test-conf/TestMySQLDiskCache.ccf
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test-conf/TestMySQLDiskCache.ccf?rev=707758&r1=707757&r2=707758&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test-conf/TestMySQLDiskCache.ccf (original)
+++ jakarta/jcs/trunk/src/test-conf/TestMySQLDiskCache.ccf Fri Oct 24 14:56:06 2008
@@ -21,7 +21,7 @@
jcs.default=MYSQL
jcs.default.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
-jcs.default.cacheattributes.MaxObjects=100
+jcs.default.cacheattributes.MaxObjects=0
jcs.default.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
jcs.default.cacheattributes.UseMemoryShrinker=false
jcs.default.cacheattributes.MaxMemoryIdleTimeSeconds=3600
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/JCSLightLoadUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/JCSLightLoadUnitTest.java?rev=707758&r1=707757&r2=707758&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/JCSLightLoadUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/JCSLightLoadUnitTest.java Fri Oct 24 14:56:06 2008
@@ -24,17 +24,17 @@
import junit.framework.TestSuite;
/**
- * Description of the Class
- *
+ * Runs a few thousand queries.
*/
public class JCSLightLoadUnitTest
extends TestCase
{
-
+ /** number to use for the test */
private static int items = 20000;
/**
* Test setup
+ * @throws Exception
*/
public void setUp()
throws Exception
@@ -44,10 +44,7 @@
}
/**
- * Constructor for the TestSimpleLoad object
- *
* @param testName
- * Description of the Parameter
*/
public JCSLightLoadUnitTest( String testName )
{
@@ -56,9 +53,7 @@
/**
* Description of the Method
- *
- * @param args
- * Description of the Parameter
+ * @param args Description of the Parameter
*/
public static void main( String args[] )
{
@@ -68,7 +63,6 @@
/**
* A unit test suite for JUnit
- *
* @return The test suite
*/
public static Test suite()
@@ -78,9 +72,7 @@
/**
* A unit test for JUnit
- *
- * @exception Exception
- * Description of the Exception
+ * @exception Exception Description of the Exception
*/
public void testSimpleLoad()
throws Exception
@@ -107,7 +99,5 @@
// test removal
jcs.remove( "300:key" );
assertNull( jcs.get( "300:key" ) );
-
}
-
}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/JCSRemovalSimpleConcurrentTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/JCSRemovalSimpleConcurrentTest.java?rev=707758&r1=707757&r2=707758&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/JCSRemovalSimpleConcurrentTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/JCSRemovalSimpleConcurrentTest.java Fri Oct 24 14:56:06 2008
@@ -28,8 +28,6 @@
extends TestCase
{
/**
- * Constructor for the TestDiskCache object.
- *
* @param testName
*/
public JCSRemovalSimpleConcurrentTest( String testName )
@@ -39,6 +37,8 @@
/**
* Test setup
+ * <p>
+ * @throws Exception
*/
public void setUp()
throws Exception
@@ -49,7 +49,7 @@
/**
* Main method passes this test to the text test runner.
- *
+ * <p>
* @param args
*/
public static void main( String args[] )
@@ -60,13 +60,12 @@
/**
* Verify that 2 level deep hierchical removal works.
- *
+ * <p>
* @throws Exception
*/
public void testTwoDeepRemoval()
throws Exception
{
-
System.out.println( "------------------------------------------" );
System.out.println( "testTwoDeepRemoval" );
@@ -142,7 +141,7 @@
/**
* Verify that clear removes everyting as it should.
- *
+ * <p>
* @throws Exception
*/
public void testClear()
@@ -231,6 +230,5 @@
}
}
System.out.println( "Confirmed that all items were removed" );
-
}
}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/JCSThrashTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/JCSThrashTest.java?rev=707758&r1=707757&r2=707758&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/JCSThrashTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/JCSThrashTest.java Fri Oct 24 14:56:06 2008
@@ -31,14 +31,13 @@
/**
* This is based on a test that was posted to the user's list:
- *
+ * <p>
* http://www.opensubscriber.com/message/[email protected]/2435965.html
- *
*/
public class JCSThrashTest
extends TestCase
{
-
+ /** The logger. */
private static final Log LOG = LogFactory.getLog( JCSThrashTest.class.getName() );
/**
@@ -62,6 +61,10 @@
super( arg0 );
}
+ /**
+ * Sets up the test
+ * @throws Exception
+ */
protected void setUp()
throws Exception
{
@@ -70,6 +73,9 @@
jcs = JCS.getInstance( "testcache" );
}
+ /**
+ * @throws Exception
+ */
protected void tearDown()
throws Exception
{
@@ -128,9 +134,8 @@
}
/**
- * This does a bunch of work and then verifies that the memory has not grown by much.
- * Most of the time the amount of memory used after the test is less.
- *
+ * This does a bunch of work and then verifies that the memory has not grown by much. Most of
+ * the time the amount of memory used after the test is less.
* @throws Exception
*/
public void testForMemoryLeaks()
@@ -144,13 +149,12 @@
}
/**
- * @return
+ * @return time
* @throws Exception
*/
protected long thrashCache()
throws Exception
{
-
long startingSize = measureMemoryUse();
LOG.info( "Memory Used is: " + startingSize );
@@ -213,6 +217,7 @@
/**
* Runs a set of threads, for a fixed amount of time.
+ * <p>
* @param executables
* @throws Exception
*/
@@ -265,8 +270,8 @@
/**
* Measure memory used by the VM.
- *
- * @return
+ * <p>
+ * @return bytes
* @throws InterruptedException
*/
protected long measureMemoryUse()
@@ -285,7 +290,6 @@
{
/**
* Executes this object.
- *
* @throws Exception
*/
void execute()
@@ -293,8 +297,7 @@
}
/**
- *
- * @return
+ * @return size
*/
private int getListSize()
{
@@ -315,23 +318,7 @@
}
}
}
-
}
return Integer.parseInt( result );
}
-
-// private int getMapSize()
-// {
-// final String listSize = "Map Size";
-// String result = "0";
-// IStatElement statElements[] = jcs.getStatistics().getStatElements();
-// for ( int i = 0; i < statElements.length; i++ )
-// {
-// if ( listSize.equals( statElements[i].getName() ) )
-// {
-// result = statElements[i].getData();
-// }
-// }
-// return Integer.parseInt( result );
-// }
}
Copied: jakarta/jcs/trunk/src/test/org/apache/jcs/JCSUnitTest.java (from r682483, jakarta/jcs/trunk/src/test/org/apache/jcs/JCSUniTest.java)
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/JCSUnitTest.java?p2=jakarta/jcs/trunk/src/test/org/apache/jcs/JCSUnitTest.java&p1=jakarta/jcs/trunk/src/test/org/apache/jcs/JCSUniTest.java&r1=682483&r2=707758&rev=707758&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/JCSUniTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/JCSUnitTest.java Fri Oct 24 14:56:06 2008
@@ -19,30 +19,27 @@
* under the License.
*/
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.Random;
+
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
-import org.apache.jcs.JCS;
-
-import java.util.LinkedList;
-import java.util.HashMap;
-import java.util.Random;
-
/**
* Simple test for the JCS class.
- *
- * @version $Id$
*/
-public class JCSUniTest
+public class JCSUnitTest
extends TestCase
{
+ /** A random for key generation. */
Random random = new Random();
/**
* @param testName
*/
- public JCSUniTest( String testName )
+ public JCSUnitTest( String testName )
{
super( testName );
}
@@ -52,7 +49,7 @@
*/
public static Test suite()
{
- return new TestSuite( JCSUniTest.class );
+ return new TestSuite( JCSUnitTest.class );
}
/**
@@ -60,7 +57,7 @@
*/
public static void main( String args[] )
{
- String[] testCaseName = { JCSUniTest.class.getName() };
+ String[] testCaseName = { JCSUnitTest.class.getName() };
junit.textui.TestRunner.main( testCaseName );
}
@@ -79,6 +76,9 @@
assertEquals( list, jcs.get( "some:key" ) );
}
+ /**
+ * @return builds a list
+ */
private LinkedList buildList()
{
LinkedList list = new LinkedList();
@@ -91,6 +91,9 @@
return list;
}
+ /**
+ * @return a map
+ */
private HashMap buildMap()
{
HashMap map = new HashMap();
@@ -108,5 +111,4 @@
return map;
}
-
}
Propchange: jakarta/jcs/trunk/src/test/org/apache/jcs/JCSUnitTest.java
------------------------------------------------------------------------------
cvs2svn:cvs-rev = 1.4
Propchange: jakarta/jcs/trunk/src/test/org/apache/jcs/JCSUnitTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/jcs/trunk/src/test/org/apache/jcs/JCSUnitTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: jakarta/jcs/trunk/src/test/org/apache/jcs/JCSUnitTest.java
------------------------------------------------------------------------------
svn:mergeinfo =
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/JCSvsHashtablePerformanceTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/JCSvsHashtablePerformanceTest.java?rev=707758&r1=707757&r2=707758&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/JCSvsHashtablePerformanceTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/JCSvsHashtablePerformanceTest.java Fri Oct 24 14:56:06 2008
@@ -30,24 +30,27 @@
import org.apache.jcs.engine.memory.lru.LRUMemoryCache;
/**
- * This test ensures that basic memory operations are with a speficified order
- * of magnitude of the java.util.Hashtable.
+ * This test ensures that basic memory operations are with a speficified order of magnitude of the
+ * java.util.Hashtable.
* <p>
* Currenlty JCS is un 2x a hashtable for gets, and under 1.2x for puts.
- *
*/
public class JCSvsHashtablePerformanceTest
extends TestCase
{
-
+ /** jcs / hashtable */
float ratioPut = 0;
+ /** jcs / hashtable */
float ratioGet = 0;
+ /** ration goal */
float target = 3.50f;
+ /** Times to run the test */
int loops = 20;
+ /** how many puts and gets to run */
int tries = 50000;
/**
@@ -60,7 +63,6 @@
/**
* A unit test suite for JUnit
- *
* @return The test suite
*/
public static Test suite()
@@ -70,9 +72,7 @@
/**
* A unit test for JUnit
- *
- * @exception Exception
- * Description of the Exception
+ * @exception Exception Description of the Exception
*/
public void testSimpleLoad()
throws Exception
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/MockAuxiliaryCache.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/MockAuxiliaryCache.java?rev=707758&r1=707757&r2=707758&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/MockAuxiliaryCache.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/MockAuxiliaryCache.java Fri Oct 24 14:56:06 2008
@@ -55,6 +55,9 @@
/** IElementSerializer elementSerializer */
public IElementSerializer elementSerializer;
+ /** Times getMatching was Called */
+ public int getMatchingCallCount = 0;
+
/**
* @param ce
* @throws IOException
@@ -79,6 +82,18 @@
}
/**
+ * @param pattern
+ * @return Map
+ * @throws IOException
+ */
+ public Map getMatching( String pattern )
+ throws IOException
+ {
+ getMatchingCallCount++;
+ return new HashMap();
+ }
+
+ /**
* Gets multiple items from the cache based on the given set of keys.
* <p>
* @param keys
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/HsqlSetupTableUtil.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/HsqlSetupTableUtil.java?rev=707758&r1=707757&r2=707758&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/HsqlSetupTableUtil.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/HsqlSetupTableUtil.java Fri Oct 24 14:56:06 2008
@@ -75,6 +75,6 @@
System.out.println( "Exception: " + e );
}
}
- } // end ifnew
+ }
}
}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheUnitTest.java?rev=707758&r1=707757&r2=707758&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheUnitTest.java Fri Oct 24 14:56:06 2008
@@ -180,6 +180,7 @@
new org.hsqldb.jdbcDriver();
Class.forName( driverClassName ).newInstance();
Connection cConn = DriverManager.getConnection( url + database, userName, password );
+
HsqlSetupTableUtil.setupTABLE( cConn, "JCSTESTTABLE_InitializePoolAccess" );
// DO WORK
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheHsqlBackedUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheHsqlBackedUnitTest.java?rev=707758&r1=707757&r2=707758&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheHsqlBackedUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheHsqlBackedUnitTest.java Fri Oct 24 14:56:06 2008
@@ -35,30 +35,20 @@
/**
* Runs basic tests for the JDBC disk cache.
- *
* @author Aaron Smuts
- *
*/
public class MySQLDiskCacheHsqlBackedUnitTest
extends TestCase
{
-
- /**
- * Test setup
- */
- public void setUp()
- {
- JCS.setConfigFilename( "/TestMySQLDiskCache.ccf" );
- }
-
/**
- * Test the basic JDBC disk cache functionality with a hsql backing.
- *
+ * Creates the DB
+ * <p>
* @throws Exception
*/
- public void testSimpleJDBCPutGetWithHSQL()
+ public MySQLDiskCacheHsqlBackedUnitTest()
throws Exception
{
+ super();
System.setProperty( "hsqldb.cache_scale", "8" );
String rafroot = "target";
@@ -74,40 +64,49 @@
Connection cConn = DriverManager.getConnection( url + database, user, password );
setupTABLE( cConn );
+ }
- runTestForRegion( "testCache1", 30 );
+ /**
+ * Test setup
+ */
+ public void setUp()
+ {
+ JCS.setConfigFilename( "/TestMySQLDiskCache.ccf" );
+ }
+
+ /**
+ * Test the basic JDBC disk cache functionality with a hsql backing.
+ * @throws Exception
+ */
+ public void testSimpleJDBCPutGetWithHSQL()
+ throws Exception
+ {
+ runTestForRegion( "testCache1", 200 );
}
/**
- * Adds items to cache, gets them, and removes them. The item count is more
- * than the size of the memory cache, so items should spool to disk.
- *
- * @param region
- * Name of the region to access
+ * Adds items to cache, gets them, and removes them. The item 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 items
- *
- * @exception Exception
- * If an error occurs
+ * @exception Exception If an error occurs
*/
public void runTestForRegion( String region, int items )
throws Exception
{
JCS jcs = JCS.getInstance( region );
-
- System.out.println( "BEFORE PUT \n" + jcs.getStats() );
+ //System.out.println( "BEFORE PUT \n" + jcs.getStats() );
// Add items to cache
-
for ( int i = 0; i <= items; i++ )
{
jcs.put( i + ":key", region + " data " + i );
}
- System.out.println( jcs.getStats() );
-
+ //System.out.println( jcs.getStats() );
Thread.sleep( 1000 );
-
- System.out.println( jcs.getStats() );
+ //System.out.println( jcs.getStats() );
// Test that all items are in cache
for ( int i = 0; i <= items; i++ )
@@ -147,8 +146,36 @@
}
/**
+ * Test the basic JDBC disk cache functionality with a hsql backing.
+ * <p>
+ * @throws Exception
+ */
+ public void testPutGetMatchingWithHSQL()
+ throws Exception
+ {
+ // SETUP
+ int items = 200;
+ String region = "testCache2";
+ JCS jcs = JCS.getInstance( region );
+ System.out.println( "BEFORE PUT \n" + jcs.getStats() );
+
+ // DO WORK
+ for ( int i = 0; i <= items; i++ )
+ {
+ jcs.put( i + ":key", region + " data " + i );
+ }
+ Thread.sleep( 1000 );
+
+ Map matchingResults = jcs.getMatchingCacheElements( "1.8.+" );
+
+ // VERIFY
+ assertEquals( "Wrong number returned", 10, matchingResults.size() );
+ System.out.println( "matchingResults.keySet() " + matchingResults.keySet() );
+ System.out.println( "\nAFTER TEST \n" + jcs.getStats() );
+ }
+
+ /**
* SETUP TABLE FOR CACHE
- *
* @param cConn
*/
void setupTABLE( Connection cConn )
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheUnitTest.java?rev=707758&r1=707757&r2=707758&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheUnitTest.java Fri Oct 24 14:56:06 2008
@@ -43,6 +43,7 @@
*/
public void testBalkOnGet()
{
+ // SETUP
MySQLDiskCacheAttributes attributes = new MySQLDiskCacheAttributes();
String tableName = "JCS_TEST";
attributes.setDriverClassName( "org.gjt.mm.mysql.Driver" );
@@ -54,7 +55,10 @@
MySQLDiskCache cache = new MySQLDiskCache( attributes, tableState, CompositeCacheManager.getUnconfiguredInstance() );
+ // DO WORK
Object result = cache.processGet( "myKey" );
+
+ // VERIFY
assertNull( "The result should be null", result );
}
}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/MockRemoteCacheClient.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/MockRemoteCacheClient.java?rev=707758&r1=707757&r2=707758&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/MockRemoteCacheClient.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/MockRemoteCacheClient.java Fri Oct 24 14:56:06 2008
@@ -19,6 +19,7 @@
* under the License.
*/
+import java.io.IOException;
import java.io.Serializable;
import java.util.HashMap;
import java.util.LinkedList;
@@ -249,4 +250,15 @@
{
// TODO Auto-generated method stub
}
+
+ /**
+ * @param pattern
+ * @return Map
+ * @throws IOException
+ */
+ public Map getMatching( String pattern )
+ throws IOException
+ {
+ return new HashMap();
+ }
}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/MockRemoteCacheService.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/MockRemoteCacheService.java?rev=707758&r1=707757&r2=707758&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/MockRemoteCacheService.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/MockRemoteCacheService.java Fri Oct 24 14:56:06 2008
@@ -190,4 +190,17 @@
{
return new HashMap();
}
+
+ /**
+ * @param cacheName
+ * @param pattern
+ * @param requesterId
+ * @return Map
+ * @throws IOException
+ */
+ public Map getMatching( String cacheName, String pattern, long requesterId )
+ throws IOException
+ {
+ return new HashMap();
+ }
}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/CompositeCacheDiskUsageUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/CompositeCacheDiskUsageUnitTest.java?rev=707758&r1=707757&r2=707758&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/CompositeCacheDiskUsageUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/CompositeCacheDiskUsageUnitTest.java Fri Oct 24 14:56:06 2008
@@ -291,26 +291,19 @@
public class MockAuxCache
implements AuxiliaryCache
{
+ /** Don't change */
private static final long serialVersionUID = 1L;
- /**
- * The last item passed to update.
- */
+ /** The last item passed to update. */
public ICacheElement lastUpdatedItem;
- /**
- * The number of times update was called.
- */
+ /** The number of times update was called. */
public int updateCount = 0;
- /**
- * The type that should be returned from getCacheType.
- */
+ /** The type that should be returned from getCacheType. */
public int cacheType = AuxiliaryCache.DISK_CACHE;
- /**
- * Resets counters and catchers.
- */
+ /** Resets counters and catchers. */
public void reset()
{
updateCount = 0;
@@ -343,7 +336,8 @@
* Gets multiple items from the cache based on the given set of keys.
* <p>
* @param keys
- * @return a map of Serializable key to ICacheElement element, or an empty map if there is no data in cache for any of these keys
+ * @return a map of Serializable key to ICacheElement element, or an empty map if there is
+ * no data in cache for any of these keys
*/
public Map getMultiple( Set keys )
{
@@ -434,9 +428,8 @@
return null;
}
- /*
- * (non-Javadoc)
- * @see org.apache.jcs.engine.behavior.ICache#getStats()
+ /**
+ * @return null
*/
public String getStats()
{
@@ -463,16 +456,33 @@
return null;
}
+ /**
+ * @param cacheEventLogger
+ */
public void setCacheEventLogger( ICacheEventLogger cacheEventLogger )
{
// TODO Auto-generated method stub
-
+
}
+ /**
+ * @param elementSerializer
+ */
public void setElementSerializer( IElementSerializer elementSerializer )
{
// TODO Auto-generated method stub
-
+
+ }
+
+ /**
+ * @param pattern
+ * @return Map
+ * @throws IOException
+ */
+ public Map getMatching( String pattern )
+ throws IOException
+ {
+ return new HashMap();
}
}