You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by jm...@apache.org on 2002/04/02 20:41:29 UTC
cvs commit: jakarta-turbine-torque/src/java/org/apache/torque/manager MethodCacheKey.java MethodResultCache.java
jmcnally 02/04/02 10:41:29
Modified: . build.xml default.properties
src/java/org/apache/torque/manager MethodCacheKey.java
MethodResultCache.java
Log:
switch to use the commons pool instead of the one in stratum.
Revision Changes Path
1.38 +16 -1 jakarta-turbine-torque/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-turbine-torque/build.xml,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- build.xml 6 Mar 2002 19:01:48 -0000 1.37
+++ build.xml 2 Apr 2002 18:41:29 -0000 1.38
@@ -19,6 +19,7 @@
<pathelement location="${log4j.jar}"/>
<pathelement location="${commons-collections.jar}"/>
<pathelement location="${commons-lang.jar}"/>
+ <pathelement location="${commons-pool.jar}"/>
<pathelement location="${junit.jar}"/>
<pathelement location="${stratum.jar}"/>
<pathelement location="tdk.jar"/>
@@ -66,6 +67,7 @@
<echo message="junit.jar = ${junit.jar}"/>
<echo message="commons-collections.jar = ${commons-collections.jar}"/>
<echo message="commons-lang.jar = ${commons-lang.jar}"/>
+ <echo message="commons-pool.jar = ${commons-pool.jar}"/>
<echo message="stratum.jar = ${stratum.jar}"/>
</target>
@@ -147,6 +149,12 @@
/>
<available
+ classname="org.apache.commons.pool.ObjectPool"
+ property="commons-pool.present"
+ classpathref="classpath"
+ />
+
+ <available
classname="org.apache.stratum.configuration.Configuration"
property="stratum.present"
classpathref="classpath"
@@ -242,6 +250,13 @@
</antcall>
</target>
+ <target name="check.commons-pool" unless="commons-pool.present">
+ <antcall target="property-warning">
+ <param name="name" value="commons-pool.jar"/>
+ <param name="value" value="${commons-pool.jar}"/>
+ </antcall>
+ </target>
+
<target
name="check.stratum"
unless="stratum.present">
@@ -288,7 +303,7 @@
name="prepare"
depends="init,check.velocity,check.xerces,check.village,
check.log4j,check.commons-collections,check.commons-lang,
- check.stratum,check.jdbc,env">
+ check.stratum,check.commons-pool,check.jdbc,env">
<mkdir dir="${build.dir}"/>
<mkdir dir="${build.dest}"/>
1.21 +1 -0 jakarta-turbine-torque/default.properties
Index: default.properties
===================================================================
RCS file: /home/cvs/jakarta-turbine-torque/default.properties,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- default.properties 20 Mar 2002 15:16:17 -0000 1.20
+++ default.properties 2 Apr 2002 18:41:29 -0000 1.21
@@ -53,6 +53,7 @@
log4j.jar = ${lib.repo}/log4j-1.1.3.jar
commons-collections.jar = ${lib.repo}/commons-collections.jar
commons-lang.jar = ${lib.repo}/commons-lang-0.1-dev.jar
+commons-pool.jar = ${lib.repo}/commons-pool.jar
jdbc.jar = ${lib.repo}/jdbc2_0-stdext.jar
junit.jar = ${lib.repo}/junit-3.7.jar
stratum.jar = ${lib.repo}/stratum-1.0-b2-dev.jar
1.3 +30 -17 jakarta-turbine-torque/src/java/org/apache/torque/manager/MethodCacheKey.java
Index: MethodCacheKey.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/manager/MethodCacheKey.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- MethodCacheKey.java 27 Mar 2002 23:54:54 -0000 1.2
+++ MethodCacheKey.java 2 Apr 2002 18:41:29 -0000 1.3
@@ -49,10 +49,9 @@
import java.io.Serializable;
import org.apache.commons.lang.Objects;
import org.apache.log4j.Category;
-import org.apache.stratum.pool.AbstractPoolable;
+import org.apache.commons.pool.BasePoolableObjectFactory;
public class MethodCacheKey
- extends AbstractPoolable
implements Serializable
{
//private static final Category log =
@@ -296,22 +295,36 @@
return sb.toString();
}
- // ****************** Poolable implementation ************************
+ // ************* PoolableObjectFactory implementation *******************
- /**
- * Disposes the object after use. The method is called when the
- * object is returned to its pool. The dispose method must call
- * its super.
- */
- public void dispose()
+ public static class Factory
+ extends BasePoolableObjectFactory
{
- super.dispose();
- instanceOrClass = null;
- method = null;
- arg1 = null;
- arg2 = null;
- arg3 = null;
- moreThanThree = null;
- groupKey = null;
+ /**
+ * Creates an instance that can be returned by the pool.
+ * @return an instance that can be returned by the pool.
+ */
+ public Object makeObject()
+ throws Exception
+ {
+ return new MethodCacheKey();
+ }
+
+ /**
+ * Uninitialize an instance to be returned to the pool.
+ * @param obj the instance to be passivated
+ */
+ public void passivateObject(Object obj)
+ throws Exception
+ {
+ MethodCacheKey key = (MethodCacheKey)obj;
+ key.instanceOrClass = null;
+ key.method = null;
+ key.arg1 = null;
+ key.arg2 = null;
+ key.arg3 = null;
+ key.moreThanThree = null;
+ key.groupKey = null;
+ }
}
}
1.3 +150 -46 jakarta-turbine-torque/src/java/org/apache/torque/manager/MethodResultCache.java
Index: MethodResultCache.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/manager/MethodResultCache.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- MethodResultCache.java 27 Mar 2002 23:54:54 -0000 1.2
+++ MethodResultCache.java 2 Apr 2002 18:41:29 -0000 1.3
@@ -52,10 +52,11 @@
import java.util.Iterator;
import java.io.Serializable;
import org.apache.log4j.Category;
-//import org.apache.stratum.configuration.Configuration;
-import org.apache.stratum.pool.DefaultPoolManager;
import org.apache.stratum.jcs.access.GroupCacheAccess;
import org.apache.stratum.jcs.access.exception.CacheException;
+import org.apache.commons.pool.PoolableObjectFactory;
+import org.apache.commons.pool.ObjectPool;
+import org.apache.commons.pool.impl.StackObjectPool;
import org.apache.torque.TorqueException;
@@ -63,7 +64,7 @@
* This class provides a cache for convenient storage of method results
*
* @author <a href="mailto:jmcnally@collab.net">John McNally</a>
- * @version $Id: MethodResultCache.java,v 1.2 2002/03/27 23:54:54 jmcnally Exp $
+ * @version $Id: MethodResultCache.java,v 1.3 2002/04/02 18:41:29 jmcnally Exp $
*/
public class MethodResultCache
{
@@ -72,31 +73,30 @@
private static final String keyClassName =
"org.apache.torque.manager.MethodCacheKey";
- private DefaultPoolManager pool;
+ private ObjectPool pool;
private Map keys;
private GroupCacheAccess jcsCache;
- private Class keyClass;
private boolean lockCache;
private int inGet;
private Map groups;
- /*
- public MethodResultCache()
- {
- keyClass = Class
- .forName(keyClassName);
- }
- */
-
public MethodResultCache(GroupCacheAccess cache)
- throws ClassNotFoundException
+ throws TorqueException
{
keys = new WeakHashMap();
- keyClass = Class.forName(keyClassName);
this.jcsCache = cache;
- pool = new DefaultPoolManager();
- pool.setCapacity(keyClassName, 10000);
groups = new HashMap();
+
+ try
+ {
+ PoolableObjectFactory factory =
+ new MethodCacheKey.Factory();
+ pool = new StackObjectPool(factory, 10000);
+ }
+ catch (Exception e)
+ {
+ throw new TorqueException(e);
+ }
}
public void clear()
@@ -111,7 +111,15 @@
Iterator i = keys.keySet().iterator();
while (i.hasNext())
{
- pool.putInstance(i.next());
+ try
+ {
+ pool.returnObject(i.next());
+ }
+ catch (Exception e)
+ {
+ log.warn(
+ "Nonfatal error. Could not return key to pool", e);
+ }
}
keys.clear();
}
@@ -223,7 +231,15 @@
Thread.yield();
}
jcsCache.remove(key, key.getGroupKey());
- pool.putInstance(key);
+ try
+ {
+ pool.returnObject(key);
+ }
+ catch (Exception e)
+ {
+ log.warn(
+ "Nonfatal error. Could not return key to pool", e);
+ }
}
// jcs does not throw an exception here, might remove this
catch (Exception ce)
@@ -250,10 +266,18 @@
try
{
MethodCacheKey key =
- (MethodCacheKey)pool.getInstance(keyClass);
+ (MethodCacheKey)pool.borrowObject();
key.init(instanceOrClass, method);
result = getImpl(key);
- pool.putInstance(key);
+ try
+ {
+ pool.returnObject(key);
+ }
+ catch (Exception e)
+ {
+ log.warn(
+ "Nonfatal error. Could not return key to pool", e);
+ }
}
catch (Exception e)
{
@@ -272,10 +296,18 @@
try
{
MethodCacheKey key =
- (MethodCacheKey)pool.getInstance(keyClass);
+ (MethodCacheKey)pool.borrowObject();
key.init(instanceOrClass, method, arg1);
result = getImpl(key);
- pool.putInstance(key);
+ try
+ {
+ pool.returnObject(key);
+ }
+ catch (Exception e)
+ {
+ log.warn(
+ "Nonfatal error. Could not return key to pool", e);
+ }
}
catch (Exception e)
{
@@ -294,10 +326,18 @@
try
{
MethodCacheKey key =
- (MethodCacheKey)pool.getInstance(keyClass);
+ (MethodCacheKey)pool.borrowObject();
key.init(instanceOrClass, method, arg1, arg2);
result = getImpl(key);
- pool.putInstance(key);
+ try
+ {
+ pool.returnObject(key);
+ }
+ catch (Exception e)
+ {
+ log.warn(
+ "Nonfatal error. Could not return key to pool", e);
+ }
}
catch (Exception e)
{
@@ -317,10 +357,18 @@
try
{
MethodCacheKey key =
- (MethodCacheKey)pool.getInstance(keyClass);
+ (MethodCacheKey)pool.borrowObject();
key.init(instanceOrClass, method, arg1, arg2, arg3);
result = getImpl(key);
- pool.putInstance(key);
+ try
+ {
+ pool.returnObject(key);
+ }
+ catch (Exception e)
+ {
+ log.warn(
+ "Nonfatal error. Could not return key to pool", e);
+ }
}
catch (Exception e)
{
@@ -338,10 +386,18 @@
try
{
MethodCacheKey key =
- (MethodCacheKey)pool.getInstance(keyClass);
+ (MethodCacheKey)pool.borrowObject();
key.init(keys);
result = getImpl(key);
- pool.putInstance(key);
+ try
+ {
+ pool.returnObject(key);
+ }
+ catch (Exception e)
+ {
+ log.warn(
+ "Nonfatal error. Could not return key to pool", e);
+ }
}
catch (Exception e)
{
@@ -356,7 +412,7 @@
try
{
MethodCacheKey key =
- (MethodCacheKey)pool.getInstance(keyClass);
+ (MethodCacheKey)pool.borrowObject();
key.init(instanceOrClass, method);
putImpl(key, value);
}
@@ -372,7 +428,7 @@
try
{
MethodCacheKey key =
- (MethodCacheKey)pool.getInstance(keyClass);
+ (MethodCacheKey)pool.borrowObject();
key.init(instanceOrClass, method, arg1);
putImpl(key, value);
}
@@ -388,7 +444,7 @@
try
{
MethodCacheKey key =
- (MethodCacheKey)pool.getInstance(keyClass);
+ (MethodCacheKey)pool.borrowObject();
key.init(instanceOrClass, method, arg1, arg2);
putImpl(key, value);
}
@@ -404,7 +460,7 @@
try
{
MethodCacheKey key =
- (MethodCacheKey)pool.getInstance(keyClass);
+ (MethodCacheKey)pool.borrowObject();
key.init(instanceOrClass, method, arg1, arg2, arg3);
putImpl(key, value);
}
@@ -419,7 +475,7 @@
try
{
MethodCacheKey key =
- (MethodCacheKey)pool.getInstance(keyClass);
+ (MethodCacheKey)pool.borrowObject();
key.init(keys);
putImpl(key, value);
}
@@ -437,10 +493,18 @@
try
{
MethodCacheKey key =
- (MethodCacheKey)pool.getInstance(keyClass);
+ (MethodCacheKey)pool.borrowObject();
key.init(instanceOrClass, method);
jcsCache.invalidateGroup(key.getGroupKey());
- pool.putInstance(key);
+ try
+ {
+ pool.returnObject(key);
+ }
+ catch (Exception e)
+ {
+ log.warn(
+ "Nonfatal error. Could not return key to pool", e);
+ }
}
catch (Exception e)
{
@@ -458,10 +522,18 @@
try
{
MethodCacheKey key =
- (MethodCacheKey)pool.getInstance(keyClass);
+ (MethodCacheKey)pool.borrowObject();
key.init(instanceOrClass, method);
result = removeImpl(key);
- pool.putInstance(key);
+ try
+ {
+ pool.returnObject(key);
+ }
+ catch (Exception e)
+ {
+ log.warn(
+ "Nonfatal error. Could not return key to pool", e);
+ }
}
catch (Exception e)
{
@@ -480,10 +552,18 @@
try
{
MethodCacheKey key =
- (MethodCacheKey)pool.getInstance(keyClass);
+ (MethodCacheKey)pool.borrowObject();
key.init(instanceOrClass, method, arg1);
result = removeImpl(key);
- pool.putInstance(key);
+ try
+ {
+ pool.returnObject(key);
+ }
+ catch (Exception e)
+ {
+ log.warn(
+ "Nonfatal error. Could not return key to pool", e);
+ }
}
catch (Exception e)
{
@@ -502,10 +582,18 @@
try
{
MethodCacheKey key =
- (MethodCacheKey)pool.getInstance(keyClass);
+ (MethodCacheKey)pool.borrowObject();
key.init(instanceOrClass, method, arg1, arg2);
result = removeImpl(key);
- pool.putInstance(key);
+ try
+ {
+ pool.returnObject(key);
+ }
+ catch (Exception e)
+ {
+ log.warn(
+ "Nonfatal error. Could not return key to pool", e);
+ }
}
catch (Exception e)
{
@@ -525,10 +613,18 @@
try
{
MethodCacheKey key =
- (MethodCacheKey)pool.getInstance(keyClass);
+ (MethodCacheKey)pool.borrowObject();
key.init(instanceOrClass, method, arg1, arg2, arg3);
result = removeImpl(key);
- pool.putInstance(key);
+ try
+ {
+ pool.returnObject(key);
+ }
+ catch (Exception e)
+ {
+ log.warn(
+ "Nonfatal error. Could not return key to pool", e);
+ }
}
catch (Exception e)
{
@@ -546,10 +642,18 @@
try
{
MethodCacheKey key =
- (MethodCacheKey)pool.getInstance(keyClass);
+ (MethodCacheKey)pool.borrowObject();
key.init(keys);
result = removeImpl(key);
- pool.putInstance(key);
+ try
+ {
+ pool.returnObject(key);
+ }
+ catch (Exception e)
+ {
+ log.warn(
+ "Nonfatal error. Could not return key to pool", e);
+ }
}
catch (Exception e)
{
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>