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/09/29 03:48:48 UTC
svn commit: r292368 - in /jakarta/jcs/trunk/src:
java/org/apache/jcs/auxiliary/remote/
java/org/apache/jcs/auxiliary/remote/server/
java/org/apache/jcs/engine/control/ java/org/apache/jcs/engine/memory/lru/
scripts/ test/org/apache/jcs/engine/control/
Author: asmuts
Date: Wed Sep 28 18:48:33 2005
New Revision: 292368
URL: http://svn.apache.org/viewcvs?rev=292368&view=rev
Log:
Improved string returned from CacheManager.getStats()
Trying to get remote client shutdown working.
Started to clean up remote cache factory for stats and shutdown.
Added:
jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/TestCacheManagerStats.java
Modified:
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCache.java
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerFactory.java
jakarta/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCacheManager.java
jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/lru/LRUMemoryCache.java
jakarta/jcs/trunk/src/scripts/remoteCacheStats.bat
jakarta/jcs/trunk/src/scripts/startRemoteCache.bat
jakarta/jcs/trunk/src/scripts/stopRemoteCache.bat
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=292368&r1=292367&r2=292368&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 Wed Sep 28 18:48:33 2005
@@ -27,6 +27,7 @@
import EDU.oswego.cs.dl.util.concurrent.Callable;
import EDU.oswego.cs.dl.util.concurrent.FutureResult;
+import EDU.oswego.cs.dl.util.concurrent.ThreadFactory;
import org.apache.jcs.access.exception.ObjectNotFoundException;
import org.apache.jcs.auxiliary.AuxiliaryCacheAttributes;
@@ -109,17 +110,10 @@
if ( pool != null )
{
usePoolForGet = true;
+ pool.getPool().setThreadFactory( new MyThreadFactory() );
}
}
- /*
- * TODO should be done by the remote cache, not the job of the hub
- * manager Set up the idle period for the RemoteCacheMonitor. long
- * monPeriod = 0; try { monPeriod =
- * Long.parseLong(props.getProperty("remote.monitor.idle.period", "0")); }
- * catch(NumberFormatException ex) { log.warn(ex.getMessage()); }
- * RemoteCacheMonitor.setIdlePeriod(monPeriod);
- */
}
/**
@@ -631,4 +625,27 @@
return "RemoteCache: " + cacheName + " attributes = " + irca;
}
+ /**
+ * Allows us to set the daemon status on the clockdaemon
+ *
+ * @author aaronsm
+ *
+ */
+ class MyThreadFactory
+ implements ThreadFactory
+ {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see EDU.oswego.cs.dl.util.concurrent.ThreadFactory#newThread(java.lang.Runnable)
+ */
+ public Thread newThread( Runnable runner )
+ {
+ Thread t = new Thread( runner );
+ t.setDaemon( true );
+ return t;
+ }
+
+ }
}
Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerFactory.java?rev=292368&r1=292367&r2=292368&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerFactory.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerFactory.java Wed Sep 28 18:48:33 2005
@@ -25,12 +25,9 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-
import org.apache.jcs.auxiliary.remote.RemoteUtils;
import org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheConstants;
import org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheServiceAdmin;
-import org.apache.jcs.engine.behavior.ICacheServiceAdmin;
-import org.apache.jcs.utils.props.PropertyLoader;
/**
* Provides remote cache services.
@@ -55,6 +52,7 @@
/**
* Starts up the remote cache server on this JVM, and binds it to the
* registry on the given host and port.
+ *
* @param host
* @param port
* @param propFile
@@ -86,7 +84,7 @@
Properties prop = RemoteUtils.loadProps( propFile );
//Properties prop = PropertyLoader.loadProperties( propFile );
-
+
String servicePortStr = prop.getProperty( REMOTE_CACHE_SERVICE_PORT );
int servicePort = -1;
try
@@ -160,7 +158,7 @@
{
return;
}
- log.debug( "Unbinding host=" + host + ", port=" + port + ", serviceName=" + serviceName );
+ log.info( "Unbinding host=" + host + ", port=" + port + ", serviceName=" + serviceName );
try
{
Naming.unbind( "//" + host + ":" + port + "/" + serviceName );
@@ -202,11 +200,21 @@
{
Properties prop = args.length > 0 ? RemoteUtils.loadProps( args[args.length - 1] ) : new Properties();
+ int port;
+ try
+ {
+ port = Integer.parseInt( prop.getProperty( "registry.port" ) );
+ }
+ catch ( NumberFormatException ex )
+ {
+ port = Registry.REGISTRY_PORT;
+ }
+
// shutdown
if ( args.length > 0 && args[0].toLowerCase().indexOf( "-shutdown" ) != -1 )
{
String serviceName = prop.getProperty( REMOTE_CACHE_SERVICE_NAME, REMOTE_CACHE_SERVICE_VAL ).trim();
- String registry = "//:" + Registry.REGISTRY_PORT + "/" + serviceName;
+ String registry = "//:" + port + "/" + serviceName;
if ( log.isDebugEnabled() )
{
@@ -217,14 +225,14 @@
{
log.debug( "server found" );
}
- ICacheServiceAdmin admin = (ICacheServiceAdmin) obj;
+ IRemoteCacheServiceAdmin admin = (IRemoteCacheServiceAdmin) obj;
try
{
admin.shutdown();
}
catch ( Exception ex )
{
- log.error( ex );
+ log.error( "Problem calling shutdown.", ex );
}
log.debug( "done." );
System.exit( 0 );
@@ -238,13 +246,10 @@
try
{
-
- int port = Registry.REGISTRY_PORT;
-
- if ( args.length > 1 )
- {
- port = Integer.parseInt( args[1] );
- }
+ //if ( args.length > 1 )
+ //{
+ // port = Integer.parseInt( args[1] );
+ //}
String serviceName = prop.getProperty( REMOTE_CACHE_SERVICE_NAME, REMOTE_CACHE_SERVICE_VAL ).trim();
String registry = "//:" + port + "/" + serviceName;
@@ -268,22 +273,13 @@
}
catch ( Exception ex )
{
- log.error( ex );
+ log.error( "Problem getting stats.", ex );
}
log.debug( "done." );
System.exit( 0 );
}
// startup.
- int port;
- try
- {
- port = Integer.parseInt( prop.getProperty( "registry.port" ) );
- }
- catch ( NumberFormatException ex )
- {
- port = Registry.REGISTRY_PORT;
- }
String host = prop.getProperty( "registry.host" );
if ( host == null || host.trim().equals( "" ) || host.trim().equals( "localhost" ) )
Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCacheManager.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCacheManager.java?rev=292368&r1=292367&r2=292368&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCacheManager.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCacheManager.java Wed Sep 28 18:48:33 2005
@@ -153,6 +153,7 @@
/**
* Simple factory method, must override in subclasses so getInstance creates /
* returns the correct object.
+ * @return CompositeCacheManager
*/
protected static CompositeCacheManager createInstance()
{
@@ -481,7 +482,10 @@
}
}
- /** Returns a list of the current cache names. */
+ /**
+ * Returns a list of the current cache names.
+ * @return String[]
+ */
public String[] getCacheNames()
{
String[] list = new String[caches.size()];
@@ -499,31 +503,42 @@
return ICacheType.CACHE_HUB;
}
- /** */
+ /**
+ * @return ICompositeCacheAttributes
+ */
public ICompositeCacheAttributes getDefaultCattr()
{
return this.defaultCacheAttr;
}
- /** */
+ /**
+ */
void registryFacPut( AuxiliaryCacheFactory auxFac )
{
auxFacs.put( auxFac.getName(), auxFac );
}
- /** */
+ /**
+ * @param name
+ * @return AuxiliaryCacheFactory
+ */
AuxiliaryCacheFactory registryFacGet( String name )
{
return (AuxiliaryCacheFactory) auxFacs.get( name );
}
- /** */
+ /**
+ * @param auxAttr
+ */
void registryAttrPut( AuxiliaryCacheAttributes auxAttr )
{
auxAttrs.put( auxAttr.getName(), auxAttr );
}
- /** */
+ /**
+ * @param name
+ * @return AuxiliaryCacheAttributes
+ */
AuxiliaryCacheAttributes registryAttrGet( String name )
{
return (AuxiliaryCacheAttributes) auxAttrs.get( name );
@@ -536,11 +551,24 @@
*/
public String getStats()
{
- return getStatistics().toString();
+ ICacheStats[] stats = getStatistics();
+ if ( stats == null )
+ {
+ return "NONE";
+ }
+
+ // force the array elements into a string.
+ StringBuffer buf = new StringBuffer();
+ int statsLen = stats.length;
+ for ( int i = 0; i < statsLen; i++ )
+ {
+ buf.append( stats[i] );
+ }
+ return buf.toString();
}
/**
- * This returns data gathered for all region and all the auxiliaries they
+ * This returns data gathered for all regions and all the auxiliaries they
* currently uses.
*
* @return
@@ -564,7 +592,7 @@
/**
* Perhaps the composite cache itself should be the observable object. It
* doesn't make much of a difference. There are some problems with region by
- * region shutdown. Some auxiliaries are glocal. They will need to track
+ * region shutdown. Some auxiliaries are global. They will need to track
* when every region has shutdown before doing things like closing the
* socket with a lateral.
*
Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/lru/LRUMemoryCache.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/lru/LRUMemoryCache.java?rev=292368&r1=292367&r2=292368&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/lru/LRUMemoryCache.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/lru/LRUMemoryCache.java Wed Sep 28 18:48:33 2005
@@ -43,10 +43,14 @@
* A fast reference management system. The least recently used items move to the
* end of the list and get spooled to disk if the cache hub is configured to use
* a disk cache. Most of the cache bottelnecks are in IO. There are no io
- * bottlenecks here, it's all about processing power. Even though there are only
+ * bottlenecks here, it's all about processing power.
+ * <p>
+ * Even though there are only
* a few adjustments necessary to maintain the double linked list, we might want
- * to find a more efficient memory manager for large cache regions. The
- * LRUMemoryCache is most efficeint when the first element is selected. The
+ * to find a more efficient memory manager for large cache regions.
+ * <p>
+ * The
+ * LRUMemoryCache is most efficient when the first element is selected. The
* smaller the region, the better the chance that this will be the case. < .04
* ms per put, p3 866, 1/10 of that per get
*
@@ -67,7 +71,7 @@
int putCnt = 0;
/**
- * For post reflection creation initialization
+ * For post reflection creation initialization.
*
* @param hub
*/
@@ -79,10 +83,13 @@
}
/**
- * Puts an item to the cache.
+ * Puts an item to the cache. Removes any pre-existing entries of the same key from the
+ * linked list and adds this one first.
+ * <p>
+ * If the max size is reached, an element will be put to disk.
*
* @param ce
- * Description of the Parameter
+ * The cache element, or entry wrapper
* @exception IOException
*/
public void update( ICacheElement ce )
@@ -333,6 +340,7 @@
/**
* Remove all of the elements from both the Map and the linked list
* implementation. Overrides base class.
+ * @throws IOException
*/
public synchronized void removeAll()
throws IOException
Modified: jakarta/jcs/trunk/src/scripts/remoteCacheStats.bat
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/scripts/remoteCacheStats.bat?rev=292368&r1=292367&r2=292368&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/scripts/remoteCacheStats.bat (original)
+++ jakarta/jcs/trunk/src/scripts/remoteCacheStats.bat Wed Sep 28 18:48:33 2005
@@ -4,7 +4,7 @@
:run
rem set DBUGPARM=-classic -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,address=5000,suspend=n
-%JAVA_HOME%\bin\java %DBUGPARM% -ms10m -mx20m -classpath %CLASSPATH% "-Djava.security.policy=%CURDIR%\src\conf\cache.policy" org.apache.jcs.auxiliary.remote.server.RemoteCacheServerFactory -stats 1101 /remote.cache%1.ccf
+%JAVA_HOME%\bin\java %DBUGPARM% -ms10m -mx20m -classpath %CLASSPATH% "-Djava.security.policy=%CURDIR%\src\conf\cache.policy" org.apache.jcs.auxiliary.remote.server.RemoteCacheServerFactory -stats /remote.cache%1.ccf
Modified: jakarta/jcs/trunk/src/scripts/startRemoteCache.bat
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/scripts/startRemoteCache.bat?rev=292368&r1=292367&r2=292368&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/scripts/startRemoteCache.bat (original)
+++ jakarta/jcs/trunk/src/scripts/startRemoteCache.bat Wed Sep 28 18:48:33 2005
@@ -4,6 +4,6 @@
:run
rem set DBUGPARM=-classic -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,address=5000,suspend=n
-%JAVA_HOME%\bin\java %DBUGPARM% -verbosegc -ms10m -mx200m -classpath %CLASSPATH% "-Djava.security.policy=%CURDIR%\src\conf\cache.policy" org.apache.jcs.auxiliary.remote.server.RemoteCacheServerFactory /remote.cache%1.ccf
+%JAVA_HOME%\bin\java %DBUGPARM% -verbosegc -XX:+PrintTenuringDistribution -ms10m -mx200m -classpath %CLASSPATH% "-Djava.security.policy=%CURDIR%\src\conf\cache.policy" org.apache.jcs.auxiliary.remote.server.RemoteCacheServerFactory /remote.cache%1.ccf
Modified: jakarta/jcs/trunk/src/scripts/stopRemoteCache.bat
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/scripts/stopRemoteCache.bat?rev=292368&r1=292367&r2=292368&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/scripts/stopRemoteCache.bat (original)
+++ jakarta/jcs/trunk/src/scripts/stopRemoteCache.bat Wed Sep 28 18:48:33 2005
@@ -3,7 +3,7 @@
call prep.bat
:run
-rem org.apache.jcs.remote.group.RemoteGroupCacheServerFactory
+rem org.apache.jcs.auxiliary.remote.server.RemoteCacheServerFactory
rem set DBUGPARM=-classic -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,address=5000,suspend=n
-%JAVA_HOME%\bin\java %DBUGPARM% -ms1m -mx20m -classpath %CLASSPATH% "-Djava.security.policy=C:/dev/cache/props/cache.policy" org.apache.jcs.auxiliary.remote.server.group.RemoteGroupCacheServerFactory -shutdown 1102 /remote.cache.properties
+%JAVA_HOME%\bin\java %DBUGPARM% -ms1m -mx20m -classpath %CLASSPATH% "-Djava.security.policy=C:/dev/cache/props/cache.policy" org.apache.jcs.auxiliary.remote.server.RemoteCacheServerFactory -shutdown /remote.cache.ccf
Added: jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/TestCacheManagerStats.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/TestCacheManagerStats.java?rev=292368&view=auto
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/TestCacheManagerStats.java (added)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/TestCacheManagerStats.java Wed Sep 28 18:48:33 2005
@@ -0,0 +1,57 @@
+package org.apache.jcs.engine.control;
+
+/*
+ * 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.JCS;
+import org.apache.jcs.engine.stats.behavior.ICacheStats;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Aaron Smuts
+ *
+ */
+public class TestCacheManagerStats
+ extends TestCase
+{
+
+ public void testSimpleGetStats() throws Exception
+ {
+ JCS cache = JCS.getInstance( "testCache1" );
+
+ // 1 miss, 1 hit, 1 put
+ cache.get( "testKey" );
+ cache.put( "testkey", "testdata" );
+ cache.get( "testKey" );
+
+ CompositeCacheManager mgr = CompositeCacheManager.getInstance();
+ String statsString = mgr.getStats();
+
+ System.out.println( statsString );
+
+ assertTrue( "Should have the cacheName in here.", statsString.indexOf("testCache1") != -1 );
+
+ ICacheStats[] stats = mgr.getStatistics();
+ int statsLen = stats.length;
+ for ( int i = 0; i < statsLen; i++ )
+ {
+ //buf.append( stats[i] );
+ // TODO finish
+ }
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-dev-help@jakarta.apache.org