You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jcs-dev@jakarta.apache.org by as...@apache.org on 2005/01/06 02:18:28 UTC
cvs commit: jakarta-turbine-jcs/src/java/org/apache/jcs/engine/stats/behavior ICacheStats.java
asmuts 2005/01/05 17:18:27
Modified: src/java/org/apache/jcs/engine CacheEventQueue.java
src/java/org/apache/jcs/engine/control CompositeCache.java
CompositeCacheManager.java
src/java/org/apache/jcs/engine/behavior
ICacheEventQueue.java
Added: src/java/org/apache/jcs/engine/stats CacheStats.java
src/java/org/apache/jcs/engine/stats/behavior
ICacheStats.java
Removed: src/experimental/org/apache/jcs/engine CacheEventQueue.java
Log:
1. Put in a solution for the RMI bug. Now, gets can be done asynchronously with a configurable timeout.
You can specify that your remote region should timeout gets.
#-1 means no timeout, this is the default
# if the timeout is -1, no threadpool will be used.
jcs.auxiliary.RC.attributes.GetTimeoutMillis=5000
jcs.auxiliary.RC.attributes.ThreadPoolName=remote_cache_client
Here RC is my auxiliary name. I tell it to time out at 5 seconds and to use the thread pool named remote_cache_client.
You can define pools in the file. Below I define defaults for a thread pool and the settings for the pool I want the remote cache
client to use.
If the timeout is less than 0, no threadpool will be used.
##############################################################
################## THREAD POOL CONFIGURATION ###################
# default thread pool config
thread_pool.default.boundarySize=75
thread_pool.default.maximumPoolSize=150
thread_pool.default.minimumPoolSize=4
thread_pool.default.keepAliveTime=350000
thread_pool.default.abortWhenBlocked=false
thread_pool.default.startUpSize=4
# remote cache client thread pool config
thread_pool.remote_cache_client.boundarySize=75
thread_pool.remote_cache_client.maximumPoolSize=150
thread_pool.remote_cache_client.minimumPoolSize=4
thread_pool.remote_cache_client.keepAliveTime=350000
thread_pool.remote_cache_client.abortWhenBlocked=false
thread_pool.remote_cache_client.startUpSize=4
2. Changed stats gathering mechanism. I will update the admin jsp to make use of the
more easily formattable data.
Revision Changes Path
1.13 +44 -13 jakarta-turbine-jcs/src/java/org/apache/jcs/engine/CacheEventQueue.java
Index: CacheEventQueue.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-jcs/src/java/org/apache/jcs/engine/CacheEventQueue.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- CacheEventQueue.java 4 Jan 2005 21:13:53 -0000 1.12
+++ CacheEventQueue.java 6 Jan 2005 01:18:27 -0000 1.13
@@ -18,12 +18,17 @@
import java.io.IOException;
import java.io.Serializable;
+import java.util.ArrayList;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.jcs.engine.behavior.ICacheElement;
import org.apache.jcs.engine.behavior.ICacheEventQueue;
import org.apache.jcs.engine.behavior.ICacheListener;
+import org.apache.jcs.engine.stats.StatElement;
+import org.apache.jcs.engine.stats.Stats;
+import org.apache.jcs.engine.stats.behavior.IStatElement;
+import org.apache.jcs.engine.stats.behavior.IStats;
/**
* An event queue is used to propagate ordered cache events to one and only one
@@ -349,15 +354,33 @@
}
}
-
- public String getStats()
- {
- StringBuffer buf = new StringBuffer();
- buf.append( "\n -------------------------" );
- buf.append( "\n Cache Event Queue:" );
- buf.append( "\n working = " + this.working );
- buf.append( "\n isAlive() = " + this.isAlive() );
- buf.append( "\n isEmpty() = " + this.isEmpty() );
+ /*
+ * (non-Javadoc)
+ * @see org.apache.jcs.engine.behavior.ICacheEventQueue#getStatistics()
+ */
+ public IStats getStatistics()
+ {
+ IStats stats = new Stats();
+ stats.setTypeName( "Cache Event Queue" );
+
+ ArrayList elems = new ArrayList();
+
+ IStatElement se = null;
+
+ se = new StatElement();
+ se.setName( "Working" );
+ se.setData("" + this.working);
+ elems.add(se);
+
+ se.setName( "Alive" );
+ se = new StatElement();
+ se.setData("" + this.isAlive());
+ elems.add(se);
+
+ se.setName( "Empty" );
+ se = new StatElement();
+ se.setData("" + this.isEmpty());
+ elems.add(se);
int size = 0;
synchronized (queueLock)
@@ -377,12 +400,20 @@
}
}
- buf.append( "\n size = " + size );
+ se.setName( "Size" );
+ se = new StatElement();
+ se.setData("" + size);
+ elems.add(se);
}
- return buf.toString();
- }
-
+ // get an array and put them in the Stats object
+ IStatElement[] ses = (IStatElement[])elems.toArray( new StatElement[0] );
+ stats.setStatElements( ses );
+
+ return stats;
+ }
+
+
///////////////////////////// Inner classes /////////////////////////////
private static class Node
1.1 jakarta-turbine-jcs/src/java/org/apache/jcs/engine/stats/CacheStats.java
Index: CacheStats.java
===================================================================
package org.apache.jcs.engine.stats;
/*
* 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 org.apache.jcs.engine.stats.behavior.ICacheStats;
import org.apache.jcs.engine.stats.behavior.IStatElement;
import org.apache.jcs.engine.stats.behavior.IStats;
/**
* This class stores cache historical and statistics data for a region.
*
* Only the composite cache knows what the hit count across all auxiliaries is.
*
* @author aaronsm
*
*/
public class CacheStats extends Stats implements ICacheStats {
private String regionName = null;
private IStats[] auxStats = null;
private IStatElement[] stats = null;
/*
* (non-Javadoc)
*
* @see org.apache.jcs.engine.stats.behavior.ICacheStats#getRegionName()
*/
public String getRegionName() {
return regionName;
}
/*
* (non-Javadoc)
*
* @see org.apache.jcs.engine.stats.behavior.ICacheStats#setRegionName(java.lang.String)
*/
public void setRegionName(String name) {
regionName = name;
}
/*
* (non-Javadoc)
*
* @see org.apache.jcs.engine.stats.behavior.ICacheStats#getAuxiliaryCacheStats()
*/
public IStats[] getAuxiliaryCacheStats() {
return auxStats;
}
/*
* (non-Javadoc)
*
* @see org.apache.jcs.engine.stats.behavior.ICacheStats#setAuxiliaryCacheStats(org.apache.jcs.engine.stats.behavior.IAuxiliaryCacheStats[])
*/
public void setAuxiliaryCacheStats(IStats[] stats) {
auxStats = stats;
}
/**
* This returns data about the auxiliaries, such as hit count. Only the
* composite cache knows what the hit count across all auxiliaries is.
*/
public IStatElement[] getStatElements() {
return stats;
}
/*
* (non-Javadoc)
*
* @see org.apache.jcs.engine.stats.behavior.IStats#setStatElements(org.apache.jcs.engine.stats.behavior.IStatElement[])
*/
public void setStatElements(IStatElement[] stats) {
this.stats = stats;
}
/*
* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public String toString()
{
StringBuffer buf = new StringBuffer();
buf.append( "Region Name = " + regionName );
if ( stats != null )
{
for( int i = 0; i < stats.length; i++ )
{
buf.append( "\n" );
buf.append( stats[i] );
}
}
if ( auxStats != null )
{
for( int i = 0; i < auxStats.length; i++ )
{
buf.append( "\n" );
buf.append( "---------------------------" );
buf.append( auxStats[i] );
}
}
return buf.toString();
}
}
1.17 +52 -17 jakarta-turbine-jcs/src/java/org/apache/jcs/engine/control/CompositeCache.java
Index: CompositeCache.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-jcs/src/java/org/apache/jcs/engine/control/CompositeCache.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- CompositeCache.java 16 Jul 2004 01:29:07 -0000 1.16
+++ CompositeCache.java 6 Jan 2005 01:18:27 -0000 1.17
@@ -21,6 +21,7 @@
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
@@ -41,6 +42,12 @@
import org.apache.jcs.engine.memory.MemoryCache;
import org.apache.jcs.engine.memory.lru.LRUMemoryCache;
+import org.apache.jcs.engine.stats.CacheStats;
+import org.apache.jcs.engine.stats.StatElement;
+import org.apache.jcs.engine.stats.Stats;
+import org.apache.jcs.engine.stats.behavior.ICacheStats;
+import org.apache.jcs.engine.stats.behavior.IStatElement;
+import org.apache.jcs.engine.stats.behavior.IStats;
import org.apache.jcs.engine.control.event.ElementEvent;
import org.apache.jcs.engine.control.event.behavior.IElementEventHandler;
@@ -991,24 +998,52 @@
* @return String
*/
public String getStats()
- {
- StringBuffer buf = new StringBuffer();
- buf.append( "\n -------------------------" );
- buf.append( "\n Composite Cache:" );
- buf.append("\n HitCountRam = " + getHitCountRam());
- buf.append("\n HitCountAux = " + getHitCountAux());
-
- buf.append(getMemoryCache().getStats());
-
- for ( int i = 0; i < auxCaches.length; i++ )
- {
- ICache aux = auxCaches[i];
- buf.append(aux.getStats());
- }
+ {
+ return getStatistics().toString();
+ }
- return buf.toString();
+ /**
+ * This returns data gathered for this region and all the
+ * auxiliaries it currently uses.
+ *
+ * @return
+ */
+ public ICacheStats getStatistics()
+ {
+ ICacheStats stats = new CacheStats();
+ stats.setRegionName( this.getCacheName() );
+
+ // store the composite cache stats first
+ IStatElement[] elems = new StatElement[2];
+ elems[0] = new StatElement();
+ elems[0].setName( "HitCountRam" );
+ elems[0].setData( "" + getHitCountRam() );
+
+ elems[1] = new StatElement();
+ elems[1].setName( "HitCountAux" );
+ elems[1].setData( "" + getHitCountAux() );
+
+ // store these local stats
+ stats.setStatElements( elems );
+
+ // memory + aux, memory is not considered an auxiliary internally
+ int total = auxCaches.length + 1;
+ IStats[] auxStats = new Stats[total];
+
+ auxStats[0] = getMemoryCache().getStatistics();
+
+ for ( int i = 0; i < auxCaches.length; i++ )
+ {
+ AuxiliaryCache aux = auxCaches[i];
+ auxStats[i + 1] = aux.getStatistics();
+ }
+
+ // sore the auxiliary stats
+ stats.setAuxiliaryCacheStats( auxStats );
+
+ return stats;
}
-
+
/**
* Gets the cacheName attribute of the Cache object
1.11 +7 -18 jakarta-turbine-jcs/src/java/org/apache/jcs/engine/control/CompositeCacheManager.java
Index: CompositeCacheManager.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-jcs/src/java/org/apache/jcs/engine/control/CompositeCacheManager.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- CompositeCacheManager.java 10 Jul 2004 03:53:39 -0000 1.10
+++ CompositeCacheManager.java 6 Jan 2005 01:18:27 -0000 1.11
@@ -37,6 +37,7 @@
import org.apache.jcs.engine.behavior.ICacheType;
import org.apache.jcs.engine.behavior.ICompositeCacheAttributes;
import org.apache.jcs.engine.behavior.IElementAttributes;
+import org.apache.jcs.utils.threadpool.ThreadPoolManager;
/** Manages a composite cache. */
public class CompositeCacheManager
@@ -116,6 +117,7 @@
/**
* Get a CacheHub instance which is not configured.
+ * If an instance already exists, it will be returned.
*/
public static synchronized CompositeCacheManager getUnconfiguredInstance()
{
@@ -197,28 +199,15 @@
*/
public void configure( Properties props )
{
- // FIXME: need to do something for defaults
- // create a default entry in the propsfile
- // setDefaults( props );
-
+ // set the props value and then configure the ThreadPoolManager
+ ThreadPoolManager.setProps( props );
+ ThreadPoolManager poolMgr = ThreadPoolManager.getInstance();
+
+ // configure the cache
CompositeCacheConfigurator configurator =
new CompositeCacheConfigurator( this );
configurator.doConfigure( props );
-
- // FIXME: Supposedly neither of these can be thrown from the above code,
- // are they safe to remove? Or should the go elsewhere?
- //
- // catch ( IOException ex )
- // {
- // log.error( "Failed to create caches", ex );
- // throw new IllegalStateException( ex.getMessage() );
- // }
- // catch ( NotBoundException ex )
- // {
- // log.error( "Failed to create caches", ex );
- // throw new IllegalStateException( ex.getMessage() );
- // }
}
/**
1.6 +6 -6 jakarta-turbine-jcs/src/java/org/apache/jcs/engine/behavior/ICacheEventQueue.java
Index: ICacheEventQueue.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-jcs/src/java/org/apache/jcs/engine/behavior/ICacheEventQueue.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ICacheEventQueue.java 16 Jul 2004 01:28:42 -0000 1.5
+++ ICacheEventQueue.java 6 Jan 2005 01:18:27 -0000 1.6
@@ -21,6 +21,8 @@
import java.io.IOException;
import java.io.Serializable;
+import org.apache.jcs.engine.stats.behavior.IStats;
+
/**
* Interface for a cache event queue. An event queue is used to propagate
* ordered cache events to one and only one target listener.
@@ -84,12 +86,10 @@
public boolean isAlive();
/**
- * Returns debugin stats info.
- *
- * @return String
+ * Returns the historical and statistical data for an event queue cache.
+ *
+ * @return
*/
- public String getStats();
-
-
+ public IStats getStatistics();
}
1.1 jakarta-turbine-jcs/src/java/org/apache/jcs/engine/stats/behavior/ICacheStats.java
Index: ICacheStats.java
===================================================================
package org.apache.jcs.engine.stats.behavior;
/*
* 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.
*/
/**
* This holds stat information on a region.
*
* @author aaronsm
*
*/
public interface ICacheStats extends IStats {
/**
*
* @return
*/
public abstract String getRegionName();
/**
*
* @param name
*/
public abstract void setRegionName( String name );
/**
*
* @return
*/
public abstract IStats[] getAuxiliaryCacheStats();
/**
*
* @param stats
*/
public abstract void setAuxiliaryCacheStats(IStats[] stats);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-jcs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-jcs-dev-help@jakarta.apache.org