Return-Path: Delivered-To: apmail-jakarta-avalon-cvs-archive@apache.org Received: (qmail 21571 invoked from network); 2 Feb 2002 09:16:16 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 2 Feb 2002 09:16:16 -0000 Received: (qmail 19613 invoked by uid 97); 2 Feb 2002 09:16:27 -0000 Delivered-To: qmlist-jakarta-archive-avalon-cvs@jakarta.apache.org Received: (qmail 19555 invoked by uid 97); 2 Feb 2002 09:16:27 -0000 Mailing-List: contact avalon-cvs-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Avalon CVS List" Reply-To: "Avalon Developers List" Delivered-To: mailing list avalon-cvs@jakarta.apache.org Received: (qmail 19544 invoked by uid 97); 2 Feb 2002 09:16:26 -0000 Date: 2 Feb 2002 09:16:13 -0000 Message-ID: <20020202091613.96039.qmail@icarus.apache.org> From: leif@apache.org To: jakarta-avalon-excalibur-cvs@apache.org Subject: cvs commit: jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/pool SingleThreadedPool.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N 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 Berin Loritsch * @author Stefano Mazzocchi * @author Peter Donald - * @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: For additional commands, e-mail: