leif 02/02/02 01:16:13
Modified: src/java/org/apache/avalon/excalibur/pool
SingleThreadedPool.java
Log:
Brought the SingleThreadedPool into complience with the ObjectFactory
contract.
Revision Changes Path
1.8 +59 -8
jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/pool/SingleThreadedPool.java
Index: SingleThreadedPool.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/pool/SingleThreadedPool.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- SingleThreadedPool.java 26 Dec 2001 16:15:22 -0000 1.7
+++ SingleThreadedPool.java 2 Feb 2002 09:16:13 -0000 1.8
@@ -8,6 +8,8 @@
package org.apache.avalon.excalibur.pool;
import org.apache.avalon.framework.activity.Initializable;
+import org.apache.avalon.framework.activity.Disposable;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.thread.SingleThreaded;
/**
@@ -16,12 +18,14 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
- * @version CVS $Revision: 1.7 $ $Date: 2001/12/26 16:15:22 $
+ * @version CVS $Revision: 1.8 $ $Date: 2002/02/02 09:16:13 $
* @since 4.0
*/
public class SingleThreadedPool
- implements Pool, SingleThreaded, Resizable
+ extends AbstractLogEnabled
+ implements Pool, Initializable, SingleThreaded, Resizable, Disposable
{
+ protected boolean m_initialized;
protected int m_count;
protected Poolable[] m_pool;
protected ObjectFactory m_factory;
@@ -33,10 +37,17 @@
final int initial,
final int maximum ) throws Exception
{
- this(new DefaultObjectFactory(clazz), null, initial, maximum);
+ this(new DefaultObjectFactory(clazz), initial, maximum);
}
public SingleThreadedPool( final ObjectFactory factory,
+ final int initial,
+ final int maximum ) throws Exception
+ {
+ this(factory, null, initial, maximum);
+ }
+
+ public SingleThreadedPool( final ObjectFactory factory,
final PoolController controller,
final int initial,
final int maximum ) throws Exception
@@ -46,16 +57,13 @@
m_controller = controller;
m_maximum = maximum;
m_initial = initial;
-
- if( !(this instanceof Initializable) )
- {
- initialize();
- }
}
public void initialize()
throws Exception
{
+ m_initialized = true;
+
grow( m_maximum );
fill( m_initial );
}
@@ -67,6 +75,12 @@
*/
public Poolable get() throws Exception
{
+ // To make this class backwards compatible, it has to auto
initialize if necessary
+ if ( !m_initialized )
+ {
+ initialize();
+ }
+
if( null == m_pool && null != m_controller )
{
final int increase = m_controller.grow();
@@ -120,6 +134,19 @@
{
m_count++;
m_pool[ m_count ] = poolable;
+ } else {
+ try
+ {
+ m_factory.decommission( poolable );
+ }
+ catch ( Exception e )
+ {
+ // To be backwards compatible, we have to support the logger
having not been set.
+ if ( ( getLogger() != null ) && (
getLogger().isDebugEnabled() ) )
+ {
+ getLogger().debug( "Error decommissioning object", e );
+ }
+ }
}
}
@@ -193,5 +220,29 @@
final Poolable[] poolables = new Poolable[ m_pool.length - decrease
];
System.arraycopy( m_pool, 0, poolables, 0, poolables.length );
m_pool = poolables;
+ }
+
+ /**
+ * Dispose the pool and decommission any Poolables.
+ */
+ public void dispose() {
+ while ( m_count > 0 )
+ {
+ int i = m_count - 1;
+ try
+ {
+ m_factory.decommission( m_pool[i] );
+ }
+ catch ( Exception e )
+ {
+ // To be backwards compatible, we have to support the logger
having not been set.
+ if ( ( getLogger() != null ) && (
getLogger().isDebugEnabled() ) )
+ {
+ getLogger().debug( "Error decommissioning object", e );
+ }
+ }
+ m_pool[i] = null;
+ m_count--;
+ }
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>