Author: asmuts
Date: Thu Aug 24 18:09:35 2006
New Revision: 434585
URL: http://svn.apache.org/viewvc?rev=434585&view=rev
Log:
Improved formatting and comments.
Improved remote cache logging.
Added a size() method to the event queue interface.
Modified:
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCache.java
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheFactory.java
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheFailoverRunner.java
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheManager.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/RemoteCacheRestore.java
jakarta/jcs/trunk/src/java/org/apache/jcs/engine/CacheEventQueue.java
jakarta/jcs/trunk/src/java/org/apache/jcs/engine/PooledCacheEventQueue.java
jakarta/jcs/trunk/src/java/org/apache/jcs/engine/behavior/ICacheEventQueue.java
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=434585&r1=434584&r2=434585&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
Thu Aug 24 18:09:35 2006
@@ -11,9 +11,8 @@
/**
* The MySQLDiskCache extends the core JDBCDiskCache.
* <p>
- * Although the generic JDBC Disk Cache can be used for MySQL, the MySQL JDBC
- * Disk Cache has additional features, such as table optimization that are
- * particular to MySQL.
+ * Although the generic JDBC Disk Cache can be used for MySQL, the MySQL JDBC
Disk Cache has
+ * additional features, such as table optimization that are particular to
MySQL.
* <p>
* @author Aaron Smuts
*/
@@ -27,8 +26,8 @@
MySQLDiskCacheAttributes mySQLDiskCacheAttributes;
/**
- * Delegates to the super and makes use of the MySQL specific parameters
- * used for scheduled optimization.
+ * Delegates to the super and makes use of the MySQL specific parameters
used for scheduled
+ * optimization.
* <p>
* @param attributes
* @param tableState
@@ -46,11 +45,10 @@
}
/**
- * This delegates to the generic JDBC disk cache. If we are currently
- * optimizing, then this method will balk and return null.
+ * This delegates to the generic JDBC disk cache. If we are currently
optimizing, then this
+ * method will balk and return null.
* <p>
- * @param key
- * Key to locate value for.
+ * @param key Key to locate value for.
* @return An object matching key, or null.
*/
public ICacheElement doGet( Serializable key )
@@ -66,8 +64,8 @@
}
/**
- * This delegates to the generic JDBC disk cache. If we are currently
- * optimizing, then this method will balk and do nothing. A
+ * This delegates to the generic JDBC disk cache. If we are currently
optimizing, then this
+ * method will balk and do nothing.
* <p>
* @param element
*/
@@ -83,4 +81,24 @@
super.doUpdate( element );
}
+ /**
+ * Removed the expired. (now - create time) > max life seconds * 1000
+ * <p>
+ * If we are currently optimizing, then this method will balk and do
nothing.
+ * <p>
+ * TODO consider blocking and trying again.
+ * <p>
+ * @return the number deleted
+ */
+ protected int deleteExpired()
+ {
+ if ( this.getTableState().getState() ==
TableState.OPTIMIZATION_RUNNING )
+ {
+ if ( this.mySQLDiskCacheAttributes.isBalkDuringOptimization() )
+ {
+ return -1;
+ }
+ }
+ return super.deleteExpired();
+ }
}
Modified:
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheFactory.java
URL:
http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheFactory.java?rev=434585&r1=434584&r2=434585&view=diff
==============================================================================
---
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheFactory.java
(original)
+++
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheFactory.java
Thu Aug 24 18:09:35 2006
@@ -1,19 +1,12 @@
package org.apache.jcs.auxiliary.remote;
/*
- * Copyright 2001-2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License")
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Copyright 2001-2004 The Apache Software Foundation. Licensed under the
Apache License, Version
+ * 2.0 (the "License") you may not use this file except in compliance with the
License. You may
+ * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by
+ * applicable law or agreed to in writing, software distributed under the
License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See
+ * the License for the specific language governing permissions and limitations
under the License.
*/
import java.util.ArrayList;
@@ -29,11 +22,10 @@
import org.apache.jcs.engine.behavior.ICompositeCacheManager;
/**
- * The RemoteCacheFactory creates remote caches for the cache hub. It returns a
- * no wait facade which is a wrapper around a no wait. The no wait object is
- * either an active connection to a remote cache or a balking zombie if the
- * remote cache is not accessible. It should be transparent to the clients.
- *
+ * The RemoteCacheFactory creates remote caches for the cache hub. It returns
a no wait facade which
+ * is a wrapper around a no wait. The no wait object is either an active
connection to a remote
+ * cache or a balking zombie if the remote cache is not accessible. It should
be transparent to the
+ * clients.
*/
public class RemoteCacheFactory
implements AuxiliaryCacheFactory
@@ -45,15 +37,18 @@
/** store reference of facades to initiate failover */
private final static HashMap facades = new HashMap();
- /*
+ /**
+ * For LOCAL clients we get a handle to all the failovers, but we do not
register a listener
+ * with them. We create the RemoteCacheManager, but we do not get a cache.
The failover runner
+ * will get a cache from the manager. When the primary is restored it will
tell the manager for
+ * the failover to deregister the listener.
+ * <p>
* (non-Javadoc)
- *
* @see
org.apache.jcs.auxiliary.AuxiliaryCacheFactory#createCache(org.apache.jcs.auxiliary.AuxiliaryCacheAttributes,
* org.apache.jcs.engine.behavior.ICompositeCacheManager)
*/
public AuxiliaryCache createCache( AuxiliaryCacheAttributes iaca,
ICompositeCacheManager cacheMgr )
{
-
RemoteCacheAttributes rca = (RemoteCacheAttributes) iaca;
ArrayList noWaits = new ArrayList();
@@ -61,7 +56,6 @@
// if LOCAL
if ( rca.getRemoteType() == RemoteCacheAttributes.LOCAL )
{
-
// a list toi be turned into an array of failover server
information
ArrayList failovers = new ArrayList();
@@ -128,14 +122,13 @@
}
else if ( rca.getRemoteType() == RemoteCacheAttributes.CLUSTER )
{
-
// REGISTER LISTENERS FOR EACH SYSTEM CLUSTERED CACHEs
StringTokenizer it = new StringTokenizer( rca.getClusterServers(),
"," );
while ( it.hasMoreElements() )
{
- //String server = (String)it.next();
+ // String server = (String)it.next();
String server = (String) it.nextElement();
- //p( "tcp server = " + server );
+ // p( "tcp server = " + server );
rca.setRemoteHost( server.substring( 0, server.indexOf( ":" )
) );
rca.setRemotePort( Integer.parseInt( server.substring(
server.indexOf( ":" ) + 1 ) ) );
RemoteCacheManager rcm = RemoteCacheManager.getInstance( rca,
cacheMgr );
@@ -166,7 +159,6 @@
/**
* Gets the name attribute of the RemoteCacheFactory object
- *
* @return The name value
*/
public String getName()
@@ -176,9 +168,7 @@
/**
* Sets the name attribute of the RemoteCacheFactory object
- *
- * @param name
- * The new name value
+ * @param name The new name value
*/
public void setName( String name )
{
@@ -187,7 +177,6 @@
/**
* The facades are what the cache hub talks to.
- *
* @return Returns the facades.
*/
public static HashMap getFacades()
Modified:
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheFailoverRunner.java
URL:
http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheFailoverRunner.java?rev=434585&r1=434584&r2=434585&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 Aug 24 18:09:35 2006
@@ -117,7 +117,7 @@
}
/**
- * This is the main loop. If there are failovers define, then this will
+ * This is the main loop. If there are failovers defined, then this will
* continue until the primary is re-connected. If no failovers are defined,
* this will exit automatically.
*/
@@ -321,7 +321,7 @@
if ( log.isInfoEnabled() )
{
- log.info( "Trying to restore conncetion to primary remopte server
[" + server + "]" );
+ log.info( "Trying to restore connection to primary remote server
[" + server + "]" );
}
try
@@ -414,14 +414,17 @@
}
// Restore primary
- // may need to do this more gracefully
+ // may need to do this more gracefully, letting the
failover finish in the background
+ RemoteCacheNoWait failoverNoWait = facade.noWaits[0];
+
+ // swap in a new one
facade.noWaits = new RemoteCacheNoWait[1];
facade.noWaits[0] = (RemoteCacheNoWait) ic;
facade.rca.setFailoverIndex( 0 );
if ( log.isInfoEnabled() )
{
- log.info( "Successfully reconnected to PRIMARY remote
server." );
+ log.info( "Successfully reconnected to PRIMARY remote
server. Substituted primary for failoverNoWait [" + failoverNoWait + "]" );
}
return true;
}
Modified:
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheManager.java
URL:
http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheManager.java?rev=434585&r1=434584&r2=434585&view=diff
==============================================================================
---
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheManager.java
(original)
+++
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheManager.java
Thu Aug 24 18:09:35 2006
@@ -33,6 +33,9 @@
* An instance of RemoteCacheManager corresponds to one remote connection of a
specific host and
* port. All RemoteCacheManager instances are monitored by the singleton
RemoteCacheMonitor
* monitoring daemon for error detection and recovery.
+ * <p>
+ * Getting an instance of the remote cache has the effect of getting a handle
on the remote server.
+ * Listeners are not registered with the server until a cache is requested
from the manager.
*/
public class RemoteCacheManager
implements AuxiliaryCacheManager, IShutdownObserver
@@ -82,6 +85,7 @@
* Constructs an instance to with the given remote connection parameters.
If the connection
* cannot be made, "zombie" services will be temporarily used until a
successful re-connection
* is made by the monitoring daemon.
+ * <p>
* @param host
* @param port
* @param service
@@ -135,7 +139,8 @@
}
/**
- * Gets the defaultCattr attribute of the RemoteCacheManager object
+ * Gets the defaultCattr attribute of the RemoteCacheManager object.
+ * <p>
* @return The defaultCattr value
*/
public IRemoteCacheAttributes getDefaultCattr()
@@ -145,6 +150,7 @@
/**
* Adds the remote cache listener to the underlying cache-watch service.
+ * <p>
* @param cattr The feature to be added to the RemoteCacheListener
attribute
* @param listener The feature to be added to the RemoteCacheListener
attribute
* @throws IOException
@@ -344,6 +350,10 @@
/**
* Gets a RemoteCacheNoWait from the RemoteCacheManager. The
RemoteCacheNoWait objects are
* identified by the cache name value of the RemoteCacheAttributes object.
+ * <p>
+ * If the client is configured to register a listener, this call results
on a listener being
+ * created if one isn't already registered with the remote cache for this
region.
+ * <p>
* @param cattr
* @return The cache value
*/
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=434585&r1=434584&r2=434585&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 Aug 24 18:09:35 2006
@@ -262,18 +262,29 @@
/**
* Resets the event q by first destroying the existing one and starting up
new one.
* <p>
- * TODO rethink this. There may be no good reason to kill the existing
queue.
+ * There may be no good reason to kill the existing queue. We will
sometimes need to set a new
+ * listener id, so we should create a new queue. We should let the old
queue drain. If we were
+ * conencted to the failover, it would be best to finish sending items.
*/
public void resetEventQ()
{
- if ( q.isWorking() )
- {
- q.destroy();
- }
+ ICacheEventQueue previousQueue = q;
+
CacheEventQueueFactory fact = new CacheEventQueueFactory();
this.q = fact.createCacheEventQueue( new CacheAdaptor( cache ),
cache.getListenerId(), cache.getCacheName(),
cache.getAuxiliaryCacheAttributes().getEventQueuePoolName(), cache
.getAuxiliaryCacheAttributes().getEventQueueTypeFactoryCode() );
+
+ if ( previousQueue.isWorking() )
+ {
+ // we don't expect anything, it would have all gone to the zombie
+ if ( log.isInfoEnabled() )
+ {
+ log.info( "resetEventQ, previous queue has [" +
previousQueue.size() + "] items queued up." );
+ }
+ // TODO consider waiting.
+ previousQueue.destroy();
+ }
}
/**
@@ -286,13 +297,15 @@
return cache;
}
- /*
+ /**
+ * Returns the stats and the cache.toString().
+ * <p>
* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public String toString()
{
- return "RemoteCacheNoWait: " + cache.toString();
+ return getStats() + "\n" + cache.toString();
}
/**
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=434585&r1=434584&r2=434585&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 Aug 24 18:09:35 2006
@@ -30,9 +30,11 @@
import org.apache.jcs.engine.stats.behavior.IStats;
/**
- * Used to provide access to multiple services under nowait protection.
factory should construct
+ * Used to provide access to multiple services under nowait protection.
Factory should construct
* NoWaitFacade to give to the composite cache out of caches it constructs
from the varies manager
* to lateral services.
+ * <p>
+ * Typically, we only connect to one remote server per facade. We use a list
of one RemoteCacheNoWait.
*/
public class RemoteCacheNoWaitFacade
implements AuxiliaryCache
@@ -53,6 +55,7 @@
/**
* Gets the remoteCacheAttributes attribute of the RemoteCacheNoWaitFacade
object
+ * <p>
* @return The remoteCacheAttributes value
*/
public RemoteCacheAttributes getRemoteCacheAttributes()
@@ -61,7 +64,8 @@
}
/**
- * Sets the remoteCacheAttributes attribute of the RemoteCacheNoWaitFacade
object
+ * Sets the remoteCacheAttributes attribute of the RemoteCacheNoWaitFacade
object.
+ * <p>
* @param rca The new remoteCacheAttributes value
*/
public void setRemoteCacheAttributes( RemoteCacheAttributes rca )
@@ -133,6 +137,7 @@
/**
* Synchronously reads from the remote cache.
+ * <p>
* @param key
* @return Either an ICacheElement or null if it is not found.
*/
@@ -159,6 +164,7 @@
/**
* Gets the set of keys of objects currently in the group.
+ * <p>
* @param group
* @return
* @throws IOException
@@ -180,6 +186,7 @@
/**
* Adds a remove request to the remote cache.
+ * <p>
* @param key
* @return wether or not it was removed, right now it return false.
*/
@@ -234,7 +241,7 @@
}
/**
- * No lateral invokation.
+ * No lateral invocation.
* @return The size value
*/
public int getSize()
@@ -244,7 +251,8 @@
}
/**
- * Gets the cacheType attribute of the RemoteCacheNoWaitFacade object
+ * Gets the cacheType attribute of the RemoteCacheNoWaitFacade object.
+ * <p>
* @return The cacheType value
*/
public int getCacheType()
@@ -253,7 +261,8 @@
}
/**
- * Gets the cacheName attribute of the RemoteCacheNoWaitFacade object
+ * Gets the cacheName attribute of the RemoteCacheNoWaitFacade object.
+ * <p>
* @return The cacheName value
*/
public String getCacheName()
@@ -282,6 +291,7 @@
/**
* String form of some of the configuratin information for the remote
cache.
+ * <p>
* @return Some info for logging.
*/
public String toString()
@@ -291,6 +301,7 @@
/**
* Begin the failover process if this is a local cache. Clustered remote
caches do not failover.
+ * <p>
* @param i The no wait in error.
*/
protected void failover( int i )
@@ -364,7 +375,6 @@
List sL = Arrays.asList( sSEs );
elems.addAll( sL );
}
-
}
// get an array and put them in the Stats object
@@ -373,5 +383,4 @@
return stats;
}
-
}
Modified:
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheRestore.java
URL:
http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheRestore.java?rev=434585&r1=434584&r2=434585&view=diff
==============================================================================
---
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheRestore.java
(original)
+++
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheRestore.java
Thu Aug 24 18:09:35 2006
@@ -11,22 +11,22 @@
import java.rmi.Naming;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheObserver;
import org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheService;
-
import org.apache.jcs.engine.behavior.ICacheRestore;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
/**
* Used to repair the remote caches managed by the associated instance of
RemoteCacheManager.
* <p>
* When there is an error the monitor kicks off. The Failover runner starts
looks for a manager with
* a connection to a remote cache that is not in error. If a manager's
connection to a remote cache
* is found to be in error, the restorer kicks off and tries to reconnect.
When it is succesful, the
- * status of the manager changes. When the failover runner finds that the
primary is in good shape,
- * it will switch back.
+ * status of the manager changes.
+ * <p>
+ * When the failover runner finds that the primary is in good shape, it will
switch back. Switching
+ * back invovles setting the first no wait on the no wait facade.
*/
public class RemoteCacheRestore
implements ICacheRestore
Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/engine/CacheEventQueue.java
URL:
http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/engine/CacheEventQueue.java?rev=434585&r1=434584&r2=434585&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/engine/CacheEventQueue.java
(original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/engine/CacheEventQueue.java Thu
Aug 24 18:09:35 2006
@@ -80,6 +80,8 @@
// the end of the queue
private Node tail = head;
+ private int size = 0;
+
/**
* Constructs with the specified listener and the cache name.
* <p>
@@ -339,6 +341,7 @@
synchronized ( queueLock )
{
+ size++;
tail.next = newNode;
tail = newNode;
if ( isWorking() )
@@ -348,7 +351,10 @@
destroyed = false;
processorThread = new QProcessor( this );
processorThread.start();
- log.info( "Cache event queue created: " + this );
+ if ( log.isInfoEnabled() )
+ {
+ log.info( "Cache event queue created: " + this );
+ }
}
else
{
@@ -395,6 +401,7 @@
node.event = null;
head = node;
+ size--;
return value;
}
}
@@ -626,7 +633,6 @@
private class PutEvent
extends AbstractCacheEvent
{
-
private ICacheElement ice;
/**
@@ -715,7 +721,6 @@
private class RemoveAllEvent
extends AbstractCacheEvent
{
-
/**
* Description of the Method
* @exception IOException
@@ -746,7 +751,6 @@
private class DisposeEvent
extends AbstractCacheEvent
{
-
/**
* Called when gets to the end of the queue
* <p>
@@ -792,4 +796,13 @@
return tail == head;
}
+ /**
+ * Returns the number of elements in the queue.
+ * <p>
+ * @return number of items in the queue.
+ */
+ public int size()
+ {
+ return size;
+ }
}
Modified:
jakarta/jcs/trunk/src/java/org/apache/jcs/engine/PooledCacheEventQueue.java
URL:
http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/engine/PooledCacheEventQueue.java?rev=434585&r1=434584&r2=434585&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 Aug 24 18:09:35 2006
@@ -1,14 +1,12 @@
package org.apache.jcs.engine;
/*
- * Copyright 2001-2004 The Apache Software Foundation. Licensed under the
Apache
- * License, Version 2.0 (the "License") you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
- * or agreed to in writing, software distributed under the License is
- * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the specific language
- * governing permissions and limitations under the License.
+ * Copyright 2001-2004 The Apache Software Foundation. Licensed under the
Apache License, Version
+ * 2.0 (the "License") you may not use this file except in compliance with the
License. You may
+ * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by
+ * applicable law or agreed to in writing, software distributed under the
License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See
+ * the License for the specific language governing permissions and limitations
under the License.
*/
import java.io.IOException;
@@ -30,17 +28,14 @@
import EDU.oswego.cs.dl.util.concurrent.BoundedBuffer;
/**
- * An event queue is used to propagate ordered cache events to one and only one
- * target listener.
+ * An event queue is used to propagate ordered cache events to one and only
one target listener.
* <p>
- * This is a modified version of the experimental version. It uses a
- * PooledExecutor and a BoundedBuffer to queue up events and execute them as
- * threads become available.
+ * This is a modified version of the experimental version. It uses a
PooledExecutor and a
+ * BoundedBuffer to queue up events and execute them as threads become
available.
* <p>
- * The PooledExecutor is static, because presumably these processes will be IO
- * bound, so throwing more than a few threads at them will serve no purpose
- * other than to saturate the IO interface. In light of this, having one thread
- * per region seems unnecessary. This may prove to be false.
+ * The PooledExecutor is static, because presumably these processes will be IO
bound, so throwing
+ * more than a few threads at them will serve no purpose other than to
saturate the IO interface. In
+ * light of this, having one thread per region seems unnecessary. This may
prove to be false.
* <p>
* @author Aaron Smuts
* @author Travis Savo <[EMAIL PROTECTED]>
@@ -126,9 +121,7 @@
*/
public synchronized void stopProcessing()
{
-
destroyed = true;
-
}
/**
@@ -194,15 +187,17 @@
// TODO decide whether to shutdown or interrupt
// pool.getPool().shutdownNow();
pool.getPool().interruptAll();
- log.info( "Cache event queue destroyed: " + this );
+ if ( log.isInfoEnabled() )
+ {
+ log.info( "Cache event queue destroyed: " + this );
+ }
}
}
/**
* Constructs a PutEvent for the object and passes it to the event queue.
* <p>
- * @param ce
- * The feature to be added to the PutEvent attribute
+ * @param ce The feature to be added to the PutEvent attribute
* @exception IOException
*/
public synchronized void addPutEvent( ICacheElement ce )
@@ -222,8 +217,7 @@
}
/**
- * @param key
- * The feature to be added to the RemoveEvent attribute
+ * @param key The feature to be added to the RemoveEvent attribute
* @exception IOException
*/
public synchronized void addRemoveEvent( Serializable key )
@@ -383,8 +377,8 @@
boolean done = false;
/**
- * Main processing method for the AbstractCacheEvent object. It calls
- * the abstract doRun method that all concrete instances must
implement.
+ * Main processing method for the AbstractCacheEvent object. It calls
the abstract doRun
+ * method that all concrete instances must implement.
*/
public void run()
{
@@ -562,7 +556,6 @@
private class DisposeEvent
extends AbstractCacheEvent
{
-
/**
* Called when gets to the end of the queue
* <p>
@@ -589,8 +582,7 @@
}
/**
- * @param isWorkingArg
- * whether the queue is functional
+ * @param isWorkingArg whether the queue is functional
*/
public void setWorking( boolean isWorkingArg )
{
@@ -598,8 +590,8 @@
}
/**
- * If the Queue is using a bounded channel we can determine the size. If it
- * is zero or we can't determine the size, we return true.
+ * If the Queue is using a bounded channel we can determine the size. If
it is zero or we can't
+ * determine the size, we return true.
* <p>
* @return whether or not there are items in the queue
*/
@@ -621,5 +613,31 @@
return true;
}
}
- }
+ }
+
+ /**
+ * Returns the number of elements in the queue. If the queue cannot
determine the size
+ * accurately it will return 1.
+ * <p>
+ * @return number of items in the queue.
+ */
+ public int size()
+ {
+ if ( pool.getQueue() == null )
+ {
+ return pool.getQueue().peek() == null ? 0 : 1;
+ }
+ else
+ {
+ if ( pool.getQueue() instanceof BoundedBuffer )
+ {
+ BoundedBuffer bb = (BoundedBuffer) pool.getQueue();
+ return bb.size();
+ }
+ else
+ {
+ return 1;
+ }
+ }
+ }
}
Modified:
jakarta/jcs/trunk/src/java/org/apache/jcs/engine/behavior/ICacheEventQueue.java
URL:
http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/engine/behavior/ICacheEventQueue.java?rev=434585&r1=434584&r2=434585&view=diff
==============================================================================
---
jakarta/jcs/trunk/src/java/org/apache/jcs/engine/behavior/ICacheEventQueue.java
(original)
+++
jakarta/jcs/trunk/src/java/org/apache/jcs/engine/behavior/ICacheEventQueue.java
Thu Aug 24 18:09:35 2006
@@ -24,7 +24,6 @@
/**
* Interface for a cache event queue. An event queue is used to propagate
* ordered cache events to one and only one target listener.
- *
*/
public interface ICacheEventQueue
{
@@ -39,15 +38,15 @@
public static final int POOLED_QUEUE_TYPE = 1;
/**
- * Returnt he type of event queue we are using, either single or pooled.
- *
+ * Return the type of event queue we are using, either single or pooled.
+ * <p>
* @return
*/
public abstract int getQueueType();
/**
* Adds a feature to the PutEvent attribute of the ICacheEventQueue object
- *
+ * <p>
* @param ce
* The feature to be added to the PutEvent attribute
* @throws IOException
@@ -58,7 +57,7 @@
/**
* Adds a feature to the RemoveEvent attribute of the ICacheEventQueue
* object
- *
+ * <p>
* @param key
* The feature to be added to the RemoveEvent attribute
* @throws IOException
@@ -69,6 +68,7 @@
/**
* Adds a feature to the RemoveAllEvent attribute of the ICacheEventQueue
* object
+ * <p>
* @throws IOException
*/
public void addRemoveAllEvent()
@@ -77,6 +77,7 @@
/**
* Adds a feature to the DisposeEvent attribute of the ICacheEventQueue
* object
+ * <p>
* @throws IOException
*/
public void addDisposeEvent()
@@ -96,28 +97,36 @@
* Gets the alive attribute of the ICacheEventQueue object. Alive just
* indicates that there are active threads. This is less important that if
* the queue is working.
- *
+ * <p>
* @return The alive value
*/
public boolean isAlive();
/**
* A Queue is working unless it has reached its max failure count.
- *
+ * <p>
* @return boolean
*/
public boolean isWorking();
/**
+ * Returns the number of elements in the queue. If the queue cannot
+ * determine the size accurately it will return 1.
+ * <p>
+ * @return number of items in the queue.
+ */
+ public int size();
+
+ /**
* Are there elements in the queue.
- *
+ * <p>
* @return true if there are stil elements.
*/
public boolean isEmpty();
/**
* Returns the historical and statistical data for an event queue cache.
- *
+ * <p>
* @return
*/
public IStats getStatistics();
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]