Author: asmuts
Date: Thu Mar 16 09:18:04 2006
New Revision: 386386
URL: http://svn.apache.org/viewcvs?rev=386386&view=rev
Log:
added the ability to get from a remote cluster
trying to get the udp discovery stuff into a reusable form
reduced synchronization block in disk cache to allow other children of the
abstract disk cache to use more threads.
increased version to 1.2.7.1
I will add a jdbc disk cache soon
Added:
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/http/
Modified:
jakarta/jcs/trunk/src/conf/cacheRC1.ccf
jakarta/jcs/trunk/src/conf/cacheRC2.ccf
jakarta/jcs/trunk/src/conf/remote.cache.ccf
jakarta/jcs/trunk/src/conf/remote.cache2.ccf
jakarta/jcs/trunk/src/experimental/org/apache/jcs/auxiliary/lateral/http/server/LateralCacheServletReciever.java
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCache.java
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCache.java
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralElementDescriptor.java
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/UDPDiscoveryManager.java
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/UDPDiscoveryService.java
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCache.java
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheFailoverRunner.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/IRemoteCacheConstants.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/auxiliary/remote/server/behavior/IRemoteCacheServerAttributes.java
jakarta/jcs/trunk/src/java/org/apache/jcs/engine/PooledCacheEventQueue.java
jakarta/jcs/trunk/src/java/org/apache/jcs/utils/serialization/SerializationConversionUtil.java
jakarta/jcs/trunk/src/test-conf/log4j.properties
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheConcurrentUnitTest.java
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheNoMemoryUnitTest.java
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/UDPDiscoveryUnitTest.java
Modified: jakarta/jcs/trunk/src/conf/cacheRC1.ccf
URL:
http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/conf/cacheRC1.ccf?rev=386386&r1=386385&r2=386386&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/conf/cacheRC1.ccf (original)
+++ jakarta/jcs/trunk/src/conf/cacheRC1.ccf Thu Mar 16 09:18:04 2006
@@ -26,7 +26,7 @@
# just a remove lock to add
jcs.auxiliary.RC=org.apache.jcs.auxiliary.remote.RemoteCacheFactory
jcs.auxiliary.RC.attributes=org.apache.jcs.auxiliary.remote.RemoteCacheAttributes
-jcs.auxiliary.RC.attributes.FailoverServers=localhost:1101
+jcs.auxiliary.RC.attributes.FailoverServers=localhost:1101,localhost:1102
jcs.auxiliary.RC.attributes.LocalPort=1201
jcs.auxiliary.RC.attributes.RemoveUponRemotePut=false
jcs.auxiliary.RC.attributes.GetTimeoutMillis=5000
Modified: jakarta/jcs/trunk/src/conf/cacheRC2.ccf
URL:
http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/conf/cacheRC2.ccf?rev=386386&r1=386385&r2=386386&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/conf/cacheRC2.ccf (original)
+++ jakarta/jcs/trunk/src/conf/cacheRC2.ccf Thu Mar 16 09:18:04 2006
@@ -26,7 +26,7 @@
# just a remove lock to add
jcs.auxiliary.RC=org.apache.jcs.auxiliary.remote.RemoteCacheFactory
jcs.auxiliary.RC.attributes=org.apache.jcs.auxiliary.remote.RemoteCacheAttributes
-jcs.auxiliary.RC.attributes.FailoverServers=localhost:1101
+jcs.auxiliary.RC.attributes.FailoverServers=localhost:1102,localhost:1101
jcs.auxiliary.RC.attributes.LocalPort=1202
jcs.auxiliary.RC.attributes.RemoveUponRemotePut=false
jcs.auxiliary.RC.attributes.GetTimeoutMillis=5000
Modified: jakarta/jcs/trunk/src/conf/remote.cache.ccf
URL:
http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/conf/remote.cache.ccf?rev=386386&r1=386385&r2=386386&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/conf/remote.cache.ccf (original)
+++ jakarta/jcs/trunk/src/conf/remote.cache.ccf Thu Mar 16 09:18:04 2006
@@ -19,7 +19,6 @@
jcs.default.cacheattributes.UseMemoryShrinker=true
jcs.default.cacheattributes.MaxMemoryIdleTimeSeconds=3600
jcs.default.cacheattributes.ShrinkerIntervalSeconds=60
-jcs.default.cacheattributes.ShrinkerIntervalSeconds=60
jcs.default.elementattributes=org.apache.jcs.engine.ElementAttributes
jcs.default.elementattributes.IsEternal=false
jcs.default.elementattributes.MaxLifeSeconds=7000
@@ -43,7 +42,7 @@
jcs.auxiliary.RCluster.attributes=org.apache.jcs.auxiliary.remote.RemoteCacheAttributes
jcs.auxiliary.RCluster.attributes.RemoteTypeName=CLUSTER
jcs.auxiliary.RCluster.attributes.RemoveUponRemotePut=false
-#jcs.auxiliary.RCluster.attributes.ClusterServers=localhost:1102
+jcs.auxiliary.RCluster.attributes.ClusterServers=localhost:1102
jcs.auxiliary.RCluster.attributes.GetOnly=false
jcs.auxiliary.RCluster.attributes.LocalClusterConsistency=true
Modified: jakarta/jcs/trunk/src/conf/remote.cache2.ccf
URL:
http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/conf/remote.cache2.ccf?rev=386386&r1=386385&r2=386386&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/conf/remote.cache2.ccf (original)
+++ jakarta/jcs/trunk/src/conf/remote.cache2.ccf Thu Mar 16 09:18:04 2006
@@ -19,7 +19,6 @@
jcs.default.cacheattributes.UseMemoryShrinker=true
jcs.default.cacheattributes.MaxMemoryIdleTimeSeconds=3600
jcs.default.cacheattributes.ShrinkerIntervalSeconds=60
-jcs.default.cacheattributes.ShrinkerIntervalSeconds=60
jcs.default.elementattributes=org.apache.jcs.engine.ElementAttributes
jcs.default.elementattributes.IsEternal=false
jcs.default.elementattributes.MaxLifeSeconds=7000
Modified:
jakarta/jcs/trunk/src/experimental/org/apache/jcs/auxiliary/lateral/http/server/LateralCacheServletReciever.java
URL:
http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/experimental/org/apache/jcs/auxiliary/lateral/http/server/LateralCacheServletReciever.java?rev=386386&r1=386385&r2=386386&view=diff
==============================================================================
---
jakarta/jcs/trunk/src/experimental/org/apache/jcs/auxiliary/lateral/http/server/LateralCacheServletReciever.java
(original)
+++
jakarta/jcs/trunk/src/experimental/org/apache/jcs/auxiliary/lateral/http/server/LateralCacheServletReciever.java
Thu Mar 16 09:18:04 2006
@@ -41,14 +41,14 @@
* @created January 15, 2002
* @version 1.0
*/
-public class LateralCacheServletReciever extends HttpServlet
+public class LateralCacheServletReciever
+ extends HttpServlet
{
- private final static Log log =
- LogFactory.getLog( LateralCacheServletReciever.class );
+ private final static Log log = LogFactory.getLog(
LateralCacheServletReciever.class );
private static CompositeCacheManager cacheMgr;
- /** Description of the Method */
+ /** Initializes the cache. */
public void init( ServletConfig config )
throws ServletException
{
@@ -58,17 +58,13 @@
}
/** SERVICE THE REQUEST */
- public void service( HttpServletRequest request,
- HttpServletResponse response )
+ public void service( HttpServletRequest request, HttpServletResponse
response )
throws ServletException, IOException
{
- log.debug( "The LateralCacheServlet has been called.\n" );
-
- if ( cacheMgr == null )
+ if ( log.isDebugEnabled() )
{
- cacheMgr = CompositeCacheManager.getInstance();
- log.debug( "cacheMgr was null in LateralCacheServlet" );
+ log.debug( "The LateralCacheServlet has been called.\n" );
}
ICacheElement item = null;
@@ -78,13 +74,15 @@
// Create the ObjectInputStream with
// the Request InputStream.
- ObjectInputStream ois =
- new ObjectInputStream( request.getInputStream() );
+ ObjectInputStream ois = new ObjectInputStream(
request.getInputStream() );
- log.debug( "after getting input stream and before reading it" );
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( "after getting input stream and before reading it"
);
+ }
// READ POLLOBJ
- item = ( ICacheElement ) ois.readObject();
+ item = (ICacheElement) ois.readObject();
ois.close();
}
@@ -95,7 +93,10 @@
if ( item == null )
{
- log.debug( "item is null in LateralCacheServlet" );
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( "item is null in LateralCacheServlet" );
+ }
}
else
{
@@ -106,7 +107,7 @@
log.debug( "item read in = " + item );
log.debug( "item.getKey = " + item.getKey() );
- CompositeCache cache = ( CompositeCache ) cacheMgr.getCache(
hashtableName );
+ CompositeCache cache = (CompositeCache) cacheMgr.getCache(
hashtableName );
try
{
// need to set as from lateral
@@ -114,7 +115,7 @@
}
catch ( Exception e )
{
- // Ignored -- log it?
+ log.error( "Problem putting item in cache " + item, e );
}
}
@@ -124,33 +125,61 @@
// BEGIN RESPONSE
response.setContentType( "application/octet-stream" );
- ObjectOutputStream oos =
- new ObjectOutputStream( response.getOutputStream() );
+ ObjectOutputStream oos = new ObjectOutputStream(
response.getOutputStream() );
- log.debug( "Opened output stream.\n" );
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( "Opened output stream.\n" );
+ }
String result = "Completed transfer";
- // ECHO THE OBJECT TO THE RESPONSE
+ // echo a message to the client
oos.writeObject( result );
- log.debug( "Wrote object to output stream" );
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( "Wrote object to output stream" );
+ }
oos.flush();
- log.debug( "Flushed output stream.\n" );
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( "Flushed output stream.\n" );
+ }
oos.close();
- log.debug( "Closed output stream.\n" );
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( "Closed output stream.\n" );
+ }
}
catch ( Exception e )
{
- log.error( e );
+ log.error( "Problem writing response.", e );
}
}
- /** */
+ /**
+ * Make sure we have a cache manager. This should have happened in the init
+ * method.
+ *
+ */
+ protected synchronized void ensureCacheManager()
+ {
+ if ( cacheMgr == null )
+ {
+ cacheMgr = CompositeCacheManager.getInstance();
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( "cacheMgr was null in LateralCacheServlet" );
+ }
+ }
+ }
+
+ /** Release the cache manager. */
public void destroy()
{
cacheMgr.release();
@@ -162,4 +191,3 @@
return "LateralCacheServlet v1";
}
}
-
Modified:
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCache.java
URL:
http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCache.java?rev=386386&r1=386385&r2=386386&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
Thu Mar 16 09:18:04 2006
@@ -73,7 +73,6 @@
* memory cache while the are still in purgatory, writing to disk can be
* cancelled.
*/
- //protected Hashtable purgatory = new Hashtable();
protected Map purgatory = new HashMap();
/**
@@ -131,7 +130,7 @@
* must have been plucked. We should make 0 work, a way to not use
* purgatory.
*
- *
+ *
*/
private void initPurgatory()
{
@@ -174,13 +173,11 @@
try
{
// Wrap the CacheElement in a PurgatoryElement
-
PurgatoryElement pe = new PurgatoryElement( cacheElement );
// Indicates the the element is eligable to be spooled to disk,
// this will remain true unless the item is pulled back into
// memory.
-
pe.setSpoolable( true );
// Add the element to purgatory
@@ -188,13 +185,13 @@
{
purgatory.put( pe.getKey(), pe );
}
- // Queue element for serialization
+ // Queue element for serialization
cacheEventQueue.addPutEvent( pe );
}
catch ( IOException ex )
{
- log.error( ex );
+ log.error( "Problem adding put event to queue.", ex );
cacheEventQueue.destroy();
}
@@ -225,7 +222,6 @@
}
// If the element was found in purgatory
-
if ( pe != null )
{
purgHits++;
@@ -239,29 +235,28 @@
}
// Since the element will go back to the memory cache, we could set
- // spoolableto false, which will prevent the queue listener from
- // serializing
- // the element. This would nto match the disk cache behavior and
the
- // behavior of other auxiliaries. Gets never remove items from
- // auxiliaries.
+ // spoolable to false, which will prevent the queue listener from
+ // serializing the element. This would not match the disk cache
+ // behavior and the behavior of other auxiliaries. Gets never
remove
+ // items from auxiliaries.
// Beyond consistency, the items should stay in purgatory and get
- // spooled
- // since the mem cache may be set to 0. If an item is active, it
- // will keep
- // getting put into purgatory and removed. The CompositeCache now
- // does
- // not put an item to memory from disk ifthe size is 0;
+ // spooled since the mem cache may be set to 0. If an item is
+ // active, it will keep getting put into purgatory and removed. The
+ // CompositeCache now does not put an item to memory from disk if
+ // the size is 0.
// Do not set spoolable to false. Just let it go to disk. This
// will allow the memory size = 0 setting to work well.
- log.debug( "Found element in purgatory, cacheName: " + cacheName +
", key: " + key );
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( "Found element in purgatory, cacheName: " +
cacheName + ", key: " + key );
+ }
return pe.cacheElement;
}
// If we reach this point, element was not found in purgatory, so get
// it from the cache.
-
try
{
return doGet( key );
@@ -288,25 +283,37 @@
*/
public final boolean remove( Serializable key )
{
- //String keyAsString = key.toString();
-
PurgatoryElement pe = null;
+
synchronized ( purgatory )
{
+ // I'm getting the object, so I can lock on the element
// Remove element from purgatory if it is there
- pe = (PurgatoryElement) purgatory.remove( key );
+ pe = (PurgatoryElement) purgatory.get( key );
}
if ( pe != null )
{
- // no way to remove from queue, just make sure it doesn't get on
- // disk
- // and then removed right afterwards
- pe.setSpoolable( false );
- }
- // Remove from persistent store immediately
+ synchronized ( pe.getCacheElement() )
+ {
+ synchronized ( purgatory )
+ {
+ purgatory.remove( key );
+ }
+
+ // no way to remove from queue, just make sure it doesn't get
on
+ // disk and then removed right afterwards
+ pe.setSpoolable( false );
- doRemove( key );
+ // Remove from persistent store immediately
+ doRemove( key );
+ }
+ }
+ else
+ {
+ // Remove from persistent store immediately
+ doRemove( key );
+ }
return false;
}
@@ -317,25 +324,23 @@
public final void removeAll()
{
// Replace purgatory with a new empty hashtable
-
initPurgatory();
// Remove all from persistent store immediately
-
doRemoveAll();
}
/**
* Adds a dispose request to the disk cache.
* <p>
- * Disposal proceeds in several steps.
+ * Disposal proceeds in several steps.
* <ul>
- * <li> 1. Prior to this call the Composite cache dumped the memory
- * into the disk cache. If it is large then we need to wait for
- * the event queue to finish.
- * <li> 2. Wait until the event queue is empty of until the configured
ShutdownSpoolTimeLimit
- * is reached.
- * <li> 3. Call doDispose on the concrete impl.
+ * <li> 1. Prior to this call the Composite cache dumped the memory into
the
+ * disk cache. If it is large then we need to wait for the event queue to
+ * finish.
+ * <li> 2. Wait until the event queue is empty of until the configured
+ * ShutdownSpoolTimeLimit is reached.
+ * <li> 3. Call doDispose on the concrete impl.
* </ul>
*
*/
@@ -355,8 +360,8 @@
try
{
Thread.sleep( interval );
- total += interval;
- //log.info( "total = " + total );
+ total += interval;
+ // log.info( "total = " + total );
}
catch ( InterruptedException e )
{
@@ -377,12 +382,11 @@
{
log.error( ex );
}
-
+
log.info( "In dispose, destroying event queue." );
// This stops the processor thread.
cacheEventQueue.destroy();
-
-
+
// Invoke any implementation specific disposal code
// need to handle the disposal first.
doDispose();
@@ -521,39 +525,40 @@
{
// If the element is a PurgatoryElement we must check to see
// if it is still spoolable, and remove it from purgatory.
-
if ( element instanceof PurgatoryElement )
{
PurgatoryElement pe = (PurgatoryElement) element;
- //String keyAsString = element.getKey().toString();
-
- synchronized ( purgatory )
+ synchronized ( pe.getCacheElement() )
{
- // If the element has already been removed from
- // purgatory do nothing
-
- if ( !purgatory.containsKey( pe.getKey() ) )
+ // String keyAsString = element.getKey().toString();
+ synchronized ( purgatory )
{
- return;
- }
+ // If the element has already been removed from
+ // purgatory do nothing
+ if ( !purgatory.containsKey( pe.getKey() ) )
+ {
+ return;
+ }
- element = pe.getCacheElement();
+ element = pe.getCacheElement();
+ }
+ // I took this out of the sync block.
// If the element is still eligable, spool it.
-
if ( pe.isSpoolable() )
{
doUpdate( element );
}
- // After the update has completed, it is safe to remove
- // the element from purgatory.
-
- purgatory.remove( element.getKey() );
-
+ synchronized ( purgatory )
+ {
+ // After the update has completed, it is safe to
+ // remove
+ // the element from purgatory.
+ purgatory.remove( element.getKey() );
+ }
}
-
}
else
{
@@ -571,13 +576,12 @@
// queue. This block handles the case where the disk cache
fails
// during normal opertations.
- //String keyAsString = element.getKey().toString();
+ // String keyAsString = element.getKey().toString();
synchronized ( purgatory )
{
purgatory.remove( element.getKey() );
}
-
}
}
Modified:
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCache.java
URL:
http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCache.java?rev=386386&r1=386385&r2=386386&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
Thu Mar 16 09:18:04 2006
@@ -334,7 +334,7 @@
* been retireved from purgatory while in queue for disk. Remove items from
* purgatory when they go to disk.
*
- * @param ce,
+ * @param ce
* The ICacheElement to put to disk.
*/
public void doUpdate( ICacheElement ce )
@@ -365,12 +365,10 @@
byte[] data = IndexedDisk.serialize( ce );
// make sure this only locks for one particular cache region
- storageLock.writeLock().acquire();
-
- ded.init( dataFile.length(), data );
-
+ storageLock.writeLock().acquire();
try
{
+ ded.init( dataFile.length(), data );
old = (IndexedDiskElementDescriptor) keyHash.put( ce.getKey(),
ded );
@@ -420,7 +418,7 @@
}
finally
- {
+ {
storageLock.writeLock().release();
}
@@ -494,6 +492,13 @@
return object;
}
+ /**
+ * Reads the item from disk.
+ *
+ * @param key
+ * @return
+ * @throws IOException
+ */
private CacheElement readElement( Serializable key )
throws IOException
{
@@ -646,12 +651,6 @@
}
else
{
-
- if ( log.isDebugEnabled() )
- {
- log.debug( "Disk removal: Removed from key hash, key " +
key );
- }
-
if ( doRecycle )
{
// reuse the spot
@@ -661,14 +660,20 @@
recycle.add( ded );
if ( log.isDebugEnabled() )
{
- log.debug( "recycling ded " + ded );
+ log.debug( "Adding to recycle bin: " + ded );
}
}
}
// remove single item.
- return keyHash.remove( key ) != null;
+ removed = keyHash.remove( key ) != null;
+
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( "Disk removal: Removed from key hash, key " +
key + " removed = " + removed );
+ }
+ return removed;
}
}
catch ( Exception e )
@@ -799,6 +804,7 @@
else
{
keyHash = new HashMap();
+ // keyHash = Collections.synchronizedMap( new HashMap() );
if ( log.isInfoEnabled() )
{
log.info( "Set maxKeySize to unlimited'" );
@@ -830,7 +836,7 @@
}
catch ( InterruptedException ex )
{
- log.error( ex );
+ log.error( "Interrupted while waiting for disposal thread to
finish.", ex );
}
}
@@ -1233,16 +1239,17 @@
* This is for debugging and testing.
*
* @return the length of the data file.
- * @throws IOException
+ * @throws IOException
*/
- protected long getDataFileSize() throws IOException
+ protected long getDataFileSize()
+ throws IOException
{
long size = 0;
try
{
storageLock.readLock().acquire();
-
+
try
{
if ( dataFile != null )
@@ -1253,14 +1260,13 @@
finally
{
storageLock.readLock().release();
- }
+ }
}
catch ( InterruptedException e )
{
// nothing
}
-
return size;
}
@@ -1348,7 +1354,7 @@
}
se = new StatElement();
- se.setName( "Optimize Opertaion Count" );
+ se.setName( "Optimize Operation Count" );
se.setData( "" + this.optCnt );
elems.add( se );
Modified:
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralElementDescriptor.java
URL:
http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralElementDescriptor.java?rev=386386&r1=386385&r2=386386&view=diff
==============================================================================
---
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralElementDescriptor.java
(original)
+++
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralElementDescriptor.java
Thu Mar 16 09:18:04 2006
@@ -55,11 +55,11 @@
*/
public long requesterId;
- /** Description of the Field */
+ /** The operation has been requested by the client. */
public int command = UPDATE;
/**
- * the hashcode value for this element.
+ * The hashcode value for this element.
*/
public int valHashCode = -1;
Modified:
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/UDPDiscoveryManager.java
URL:
http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/UDPDiscoveryManager.java?rev=386386&r1=386385&r2=386386&view=diff
==============================================================================
---
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/UDPDiscoveryManager.java
(original)
+++
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/UDPDiscoveryManager.java
Thu Mar 16 09:18:04 2006
@@ -14,7 +14,7 @@
* don't want a connection for each region.
*
* @author Aaron Smuts
- *
+ *
*/
public class UDPDiscoveryManager
{
@@ -49,7 +49,28 @@
*/
public synchronized UDPDiscoveryService getService(
ITCPLateralCacheAttributes lca, ICompositeCacheManager cacheMgr )
{
- String key = lca.getTcpServer() + ":" + lca.getTcpListenerPort();
+ UDPDiscoveryService service = getService( lca.getTcpServer(),
lca.getTcpListenerPort(), lca.getTcpListenerPort(), cacheMgr );
+
+ // TODO find a way to remote these attributes from the service, the
manager needs it on disocvery.
+ service.setTcpLateralCacheAttributes( lca );
+ return service;
+ }
+
+ /**
+ * Creates a service for the address and port if one doesn't exist already.
+ * <p>
+ * TODO we may need to key this using the listener port too
+ *
+ * @param discoveryAddress
+ * @param discoveryPort
+ * @param servicePort
+ * @param cacheMgr
+ * @return
+ */
+ public synchronized UDPDiscoveryService getService( String
discoveryAddress, int discoveryPort, int servicePort,
+ ICompositeCacheManager
cacheMgr )
+ {
+ String key = discoveryAddress + ":" + discoveryPort;
UDPDiscoveryService service = (UDPDiscoveryService) services.get( key
);
if ( service == null )
@@ -59,16 +80,17 @@
log.debug( "Creating service for " + key );
}
- service = new UDPDiscoveryService( lca, cacheMgr );
+ service = new UDPDiscoveryService( discoveryAddress,
discoveryPort, servicePort, cacheMgr );
services.put( key, service );
}
if ( log.isDebugEnabled() )
{
- log.debug( "Returning service [" + service + "] for lca [" + lca +
"]" );
+ log.debug( "Returning service [" + service + "] for key [" + key +
"]" );
}
return service;
+
}
}
Modified:
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/UDPDiscoveryService.java
URL:
http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/UDPDiscoveryService.java?rev=386386&r1=386385&r2=386386&view=diff
==============================================================================
---
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/UDPDiscoveryService.java
(original)
+++
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/UDPDiscoveryService.java
Thu Mar 16 09:18:04 2006
@@ -31,7 +31,7 @@
* addresses.
*
* @author Aaron Smuts
- *
+ *
*/
public class UDPDiscoveryService
implements IShutdownObserver
@@ -39,7 +39,7 @@
private final static Log log = LogFactory.getLog(
UDPDiscoveryService.class );
- //The background broadcaster.
+ // The background broadcaster.
private static ClockDaemon senderDaemon;
// thread that listens for messages
@@ -50,27 +50,41 @@
private Map facades = new HashMap();
- private ITCPLateralCacheAttributes tcpLateralCacheAttributes = null;
-
// the runanble that sends messages via the clock daemon
private UDPDiscoverySenderThread sender = null;
private String hostAddress = "unknown";
+ private String discoveryAddress;
+
+ private int discoveryPort;
+
+ // the port this service runs on, the service we are telling other about
+ // we should have a service info object instead
+ private int servicePort;
+
+ private ITCPLateralCacheAttributes tcpLateralCacheAttributes;
+
/**
*
- * @param facade
- * @param lca
- * ITCPLateralCacheAttributes
+ * @param discoveryAddress
+ * address to multicast to
+ * @param discoveryPort
+ * port to multicast to
+ * @param servicePort
+ * the port this service runs on, the service we are telling
+ * other about
* @param cacheMgr
- * @param receivingPort
*/
- public UDPDiscoveryService( ITCPLateralCacheAttributes lca,
ICompositeCacheManager cacheMgr )
+ public UDPDiscoveryService( String discoveryAddress, int discoveryPort,
int servicePort,
+ ICompositeCacheManager cacheMgr )
{
// register for shutdown notification
( (IShutdownObservable) cacheMgr ).registerShutdownObserver( this );
- this.setTcpLateralCacheAttributes( lca );
+ this.setDiscoveryAddress( discoveryAddress );
+ this.setDiscoveryPort( discoveryPort );
+ this.setServicePort( servicePort );
try
{
@@ -89,10 +103,10 @@
try
{
// todo need some kind of recovery here.
- receiver = new UDPDiscoveryReceiver( this,
lca.getUdpDiscoveryAddr(), lca.getUdpDiscoveryPort(), cacheMgr );
+ receiver = new UDPDiscoveryReceiver( this, getDiscoveryAddress(),
getDiscoveryPort(), cacheMgr );
udpReceiverThread = new Thread( receiver );
udpReceiverThread.setDaemon( true );
- //udpReceiverThread.setName( t.getName() + "--UDPReceiver" );
+ // udpReceiverThread.setName( t.getName() + "--UDPReceiver" );
udpReceiverThread.start();
}
catch ( Exception e )
@@ -109,8 +123,8 @@
}
// create a sender thread
- sender = new UDPDiscoverySenderThread( lca.getUdpDiscoveryAddr(),
lca.getUdpDiscoveryPort(), hostAddress, lca
- .getTcpListenerPort(), this.getCacheNames() );
+ sender = new UDPDiscoverySenderThread( getDiscoveryAddress(),
getDiscoveryPort(), hostAddress, this
+ .getServicePort(), this.getCacheNames() );
senderDaemon.executePeriodically( 30 * 1000, sender, false );
}
@@ -185,7 +199,7 @@
* request for a request. We can respond to our own reques, since a request
* broadcast is not intended as a connection request. We might want to only
* send messages, so we would send a request, but never a passive
broadcast.
- *
+ *
*/
protected void serviceRequestBroadcast()
{
@@ -194,11 +208,9 @@
{
// create this connection each time.
// more robust
- sender = new UDPDiscoverySender(
getTcpLateralCacheAttributes().getUdpDiscoveryAddr(),
-
getTcpLateralCacheAttributes().getUdpDiscoveryPort() );
+ sender = new UDPDiscoverySender( getDiscoveryAddress(),
getDiscoveryPort() );
- sender.passiveBroadcast( hostAddress,
getTcpLateralCacheAttributes().getTcpListenerPort(), this
- .getCacheNames() );
+ sender.passiveBroadcast( hostAddress, this.getServicePort(),
this.getCacheNames() );
// todo we should consider sending a request broadcast every so
// often.
@@ -248,27 +260,10 @@
}
/**
- * @param lca
- * The lca to set.
- */
- public void setTcpLateralCacheAttributes( ITCPLateralCacheAttributes lca )
- {
- this.tcpLateralCacheAttributes = lca;
- }
-
- /**
- * @return Returns the lca.
- */
- public ITCPLateralCacheAttributes getTcpLateralCacheAttributes()
- {
- return tcpLateralCacheAttributes;
- }
-
- /**
* Allows us to set the daemon status on the clockdaemon
*
* @author aaronsm
- *
+ *
*/
class MyThreadFactory
implements ThreadFactory
@@ -327,5 +322,72 @@
log.error( "Problem shutting down UDP sender." );
}
+ }
+
+ /**
+ * @param discoveryAddress
+ * The discoveryAddress to set.
+ */
+ protected void setDiscoveryAddress( String discoveryAddress )
+ {
+ this.discoveryAddress = discoveryAddress;
+ }
+
+ /**
+ * @return Returns the discoveryAddress.
+ */
+ protected String getDiscoveryAddress()
+ {
+ return discoveryAddress;
+ }
+
+ /**
+ * @param discoveryPort
+ * The discoveryPort to set.
+ */
+ protected void setDiscoveryPort( int discoveryPort )
+ {
+ this.discoveryPort = discoveryPort;
+ }
+
+ /**
+ * @return Returns the discoveryPort.
+ */
+ protected int getDiscoveryPort()
+ {
+ return discoveryPort;
+ }
+
+ /**
+ * @param servicePort
+ * The servicePort to set.
+ */
+ protected void setServicePort( int servicePort )
+ {
+ this.servicePort = servicePort;
+ }
+
+ /**
+ * @return Returns the servicePort.
+ */
+ protected int getServicePort()
+ {
+ return servicePort;
+ }
+
+ /**
+ * @param tCPLateralCacheAttributes The tCPLateralCacheAttributes to set.
+ */
+ public void setTcpLateralCacheAttributes( ITCPLateralCacheAttributes
tCPLateralCacheAttributes )
+ {
+ tcpLateralCacheAttributes = tCPLateralCacheAttributes;
+ }
+
+ /**
+ * @return Returns the tCPLateralCacheAttributes.
+ */
+ public ITCPLateralCacheAttributes getTcpLateralCacheAttributes()
+ {
+ return tcpLateralCacheAttributes;
}
}
Modified:
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCache.java
URL:
http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCache.java?rev=386386&r1=386385&r2=386386&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
Thu Mar 16 09:18:04 2006
@@ -24,7 +24,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.jcs.access.exception.ObjectNotFoundException;
import org.apache.jcs.auxiliary.AuxiliaryCacheAttributes;
import org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheAttributes;
import org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheListener;
@@ -50,7 +49,8 @@
import EDU.oswego.cs.dl.util.concurrent.ThreadFactory;
/**
- * Client proxy for an RMI remote cache.
+ * Client proxy for an RMI remote cache. This handles gets, updates, and
+ * removes. It also initiates failover recovery when an error is encountered.
*
*/
public class RemoteCache
@@ -107,6 +107,7 @@
{
log.debug( "GetTimeoutMillis() = " + irca.getGetTimeoutMillis() );
}
+
if ( irca.getGetTimeoutMillis() > 0 )
{
pool = ThreadPoolManager.getInstance().getPool(
irca.getThreadPoolName() );
@@ -120,7 +121,6 @@
pool.getPool().setThreadFactory( new MyThreadFactory() );
}
}
-
}
/**
@@ -154,7 +154,6 @@
{
if ( true )
{
-
if ( !this.irca.getGetOnly() )
{
try
@@ -163,10 +162,12 @@
{
log.debug( "sending item to remote server" );
}
-
- // convert so we don't have to know about the object on
the other end.
- ICacheElementSerialized serialized =
SerializationConversionUtil.getSerializedCacheElement( ce,
this.elementSerializer );
-
+
+ // convert so we don't have to know about the object on the
+ // other end.
+ ICacheElementSerialized serialized =
SerializationConversionUtil
+ .getSerializedCacheElement( ce, this.elementSerializer
);
+
remote.update( serialized, getListenerId() );
}
catch ( NullPointerException npe )
@@ -202,7 +203,6 @@
public ICacheElement get( Serializable key )
throws IOException
{
-
ICacheElement retVal = null;
try
@@ -213,21 +213,15 @@
}
else
{
- retVal = remote.get( cacheName, sanitized( key ) );
+ retVal = remote.get( cacheName, sanitized( key ),
getListenerId() );
}
// Eventually the instance of will not be necessary.
if ( retVal != null && retVal instanceof ICacheElementSerialized )
{
retVal =
SerializationConversionUtil.getDeSerializedCacheElement(
(ICacheElementSerialized) retVal,
-
this.elementSerializer );
+
this.elementSerializer );
}
-
- }
- catch ( ObjectNotFoundException one )
- {
- log.debug( "didn't find element " + key + " in remote" );
- return null;
}
catch ( Exception ex )
{
@@ -257,18 +251,7 @@
public Object call()
throws IOException
{
- try
- {
- return remote.get( cacheName, key );
- }
- catch ( ObjectNotFoundException onf )
- {
- if ( log.isDebugEnabled() )
- {
- log.debug( "getusingPool, Didin't find object" );
- }
- return null;
- }
+ return remote.get( cacheName, key, getListenerId() );
}
} );
@@ -384,7 +367,6 @@
{
if ( true )
{
-
if ( !this.irca.getGetOnly() )
{
try
@@ -408,14 +390,17 @@
public void dispose()
throws IOException
{
- log.debug( "disposing of remote cache" );
+ if ( log.isInfoEnabled() )
+ {
+ log.info( "Disposing of remote cache" );
+ }
try
{
remote.dispose( cacheName );
}
catch ( Exception ex )
{
- log.error( "couldn't dispose" );
+ log.error( "couldn't dispose", ex );
handleException( ex, "Failed to dispose " + cacheName );
}
}
@@ -454,7 +439,23 @@
IStatElement se = null;
+ se = new StatElement();
+ se.setName( "Remote Host:Port" );
+ se.setData( this.irca.getRemoteHost() + ":" +
this.irca.getRemotePort() );
+ elems.add( se );
+
+ se = new StatElement();
+ se.setName( "Remote Type" );
+ se.setData( this.irca.getRemoteTypeName() + "" );
+ elems.add( se );
+
+ if ( this.irca.getRemoteType() == IRemoteCacheAttributes.CLUSTER )
+ {
+ // somethign cluster specific
+ }
+
// no data gathered here
+
se = new StatElement();
se.setName( "UsePoolForGet" );
se.setData( "" + usePoolForGet );
@@ -536,7 +537,6 @@
{
log.error( "Disabling remote cache due to error " + msg );
log.error( ex );
- // log.error( ex.toString() );
remote = new ZombieRemoteCacheService();
// may want to flush if region specifies
@@ -547,14 +547,20 @@
// initiate failover if local
RemoteCacheNoWaitFacade rcnwf = (RemoteCacheNoWaitFacade)
RemoteCacheFactory.getFacades()
.get( irca.getCacheName() );
- log.debug( "Initiating failover, rcnf = " + rcnwf );
+
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( "Initiating failover, rcnf = " + rcnwf );
+ }
if ( rcnwf != null && rcnwf.rca.getRemoteType() ==
RemoteCacheAttributes.LOCAL )
{
- log.debug( "found facade, calling failover" );
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( "Found facade, calling failover" );
+ }
// may need to remove the noWait index here. It will be 0 if it is
- // local
- // since there is only 1 possible listener.
+ // local since there is only 1 possible listener.
rcnwf.failover( 0 );
}
@@ -591,13 +597,11 @@
{
log.debug( "set listenerId = " + id );
}
-
}
catch ( Exception e )
{
log.error( "Problem setting listenerId", e );
}
-
}
/**
@@ -669,7 +673,6 @@
class MyThreadFactory
implements ThreadFactory
{
-
/*
* (non-Javadoc)
*
@@ -681,6 +684,5 @@
t.setDaemon( true );
return t;
}
-
}
}
Modified:
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheFailoverRunner.java
URL:
http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheFailoverRunner.java?rev=386386&r1=386385&r2=386386&view=diff
==============================================================================
---
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheFailoverRunner.java
(original)
+++
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheFailoverRunner.java
Thu Mar 16 09:18:04 2006
@@ -129,13 +129,11 @@
{
do
{
-
log.info( "Remote cache FAILOVER RUNNING." );
// there is no active listener
if ( !alright )
{
-
// Monitor each RemoteCacheManager instance one after the
other.
// Each RemoteCacheManager corresponds to one remote
connection.
String[] failovers = facade.rca.getFailovers();
@@ -183,7 +181,6 @@
RemoteCacheAttributes rca = null;
try
{
-
rca = (RemoteCacheAttributes) facade.rca.copy();
rca.setRemoteHost( server.substring( 0,
server.indexOf( ":" ) ) );
rca.setRemotePort( Integer.parseInt( server.substring(
server.indexOf( ":" ) + 1 ) ) );
@@ -310,7 +307,7 @@
}
/**
- * Try to resotre the primary server.
+ * Try to restore the primary server.
* <p>
* Once primary is restored the failover listener must be deregistered.
* <p>
@@ -332,7 +329,6 @@
try
{
-
RemoteCacheAttributes rca = (RemoteCacheAttributes)
facade.rca.copy();
rca.setRemoteHost( server.substring( 0, server.indexOf( ":" ) ) );
rca.setRemotePort( Integer.parseInt( server.substring(
server.indexOf( ":" ) + 1 ) ) );
@@ -352,7 +348,6 @@
{
if ( ic.getStatus() == CacheConstants.STATUS_ALIVE )
{
-
try
{
// we could have more than one listener registered
right
@@ -433,7 +428,6 @@
log.info( "Successfully reconnected to PRIMARY remote
server." );
}
return true;
-
}
// else alright
@@ -452,7 +446,6 @@
log.debug( "Primary server is null, not connected." );
}
}
-
}
catch ( Exception ex )
{
Modified:
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheNoWait.java
URL:
http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheNoWait.java?rev=386386&r1=386385&r2=386386&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
Thu Mar 16 09:18:04 2006
@@ -42,7 +42,7 @@
/**
* Used to queue up update requests to the underlying cache. These requests
will
* be processed in their order of arrival via the cache event queue processor.
- *
+ *
*/
public class RemoteCacheNoWait
implements AuxiliaryCache
@@ -76,7 +76,8 @@
}
/*
- * (non-Javadoc)
+ * (non-Javadoc)
+ *
* @see
org.apache.jcs.engine.behavior.ICache#update(org.apache.jcs.engine.behavior.ICacheElement)
*/
public void update( ICacheElement ce )
@@ -94,8 +95,9 @@
}
}
- /**
- * Synchronously reads from the remote cache.
+ /**
+ * Synchronously reads from the remote cache.
+ *
* @param key
* @return
* @throws IOException
@@ -134,7 +136,9 @@
return cache.getGroupKeys( groupName );
}
- /** Adds a remove request to the remote cache.
+ /**
+ * Adds a remove request to the remote cache.
+ *
* @param key
* @return
* @throws IOException
@@ -155,8 +159,9 @@
return false;
}
- /**
- * Adds a removeAll request to the remote cache.
+ /**
+ * Adds a removeAll request to the remote cache.
+ *
* @throws IOException
*/
public void removeAll()
@@ -234,6 +239,7 @@
/**
* Replaces the remote cache service handle with the given handle and reset
* the event queue by starting up a new instance.
+ *
* @param remote
*/
public void fixCache( IRemoteCacheService remote )
@@ -270,7 +276,8 @@
}
/*
- * (non-Javadoc)
+ * (non-Javadoc)
+ *
* @see java.lang.Object#toString()
*/
public String toString()
@@ -300,7 +307,28 @@
ArrayList elems = new ArrayList();
- //IStatElement se = null;
+ IStatElement se = null;
+
+ se = new StatElement();
+ se.setName( "Status" );
+ int status = this.getStatus();
+ if ( status == CacheConstants.STATUS_ERROR )
+ {
+ se.setData( "ERROR" );
+ }
+ else if ( status == CacheConstants.STATUS_ALIVE )
+ {
+ se.setData( "ALIVE" );
+ }
+ else if ( status == CacheConstants.STATUS_DISPOSED )
+ {
+ se.setData( "DISPOSED" );
+ }
+ else
+ {
+ se.setData( "" + status );
+ }
+ elems.add( se );
// no data gathered here
Modified:
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheNoWaitFacade.java
URL:
http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheNoWaitFacade.java?rev=386386&r1=386385&r2=386386&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
Thu Mar 16 09:18:04 2006
@@ -312,7 +312,6 @@
*/
protected void failover( int i )
{
-
if ( log.isDebugEnabled() )
{
log.info( "in failover for " + i );
@@ -336,7 +335,10 @@
}
else
{
- log.info( "the noWait is not in error" );
+ if ( log.isInfoEnabled() )
+ {
+ log.info( "The noWait is not in error" );
+ }
}
}
}
Modified:
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/ZombieRemoteCacheService.java
URL:
http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/ZombieRemoteCacheService.java?rev=386386&r1=386385&r2=386386&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
Thu Mar 16 09:18:04 2006
@@ -16,6 +16,7 @@
* limitations under the License.
*/
+import java.io.IOException;
import java.io.Serializable;
import java.util.Set;
import java.util.Collections;
@@ -27,8 +28,8 @@
import org.apache.jcs.engine.behavior.ICacheElement;
/**
- * Zombie adapter for the remote cache service. It just balks.
- *
+ * Zombie adapter for the remote cache service. It just balks.
+ *
*/
public class ZombieRemoteCacheService
extends ZombieCacheService
@@ -36,8 +37,10 @@
{
/*
- * (non-Javadoc)
- * @see
org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheService#update(org.apache.jcs.engine.behavior.ICacheElement,
long)
+ * (non-Javadoc)
+ *
+ * @see
org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheService#update(org.apache.jcs.engine.behavior.ICacheElement,
+ * long)
*/
public void update( ICacheElement item, long listenerId )
{
@@ -46,8 +49,10 @@
}
/*
- * (non-Javadoc)
- * @see
org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheService#remove(java.lang.String,
java.io.Serializable, long)
+ * (non-Javadoc)
+ *
+ * @see
org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheService#remove(java.lang.String,
+ * java.io.Serializable, long)
*/
public void remove( String cacheName, Serializable key, long listenerId )
{
@@ -56,8 +61,10 @@
}
/*
- * (non-Javadoc)
- * @see
org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheService#removeAll(java.lang.String,
long)
+ * (non-Javadoc)
+ *
+ * @see
org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheService#removeAll(java.lang.String,
+ * long)
*/
public void removeAll( String cacheName, long listenerId )
{
@@ -65,6 +72,25 @@
return;
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheService#get(java.lang.String,
+ * java.io.Serializable, long)
+ */
+ public ICacheElement get( String cacheName, Serializable key, long
requesterId )
+ throws IOException
+ {
+ // Zombies have no inner life
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheService#getGroupKeys(java.lang.String,
+ * java.lang.String)
+ */
public Set getGroupKeys( String cacheName, String groupName )
{
return Collections.EMPTY_SET;
Modified:
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/behavior/IRemoteCacheConstants.java
URL:
http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/behavior/IRemoteCacheConstants.java?rev=386386&r1=386385&r2=386386&view=diff
==============================================================================
---
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/behavior/IRemoteCacheConstants.java
(original)
+++
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/behavior/IRemoteCacheConstants.java
Thu Mar 16 09:18:04 2006
@@ -17,7 +17,7 @@
*/
/**
- * Description of the Interface
+ * This holds contants that are used by the remote cache.
*
*/
public interface IRemoteCacheConstants
Modified:
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/behavior/IRemoteCacheService.java
URL:
http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/behavior/IRemoteCacheService.java?rev=386386&r1=386385&r2=386386&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
Thu Mar 16 09:18:04 2006
@@ -23,6 +23,7 @@
import java.rmi.Remote;
import org.apache.jcs.access.exception.ObjectExistsException;
+import org.apache.jcs.access.exception.ObjectNotFoundException;
import org.apache.jcs.engine.behavior.ICacheElement;
import org.apache.jcs.engine.behavior.ICacheService;
@@ -67,6 +68,22 @@
public void removeAll( String cacheName, long requesterId )
throws IOException;
+ /**
+ * 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.
+ *
+ * @param cacheName
+ * @param key
+ * @param requesterId
+ * @return ICacheElement
+ * @throws ObjectNotFoundException
+ * @throws IOException
+ */
+ public ICacheElement get( String cacheName, Serializable key, long
requesterId )
+ throws IOException;
+
/**
* @param cacheName
* @param groupName
Modified:
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServer.java
URL:
http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServer.java?rev=386386&r1=386385&r2=386386&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
Thu Mar 16 09:18:04 2006
@@ -31,6 +31,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.jcs.access.exception.ObjectNotFoundException;
import org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheAttributes;
import org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheListener;
import org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheObserver;
@@ -92,7 +93,8 @@
protected IRemoteCacheServerAttributes rcsa;
/**
- * Constructor for the RemoteCacheServer object
+ * Constructor for the RemoteCacheServer object. Thiks initializes the
+ * server with the values from the config file.
*
* @param rcsa
* @exception IOException
@@ -131,7 +133,7 @@
}
/**
- * Subclass can overrdie this method to create the specific cache manager.
+ * Subclass can override this method to create the specific cache manager.
*
* @param prop
* The anem of the configuration file.
@@ -173,8 +175,6 @@
cacheListeners = (CacheListeners) cacheListenersMap.get(
cacheName );
if ( cacheListeners == null )
{
- // NEED TO CONVERT TO USE THE FACTORY ND GET A FACADE? No
it
- // is the hub
cacheListeners = new CacheListeners(
cacheManager.getCache( cacheName ) );
cacheListenersMap.put( cacheName, cacheListeners );
}
@@ -285,7 +285,7 @@
if ( log.isInfoEnabled() )
{
- // not thread safe, but it doesn't ahve to be accurate
+ // not thread safe, but it doesn't have to be accurate
puts++;
if ( puts % 100 == 0 )
{
@@ -306,7 +306,7 @@
Integer remoteTypeL = (Integer) idTypeMap.get( new Long(
requesterId ) );
if ( log.isDebugEnabled() )
{
- log.debug( "in update, requesterId = [" + requesterId + "]
remoteType = " + remoteTypeL );
+ log.debug( "In update, requesterId = [" + requesterId + "]
remoteType = " + remoteTypeL );
}
boolean fromCluster = false;
@@ -322,7 +322,8 @@
CompositeCache c = (CompositeCache) cacheDesc.cache;
// If the source of this request was not from a cluster,
- // then consider it a local update. The cache manager will
try to
+ // then consider it a local update. The cache manager will
+ // try to
// update all auxiliaries.
//
// This requires that two local caches not be connected to
@@ -353,9 +354,13 @@
c.update( item );
}
}
- catch ( Exception oee )
+ catch ( Exception ce )
{
// swallow
+ if ( log.isInfoEnabled() )
+ {
+ log.info( "Exception caught updating item. " +
ce.getMessage() );
+ }
}
// UPDATE LOCALS IF A REQUEST COMES FROM A CLUSTER
@@ -469,15 +474,44 @@
*
* @param cacheName
* @param key
- * @return
+ * @return ICacheElement
* @throws IOException
*/
public ICacheElement get( String cacheName, Serializable key )
throws IOException
{
+ return this.get( cacheName, key, 0 );
+ }
+
+ /**
+ * 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.
+ *
+ * @param cacheName
+ * @param key
+ * @param requesterId
+ * @return ICacheElement
+ * @throws ObjectNotFoundException
+ * @throws IOException
+ */
+ public ICacheElement get( String cacheName, Serializable key, long
requesterId )
+ throws IOException
+ {
+ Integer remoteTypeL = (Integer) idTypeMap.get( new Long( requesterId )
);
+
if ( log.isDebugEnabled() )
{
- log.debug( "get " + key + " from cache " + cacheName );
+ log.debug( "get " + key + " from cache " + cacheName + "
requesterId = [" + requesterId + "] remoteType = "
+ + remoteTypeL );
+ }
+
+ boolean fromCluster = false;
+ if ( remoteTypeL.intValue() == IRemoteCacheAttributes.CLUSTER )
+ {
+ fromCluster = true;
}
CacheListeners cacheDesc = null;
@@ -496,7 +530,41 @@
}
CompositeCache c = (CompositeCache) cacheDesc.cache;
- return c.localGet( key );
+ ICacheElement element = null;
+
+ // If we have a get come in from a client and we don't have the item
+ // locally, we will allow the cache to look in other non local sources,
+ // such as a remote cache or a lateral.
+ //
+ // Since remote servers never get from clients and clients never go
+ // remote from a remote call, this
+ // will not result in any loops.
+ //
+ // This is the only instance I can think of where we allow a remote get
+ // from a remote call. The putpose is to allow remote cache servers to
+ // talk to each other. If one goes down, you want it to be able to get
+ // data from those that were up when the failed server comes back o
+ // line.
+ if ( !fromCluster && this.rcsa.getAllowClusterGet() )
+ {
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( "Get NOT from cluster, NOT allowing a get from
other auxiliaries for the region." );
+ }
+ element = c.get( key );
+ }
+ else
+ {
+ // Gets from cluster type remote will end up here.
+ // Gets from all clients will end up here if allow cluster get is
false.
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( "Allowing a get from other auxiliaries for the
region." );
+ }
+ element = c.localGet( key );
+ }
+
+ return element;
}
/**
@@ -602,7 +670,6 @@
// UPDATE LOCALS IF A REQUEST COMES FROM A CLUSTER
// IF LOCAL CLUSTER CONSISTENCY IS CONFIGURED
-
if ( !fromCluster || ( fromCluster &&
rcsa.getLocalClusterConsistency() ) )
{
ICacheEventQueue[] qlist = getEventQList( cacheDesc,
requesterId );
@@ -712,6 +779,11 @@
public void dispose( String cacheName, long requesterId )
throws IOException
{
+ if ( log.isInfoEnabled() )
+ {
+ log.info( "Dispose request received from listener [" + requesterId
+ "]" );
+ }
+
CacheListeners cacheDesc = (CacheListeners) cacheListenersMap.get(
cacheName );
// this is dangerous
@@ -861,7 +933,6 @@
// relate the type to an id
this.idTypeMap.put( new Long( id ), new Integer(
remoteType ) );
-
}
catch ( IOException ioe )
{
Modified:
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/behavior/IRemoteCacheServerAttributes.java
URL:
http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/behavior/IRemoteCacheServerAttributes.java?rev=386386&r1=386385&r2=386386&view=diff
==============================================================================
---
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/behavior/IRemoteCacheServerAttributes.java
(original)
+++
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/behavior/IRemoteCacheServerAttributes.java
Thu Mar 16 09:18:04 2006
@@ -18,11 +18,10 @@
import org.apache.jcs.auxiliary.AuxiliaryCacheAttributes;
-//import org.apache.jcs.auxiliary.*;
-
/**
- * Description of the Interface
- *
+ * This defeines the minimal behavior for the objects that are used to
configure
+ * the remote cache server.
+ *
*/
public interface IRemoteCacheServerAttributes
extends AuxiliaryCacheAttributes
@@ -175,7 +174,12 @@
public void setLocalClusterConsistency( boolean r );
/**
- * Should cluster updates be propogated to the locals
+ * Should we try to get remotely when the request does not come in from a
+ * cluster. If local L1 asks remote server R1 for element A and R1 doesn't
+ * have it, should R1 look remotely? The difference is between a local and
a
+ * remote update. The local update stays local. Normal updates, removes,
+ * etc, stay local when they come from a client. If this is set to true,
+ * then they can go remote.
*
* @return The localClusterConsistency value
*/
Modified:
jakarta/jcs/trunk/src/java/org/apache/jcs/engine/PooledCacheEventQueue.java
URL:
http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/engine/PooledCacheEventQueue.java?rev=386386&r1=386385&r2=386386&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/engine/PooledCacheEventQueue.java
(original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/engine/PooledCacheEventQueue.java
Thu Mar 16 09:18:04 2006
@@ -335,13 +335,13 @@
se.setData( "" + this.working );
elems.add( se );
- se.setName( "Destroyed" );
se = new StatElement();
+ se.setName( "Destroyed" );
se.setData( "" + this.isAlive() );
elems.add( se );
- se.setName( "Empty" );
se = new StatElement();
+ se.setName( "Empty" );
se.setData( "" + this.isEmpty() );
elems.add( se );
@@ -350,25 +350,25 @@
if ( pool.getQueue() instanceof BoundedBuffer )
{
BoundedBuffer bb = (BoundedBuffer) pool.getQueue();
- se.setName( "Queue Size" );
se = new StatElement();
+ se.setName( "Queue Size" );
se.setData( "" + bb.size() );
elems.add( se );
- se.setName( "Queue Capacity" );
se = new StatElement();
+ se.setName( "Queue Capacity" );
se.setData( "" + bb.capacity() );
elems.add( se );
}
}
- se.setName( "Pool Size" );
se = new StatElement();
+ se.setName( "Pool Size" );
se.setData( "" + pool.getPool().getPoolSize() );
elems.add( se );
- se.setName( "Maximum Pool Size" );
se = new StatElement();
+ se.setName( "Maximum Pool Size" );
se.setData( "" + pool.getPool().getMaximumPoolSize() );
elems.add( se );
Modified:
jakarta/jcs/trunk/src/java/org/apache/jcs/utils/serialization/SerializationConversionUtil.java
URL:
http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/utils/serialization/SerializationConversionUtil.java?rev=386386&r1=386385&r2=386386&view=diff
==============================================================================
---
jakarta/jcs/trunk/src/java/org/apache/jcs/utils/serialization/SerializationConversionUtil.java
(original)
+++
jakarta/jcs/trunk/src/java/org/apache/jcs/utils/serialization/SerializationConversionUtil.java
Thu Mar 16 09:18:04 2006
@@ -42,23 +42,31 @@
byte[] serialzedValue = null;
- if ( elementSerializer != null )
+ // if it has already been serialized, don't do it again.
+ if ( element instanceof ICacheElementSerialized )
{
- try
+ serialzedValue = ( (ICacheElementSerialized) element
).getSerializedValue();
+ }
+ else
+ {
+ if ( elementSerializer != null )
{
- serialzedValue = elementSerializer.serialize( element.getVal()
);
+ try
+ {
+ serialzedValue = elementSerializer.serialize(
element.getVal() );
+ }
+ catch ( IOException e )
+ {
+ log.error( "Problem serializing object.", e );
+ throw e;
+ }
}
- catch ( IOException e )
+ else
{
- log.error( "Problem serializing object.", e );
- throw e;
+ // we could just use the default.
+ log.warn( "ElementSerializer is null. Could not serialize
object." );
+ throw new IOException( "Could not serialize object. The
ElementSerializer is null." );
}
- }
- else
- {
- // we could just use the default.
- log.warn( "ElementSerializer is null. Could not serialize
object." );
- throw new IOException( "Could not serialize object. The
ElementSerializer is null." );
}
ICacheElementSerialized serialized = new CacheElementSerialized(
element.getCacheName(), element.getKey(),
serialzedValue, element.getElementAttributes() );
Modified: jakarta/jcs/trunk/src/test-conf/log4j.properties
URL:
http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test-conf/log4j.properties?rev=386386&r1=386385&r2=386386&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test-conf/log4j.properties (original)
+++ jakarta/jcs/trunk/src/test-conf/log4j.properties Thu Mar 16 09:18:04 2006
@@ -4,6 +4,7 @@
log4j.category.org.apache.jcs.config=INFO
log4j.category.org.apache.jcs.engine=INFO
log4j.category.org.apache.jcs.engine.CacheEventQueueFactory=INFO
+#log4j.category.org.apache.jcs.auxiliary.disk=DEBUG
log4j.category.org.apache.jcs.auxiliary.disk=INFO
log4j.category.org.apache.jcs.auxiliary.remote=INFO
log4j.category.org.apache.jcs.auxiliary.lateral=INFO
Modified:
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheConcurrentUnitTest.java
URL:
http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheConcurrentUnitTest.java?rev=386386&r1=386385&r2=386386&view=diff
==============================================================================
---
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheConcurrentUnitTest.java
(original)
+++
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheConcurrentUnitTest.java
Thu Mar 16 09:18:04 2006
@@ -94,6 +94,15 @@
}
} );
+ suite.addTest( new IndexedDiskCacheConcurrentUnitTest(
"testIndexedDiskCache4" )
+ {
+ public void runTest()
+ throws Exception
+ {
+ this.runTestForRegionInRange( "indexedRegion3", 300, 600 );
+ }
+ } );
+
return suite;
}
@@ -121,14 +130,12 @@
JCS jcs = JCS.getInstance( region );
// Add items to cache
-
for ( int i = 0; i <= items; i++ )
{
jcs.put( i + ":key", region + " data " + i );
}
// Test that all items are in cache
-
for ( int i = 0; i <= items; i++ )
{
String value = (String) jcs.get( i + ":key" );
@@ -137,17 +144,65 @@
}
// Remove all the items
-
for ( int i = 0; i <= items; i++ )
{
jcs.remove( i + ":key" );
}
// Verify removal
-
+ // another thread may have inserted since
for ( int i = 0; i <= items; i++ )
{
- assertNull( "Removed key should be null: " + i + ":key", jcs.get(
i + ":key" ) );
+ assertNull( "Removed key should be null: " + i + ":key" + "\n
stats " + jcs.getStats(), jcs
+ .get( i + ":key" ) );
+ }
+ }
+
+ /**
+ * 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
+ * @param start
+ * @param end
+ *
+ * @exception Exception
+ * If an error occurs
+ */
+ public void runTestForRegionInRange( String region, int start, int end )
+ throws Exception
+ {
+ JCS jcs = JCS.getInstance( region );
+
+ // Add items to cache
+ for ( int i = start; i <= end; i++ )
+ {
+ jcs.put( i + ":key", region + " data " + i );
+ }
+
+ // Test that all items are in cache
+ for ( int i = start; i <= end; i++ )
+ {
+ String value = (String) jcs.get( i + ":key" );
+
+ assertEquals( region + " data " + i, value );
+ }
+
+ // Remove all the items
+ for ( int i = start; i <= end; i++ )
+ {
+ jcs.remove( i + ":key" );
+ }
+
+ System.out.println( jcs.getStats() );
+
+ // Verify removal
+ // another thread may have inserted since
+ for ( int i = start; i <= end; i++ )
+ {
+ assertNull( "Removed key should be null: " + i + ":key " + "\n
stats " + jcs.getStats(), jcs.get( i
+ + ":key" ) );
}
}
}
Modified:
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheNoMemoryUnitTest.java
URL:
http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheNoMemoryUnitTest.java?rev=386386&r1=386385&r2=386386&view=diff
==============================================================================
---
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheNoMemoryUnitTest.java
(original)
+++
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheNoMemoryUnitTest.java
Thu Mar 16 09:18:04 2006
@@ -138,20 +138,18 @@
}
// Remove all the items
-
for ( int i = 0; i <= items; i++ )
{
jcs.remove( i + ":key" );
}
// Verify removal
-
for ( int i = 0; i <= items; i++ )
{
- assertNull( "Removed key should be null: " + i + ":key", jcs.get(
i + ":key" ) );
+ assertNull( "Removed key should be null: " + i + ":key" + "\n
stats " + jcs.getStats(), jcs.get( i + ":key" ) );
}
- // dump the stats tot he report
+ // dump the stats to the report
System.out.println( jcs.getStats() );
}
}
Modified:
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/UDPDiscoveryUnitTest.java
URL:
http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/UDPDiscoveryUnitTest.java?rev=386386&r1=386385&r2=386386&view=diff
==============================================================================
---
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/UDPDiscoveryUnitTest.java
(original)
+++
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/UDPDiscoveryUnitTest.java
Thu Mar 16 09:18:04 2006
@@ -65,7 +65,8 @@
ICompositeCacheManager cacheMgr = CompositeCacheManager.getInstance();
// create the service
- UDPDiscoveryService service = new UDPDiscoveryService( lac, cacheMgr );
+ UDPDiscoveryService service = new UDPDiscoveryService(
lac.getUdpDiscoveryAddr(), lac.getUdpDiscoveryPort(), lac.getTcpListenerPort(),
cacheMgr );
+ service.setTcpLateralCacheAttributes( lac );
// create a no wait facade for the service
ArrayList noWaits = new ArrayList();
|