jmcnally 02/03/24 23:33:37
Modified: . build.xml default.properties deps.list project.xml
src/services/org/apache/fulcrum/intake IntakeService.java
TurbineIntake.java TurbineIntakeService.java
src/services/org/apache/fulcrum/intake/model Group.java
Log:
switched from using a custom pool implementation based on pool code in stratum
to use a standard implementation from commons-pool. The pool in commons is
actually a better fit except that it does not allow per group limits on pooled
objects. Pretty confident this was not a highly used feature of intake.
Revision Changes Path
1.47 +17 -1 jakarta-turbine-fulcrum/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-turbine-fulcrum/build.xml,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -r1.46 -r1.47
--- build.xml 24 Mar 2002 21:45:11 -0000 1.46
+++ build.xml 25 Mar 2002 07:33:37 -0000 1.47
@@ -16,6 +16,7 @@
<pathelement location="${commons-email.jar}"/>
<pathelement location="${commons-lang.jar}"/>
<pathelement location="${commons-codec.jar}"/>
+ <pathelement location="${commons-pool.jar}"/>
<pathelement location="${commons-fileupload.jar}"/>
<pathelement location="${jaf.jar}"/>
<pathelement location="${javamail.jar}"/>
@@ -80,6 +81,8 @@
<echo message="commons-collections.jar = ${commons-collections.jar}"/>
<echo message="commons-lang.jar = ${commons-lang.jar}"/>
<echo message="commons-codec.jar = ${commons-codec.jar}"/>
+ <echo message="commons-pool.jar = ${commons-pool.jar}"/>
+ <echo message="commons-fileupload.jar = ${commons-fileupload.jar}"/>
<echo message="dom4j.jar = ${dom4j.jar}"/>
<echo message="dvsl.jar = ${dvsl.jar}"/>
<echo message="jaf.jar = ${jaf.jar}"/>
@@ -208,6 +211,12 @@
/>
<available
+ classname="org.apache.commons.pool.KeyedObjectPool"
+ property="commons-pool.present"
+ classpathref="classpath"
+ />
+
+ <available
classname="org.apache.commons.fileupload.FileUpload"
property="commons-fileupload.present"
classpathref="classpath"
@@ -334,6 +343,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.commons-fileupload" unless="commons-fileupload.present">
<antcall target="property-warning">
<param name="name" value="commons-fileupload.jar"/>
@@ -420,7 +436,7 @@
check.servlet,check.javamail,check.jaf,check.xerces,check.xalan,
check.xmlrpc,check.commons-collections,check.commons-lang,
check.commons-codec,check.regexp,check.dvsl,check.dom4j,
- check.commons-fileupload,include-email,om">
+ check.commons-fileupload,check.commons-pool,include-email,om">
<!-- We have some static files that should overwrite
The torque generated files so overwrite must be
1.24 +1 -0 jakarta-turbine-fulcrum/default.properties
Index: default.properties
===================================================================
RCS file: /home/cvs/jakarta-turbine-fulcrum/default.properties,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- default.properties 24 Mar 2002 21:45:11 -0000 1.23
+++ default.properties 25 Mar 2002 07:33:37 -0000 1.24
@@ -46,6 +46,7 @@
commons-email.jar = ${lib.repo}/commons-email-0.1-dev.jar
commons-lang.jar = ${lib.repo}/commons-lang-0.1-dev.jar
commons-codec.jar = ${lib.repo}/commons-codec.jar
+commons-pool.jar = ${lib.repo}/commons-pool.jar
commons-fileupload.jar = ${lib.repo}/commons-fileupload-1.0-dev.jar
dom4j.jar = ${lib.repo}/dom4j-1.1.jar
dvsl.jar = ${lib.repo}/velocity-dvsl-0.40.jar
1.9 +1 -0 jakarta-turbine-fulcrum/deps.list
Index: deps.list
===================================================================
RCS file: /home/cvs/jakarta-turbine-fulcrum/deps.list,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- deps.list 24 Mar 2002 21:45:11 -0000 1.8
+++ deps.list 25 Mar 2002 07:33:37 -0000 1.9
@@ -4,6 +4,7 @@
commons-email-0.1-dev.jar
commons-lang-0.1-dev.jar
commons-codec.jar
+commons-pool.jar
commons-fileupload-1.0-dev.jar
dom4j-1.1.jar
jakarta-regexp-1.3-dev.jar
1.15 +7 -0 jakarta-turbine-fulcrum/project.xml
Index: project.xml
===================================================================
RCS file: /home/cvs/jakarta-turbine-fulcrum/project.xml,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- project.xml 24 Mar 2002 21:45:11 -0000 1.14
+++ project.xml 25 Mar 2002 07:33:37 -0000 1.15
@@ -121,6 +121,13 @@
</dependency>
<dependency>
+ <name>commons-pool</name>
+ <type>required</type>
+ <version>0.1</version>
+ <jar>commons-pool.jar</jar>
+ </dependency>
+
+ <dependency>
<name>commons-fileupload</name>
<type>required</type>
<version>1.0</version>
1.5 +2 -32
jakarta-turbine-fulcrum/src/services/org/apache/fulcrum/intake/IntakeService.java
Index: IntakeService.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-fulcrum/src/services/org/apache/fulcrum/intake/IntakeService.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- IntakeService.java 30 Jan 2002 05:56:13 -0000 1.4
+++ IntakeService.java 25 Mar 2002 07:33:37 -0000 1.5
@@ -73,7 +73,7 @@
* </p>
*
* @author <a href="mailto:[EMAIL PROTECTED]">John McNally</a>
- * @version $Id: IntakeService.java,v 1.4 2002/01/30 05:56:13 jmcnally Exp $
+ * @version $Id: IntakeService.java,v 1.5 2002/03/25 07:33:37 jmcnally Exp $
*/
public interface IntakeService
{
@@ -153,25 +153,7 @@
* @param instance the object instance to recycle.
* @return true if the instance was accepted.
*/
- public boolean releaseGroup(Group instance);
-
- /**
- * Gets the capacity of the pool for a named group.
- *
- * @param groupName the name of the group.
- * @throws Exception if groupName is null
- */
- public int getCapacity(String groupName) throws Exception;
-
- /**
- * Sets the capacity of the pool for a named group.
- * Note that the pool will be cleared after the change.
- *
- * @param groupName the name of the group.
- * @param capacity the new capacity.
- */
- public void setCapacity(String groupName,
- int capacity);
+ public void releaseGroup(Group instance);
/**
* Gets the current size of the pool for a named group.
@@ -179,18 +161,6 @@
* @param groupName the name of the group.
*/
public int getSize(String groupName);
-
- /**
- * Clears instances of a named group from the pool.
- *
- * @param groupName the name of the group.
- */
- public void clearPool(String groupName);
-
- /**
- * Clears all instances from the pool.
- */
- public void clearPool();
/**
* Names of all the defined groups.
1.3 +3 -44
jakarta-turbine-fulcrum/src/services/org/apache/fulcrum/intake/TurbineIntake.java
Index: TurbineIntake.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-fulcrum/src/services/org/apache/fulcrum/intake/TurbineIntake.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TurbineIntake.java 30 Aug 2001 05:23:57 -0000 1.2
+++ TurbineIntake.java 25 Mar 2002 07:33:37 -0000 1.3
@@ -67,7 +67,7 @@
* the settings in TurbineResources.
*
* @author <a href="mailto:[EMAIL PROTECTED]">John McNally</a>
- * @version $Id: TurbineIntake.java,v 1.2 2001/08/30 05:23:57 jmcnally Exp $
+ * @version $Id: TurbineIntake.java,v 1.3 2002/03/25 07:33:37 jmcnally Exp $
*/
public abstract class TurbineIntake
{
@@ -130,32 +130,9 @@
* @param instance the object instance to recycle.
* @return true if the instance was accepted.
*/
- public static boolean releaseGroup(Group instance)
+ public static void releaseGroup(Group instance)
{
- return getService().releaseGroup(instance);
- }
-
- /**
- * Gets the capacity of the pool for a named group.
- *
- * @param groupName the name of the group.
- */
- public static int getCapacity(String groupName)
- throws Exception
- {
- return getService().getCapacity(groupName);
- }
-
- /**
- * Sets the capacity of the pool for a named group.
- * Note that the pool will be cleared after the change.
- *
- * @param groupName the name of the group.
- * @param capacity the new capacity.
- */
- public static void setCapacity(String groupName, int capacity)
- {
- getService().setCapacity(groupName, capacity);
+ getService().releaseGroup(instance);
}
/**
@@ -166,24 +143,6 @@
public static int getSize(String groupName)
{
return getService().getSize(groupName);
- }
-
- /**
- * Clears instances of a named group from the pool.
- *
- * @param groupName the name of the group.
- */
- public static void clearPool(String groupName)
- {
- getService().clearPool(groupName);
- }
-
- /**
- * Clears all instances from the pool.
- */
- public static void clearPool()
- {
- getService().clearPool();
}
/**
1.8 +36 -206
jakarta-turbine-fulcrum/src/services/org/apache/fulcrum/intake/TurbineIntakeService.java
Index: TurbineIntakeService.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-fulcrum/src/services/org/apache/fulcrum/intake/TurbineIntakeService.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- TurbineIntakeService.java 30 Jan 2002 05:56:13 -0000 1.7
+++ TurbineIntakeService.java 25 Mar 2002 07:33:37 -0000 1.8
@@ -71,6 +71,9 @@
import java.util.List;
import java.util.Map;
//import org.apache.turbine.om.OMTool;
+import org.apache.commons.pool.KeyedPoolableObjectFactory;
+import org.apache.commons.pool.KeyedObjectPool;
+import org.apache.commons.pool.impl.StackKeyedObjectPool;
import org.apache.fulcrum.intake.model.Group;
import org.apache.fulcrum.intake.transform.XmlToAppData;
import org.apache.fulcrum.intake.xmlmodel.AppData;
@@ -87,7 +90,7 @@
* on an XML specification.
*
* @author <a href="mailto:[EMAIL PROTECTED]">John McNally</a>
- * @version $Id: TurbineIntakeService.java,v 1.7 2002/01/30 05:56:13 jmcnally Exp $
+ * @version $Id: TurbineIntakeService.java,v 1.8 2002/03/25 07:33:37 jmcnally Exp $
*/
public class TurbineIntakeService
extends BaseService
@@ -114,10 +117,8 @@
/** The top element of the object tree */
private AppData appData;
- /**
- * The pool repository, one pool for each class.
- */
- private HashMap poolRepository = new HashMap();
+ /** pools Group objects */
+ KeyedObjectPool keyedPool;
// a couple integers for a switch statement
private static final int GETTER = 0;
@@ -236,6 +237,7 @@
// omTool = new OMTool();
String pkg = appData.getBasePackage();
+ int maxPooledGroups = 0;
List glist = appData.getGroups();
for ( int i=glist.size()-1; i>=0; i-- )
{
@@ -244,7 +246,9 @@
groupNames[i] = groupName;
groupKeyMap.put(groupName, g.getKey());
groupNameMap.put(g.getKey(), groupName);
-
+ maxPooledGroups =
+ Math.max(maxPooledGroups,
+ Integer.parseInt(g.getPoolCapacity()));
List classNames = g.getMapToObjects();
Iterator iter2 = classNames.iterator();
while (iter2.hasNext())
@@ -258,6 +262,17 @@
}
}
+ KeyedPoolableObjectFactory factory = null;
+ try
+ {
+ factory = new Group.GroupFactory(appData);
+ keyedPool = new StackKeyedObjectPool(factory, maxPooledGroups);
+ }
+ catch (Exception e)
+ {
+ throw new ServiceException(e);
+ }
+
setInit(true);
}
catch (Exception e)
@@ -314,95 +329,6 @@
}
/**
- * An inner class for group specific pools.
- */
- private class PoolBuffer
- {
- /**
- * A buffer for class instances.
- */
- private BoundedBuffer pool;
-
- /**
- * A cache for recycling methods.
- */
- private HashMap recyclers;
-
- /**
- * Contructs a new pool buffer with a specific capacity.
- *
- * @param capacity a capacity.
- */
- public PoolBuffer(int capacity)
- {
- pool = new BoundedBuffer(capacity);
- }
-
- /**
- * Polls for an instance from the pool.
- *
- * @return an instance or null.
- */
- public Group poll()
- throws ServiceException
- {
- Group instance = (Group)pool.poll();
- if ((instance != null) &&
- (instance instanceof Recyclable))
- {
- try
- {
- ((Recyclable) instance).recycle();
- }
- catch (Exception x)
- {
- throw new ServiceException("Recycling failed for " +
- instance.getClass().getName(),x);
- }
- }
- return instance;
- }
-
- /**
- * Offers an instance to the pool.
- *
- * @param instance an instance.
- */
- public boolean offer(Group instance)
- {
- try
- {
- ((Recyclable) instance).dispose();
- }
- catch (Exception x)
- {
- return false;
- }
- return pool.offer(instance);
- }
-
- /**
- * Returns the capacity of the pool.
- *
- * @return the capacity.
- */
- public int capacity()
- {
- return pool.capacity();
- }
-
- /**
- * Returns the size of the pool.
- *
- * @return the size.
- */
- public int size()
- {
- return pool.size();
- }
- }
-
- /**
* Gets an instance of a named group either from the pool
* or by calling the Factory Service if the pool is empty.
*
@@ -413,24 +339,21 @@
public Group getGroup(String groupName)
throws ServiceException
{
+ Group group = null;
if (groupName == null)
{
throw new ServiceException (
"Intake TurbineIntakeService.getGroup(groupName) is null");
}
- Group instance = (Group)pollInstance(groupName);
- if ( instance == null )
+ try
{
- try
- {
- instance = new Group(appData.getGroup(groupName));
- }
- catch (Exception e)
- {
- throw new ServiceException(e);
- }
+ group = (Group)keyedPool.borrowObject(groupName);
}
- return instance;
+ catch (Exception e)
+ {
+ new ServiceException(e);
+ }
+ return group;
}
@@ -440,72 +363,25 @@
* @param instance the object instance to recycle.
* @return true if the instance was accepted.
*/
- public boolean releaseGroup(Group instance)
+ public void releaseGroup(Group instance)
{
if (instance != null)
{
- HashMap repository = poolRepository;
String name = instance.getIntakeGroupName();
- PoolBuffer pool = (PoolBuffer) repository.get(name);
- if (pool == null)
- {
- pool = new PoolBuffer(instance.getPoolCapacity());
- repository = (HashMap) repository.clone();
- repository.put(name,pool);
- poolRepository = repository;
- }
- return pool.offer(instance);
- }
- else
- {
- return false;
- }
- }
-
- /**
- * Gets the capacity of the pool for a named group.
- *
- * @param name the name of the class.
- */
- public int getCapacity(String name)
- throws Exception
- {
- int capacity = DEFAULT_POOL_CAPACITY;
- PoolBuffer pool = (PoolBuffer) poolRepository.get(name);
- if ( pool == null )
- {
try
{
- capacity = Integer
- .parseInt(appData.getGroup(name).getPoolCapacity());
+ keyedPool.returnObject(name, instance);
}
- catch (NumberFormatException nfe)
+ catch (Exception e)
{
- // Ignored
+ new ServiceException(e);
}
+ //return true;
}
else
{
- capacity = pool.capacity();
+ //return false;
}
- return capacity;
- }
-
- /**
- * Sets the capacity of the pool for a group.
- * Note that the pool will be cleared after the change.
- *
- * @param name the name of the group.
- * @param capacity the new capacity.
- */
- public void setCapacity(String name,
- int capacity)
- {
- HashMap repository = poolRepository;
- repository = repository != null ?
- (HashMap) repository.clone() : new HashMap();
- repository.put(name,new PoolBuffer(capacity));
- poolRepository = repository;
}
/**
@@ -515,53 +391,7 @@
*/
public int getSize(String name)
{
- PoolBuffer pool = (PoolBuffer) poolRepository.get(name);
- return pool != null ? pool.size() : 0;
- }
-
- /**
- * Clears instances of a group from the pool.
- *
- * @param name the name of the group.
- */
- public void clearPool(String name)
- {
- throw new Error("Not implemented");
- /* FIXME!! We need to worry about objects that are checked out
-
- HashMap repository = poolRepository;
- if (repository.get(name) != null)
- {
- repository = (HashMap) repository.clone();
- repository.remove(name);
- poolRepository = repository;
- }
- */
- }
-
- /**
- * Clears all instances from the pool.
- */
- public void clearPool()
- {
- throw new Error("Not implemented");
- /* FIXME!! We need to worry about objects that are checked out
- poolRepository = new HashMap();
- */
- }
-
- /**
- * Polls and recycles an object of the named group from the pool.
- *
- * @param groupName the name of the group.
- * @return the object or null.
- * @throws ServiceException if recycling fails.
- */
- private Object pollInstance(String groupName)
- throws ServiceException
- {
- PoolBuffer pool = (PoolBuffer) poolRepository.get(groupName);
- return pool != null ? pool.poll() : null;
+ return keyedPool.numActive(name) + keyedPool.numIdle(name);
}
/**
1.7 +34 -39
jakarta-turbine-fulcrum/src/services/org/apache/fulcrum/intake/model/Group.java
Index: Group.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-fulcrum/src/services/org/apache/fulcrum/intake/model/Group.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Group.java 24 Jan 2002 18:29:53 -0000 1.6
+++ Group.java 25 Mar 2002 07:33:37 -0000 1.7
@@ -60,8 +60,10 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import org.apache.commons.pool.BaseKeyedPoolableObjectFactory;
import org.apache.fulcrum.intake.Retrievable;
import org.apache.fulcrum.intake.TurbineIntake;
+import org.apache.fulcrum.intake.xmlmodel.AppData;
import org.apache.fulcrum.intake.xmlmodel.XmlField;
import org.apache.fulcrum.intake.xmlmodel.XmlGroup;
import org.apache.fulcrum.util.parser.ValueParser;
@@ -71,7 +73,6 @@
/** Holds a group of Fields */
public class Group
- implements Recyclable
{
public static final String EMPTY = "";
@@ -520,50 +521,44 @@
}
}
- // ****************** Recyclable implementation ************************
+ // ********** PoolableObjectFactory implementation ******************
- private boolean disposed;
-
- /**
- * Recycles the object for a new client. Recycle methods with
- * parameters must be added to implementing object and they will be
- * automatically called by pool implementations when the object is
- * taken from the pool for a new client. The parameters must
- * correspond to the parameters of the constructors of the object.
- * For new objects, constructors can call their corresponding recycle
- * methods whenever applicable.
- * The recycle methods must call their super.
- */
- public void recycle()
+ public static class GroupFactory
+ extends BaseKeyedPoolableObjectFactory
{
- disposed = false;
- }
+ private AppData appData;
- /**
- * 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()
- {
- oid = null;
- pp = null;
- for (int i=fieldsArray.length-1; i>=0; i--)
+ public GroupFactory(AppData appData)
{
- fieldsArray[i].dispose();
+ this.appData = appData;
}
- isDeclared = false;
-
- disposed = true;
- }
- /**
- * Checks whether the recyclable has been disposed.
- * @return true, if the recyclable is disposed.
- */
- public boolean isDisposed()
- {
- return disposed;
+ /**
+ * Creates an instance that can be returned by the pool.
+ * @return an instance that can be returned by the pool.
+ */
+ public Object makeObject(Object key)
+ throws Exception
+ {
+ return new Group(appData.getGroup((String)key));
+ }
+
+ /**
+ * Uninitialize an instance to be returned to the pool.
+ * @param obj the instance to be passivated
+ */
+ public void passivateObject(Object key, Object obj)
+ throws Exception
+ {
+ Group group = (Group)obj;
+ group.oid = null;
+ group.pp = null;
+ for (int i=group.fieldsArray.length-1; i>=0; i--)
+ {
+ group.fieldsArray[i].dispose();
+ }
+ group.isDeclared = false;
+ }
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>