avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From je...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/event/src/test/org/apache/excalibur/mpool/test ClassInstanceObjectFactory.java MultiThreadedPoolComparisonProfile.java PoolComparisonProfileAbstract.java SingleThreadedPoolComparisonProfile.java
Date Tue, 13 Aug 2002 08:15:21 GMT
jefft       2002/08/13 01:15:21

  Modified:    event/src/java/org/apache/excalibur/mpool
                        DefaultPoolManager.java FixedSizePool.java
                        ManagablePool.java ObjectFactory.java Pool.java
                        PoolManager.java VariableSizePool.java
               event/src/test QueueTest.java
               event/src/test/org/apache/excalibur/event/test
                        ThreadedQueueTestCase.java
               event/src/test/org/apache/excalibur/mpool/test
                        ClassInstanceObjectFactory.java
                        MultiThreadedPoolComparisonProfile.java
                        PoolComparisonProfileAbstract.java
                        SingleThreadedPoolComparisonProfile.java
  Log:
  Fix linefeeds
  
  Revision  Changes    Path
  1.2       +174 -174  jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/mpool/DefaultPoolManager.java
  
  Index: DefaultPoolManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/mpool/DefaultPoolManager.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultPoolManager.java	7 Aug 2002 22:44:25 -0000	1.1
  +++ DefaultPoolManager.java	13 Aug 2002 08:15:20 -0000	1.2
  @@ -1,174 +1,174 @@
  -/*
  -
  - ============================================================================
  -                   The Apache Software License, Version 1.1
  - ============================================================================
  -
  - Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  -
  - Redistribution and use in source and binary forms, with or without modifica-
  - tion, are permitted provided that the following conditions are met:
  -
  - 1. Redistributions of  source code must  retain the above copyright  notice,
  -    this list of conditions and the following disclaimer.
  -
  - 2. Redistributions in binary form must reproduce the above copyright notice,
  -    this list of conditions and the following disclaimer in the documentation
  -    and/or other materials provided with the distribution.
  -
  - 3. The end-user documentation included with the redistribution, if any, must
  -    include  the following  acknowledgment:  "This product includes  software
  -    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  -    Alternately, this  acknowledgment may  appear in the software itself,  if
  -    and wherever such third-party acknowledgments normally appear.
  -
  - 4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
  -    must not be used to endorse or promote products derived from this  software
  -    without  prior written permission. For written permission, please contact
  -    apache@apache.org.
  -
  - 5. Products  derived from this software may not  be called "Apache", nor may
  -    "Apache" appear  in their name,  without prior written permission  of the
  -    Apache Software Foundation.
  -
  - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  - FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  - APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  - INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  - DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  - OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  - ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  - (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  -
  - This software  consists of voluntary contributions made  by many individuals
  - on  behalf of the Apache Software  Foundation. For more  information on the
  - Apache Software Foundation, please see <http://www.apache.org/>.
  -
  -*/
  -package org.apache.excalibur.mpool;
  -
  -import java.util.Iterator;
  -import java.util.Random;
  -import org.apache.avalon.excalibur.collections.BucketMap;
  -import org.apache.excalibur.event.Queue;
  -import org.apache.excalibur.event.command.RepeatedCommand;
  -
  -/**
  - * This interface is for a PoolManager that creates pools that are managed
  - * asynchronously.  The contract is that the controller type is specified in
  - * the constructor.
  - *
  - * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  - * @version CVS $Revision$ $Date$
  - * @since 4.1
  - */
  -public class DefaultPoolManager implements PoolManager
  -{
  -    private final long m_managerKey;
  -    private final Random m_keyGenerator;
  -    private final BucketMap m_keyMap = new BucketMap();
  -    private final BucketMap m_factoryMap = new BucketMap();
  -
  -    public DefaultPoolManager()
  -    {
  -        this( null );
  -    }
  -
  -    public DefaultPoolManager( final Queue commandQueue )
  -    {
  -        m_keyGenerator = new Random();
  -        m_managerKey = m_keyGenerator.nextLong();
  -
  -        if( null != commandQueue )
  -        {
  -            try
  -            {
  -                commandQueue.enqueue( new PoolManagerCommand( m_keyMap ) );
  -            }
  -            catch( Exception e )
  -            {
  -                // ignore silently for now
  -            }
  -        }
  -    }
  -
  -    /**
  -     * Return a managed pool that has a controller.
  -     */
  -    public Pool getManagedPool( ObjectFactory factory, int initialEntries )
  -        throws Exception
  -    {
  -        ManagablePool pool = (ManagablePool)m_factoryMap.get( factory );
  -
  -        if( null == pool )
  -        {
  -            final long poolKey = getKey();
  -            pool = new VariableSizePool( factory, initialEntries, poolKey );
  -            m_keyMap.put( pool, new Long( poolKey ) );
  -            m_factoryMap.put( factory, pool );
  -        }
  -
  -        return pool;
  -    }
  -
  -    /**
  -     * Return a new key for the pool and controller.
  -     */
  -    private final long getKey()
  -    {
  -        return m_keyGenerator.nextLong();
  -    }
  -
  -    private static final class PoolManagerCommand implements RepeatedCommand
  -    {
  -        private final BucketMap m_map;
  -        private final int m_min = 4;
  -        private final int m_max = 256;
  -        private final int m_grow = 4;
  -
  -        protected PoolManagerCommand( BucketMap map )
  -        {
  -            m_map = map;
  -        }
  -
  -        public long getDelayInterval()
  -        {
  -            return 10 * 1000L;
  -        }
  -
  -        public long getRepeatInterval()
  -        {
  -            return 10 * 1000L;
  -        }
  -
  -        public int getNumberOfRepeats()
  -        {
  -            return 0;
  -        }
  -
  -        public void execute()
  -            throws Exception
  -        {
  -            Iterator i = m_map.keySet().iterator();
  -
  -            while( i.hasNext() )
  -            {
  -                ManagablePool pool = (ManagablePool)i.next();
  -                long key = ( (Long)m_map.get( pool ) ).longValue();
  -                int size = pool.size( key );
  -
  -                if( size < m_min )
  -                {
  -                    pool.grow( m_grow, key );
  -                }
  -
  -                if( size > m_max )
  -                {
  -                    pool.shrink( m_grow, key );
  -                }
  -            }
  -        }
  -    }
  -}
  +/*
  +
  + ============================================================================
  +                   The Apache Software License, Version 1.1
  + ============================================================================
  +
  + Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  +
  + Redistribution and use in source and binary forms, with or without modifica-
  + tion, are permitted provided that the following conditions are met:
  +
  + 1. Redistributions of  source code must  retain the above copyright  notice,
  +    this list of conditions and the following disclaimer.
  +
  + 2. Redistributions in binary form must reproduce the above copyright notice,
  +    this list of conditions and the following disclaimer in the documentation
  +    and/or other materials provided with the distribution.
  +
  + 3. The end-user documentation included with the redistribution, if any, must
  +    include  the following  acknowledgment:  "This product includes  software
  +    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  +    Alternately, this  acknowledgment may  appear in the software itself,  if
  +    and wherever such third-party acknowledgments normally appear.
  +
  + 4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
  +    must not be used to endorse or promote products derived from this  software
  +    without  prior written permission. For written permission, please contact
  +    apache@apache.org.
  +
  + 5. Products  derived from this software may not  be called "Apache", nor may
  +    "Apache" appear  in their name,  without prior written permission  of the
  +    Apache Software Foundation.
  +
  + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  + FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  + APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  + INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  + DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  + OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  + ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  + (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  +
  + This software  consists of voluntary contributions made  by many individuals
  + on  behalf of the Apache Software  Foundation. For more  information on the
  + Apache Software Foundation, please see <http://www.apache.org/>.
  +
  +*/
  +package org.apache.excalibur.mpool;
  +
  +import java.util.Iterator;
  +import java.util.Random;
  +import org.apache.avalon.excalibur.collections.BucketMap;
  +import org.apache.excalibur.event.Queue;
  +import org.apache.excalibur.event.command.RepeatedCommand;
  +
  +/**
  + * This interface is for a PoolManager that creates pools that are managed
  + * asynchronously.  The contract is that the controller type is specified in
  + * the constructor.
  + *
  + * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  + * @version CVS $Revision$ $Date$
  + * @since 4.1
  + */
  +public class DefaultPoolManager implements PoolManager
  +{
  +    private final long m_managerKey;
  +    private final Random m_keyGenerator;
  +    private final BucketMap m_keyMap = new BucketMap();
  +    private final BucketMap m_factoryMap = new BucketMap();
  +
  +    public DefaultPoolManager()
  +    {
  +        this( null );
  +    }
  +
  +    public DefaultPoolManager( final Queue commandQueue )
  +    {
  +        m_keyGenerator = new Random();
  +        m_managerKey = m_keyGenerator.nextLong();
  +
  +        if( null != commandQueue )
  +        {
  +            try
  +            {
  +                commandQueue.enqueue( new PoolManagerCommand( m_keyMap ) );
  +            }
  +            catch( Exception e )
  +            {
  +                // ignore silently for now
  +            }
  +        }
  +    }
  +
  +    /**
  +     * Return a managed pool that has a controller.
  +     */
  +    public Pool getManagedPool( ObjectFactory factory, int initialEntries )
  +        throws Exception
  +    {
  +        ManagablePool pool = (ManagablePool)m_factoryMap.get( factory );
  +
  +        if( null == pool )
  +        {
  +            final long poolKey = getKey();
  +            pool = new VariableSizePool( factory, initialEntries, poolKey );
  +            m_keyMap.put( pool, new Long( poolKey ) );
  +            m_factoryMap.put( factory, pool );
  +        }
  +
  +        return pool;
  +    }
  +
  +    /**
  +     * Return a new key for the pool and controller.
  +     */
  +    private final long getKey()
  +    {
  +        return m_keyGenerator.nextLong();
  +    }
  +
  +    private static final class PoolManagerCommand implements RepeatedCommand
  +    {
  +        private final BucketMap m_map;
  +        private final int m_min = 4;
  +        private final int m_max = 256;
  +        private final int m_grow = 4;
  +
  +        protected PoolManagerCommand( BucketMap map )
  +        {
  +            m_map = map;
  +        }
  +
  +        public long getDelayInterval()
  +        {
  +            return 10 * 1000L;
  +        }
  +
  +        public long getRepeatInterval()
  +        {
  +            return 10 * 1000L;
  +        }
  +
  +        public int getNumberOfRepeats()
  +        {
  +            return 0;
  +        }
  +
  +        public void execute()
  +            throws Exception
  +        {
  +            Iterator i = m_map.keySet().iterator();
  +
  +            while( i.hasNext() )
  +            {
  +                ManagablePool pool = (ManagablePool)i.next();
  +                long key = ( (Long)m_map.get( pool ) ).longValue();
  +                int size = pool.size( key );
  +
  +                if( size < m_min )
  +                {
  +                    pool.grow( m_grow, key );
  +                }
  +
  +                if( size > m_max )
  +                {
  +                    pool.shrink( m_grow, key );
  +                }
  +            }
  +        }
  +    }
  +}
  
  
  
  1.5       +150 -150  jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/mpool/FixedSizePool.java
  
  Index: FixedSizePool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/mpool/FixedSizePool.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- FixedSizePool.java	9 Aug 2002 19:06:51 -0000	1.4
  +++ FixedSizePool.java	13 Aug 2002 08:15:20 -0000	1.5
  @@ -1,150 +1,150 @@
  -/*
  -
  - ============================================================================
  -                   The Apache Software License, Version 1.1
  - ============================================================================
  -
  - Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  -
  - Redistribution and use in source and binary forms, with or without modifica-
  - tion, are permitted provided that the following conditions are met:
  -
  - 1. Redistributions of  source code must  retain the above copyright  notice,
  -    this list of conditions and the following disclaimer.
  -
  - 2. Redistributions in binary form must reproduce the above copyright notice,
  -    this list of conditions and the following disclaimer in the documentation
  -    and/or other materials provided with the distribution.
  -
  - 3. The end-user documentation included with the redistribution, if any, must
  -    include  the following  acknowledgment:  "This product includes  software
  -    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  -    Alternately, this  acknowledgment may  appear in the software itself,  if
  -    and wherever such third-party acknowledgments normally appear.
  -
  - 4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
  -    must not be used to endorse or promote products derived from this  software
  -    without  prior written permission. For written permission, please contact
  -    apache@apache.org.
  -
  - 5. Products  derived from this software may not  be called "Apache", nor may
  -    "Apache" appear  in their name,  without prior written permission  of the
  -    Apache Software Foundation.
  -
  - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  - FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  - APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  - INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  - DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  - OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  - ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  - (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  -
  - This software  consists of voluntary contributions made  by many individuals
  - on  behalf of the Apache Software  Foundation. For more  information on the
  - Apache Software Foundation, please see <http://www.apache.org/>.
  -
  -*/
  -package org.apache.excalibur.mpool;
  -
  -import org.apache.avalon.excalibur.concurrent.Mutex;
  -import org.apache.avalon.excalibur.collections.Buffer;
  -import org.apache.avalon.excalibur.collections.FixedSizeBuffer;
  -import org.apache.avalon.framework.activity.Disposable;
  -
  -/**
  - * This is an <code>Pool</code> that caches Poolable objects for reuse.
  - * Please note that this pool offers no resource limiting whatsoever.
  - *
  - * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  - * @version CVS $Revision$ $Date$
  - * @since 4.1
  - */
  -public final class FixedSizePool
  -    implements Pool, Disposable
  -{
  -    private boolean m_disposed = false;
  -    private final Buffer m_buffer;
  -    private final ObjectFactory m_factory;
  -
  -    public FixedSizePool( ObjectFactory factory, int size )
  -        throws Exception
  -    {
  -        m_buffer = new FixedSizeBuffer( size );
  -        m_factory = factory;
  -
  -        for( int i = 0; i < size; i++ )
  -        {
  -            m_buffer.add( newInstance() );
  -        }
  -    }
  -
  -    public Object acquire()
  -    {
  -        if( m_disposed )
  -        {
  -            throw new IllegalStateException( "Cannot get an object from a disposed pool" );
  -        }
  -
  -        Object object = null;
  -
  -        synchronized( m_buffer )
  -        {
  -            object = m_buffer.remove();
  -        }
  -
  -        return object;
  -    }
  -
  -    public void release( Object object )
  -    {
  -        if( m_disposed )
  -        {
  -            try
  -            {
  -                m_factory.dispose( object );
  -            }
  -            catch( Exception e )
  -            {
  -                // We should never get here, but ignore the exception if it happens
  -            }
  -        }
  -        else
  -        {
  -            synchronized( m_buffer )
  -            {
  -                m_buffer.add( object );
  -                m_buffer.notifyAll();
  -            }
  -        }
  -    }
  -
  -    public Object newInstance()
  -        throws Exception
  -    {
  -        return m_factory.newInstance();
  -    }
  -
  -    public void dispose()
  -    {
  -        m_disposed = true;
  -
  -        synchronized( m_buffer )
  -        {
  -            while( !m_buffer.isEmpty() )
  -            {
  -                try
  -                {
  -                    m_factory.dispose( m_buffer.remove() );
  -                }
  -                catch( Exception e )
  -                {
  -                    // We should never get here, but ignore the exception if it happens
  -                }
  -            }
  -        }
  -    }
  -}
  -
  +/*
  +
  + ============================================================================
  +                   The Apache Software License, Version 1.1
  + ============================================================================
  +
  + Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  +
  + Redistribution and use in source and binary forms, with or without modifica-
  + tion, are permitted provided that the following conditions are met:
  +
  + 1. Redistributions of  source code must  retain the above copyright  notice,
  +    this list of conditions and the following disclaimer.
  +
  + 2. Redistributions in binary form must reproduce the above copyright notice,
  +    this list of conditions and the following disclaimer in the documentation
  +    and/or other materials provided with the distribution.
  +
  + 3. The end-user documentation included with the redistribution, if any, must
  +    include  the following  acknowledgment:  "This product includes  software
  +    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  +    Alternately, this  acknowledgment may  appear in the software itself,  if
  +    and wherever such third-party acknowledgments normally appear.
  +
  + 4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
  +    must not be used to endorse or promote products derived from this  software
  +    without  prior written permission. For written permission, please contact
  +    apache@apache.org.
  +
  + 5. Products  derived from this software may not  be called "Apache", nor may
  +    "Apache" appear  in their name,  without prior written permission  of the
  +    Apache Software Foundation.
  +
  + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  + FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  + APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  + INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  + DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  + OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  + ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  + (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  +
  + This software  consists of voluntary contributions made  by many individuals
  + on  behalf of the Apache Software  Foundation. For more  information on the
  + Apache Software Foundation, please see <http://www.apache.org/>.
  +
  +*/
  +package org.apache.excalibur.mpool;
  +
  +import org.apache.avalon.excalibur.concurrent.Mutex;
  +import org.apache.avalon.excalibur.collections.Buffer;
  +import org.apache.avalon.excalibur.collections.FixedSizeBuffer;
  +import org.apache.avalon.framework.activity.Disposable;
  +
  +/**
  + * This is an <code>Pool</code> that caches Poolable objects for reuse.
  + * Please note that this pool offers no resource limiting whatsoever.
  + *
  + * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  + * @version CVS $Revision$ $Date$
  + * @since 4.1
  + */
  +public final class FixedSizePool
  +    implements Pool, Disposable
  +{
  +    private boolean m_disposed = false;
  +    private final Buffer m_buffer;
  +    private final ObjectFactory m_factory;
  +
  +    public FixedSizePool( ObjectFactory factory, int size )
  +        throws Exception
  +    {
  +        m_buffer = new FixedSizeBuffer( size );
  +        m_factory = factory;
  +
  +        for( int i = 0; i < size; i++ )
  +        {
  +            m_buffer.add( newInstance() );
  +        }
  +    }
  +
  +    public Object acquire()
  +    {
  +        if( m_disposed )
  +        {
  +            throw new IllegalStateException( "Cannot get an object from a disposed pool" );
  +        }
  +
  +        Object object = null;
  +
  +        synchronized( m_buffer )
  +        {
  +            object = m_buffer.remove();
  +        }
  +
  +        return object;
  +    }
  +
  +    public void release( Object object )
  +    {
  +        if( m_disposed )
  +        {
  +            try
  +            {
  +                m_factory.dispose( object );
  +            }
  +            catch( Exception e )
  +            {
  +                // We should never get here, but ignore the exception if it happens
  +            }
  +        }
  +        else
  +        {
  +            synchronized( m_buffer )
  +            {
  +                m_buffer.add( object );
  +                m_buffer.notifyAll();
  +            }
  +        }
  +    }
  +
  +    public Object newInstance()
  +        throws Exception
  +    {
  +        return m_factory.newInstance();
  +    }
  +
  +    public void dispose()
  +    {
  +        m_disposed = true;
  +
  +        synchronized( m_buffer )
  +        {
  +            while( !m_buffer.isEmpty() )
  +            {
  +                try
  +                {
  +                    m_factory.dispose( m_buffer.remove() );
  +                }
  +                catch( Exception e )
  +                {
  +                    // We should never get here, but ignore the exception if it happens
  +                }
  +            }
  +        }
  +    }
  +}
  +
  
  
  
  1.2       +118 -118  jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/mpool/ManagablePool.java
  
  Index: ManagablePool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/mpool/ManagablePool.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ManagablePool.java	7 Aug 2002 22:44:25 -0000	1.1
  +++ ManagablePool.java	13 Aug 2002 08:15:20 -0000	1.2
  @@ -1,118 +1,118 @@
  -/*
  -
  - ============================================================================
  -                   The Apache Software License, Version 1.1
  - ============================================================================
  -
  - Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  -
  - Redistribution and use in source and binary forms, with or without modifica-
  - tion, are permitted provided that the following conditions are met:
  -
  - 1. Redistributions of  source code must  retain the above copyright  notice,
  -    this list of conditions and the following disclaimer.
  -
  - 2. Redistributions in binary form must reproduce the above copyright notice,
  -    this list of conditions and the following disclaimer in the documentation
  -    and/or other materials provided with the distribution.
  -
  - 3. The end-user documentation included with the redistribution, if any, must
  -    include  the following  acknowledgment:  "This product includes  software
  -    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  -    Alternately, this  acknowledgment may  appear in the software itself,  if
  -    and wherever such third-party acknowledgments normally appear.
  -
  - 4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
  -    must not be used to endorse or promote products derived from this  software
  -    without  prior written permission. For written permission, please contact
  -    apache@apache.org.
  -
  - 5. Products  derived from this software may not  be called "Apache", nor may
  -    "Apache" appear  in their name,  without prior written permission  of the
  -    Apache Software Foundation.
  -
  - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  - FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  - APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  - INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  - DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  - OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  - ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  - (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  -
  - This software  consists of voluntary contributions made  by many individuals
  - on  behalf of the Apache Software  Foundation. For more  information on the
  - Apache Software Foundation, please see <http://www.apache.org/>.
  -
  -*/
  -package org.apache.excalibur.mpool;
  -
  -/**
  - * This is the interface for Pools that are not a fixed size.  This interface
  - * exposes enough explicit state so that an external asynchronous Controller
  - * can do it's job.  A secondary purpose of this interface is to supply a
  - * simple authentication mechanism so that the Pool only responds to method
  - * invocations by the legitimate controller.
  - *
  - * <p>
  - *   The key is a randomly generated number greater than one assigned by the
  - *   PoolManager and given to the Pool and the PoolController.  The mechanism
  - *   to generate the number is up to the PoolManager's policy.  Keep in mind
  - *   that should the key be made publicly available, the Pool is susceptible
  - *   to a replay attack.  Therefore, it is suggested that the key be created
  - *   at the same time the Pool is created.
  - * </p>
  - *
  - * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  - * @version CVS $Revision$ $Date$
  - * @since 4.1
  - */
  -public interface ManagablePool extends Pool
  -{
  -    /**
  -     * Grow by the specified amount.  The pool should trust the Controller
  -     * for the Grow size.
  -     *
  -     * @param  amount  an integer amount to increase the pool size by.
  -     * @param  key     an integer number supplied by the PoolManager to
  -     *                 validate that the method is called legitimately
  -     *
  -     * @throws IllegalAccessException if the key does not match the
  -     *                                controller's key.
  -     */
  -    void grow( int amount, long key )
  -        throws IllegalAccessException;
  -
  -    /**
  -     * Shrink the pool by the specified amount.  The pool should trust the
  -     * Controller, but be smart enough not to achieve a negative pool size.
  -     * In other words, you should clip the shrink amount so that the pool
  -     * does not go below 0.
  -     *
  -     * @param  amount  an integer amount to decrease the pool size by.
  -     * @param  key     an integer number supplied by the PoolManager to
  -     *                 validate that the method is called legitimately
  -     *
  -     * @throws IllegalAccessException if the key does not match the
  -     *                                controller's key.
  -     */
  -    void shrink( int amount, long key )
  -        throws IllegalAccessException;
  -
  -    /**
  -     * Determine the pool's current size.  The size is defined as the number
  -     * of Poolable objects in reserve.
  -     *
  -     * @param  key     an integer number supplied by the PoolManager to
  -     *                 validate that the method is called legitimately
  -     *
  -     * @return  size of pool's reserve.
  -     *
  -     * @throws IllegalAccessException if the key does not match the
  -     *                                controller's key.
  -     */
  -    int size( long key )
  -        throws IllegalAccessException;
  -}
  +/*
  +
  + ============================================================================
  +                   The Apache Software License, Version 1.1
  + ============================================================================
  +
  + Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  +
  + Redistribution and use in source and binary forms, with or without modifica-
  + tion, are permitted provided that the following conditions are met:
  +
  + 1. Redistributions of  source code must  retain the above copyright  notice,
  +    this list of conditions and the following disclaimer.
  +
  + 2. Redistributions in binary form must reproduce the above copyright notice,
  +    this list of conditions and the following disclaimer in the documentation
  +    and/or other materials provided with the distribution.
  +
  + 3. The end-user documentation included with the redistribution, if any, must
  +    include  the following  acknowledgment:  "This product includes  software
  +    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  +    Alternately, this  acknowledgment may  appear in the software itself,  if
  +    and wherever such third-party acknowledgments normally appear.
  +
  + 4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
  +    must not be used to endorse or promote products derived from this  software
  +    without  prior written permission. For written permission, please contact
  +    apache@apache.org.
  +
  + 5. Products  derived from this software may not  be called "Apache", nor may
  +    "Apache" appear  in their name,  without prior written permission  of the
  +    Apache Software Foundation.
  +
  + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  + FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  + APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  + INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  + DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  + OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  + ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  + (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  +
  + This software  consists of voluntary contributions made  by many individuals
  + on  behalf of the Apache Software  Foundation. For more  information on the
  + Apache Software Foundation, please see <http://www.apache.org/>.
  +
  +*/
  +package org.apache.excalibur.mpool;
  +
  +/**
  + * This is the interface for Pools that are not a fixed size.  This interface
  + * exposes enough explicit state so that an external asynchronous Controller
  + * can do it's job.  A secondary purpose of this interface is to supply a
  + * simple authentication mechanism so that the Pool only responds to method
  + * invocations by the legitimate controller.
  + *
  + * <p>
  + *   The key is a randomly generated number greater than one assigned by the
  + *   PoolManager and given to the Pool and the PoolController.  The mechanism
  + *   to generate the number is up to the PoolManager's policy.  Keep in mind
  + *   that should the key be made publicly available, the Pool is susceptible
  + *   to a replay attack.  Therefore, it is suggested that the key be created
  + *   at the same time the Pool is created.
  + * </p>
  + *
  + * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  + * @version CVS $Revision$ $Date$
  + * @since 4.1
  + */
  +public interface ManagablePool extends Pool
  +{
  +    /**
  +     * Grow by the specified amount.  The pool should trust the Controller
  +     * for the Grow size.
  +     *
  +     * @param  amount  an integer amount to increase the pool size by.
  +     * @param  key     an integer number supplied by the PoolManager to
  +     *                 validate that the method is called legitimately
  +     *
  +     * @throws IllegalAccessException if the key does not match the
  +     *                                controller's key.
  +     */
  +    void grow( int amount, long key )
  +        throws IllegalAccessException;
  +
  +    /**
  +     * Shrink the pool by the specified amount.  The pool should trust the
  +     * Controller, but be smart enough not to achieve a negative pool size.
  +     * In other words, you should clip the shrink amount so that the pool
  +     * does not go below 0.
  +     *
  +     * @param  amount  an integer amount to decrease the pool size by.
  +     * @param  key     an integer number supplied by the PoolManager to
  +     *                 validate that the method is called legitimately
  +     *
  +     * @throws IllegalAccessException if the key does not match the
  +     *                                controller's key.
  +     */
  +    void shrink( int amount, long key )
  +        throws IllegalAccessException;
  +
  +    /**
  +     * Determine the pool's current size.  The size is defined as the number
  +     * of Poolable objects in reserve.
  +     *
  +     * @param  key     an integer number supplied by the PoolManager to
  +     *                 validate that the method is called legitimately
  +     *
  +     * @return  size of pool's reserve.
  +     *
  +     * @throws IllegalAccessException if the key does not match the
  +     *                                controller's key.
  +     */
  +    int size( long key )
  +        throws IllegalAccessException;
  +}
  
  
  
  1.2       +89 -89    jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/mpool/ObjectFactory.java
  
  Index: ObjectFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/mpool/ObjectFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ObjectFactory.java	7 Aug 2002 22:44:25 -0000	1.1
  +++ ObjectFactory.java	13 Aug 2002 08:15:20 -0000	1.2
  @@ -1,89 +1,89 @@
  -/*
  -
  - ============================================================================
  -                   The Apache Software License, Version 1.1
  - ============================================================================
  -
  - Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  -
  - Redistribution and use in source and binary forms, with or without modifica-
  - tion, are permitted provided that the following conditions are met:
  -
  - 1. Redistributions of  source code must  retain the above copyright  notice,
  -    this list of conditions and the following disclaimer.
  -
  - 2. Redistributions in binary form must reproduce the above copyright notice,
  -    this list of conditions and the following disclaimer in the documentation
  -    and/or other materials provided with the distribution.
  -
  - 3. The end-user documentation included with the redistribution, if any, must
  -    include  the following  acknowledgment:  "This product includes  software
  -    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  -    Alternately, this  acknowledgment may  appear in the software itself,  if
  -    and wherever such third-party acknowledgments normally appear.
  -
  - 4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
  -    must not be used to endorse or promote products derived from this  software
  -    without  prior written permission. For written permission, please contact
  -    apache@apache.org.
  -
  - 5. Products  derived from this software may not  be called "Apache", nor may
  -    "Apache" appear  in their name,  without prior written permission  of the
  -    Apache Software Foundation.
  -
  - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  - FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  - APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  - INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  - DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  - OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  - ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  - (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  -
  - This software  consists of voluntary contributions made  by many individuals
  - on  behalf of the Apache Software  Foundation. For more  information on the
  - Apache Software Foundation, please see <http://www.apache.org/>.
  -
  -*/
  -package org.apache.excalibur.mpool;
  -
  -/**
  - * This interface is to define how an ObjectFactory is defined.  While this
  - * class is not strictly necessary, the implementation of the Pool can differ
  - * object creation to and instance of this interface.
  - *
  - * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  - * @version CVS $Revision$ $Date$
  - * @since 4.1.2
  - */
  -public interface ObjectFactory
  -{
  -    /**
  -     * Create a new instance of the object being pooled.
  -     *
  -     * @return the pooled Object instance
  -     * @throws Exception if the object cannot be instantiated
  -     */
  -    Object newInstance() throws Exception;
  -
  -    /**
  -     * Get the class of the object you are creating.
  -     *
  -     * @return Class object of the factory's class
  -     */
  -    Class getCreatedClass();
  -
  -    /**
  -     * Performs any deconstruction that is necessary for the
  -     * object.
  -     *
  -     * @param object to destroy
  -     * @throws IllegalArgumentException if the object is not of
  -     *         the same class that the factory creates.
  -     * @throws Exception if there is any other reason that the
  -     *         factory has problems disposing of the object.
  -     */
  -    void dispose( Object object ) throws Exception;
  -}
  +/*
  +
  + ============================================================================
  +                   The Apache Software License, Version 1.1
  + ============================================================================
  +
  + Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  +
  + Redistribution and use in source and binary forms, with or without modifica-
  + tion, are permitted provided that the following conditions are met:
  +
  + 1. Redistributions of  source code must  retain the above copyright  notice,
  +    this list of conditions and the following disclaimer.
  +
  + 2. Redistributions in binary form must reproduce the above copyright notice,
  +    this list of conditions and the following disclaimer in the documentation
  +    and/or other materials provided with the distribution.
  +
  + 3. The end-user documentation included with the redistribution, if any, must
  +    include  the following  acknowledgment:  "This product includes  software
  +    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  +    Alternately, this  acknowledgment may  appear in the software itself,  if
  +    and wherever such third-party acknowledgments normally appear.
  +
  + 4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
  +    must not be used to endorse or promote products derived from this  software
  +    without  prior written permission. For written permission, please contact
  +    apache@apache.org.
  +
  + 5. Products  derived from this software may not  be called "Apache", nor may
  +    "Apache" appear  in their name,  without prior written permission  of the
  +    Apache Software Foundation.
  +
  + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  + FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  + APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  + INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  + DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  + OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  + ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  + (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  +
  + This software  consists of voluntary contributions made  by many individuals
  + on  behalf of the Apache Software  Foundation. For more  information on the
  + Apache Software Foundation, please see <http://www.apache.org/>.
  +
  +*/
  +package org.apache.excalibur.mpool;
  +
  +/**
  + * This interface is to define how an ObjectFactory is defined.  While this
  + * class is not strictly necessary, the implementation of the Pool can differ
  + * object creation to and instance of this interface.
  + *
  + * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  + * @version CVS $Revision$ $Date$
  + * @since 4.1.2
  + */
  +public interface ObjectFactory
  +{
  +    /**
  +     * Create a new instance of the object being pooled.
  +     *
  +     * @return the pooled Object instance
  +     * @throws Exception if the object cannot be instantiated
  +     */
  +    Object newInstance() throws Exception;
  +
  +    /**
  +     * Get the class of the object you are creating.
  +     *
  +     * @return Class object of the factory's class
  +     */
  +    Class getCreatedClass();
  +
  +    /**
  +     * Performs any deconstruction that is necessary for the
  +     * object.
  +     *
  +     * @param object to destroy
  +     * @throws IllegalArgumentException if the object is not of
  +     *         the same class that the factory creates.
  +     * @throws Exception if there is any other reason that the
  +     *         factory has problems disposing of the object.
  +     */
  +    void dispose( Object object ) throws Exception;
  +}
  
  
  
  1.4       +97 -97    jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/mpool/Pool.java
  
  Index: Pool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/mpool/Pool.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Pool.java	8 Aug 2002 00:57:25 -0000	1.3
  +++ Pool.java	13 Aug 2002 08:15:20 -0000	1.4
  @@ -1,97 +1,97 @@
  -/*
  -
  - ============================================================================
  -                   The Apache Software License, Version 1.1
  - ============================================================================
  -
  - Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  -
  - Redistribution and use in source and binary forms, with or without modifica-
  - tion, are permitted provided that the following conditions are met:
  -
  - 1. Redistributions of  source code must  retain the above copyright  notice,
  -    this list of conditions and the following disclaimer.
  -
  - 2. Redistributions in binary form must reproduce the above copyright notice,
  -    this list of conditions and the following disclaimer in the documentation
  -    and/or other materials provided with the distribution.
  -
  - 3. The end-user documentation included with the redistribution, if any, must
  -    include  the following  acknowledgment:  "This product includes  software
  -    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  -    Alternately, this  acknowledgment may  appear in the software itself,  if
  -    and wherever such third-party acknowledgments normally appear.
  -
  - 4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
  -    must not be used to endorse or promote products derived from this  software
  -    without  prior written permission. For written permission, please contact
  -    apache@apache.org.
  -
  - 5. Products  derived from this software may not  be called "Apache", nor may
  -    "Apache" appear  in their name,  without prior written permission  of the
  -    Apache Software Foundation.
  -
  - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  - FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  - APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  - INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  - DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  - OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  - ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  - (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  -
  - This software  consists of voluntary contributions made  by many individuals
  - on  behalf of the Apache Software  Foundation. For more  information on the
  - Apache Software Foundation, please see <http://www.apache.org/>.
  -
  -*/
  -package org.apache.excalibur.mpool;
  -
  -/**
  - * This interface is to define how a Pool is used.  We have determined by
  - * using the previous Pool implementations that the Pool marker interface
  - * is considered harmful.  When generics are introduced in JDK 1.5, this
  - * interface will be a prime candidate for those improvements.
  - *
  - * <p>
  - *  It is important to realize that some objects are cheaper to simply allow
  - *  the garbage collector to take care of them.  Therefore, only pool objects
  - *  that are computationally expensive to create.  Prime candidates would be
  - *  Components, JDBC Connection objects, Socket connections, etc.
  - * </p>
  - * <p>
  - *  The interface is inspired by both the Mutex acquire/release and the
  - *  structure of the ThreadLocal object.  In fact, it would be trivial
  - *  to implement a "ThreadLocal" pool.
  - * </p>
  - *
  - * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  - * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  - * @version CVS $Revision$ $Date$
  - * @since 4.1.2
  - */
  -public interface Pool
  -{
  -    /**
  -     * Acquire an instance of the pooled object.
  -     *
  -     * @return the pooled Object instance
  -     */
  -    Object acquire() throws Exception;
  -
  -    /**
  -     * Release the instance of the pooled object.
  -     *
  -     * @param pooledObject  The pooled object to release to the pool.
  -     */
  -    void release( Object pooledObject );
  -
  -    /**
  -     * Create a new instance of the object being pooled.
  -     *
  -     * @return the pooled Object instance
  -     */
  -    Object newInstance() throws Exception;
  -}
  +/*
  +
  + ============================================================================
  +                   The Apache Software License, Version 1.1
  + ============================================================================
  +
  + Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  +
  + Redistribution and use in source and binary forms, with or without modifica-
  + tion, are permitted provided that the following conditions are met:
  +
  + 1. Redistributions of  source code must  retain the above copyright  notice,
  +    this list of conditions and the following disclaimer.
  +
  + 2. Redistributions in binary form must reproduce the above copyright notice,
  +    this list of conditions and the following disclaimer in the documentation
  +    and/or other materials provided with the distribution.
  +
  + 3. The end-user documentation included with the redistribution, if any, must
  +    include  the following  acknowledgment:  "This product includes  software
  +    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  +    Alternately, this  acknowledgment may  appear in the software itself,  if
  +    and wherever such third-party acknowledgments normally appear.
  +
  + 4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
  +    must not be used to endorse or promote products derived from this  software
  +    without  prior written permission. For written permission, please contact
  +    apache@apache.org.
  +
  + 5. Products  derived from this software may not  be called "Apache", nor may
  +    "Apache" appear  in their name,  without prior written permission  of the
  +    Apache Software Foundation.
  +
  + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  + FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  + APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  + INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  + DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  + OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  + ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  + (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  +
  + This software  consists of voluntary contributions made  by many individuals
  + on  behalf of the Apache Software  Foundation. For more  information on the
  + Apache Software Foundation, please see <http://www.apache.org/>.
  +
  +*/
  +package org.apache.excalibur.mpool;
  +
  +/**
  + * This interface is to define how a Pool is used.  We have determined by
  + * using the previous Pool implementations that the Pool marker interface
  + * is considered harmful.  When generics are introduced in JDK 1.5, this
  + * interface will be a prime candidate for those improvements.
  + *
  + * <p>
  + *  It is important to realize that some objects are cheaper to simply allow
  + *  the garbage collector to take care of them.  Therefore, only pool objects
  + *  that are computationally expensive to create.  Prime candidates would be
  + *  Components, JDBC Connection objects, Socket connections, etc.
  + * </p>
  + * <p>
  + *  The interface is inspired by both the Mutex acquire/release and the
  + *  structure of the ThreadLocal object.  In fact, it would be trivial
  + *  to implement a "ThreadLocal" pool.
  + * </p>
  + *
  + * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  + * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  + * @version CVS $Revision$ $Date$
  + * @since 4.1.2
  + */
  +public interface Pool
  +{
  +    /**
  +     * Acquire an instance of the pooled object.
  +     *
  +     * @return the pooled Object instance
  +     */
  +    Object acquire() throws Exception;
  +
  +    /**
  +     * Release the instance of the pooled object.
  +     *
  +     * @param pooledObject  The pooled object to release to the pool.
  +     */
  +    void release( Object pooledObject );
  +
  +    /**
  +     * Create a new instance of the object being pooled.
  +     *
  +     * @return the pooled Object instance
  +     */
  +    Object newInstance() throws Exception;
  +}
  
  
  
  1.2       +68 -68    jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/mpool/PoolManager.java
  
  Index: PoolManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/mpool/PoolManager.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PoolManager.java	7 Aug 2002 22:44:26 -0000	1.1
  +++ PoolManager.java	13 Aug 2002 08:15:20 -0000	1.2
  @@ -1,68 +1,68 @@
  -/*
  -
  - ============================================================================
  -                   The Apache Software License, Version 1.1
  - ============================================================================
  -
  - Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  -
  - Redistribution and use in source and binary forms, with or without modifica-
  - tion, are permitted provided that the following conditions are met:
  -
  - 1. Redistributions of  source code must  retain the above copyright  notice,
  -    this list of conditions and the following disclaimer.
  -
  - 2. Redistributions in binary form must reproduce the above copyright notice,
  -    this list of conditions and the following disclaimer in the documentation
  -    and/or other materials provided with the distribution.
  -
  - 3. The end-user documentation included with the redistribution, if any, must
  -    include  the following  acknowledgment:  "This product includes  software
  -    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  -    Alternately, this  acknowledgment may  appear in the software itself,  if
  -    and wherever such third-party acknowledgments normally appear.
  -
  - 4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
  -    must not be used to endorse or promote products derived from this  software
  -    without  prior written permission. For written permission, please contact
  -    apache@apache.org.
  -
  - 5. Products  derived from this software may not  be called "Apache", nor may
  -    "Apache" appear  in their name,  without prior written permission  of the
  -    Apache Software Foundation.
  -
  - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  - FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  - APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  - INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  - DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  - OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  - ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  - (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  -
  - This software  consists of voluntary contributions made  by many individuals
  - on  behalf of the Apache Software  Foundation. For more  information on the
  - Apache Software Foundation, please see <http://www.apache.org/>.
  -
  -*/
  -package org.apache.excalibur.mpool;
  -
  -/**
  - * This interface is for a PoolManager that creates pools that are managed
  - * asynchronously.  The contract is that the controller type is specified in
  - * the constructor.
  - *
  - * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  - * @version CVS $Revision$ $Date$
  - * @since 4.1
  - */
  -public interface PoolManager
  -{
  -    /**
  -     * Return a managed pool that has a controller.
  -     */
  -    Pool getManagedPool( ObjectFactory factory, int initialEntries )
  -        throws Exception;
  -}
  +/*
  +
  + ============================================================================
  +                   The Apache Software License, Version 1.1
  + ============================================================================
  +
  + Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  +
  + Redistribution and use in source and binary forms, with or without modifica-
  + tion, are permitted provided that the following conditions are met:
  +
  + 1. Redistributions of  source code must  retain the above copyright  notice,
  +    this list of conditions and the following disclaimer.
  +
  + 2. Redistributions in binary form must reproduce the above copyright notice,
  +    this list of conditions and the following disclaimer in the documentation
  +    and/or other materials provided with the distribution.
  +
  + 3. The end-user documentation included with the redistribution, if any, must
  +    include  the following  acknowledgment:  "This product includes  software
  +    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  +    Alternately, this  acknowledgment may  appear in the software itself,  if
  +    and wherever such third-party acknowledgments normally appear.
  +
  + 4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
  +    must not be used to endorse or promote products derived from this  software
  +    without  prior written permission. For written permission, please contact
  +    apache@apache.org.
  +
  + 5. Products  derived from this software may not  be called "Apache", nor may
  +    "Apache" appear  in their name,  without prior written permission  of the
  +    Apache Software Foundation.
  +
  + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  + FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  + APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  + INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  + DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  + OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  + ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  + (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  +
  + This software  consists of voluntary contributions made  by many individuals
  + on  behalf of the Apache Software  Foundation. For more  information on the
  + Apache Software Foundation, please see <http://www.apache.org/>.
  +
  +*/
  +package org.apache.excalibur.mpool;
  +
  +/**
  + * This interface is for a PoolManager that creates pools that are managed
  + * asynchronously.  The contract is that the controller type is specified in
  + * the constructor.
  + *
  + * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  + * @version CVS $Revision$ $Date$
  + * @since 4.1
  + */
  +public interface PoolManager
  +{
  +    /**
  +     * Return a managed pool that has a controller.
  +     */
  +    Pool getManagedPool( ObjectFactory factory, int initialEntries )
  +        throws Exception;
  +}
  
  
  
  1.2       +245 -245  jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/mpool/VariableSizePool.java
  
  Index: VariableSizePool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/mpool/VariableSizePool.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- VariableSizePool.java	7 Aug 2002 22:44:26 -0000	1.1
  +++ VariableSizePool.java	13 Aug 2002 08:15:20 -0000	1.2
  @@ -1,245 +1,245 @@
  -/*
  -
  - ============================================================================
  -                   The Apache Software License, Version 1.1
  - ============================================================================
  -
  - Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  -
  - Redistribution and use in source and binary forms, with or without modifica-
  - tion, are permitted provided that the following conditions are met:
  -
  - 1. Redistributions of  source code must  retain the above copyright  notice,
  -    this list of conditions and the following disclaimer.
  -
  - 2. Redistributions in binary form must reproduce the above copyright notice,
  -    this list of conditions and the following disclaimer in the documentation
  -    and/or other materials provided with the distribution.
  -
  - 3. The end-user documentation included with the redistribution, if any, must
  -    include  the following  acknowledgment:  "This product includes  software
  -    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  -    Alternately, this  acknowledgment may  appear in the software itself,  if
  -    and wherever such third-party acknowledgments normally appear.
  -
  - 4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
  -    must not be used to endorse or promote products derived from this  software
  -    without  prior written permission. For written permission, please contact
  -    apache@apache.org.
  -
  - 5. Products  derived from this software may not  be called "Apache", nor may
  -    "Apache" appear  in their name,  without prior written permission  of the
  -    Apache Software Foundation.
  -
  - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  - FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  - APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  - INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  - DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  - OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  - ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  - (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  -
  - This software  consists of voluntary contributions made  by many individuals
  - on  behalf of the Apache Software  Foundation. For more  information on the
  - Apache Software Foundation, please see <http://www.apache.org/>.
  -
  -*/
  -package org.apache.excalibur.mpool;
  -
  -import org.apache.avalon.excalibur.collections.Buffer;
  -import org.apache.avalon.excalibur.collections.BufferUnderflowException;
  -import org.apache.avalon.excalibur.collections.VariableSizeBuffer;
  -import org.apache.avalon.framework.activity.Disposable;
  -
  -/**
  - * This is an <code>Pool</code> that caches Poolable objects for reuse.
  - * Please note that this pool offers no resource limiting whatsoever.
  - *
  - * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  - * @version CVS $Revision$ $Date$
  - * @since 4.1
  - */
  -public final class VariableSizePool
  -    implements Pool, Disposable, ManagablePool
  -{
  -    private boolean m_disposed = false;
  -    private final Buffer m_buffer;
  -    private final ObjectFactory m_factory;
  -    private final long m_key;
  -
  -    /**
  -     * Constructor for an unmanaged pool
  -     */
  -    public VariableSizePool( ObjectFactory factory, int size )
  -        throws Exception
  -    {
  -        this( factory, size, -1 );
  -    }
  -
  -    /**
  -     * Constructor for a managed pool
  -     */
  -    public VariableSizePool( ObjectFactory factory, int size, long key )
  -        throws Exception
  -    {
  -        m_buffer = new VariableSizeBuffer( size );
  -        m_factory = factory;
  -        m_key = key;
  -
  -        synchronized( m_factory )
  -        {
  -            for( int i = 0; i < size; i++ )
  -            {
  -                m_buffer.add( newInstance() );
  -            }
  -        }
  -    }
  -
  -    public Object acquire()
  -        throws Exception
  -    {
  -        if( m_disposed )
  -        {
  -            throw new IllegalStateException( "Cannot get an object from a disposed pool" );
  -        }
  -
  -        Object object = null;
  -
  -        try
  -        {
  -            synchronized( m_buffer )
  -            {
  -                object = m_buffer.remove();
  -            }
  -        }
  -        catch( BufferUnderflowException bue )
  -        {
  -            object = newInstance();
  -        }
  -
  -        if( null == object )
  -        {
  -            object = newInstance();
  -        }
  -
  -        return object;
  -    }
  -
  -    public void release( Object pooledObject )
  -    {
  -        if( m_disposed )
  -        {
  -            try
  -            {
  -                m_factory.dispose( pooledObject );
  -            }
  -            catch( Exception e )
  -            {
  -                // We should never get here, but ignore the exception if it happens
  -            }
  -        }
  -        else
  -        {
  -            synchronized( m_buffer )
  -            {
  -                m_buffer.add( pooledObject );
  -            }
  -        }
  -    }
  -
  -    public Object newInstance()
  -        throws Exception
  -    {
  -        synchronized( m_factory )
  -        {
  -            return m_factory.newInstance();
  -        }
  -    }
  -
  -    public void dispose()
  -    {
  -        m_disposed = true;
  -
  -        synchronized( m_buffer )
  -        {
  -            while( !m_buffer.isEmpty() )
  -            {
  -                try
  -                {
  -                    m_factory.dispose( m_buffer.remove() );
  -                }
  -                catch( Exception e )
  -                {
  -                    // We should never get here, but ignore the exception if it happens
  -                }
  -            }
  -        }
  -    }
  -
  -    public void shrink( final int byNum, final long key )
  -        throws IllegalAccessException
  -    {
  -        if( m_key < 0 || m_key != key )
  -        {
  -            throw new IllegalAccessException();
  -        }
  -
  -        synchronized( m_buffer )
  -        {
  -            final int num = Math.min( byNum, m_buffer.size() );
  -
  -            for( int i = 0; i < num; i++ )
  -            {
  -                try
  -                {
  -                    m_factory.dispose( m_buffer.remove() );
  -                }
  -                catch( Exception e )
  -                {
  -                    // ignore exception
  -                }
  -            }
  -        }
  -    }
  -
  -    public void grow( final int byNum, final long key )
  -        throws IllegalAccessException
  -    {
  -        if( m_key < 0 || m_key != key )
  -        {
  -            throw new IllegalAccessException();
  -        }
  -
  -        synchronized( m_buffer )
  -        {
  -            for( int i = 0; i < byNum; i++ )
  -            {
  -                try
  -                {
  -                    m_buffer.add( newInstance() );
  -                }
  -                catch( Exception e )
  -                {
  -                    // ignore exception
  -                }
  -            }
  -        }
  -    }
  -
  -    public int size( final long key )
  -        throws IllegalAccessException
  -    {
  -        if( m_key < 0 || m_key != key )
  -        {
  -            throw new IllegalAccessException();
  -        }
  -
  -        synchronized( m_buffer )
  -        {
  -            return m_buffer.size();
  -        }
  -    }
  -}
  +/*
  +
  + ============================================================================
  +                   The Apache Software License, Version 1.1
  + ============================================================================
  +
  + Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  +
  + Redistribution and use in source and binary forms, with or without modifica-
  + tion, are permitted provided that the following conditions are met:
  +
  + 1. Redistributions of  source code must  retain the above copyright  notice,
  +    this list of conditions and the following disclaimer.
  +
  + 2. Redistributions in binary form must reproduce the above copyright notice,
  +    this list of conditions and the following disclaimer in the documentation
  +    and/or other materials provided with the distribution.
  +
  + 3. The end-user documentation included with the redistribution, if any, must
  +    include  the following  acknowledgment:  "This product includes  software
  +    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  +    Alternately, this  acknowledgment may  appear in the software itself,  if
  +    and wherever such third-party acknowledgments normally appear.
  +
  + 4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
  +    must not be used to endorse or promote products derived from this  software
  +    without  prior written permission. For written permission, please contact
  +    apache@apache.org.
  +
  + 5. Products  derived from this software may not  be called "Apache", nor may
  +    "Apache" appear  in their name,  without prior written permission  of the
  +    Apache Software Foundation.
  +
  + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  + FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  + APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  + INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  + DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  + OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  + ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  + (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  +
  + This software  consists of voluntary contributions made  by many individuals
  + on  behalf of the Apache Software  Foundation. For more  information on the
  + Apache Software Foundation, please see <http://www.apache.org/>.
  +
  +*/
  +package org.apache.excalibur.mpool;
  +
  +import org.apache.avalon.excalibur.collections.Buffer;
  +import org.apache.avalon.excalibur.collections.BufferUnderflowException;
  +import org.apache.avalon.excalibur.collections.VariableSizeBuffer;
  +import org.apache.avalon.framework.activity.Disposable;
  +
  +/**
  + * This is an <code>Pool</code> that caches Poolable objects for reuse.
  + * Please note that this pool offers no resource limiting whatsoever.
  + *
  + * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  + * @version CVS $Revision$ $Date$
  + * @since 4.1
  + */
  +public final class VariableSizePool
  +    implements Pool, Disposable, ManagablePool
  +{
  +    private boolean m_disposed = false;
  +    private final Buffer m_buffer;
  +    private final ObjectFactory m_factory;
  +    private final long m_key;
  +
  +    /**
  +     * Constructor for an unmanaged pool
  +     */
  +    public VariableSizePool( ObjectFactory factory, int size )
  +        throws Exception
  +    {
  +        this( factory, size, -1 );
  +    }
  +
  +    /**
  +     * Constructor for a managed pool
  +     */
  +    public VariableSizePool( ObjectFactory factory, int size, long key )
  +        throws Exception
  +    {
  +        m_buffer = new VariableSizeBuffer( size );
  +        m_factory = factory;
  +        m_key = key;
  +
  +        synchronized( m_factory )
  +        {
  +            for( int i = 0; i < size; i++ )
  +            {
  +                m_buffer.add( newInstance() );
  +            }
  +        }
  +    }
  +
  +    public Object acquire()
  +        throws Exception
  +    {
  +        if( m_disposed )
  +        {
  +            throw new IllegalStateException( "Cannot get an object from a disposed pool" );
  +        }
  +
  +        Object object = null;
  +
  +        try
  +        {
  +            synchronized( m_buffer )
  +            {
  +                object = m_buffer.remove();
  +            }
  +        }
  +        catch( BufferUnderflowException bue )
  +        {
  +            object = newInstance();
  +        }
  +
  +        if( null == object )
  +        {
  +            object = newInstance();
  +        }
  +
  +        return object;
  +    }
  +
  +    public void release( Object pooledObject )
  +    {
  +        if( m_disposed )
  +        {
  +            try
  +            {
  +                m_factory.dispose( pooledObject );
  +            }
  +            catch( Exception e )
  +            {
  +                // We should never get here, but ignore the exception if it happens
  +            }
  +        }
  +        else
  +        {
  +            synchronized( m_buffer )
  +            {
  +                m_buffer.add( pooledObject );
  +            }
  +        }
  +    }
  +
  +    public Object newInstance()
  +        throws Exception
  +    {
  +        synchronized( m_factory )
  +        {
  +            return m_factory.newInstance();
  +        }
  +    }
  +
  +    public void dispose()
  +    {
  +        m_disposed = true;
  +
  +        synchronized( m_buffer )
  +        {
  +            while( !m_buffer.isEmpty() )
  +            {
  +                try
  +                {
  +                    m_factory.dispose( m_buffer.remove() );
  +                }
  +                catch( Exception e )
  +                {
  +                    // We should never get here, but ignore the exception if it happens
  +                }
  +            }
  +        }
  +    }
  +
  +    public void shrink( final int byNum, final long key )
  +        throws IllegalAccessException
  +    {
  +        if( m_key < 0 || m_key != key )
  +        {
  +            throw new IllegalAccessException();
  +        }
  +
  +        synchronized( m_buffer )
  +        {
  +            final int num = Math.min( byNum, m_buffer.size() );
  +
  +            for( int i = 0; i < num; i++ )
  +            {
  +                try
  +                {
  +                    m_factory.dispose( m_buffer.remove() );
  +                }
  +                catch( Exception e )
  +                {
  +                    // ignore exception
  +                }
  +            }
  +        }
  +    }
  +
  +    public void grow( final int byNum, final long key )
  +        throws IllegalAccessException
  +    {
  +        if( m_key < 0 || m_key != key )
  +        {
  +            throw new IllegalAccessException();
  +        }
  +
  +        synchronized( m_buffer )
  +        {
  +            for( int i = 0; i < byNum; i++ )
  +            {
  +                try
  +                {
  +                    m_buffer.add( newInstance() );
  +                }
  +                catch( Exception e )
  +                {
  +                    // ignore exception
  +                }
  +            }
  +        }
  +    }
  +
  +    public int size( final long key )
  +        throws IllegalAccessException
  +    {
  +        if( m_key < 0 || m_key != key )
  +        {
  +            throw new IllegalAccessException();
  +        }
  +
  +        synchronized( m_buffer )
  +        {
  +            return m_buffer.size();
  +        }
  +    }
  +}
  
  
  
  1.6       +232 -232  jakarta-avalon-excalibur/event/src/test/QueueTest.java
  
  Index: QueueTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/event/src/test/QueueTest.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- QueueTest.java	8 Aug 2002 00:57:25 -0000	1.5
  +++ QueueTest.java	13 Aug 2002 08:15:21 -0000	1.6
  @@ -1,232 +1,232 @@
  -/*
  -
  - ============================================================================
  -                   The Apache Software License, Version 1.1
  - ============================================================================
  -
  - Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  -
  - Redistribution and use in source and binary forms, with or without modifica-
  - tion, are permitted provided that the following conditions are met:
  -
  - 1. Redistributions of  source code must  retain the above copyright  notice,
  -    this list of conditions and the following disclaimer.
  -
  - 2. Redistributions in binary form must reproduce the above copyright notice,
  -    this list of conditions and the following disclaimer in the documentation
  -    and/or other materials provided with the distribution.
  -
  - 3. The end-user documentation included with the redistribution, if any, must
  -    include  the following  acknowledgment:  "This product includes  software
  -    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  -    Alternately, this  acknowledgment may  appear in the software itself,  if
  -    and wherever such third-party acknowledgments normally appear.
  -
  - 4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
  -    must not be used to endorse or promote products derived from this  software
  -    without  prior written permission. For written permission, please contact
  -    apache@apache.org.
  -
  - 5. Products  derived from this software may not  be called "Apache", nor may
  -    "Apache" appear  in their name,  without prior written permission  of the
  -    Apache Software Foundation.
  -
  - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  - FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  - APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  - INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  - DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  - OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  - ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  - (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  -
  - This software  consists of voluntary contributions made  by many individuals
  - on  behalf of the Apache Software  Foundation. For more  information on the
  - Apache Software Foundation, please see <http://www.apache.org/>.
  -
  -*/
  -
  -import org.apache.avalon.framework.CascadingRuntimeException;
  -import org.apache.excalibur.event.DefaultQueue;
  -import org.apache.excalibur.event.Queue;
  -import org.apache.excalibur.event.QueueElement;
  -import org.apache.excalibur.event.Sink;
  -import org.apache.excalibur.event.SinkException;
  -import org.apache.excalibur.event.Source;
  -
  -/**
  - * Simple test to expose the thread queue bug
  - *
  - * @author <a href="mailto:proyal@managingpartners.com">Peter Royal</a>
  - * @version VSS $Revision$ $Date$
  - */
  -public class QueueTest
  -{
  -    private QueueStart start;
  -    private QueueEnd end;
  -
  -    private Queue queue;
  -
  -    private Thread[] stages;
  -
  -    public static void main( String[] args ) throws Exception
  -    {
  -        QueueTest qt = new QueueTest();
  -
  -        qt.initialize( Integer.parseInt( args[ 0 ] ) );
  -        qt.start();
  -    }
  -
  -    public void initialize( int count ) throws Exception
  -    {
  -        this.stages = new Thread[ 2 ];
  -
  -        this.queue = new DefaultQueue();
  -
  -        this.start = new QueueStart( count );
  -        this.start.setSink( this.queue );
  -        this.stages[ 0 ] = new Thread( this.start );
  -
  -        this.end = new QueueEnd();
  -        this.end.setSource( this.queue );
  -        this.stages[ 1 ] = new Thread( this.end );
  -    }
  -
  -    public void start() throws Exception
  -    {
  -        System.out.println( "Starting test" );
  -
  -        for( int i = 0; i < this.stages.length; i++ )
  -        {
  -            this.stages[ i ].start();
  -        }
  -
  -        stop();
  -    }
  -
  -    public void stop() throws Exception
  -    {
  -        for( int i = 0; i < this.stages.length; i++ )
  -        {
  -            try
  -            {
  -                this.stages[ i ].join();
  -            }
  -            catch( InterruptedException e )
  -            {
  -                throw new CascadingRuntimeException( "Stage unexpectedly interrupted", e );
  -            }
  -        }
  -
  -        System.out.println( "Test complete" );
  -
  -        System.out.println( "Enqueue: " + this.start.getCount() );
  -        System.out.println( "Dequeue: " + this.end.getCount() );
  -    }
  -
  -    private class QueueInteger implements QueueElement
  -    {
  -        private int integer;
  -
  -        public QueueInteger( int integer )
  -        {
  -            this.integer = integer;
  -        }
  -
  -        public int getInteger()
  -        {
  -            return integer;
  -        }
  -    }
  -
  -    private class QueueStart implements Runnable
  -    {
  -        private Sink sink;
  -        private int queueCount;
  -        private int count;
  -
  -        public QueueStart( int queueCount )
  -        {
  -            this.queueCount = queueCount;
  -        }
  -
  -        protected void setSink( Sink sink )
  -        {
  -            this.sink = sink;
  -        }
  -
  -        public int getCount()
  -        {
  -            return count;
  -        }
  -
  -        public void run()
  -        {
  -            for( int i = 0; i < this.queueCount; i++ )
  -            {
  -                try
  -                {
  -                    this.sink.enqueue( new QueueInteger( i ) );
  -                    this.count++;
  -                }
  -                catch( SinkException e )
  -                {
  -                    System.out.println( "Unable to queue: " + e.getMessage() );
  -                }
  -            }
  -
  -            try
  -            {
  -                this.sink.enqueue( new QueueInteger( -1 ) );
  -            }
  -            catch( SinkException e )
  -            {
  -                System.out.println( "Unable to queue stop" );
  -            }
  -        }
  -    }
  -
  -    private class QueueEnd implements Runnable
  -    {
  -        private Source source;
  -        private int count;
  -
  -        protected void setSource( Source source )
  -        {
  -            this.source = source;
  -        }
  -
  -        public int getCount()
  -        {
  -            return count;
  -        }
  -
  -        public void run()
  -        {
  -            while( true )
  -            {
  -                QueueElement qe = this.source.dequeue();
  -
  -                if( qe == null )
  -                {
  -
  -                }
  -                else if( qe instanceof QueueInteger )
  -                {
  -                    QueueInteger qi = (QueueInteger)qe;
  -
  -                    if( qi.getInteger() == -1 )
  -                    {
  -                        break;
  -                    }
  -                    else
  -                    {
  -                        this.count++;
  -                    }
  -                }
  -            }
  -        }
  -    }
  -}
  +/*
  +
  + ============================================================================
  +                   The Apache Software License, Version 1.1
  + ============================================================================
  +
  + Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  +
  + Redistribution and use in source and binary forms, with or without modifica-
  + tion, are permitted provided that the following conditions are met:
  +
  + 1. Redistributions of  source code must  retain the above copyright  notice,
  +    this list of conditions and the following disclaimer.
  +
  + 2. Redistributions in binary form must reproduce the above copyright notice,
  +    this list of conditions and the following disclaimer in the documentation
  +    and/or other materials provided with the distribution.
  +
  + 3. The end-user documentation included with the redistribution, if any, must
  +    include  the following  acknowledgment:  "This product includes  software
  +    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  +    Alternately, this  acknowledgment may  appear in the software itself,  if
  +    and wherever such third-party acknowledgments normally appear.
  +
  + 4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
  +    must not be used to endorse or promote products derived from this  software
  +    without  prior written permission. For written permission, please contact
  +    apache@apache.org.
  +
  + 5. Products  derived from this software may not  be called "Apache", nor may
  +    "Apache" appear  in their name,  without prior written permission  of the
  +    Apache Software Foundation.
  +
  + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  + FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  + APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  + INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  + DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  + OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  + ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  + (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  +
  + This software  consists of voluntary contributions made  by many individuals
  + on  behalf of the Apache Software  Foundation. For more  information on the
  + Apache Software Foundation, please see <http://www.apache.org/>.
  +
  +*/
  +
  +import org.apache.avalon.framework.CascadingRuntimeException;
  +import org.apache.excalibur.event.DefaultQueue;
  +import org.apache.excalibur.event.Queue;
  +import org.apache.excalibur.event.QueueElement;
  +import org.apache.excalibur.event.Sink;
  +import org.apache.excalibur.event.SinkException;
  +import org.apache.excalibur.event.Source;
  +
  +/**
  + * Simple test to expose the thread queue bug
  + *
  + * @author <a href="mailto:proyal@managingpartners.com">Peter Royal</a>
  + * @version VSS $Revision$ $Date$
  + */
  +public class QueueTest
  +{
  +    private QueueStart start;
  +    private QueueEnd end;
  +
  +    private Queue queue;
  +
  +    private Thread[] stages;
  +
  +    public static void main( String[] args ) throws Exception
  +    {
  +        QueueTest qt = new QueueTest();
  +
  +        qt.initialize( Integer.parseInt( args[ 0 ] ) );
  +        qt.start();
  +    }
  +
  +    public void initialize( int count ) throws Exception
  +    {
  +        this.stages = new Thread[ 2 ];
  +
  +        this.queue = new DefaultQueue();
  +
  +        this.start = new QueueStart( count );
  +        this.start.setSink( this.queue );
  +        this.stages[ 0 ] = new Thread( this.start );
  +
  +        this.end = new QueueEnd();
  +        this.end.setSource( this.queue );
  +        this.stages[ 1 ] = new Thread( this.end );
  +    }
  +
  +    public void start() throws Exception
  +    {
  +        System.out.println( "Starting test" );
  +
  +        for( int i = 0; i < this.stages.length; i++ )
  +        {
  +            this.stages[ i ].start();
  +        }
  +
  +        stop();
  +    }
  +
  +    public void stop() throws Exception
  +    {
  +        for( int i = 0; i < this.stages.length; i++ )
  +        {
  +            try
  +            {
  +                this.stages[ i ].join();
  +            }
  +            catch( InterruptedException e )
  +            {
  +                throw new CascadingRuntimeException( "Stage unexpectedly interrupted", e );
  +            }
  +        }
  +
  +        System.out.println( "Test complete" );
  +
  +        System.out.println( "Enqueue: " + this.start.getCount() );
  +        System.out.println( "Dequeue: " + this.end.getCount() );
  +    }
  +
  +    private class QueueInteger implements QueueElement
  +    {
  +        private int integer;
  +
  +        public QueueInteger( int integer )
  +        {
  +            this.integer = integer;
  +        }
  +
  +        public int getInteger()
  +        {
  +            return integer;
  +        }
  +    }
  +
  +    private class QueueStart implements Runnable
  +    {
  +        private Sink sink;
  +        private int queueCount;
  +        private int count;
  +
  +        public QueueStart( int queueCount )
  +        {
  +            this.queueCount = queueCount;
  +        }
  +
  +        protected void setSink( Sink sink )
  +        {
  +            this.sink = sink;
  +        }
  +
  +        public int getCount()
  +        {
  +            return count;
  +        }
  +
  +        public void run()
  +        {
  +            for( int i = 0; i < this.queueCount; i++ )
  +            {
  +                try
  +                {
  +                    this.sink.enqueue( new QueueInteger( i ) );
  +                    this.count++;
  +                }
  +                catch( SinkException e )
  +                {
  +                    System.out.println( "Unable to queue: " + e.getMessage() );
  +                }
  +            }
  +
  +            try
  +            {
  +                this.sink.enqueue( new QueueInteger( -1 ) );
  +            }
  +            catch( SinkException e )
  +            {
  +                System.out.println( "Unable to queue stop" );
  +            }
  +        }
  +    }
  +
  +    private class QueueEnd implements Runnable
  +    {
  +        private Source source;
  +        private int count;
  +
  +        protected void setSource( Source source )
  +        {
  +            this.source = source;
  +        }
  +
  +        public int getCount()
  +        {
  +            return count;
  +        }
  +
  +        public void run()
  +        {
  +            while( true )
  +            {
  +                QueueElement qe = this.source.dequeue();
  +
  +                if( qe == null )
  +                {
  +
  +                }
  +                else if( qe instanceof QueueInteger )
  +                {
  +                    QueueInteger qi = (QueueInteger)qe;
  +
  +                    if( qi.getInteger() == -1 )
  +                    {
  +                        break;
  +                    }
  +                    else
  +                    {
  +                        this.count++;
  +                    }
  +                }
  +            }
  +        }
  +    }
  +}
  
  
  
  1.7       +294 -294  jakarta-avalon-excalibur/event/src/test/org/apache/excalibur/event/test/ThreadedQueueTestCase.java
  
  Index: ThreadedQueueTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/event/src/test/org/apache/excalibur/event/test/ThreadedQueueTestCase.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ThreadedQueueTestCase.java	8 Aug 2002 00:57:25 -0000	1.6
  +++ ThreadedQueueTestCase.java	13 Aug 2002 08:15:21 -0000	1.7
  @@ -1,294 +1,294 @@
  -/*
  -
  - ============================================================================
  -                   The Apache Software License, Version 1.1
  - ============================================================================
  -
  - Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  -
  - Redistribution and use in source and binary forms, with or without modifica-
  - tion, are permitted provided that the following conditions are met:
  -
  - 1. Redistributions of  source code must  retain the above copyright  notice,
  -    this list of conditions and the following disclaimer.
  -
  - 2. Redistributions in binary form must reproduce the above copyright notice,
  -    this list of conditions and the following disclaimer in the documentation
  -    and/or other materials provided with the distribution.
  -
  - 3. The end-user documentation included with the redistribution, if any, must
  -    include  the following  acknowledgment:  "This product includes  software
  -    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  -    Alternately, this  acknowledgment may  appear in the software itself,  if
  -    and wherever such third-party acknowledgments normally appear.
  -
  - 4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
  -    must not be used to endorse or promote products derived from this  software
  -    without  prior written permission. For written permission, please contact
  -    apache@apache.org.
  -
  - 5. Products  derived from this software may not  be called "Apache", nor may
  -    "Apache" appear  in their name,  without prior written permission  of the
  -    Apache Software Foundation.
  -
  - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  - FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  - APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  - INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  - DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  - OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  - ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  - (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  -
  - This software  consists of voluntary contributions made  by many individuals
  - on  behalf of the Apache Software  Foundation. For more  information on the
  - Apache Software Foundation, please see <http://www.apache.org/>.
  -
  -*/
  -package org.apache.excalibur.event.test;
  -
  -import junit.framework.TestCase;
  -import org.apache.excalibur.event.DefaultQueue;
  -import org.apache.excalibur.event.Queue;
  -import org.apache.excalibur.event.QueueElement;
  -import org.apache.excalibur.event.Sink;
  -import org.apache.excalibur.event.SinkException;
  -import org.apache.excalibur.event.Source;
  -
  -/**
  - * Simple test to expose the thread queue bug
  - *
  - * @author <a href="mailto:proyal@managingpartners.com">Peter Royal</a>
  - * @author <a href="mailto:leo.sutic@inspireinfrastructure.com">Leo Sutic</a>
  - * @version VSS $Revision$ $Date$
  - */
  -public class ThreadedQueueTestCase
  -    extends TestCase
  -{
  -    private QueueStart start;
  -    private QueueEnd end;
  -
  -    private Queue queue;
  -
  -    private Thread[] stages;
  -
  -    public ThreadedQueueTestCase( String name )
  -    {
  -        super( name );
  -    }
  -
  -    public void testThreaded() throws Exception
  -    {
  -        initialize( 10000, 1 );
  -        start();
  -
  -        initialize( 10000, 1000 );
  -        start();
  -
  -        initialize( 20000, 1000 );
  -        start();
  -
  -        initialize( 30000, 1000 );
  -        start();
  -    }
  -
  -    public void initialize( int count, long timeout ) throws Exception
  -    {
  -        this.stages = new Thread[ 2 ];
  -
  -        this.queue = new DefaultQueue();
  -        this.queue.setTimeout( timeout );
  -
  -        this.start = new QueueStart( count );
  -        this.start.setSink( this.queue );
  -        this.stages[ 0 ] = new Thread( this.start );
  -
  -        this.end = new QueueEnd();
  -        this.end.setSource( this.queue );
  -        this.end.setTimeout( timeout );
  -        this.stages[ 1 ] = new Thread( this.end );
  -    }
  -
  -    public void start() throws Exception
  -    {
  -        /*
  -         * Commented out. Tests should be silent(?). /LS
  -         *
  -         * System.out.println("Starting test");
  -         */
  -
  -        for( int i = 0; i < this.stages.length; i++ )
  -        {
  -            this.stages[ i ].start();
  -        }
  -
  -        stop();
  -    }
  -
  -    public void stop() throws Exception
  -    {
  -        for( int i = 0; i < this.stages.length; i++ )
  -        {
  -            try
  -            {
  -                this.stages[ i ].join();
  -            }
  -            catch( InterruptedException e )
  -            {
  -                throw new RuntimeException( "Stage unexpectedly interrupted: " + e );
  -            }
  -        }
  -
  -        /*
  -         *
  -         * Commented out. Tests should be silent(?). /LS
  -         *
  -         * System.out.println("Test complete");
  -
  -         * System.out.println("Enqueue: " + this.start.getCount() +
  -         *     " sum " + this.start.getSum());
  -         * System.out.println("Dequeue: " + this.end.getCount() +
  -         *     " sum " + this.end.getSum());
  -         */
  -
  -        assertEquals( this.start.getCount(), this.end.getCount() );
  -        assertEquals( this.start.getSum(), this.end.getSum() );
  -    }
  -
  -    private class QueueInteger implements QueueElement
  -    {
  -        private int integer;
  -
  -        public QueueInteger( int integer )
  -        {
  -            this.integer = integer;
  -        }
  -
  -        public int getInteger()
  -        {
  -            return integer;
  -        }
  -    }
  -
  -    private class QueueStart implements Runnable
  -    {
  -        private Sink sink;
  -        private int queueCount;
  -        private int count;
  -        private long sum = 0;
  -
  -        public QueueStart( int queueCount )
  -        {
  -            this.queueCount = queueCount;
  -        }
  -
  -        protected void setSink( Sink sink )
  -        {
  -            this.sink = sink;
  -        }
  -
  -        public int getCount()
  -        {
  -            return count;
  -        }
  -
  -        public long getSum()
  -        {
  -            return sum;
  -        }
  -
  -        public void run()
  -        {
  -            for( int i = 0; i < this.queueCount; i++ )
  -            {
  -                try
  -                {
  -                    this.sink.enqueue( new QueueInteger( i ) );
  -                    this.count++;
  -                    sum = sum * 127 + i;
  -                }
  -                catch( SinkException e )
  -                {
  -                    System.out.println( "Unable to queue: " + e.getMessage() );
  -                }
  -            }
  -
  -            try
  -            {
  -                this.sink.enqueue( new QueueInteger( -1 ) );
  -            }
  -            catch( SinkException e )
  -            {
  -                System.out.println( "Unable to queue stop" );
  -            }
  -        }
  -    }
  -
  -    private class QueueEnd implements Runnable
  -    {
  -        private Source source;
  -        private int count;
  -        private long timeout = 0;
  -        private long sum = 0;
  -
  -        protected void setTimeout( long timeout )
  -        {
  -            this.timeout = timeout;
  -        }
  -
  -        protected void setSource( Source source )
  -        {
  -            this.source = source;
  -        }
  -
  -        public int getCount()
  -        {
  -            return count;
  -        }
  -
  -        public long getSum()
  -        {
  -            return sum;
  -        }
  -
  -        public void run()
  -        {
  -            while( true )
  -            {
  -                QueueElement qe = this.source.dequeue();
  -
  -                if( qe == null )
  -                {
  -                    if( timeout > 0 )
  -                    {
  -                        try
  -                        {
  -                            Thread.sleep( timeout );
  -                        }
  -                        catch( InterruptedException ie )
  -                        {
  -                            break;
  -                        }
  -                    }
  -                }
  -                else if( qe instanceof QueueInteger )
  -                {
  -                    QueueInteger qi = (QueueInteger)qe;
  -
  -                    if( qi.getInteger() == -1 )
  -                    {
  -                        break;
  -                    }
  -                    else
  -                    {
  -                        this.count++;
  -                        sum = sum * 127 + qi.getInteger();
  -                    }
  -                }
  -            }
  -        }
  -    }
  -}
  -
  +/*
  +
  + ============================================================================
  +                   The Apache Software License, Version 1.1
  + ============================================================================
  +
  + Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  +
  + Redistribution and use in source and binary forms, with or without modifica-
  + tion, are permitted provided that the following conditions are met:
  +
  + 1. Redistributions of  source code must  retain the above copyright  notice,
  +    this list of conditions and the following disclaimer.
  +
  + 2. Redistributions in binary form must reproduce the above copyright notice,
  +    this list of conditions and the following disclaimer in the documentation
  +    and/or other materials provided with the distribution.
  +
  + 3. The end-user documentation included with the redistribution, if any, must
  +    include  the following  acknowledgment:  "This product includes  software
  +    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  +    Alternately, this  acknowledgment may  appear in the software itself,  if
  +    and wherever such third-party acknowledgments normally appear.
  +
  + 4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
  +    must not be used to endorse or promote products derived from this  software
  +    without  prior written permission. For written permission, please contact
  +    apache@apache.org.
  +
  + 5. Products  derived from this software may not  be called "Apache", nor may
  +    "Apache" appear  in their name,  without prior written permission  of the
  +    Apache Software Foundation.
  +
  + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  + FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  + APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  + INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  + DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  + OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  + ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  + (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  +
  + This software  consists of voluntary contributions made  by many individuals
  + on  behalf of the Apache Software  Foundation. For more  information on the
  + Apache Software Foundation, please see <http://www.apache.org/>.
  +
  +*/
  +package org.apache.excalibur.event.test;
  +
  +import junit.framework.TestCase;
  +import org.apache.excalibur.event.DefaultQueue;
  +import org.apache.excalibur.event.Queue;
  +import org.apache.excalibur.event.QueueElement;
  +import org.apache.excalibur.event.Sink;
  +import org.apache.excalibur.event.SinkException;
  +import org.apache.excalibur.event.Source;
  +
  +/**
  + * Simple test to expose the thread queue bug
  + *
  + * @author <a href="mailto:proyal@managingpartners.com">Peter Royal</a>
  + * @author <a href="mailto:leo.sutic@inspireinfrastructure.com">Leo Sutic</a>
  + * @version VSS $Revision$ $Date$
  + */
  +public class ThreadedQueueTestCase
  +    extends TestCase
  +{
  +    private QueueStart start;
  +    private QueueEnd end;
  +
  +    private Queue queue;
  +
  +    private Thread[] stages;
  +
  +    public ThreadedQueueTestCase( String name )
  +    {
  +        super( name );
  +    }
  +
  +    public void testThreaded() throws Exception
  +    {
  +        initialize( 10000, 1 );
  +        start();
  +
  +        initialize( 10000, 1000 );
  +        start();
  +
  +        initialize( 20000, 1000 );
  +        start();
  +
  +        initialize( 30000, 1000 );
  +        start();
  +    }
  +
  +    public void initialize( int count, long timeout ) throws Exception
  +    {
  +        this.stages = new Thread[ 2 ];
  +
  +        this.queue = new DefaultQueue();
  +        this.queue.setTimeout( timeout );
  +
  +        this.start = new QueueStart( count );
  +        this.start.setSink( this.queue );
  +        this.stages[ 0 ] = new Thread( this.start );
  +
  +        this.end = new QueueEnd();
  +        this.end.setSource( this.queue );
  +        this.end.setTimeout( timeout );
  +        this.stages[ 1 ] = new Thread( this.end );
  +    }
  +
  +    public void start() throws Exception
  +    {
  +        /*
  +         * Commented out. Tests should be silent(?). /LS
  +         *
  +         * System.out.println("Starting test");
  +         */
  +
  +        for( int i = 0; i < this.stages.length; i++ )
  +        {
  +            this.stages[ i ].start();
  +        }
  +
  +        stop();
  +    }
  +
  +    public void stop() throws Exception
  +    {
  +        for( int i = 0; i < this.stages.length; i++ )
  +        {
  +            try
  +            {
  +                this.stages[ i ].join();
  +            }
  +            catch( InterruptedException e )
  +            {
  +                throw new RuntimeException( "Stage unexpectedly interrupted: " + e );
  +            }
  +        }
  +
  +        /*
  +         *
  +         * Commented out. Tests should be silent(?). /LS
  +         *
  +         * System.out.println("Test complete");
  +
  +         * System.out.println("Enqueue: " + this.start.getCount() +
  +         *     " sum " + this.start.getSum());
  +         * System.out.println("Dequeue: " + this.end.getCount() +
  +         *     " sum " + this.end.getSum());
  +         */
  +
  +        assertEquals( this.start.getCount(), this.end.getCount() );
  +        assertEquals( this.start.getSum(), this.end.getSum() );
  +    }
  +
  +    private class QueueInteger implements QueueElement
  +    {
  +        private int integer;
  +
  +        public QueueInteger( int integer )
  +        {
  +            this.integer = integer;
  +        }
  +
  +        public int getInteger()
  +        {
  +            return integer;
  +        }
  +    }
  +
  +    private class QueueStart implements Runnable
  +    {
  +        private Sink sink;
  +        private int queueCount;
  +        private int count;
  +        private long sum = 0;
  +
  +        public QueueStart( int queueCount )
  +        {
  +            this.queueCount = queueCount;
  +        }
  +
  +        protected void setSink( Sink sink )
  +        {
  +            this.sink = sink;
  +        }
  +
  +        public int getCount()
  +        {
  +            return count;
  +        }
  +
  +        public long getSum()
  +        {
  +            return sum;
  +        }
  +
  +        public void run()
  +        {
  +            for( int i = 0; i < this.queueCount; i++ )
  +            {
  +                try
  +                {
  +                    this.sink.enqueue( new QueueInteger( i ) );
  +                    this.count++;
  +                    sum = sum * 127 + i;
  +                }
  +                catch( SinkException e )
  +                {
  +                    System.out.println( "Unable to queue: " + e.getMessage() );
  +                }
  +            }
  +
  +            try
  +            {
  +                this.sink.enqueue( new QueueInteger( -1 ) );
  +            }
  +            catch( SinkException e )
  +            {
  +                System.out.println( "Unable to queue stop" );
  +            }
  +        }
  +    }
  +
  +    private class QueueEnd implements Runnable
  +    {
  +        private Source source;
  +        private int count;
  +        private long timeout = 0;
  +        private long sum = 0;
  +
  +        protected void setTimeout( long timeout )
  +        {
  +            this.timeout = timeout;
  +        }
  +
  +        protected void setSource( Source source )
  +        {
  +            this.source = source;
  +        }
  +
  +        public int getCount()
  +        {
  +            return count;
  +        }
  +
  +        public long getSum()
  +        {
  +            return sum;
  +        }
  +
  +        public void run()
  +        {
  +            while( true )
  +            {
  +                QueueElement qe = this.source.dequeue();
  +
  +                if( qe == null )
  +                {
  +                    if( timeout > 0 )
  +                    {
  +                        try
  +                        {
  +                            Thread.sleep( timeout );
  +                        }
  +                        catch( InterruptedException ie )
  +                        {
  +                            break;
  +                        }
  +                    }
  +                }
  +                else if( qe instanceof QueueInteger )
  +                {
  +                    QueueInteger qi = (QueueInteger)qe;
  +
  +                    if( qi.getInteger() == -1 )
  +                    {
  +                        break;
  +                    }
  +                    else
  +                    {
  +                        this.count++;
  +                        sum = sum * 127 + qi.getInteger();
  +                    }
  +                }
  +            }
  +        }
  +    }
  +}
  +
  
  
  
  1.2       +126 -126  jakarta-avalon-excalibur/event/src/test/org/apache/excalibur/mpool/test/ClassInstanceObjectFactory.java
  
  Index: ClassInstanceObjectFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/event/src/test/org/apache/excalibur/mpool/test/ClassInstanceObjectFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ClassInstanceObjectFactory.java	7 Aug 2002 22:44:26 -0000	1.1
  +++ ClassInstanceObjectFactory.java	13 Aug 2002 08:15:21 -0000	1.2
  @@ -1,126 +1,126 @@
  -/*
  -
  - ============================================================================
  -                   The Apache Software License, Version 1.1
  - ============================================================================
  -
  - Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  -
  - Redistribution and use in source and binary forms, with or without modifica-
  - tion, are permitted provided that the following conditions are met:
  -
  - 1. Redistributions of  source code must  retain the above copyright  notice,
  -    this list of conditions and the following disclaimer.
  -
  - 2. Redistributions in binary form must reproduce the above copyright notice,
  -    this list of conditions and the following disclaimer in the documentation
  -    and/or other materials provided with the distribution.
  -
  - 3. The end-user documentation included with the redistribution, if any, must
  -    include  the following  acknowledgment:  "This product includes  software
  -    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  -    Alternately, this  acknowledgment may  appear in the software itself,  if
  -    and wherever such third-party acknowledgments normally appear.
  -
  - 4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
  -    must not be used to endorse or promote products derived from this  software
  -    without  prior written permission. For written permission, please contact
  -    apache@apache.org.
  -
  - 5. Products  derived from this software may not  be called "Apache", nor may
  -    "Apache" appear  in their name,  without prior written permission  of the
  -    Apache Software Foundation.
  -
  - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  - FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  - APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  - INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  - DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  - OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  - ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  - (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  -
  - This software  consists of voluntary contributions made  by many individuals
  - on  behalf of the Apache Software  Foundation. For more  information on the
  - Apache Software Foundation, please see <http://www.apache.org/>.
  -
  -*/
  -package org.apache.excalibur.mpool.test;
  -
  -import java.util.HashMap;
  -import org.apache.avalon.framework.activity.Disposable;
  -import org.apache.avalon.framework.logger.Logger;
  -import org.apache.excalibur.mpool.ObjectFactory;
  -
  -/**
  - * @author <a href="mailto:leif@tanukisoftware.com">Leif Mortenson</a>
  - * @version CVS $Revision$ $Date$
  - * @since 4.1
  - */
  -public class ClassInstanceObjectFactory
  -    implements ObjectFactory, org.apache.avalon.excalibur.pool.ObjectFactory
  -{
  -    private HashMap m_instances = new HashMap();
  -    private Logger m_logger;
  -    private Class m_clazz;
  -    private int m_id;
  -
  -    /*---------------------------------------------------------------
  -     * Constructors
  -     *-------------------------------------------------------------*/
  -    /**
  -     * Creates a reproducable log of activity in the provided StringBuffer
  -     */
  -    public ClassInstanceObjectFactory( Class clazz, Logger logger )
  -    {
  -        m_clazz = clazz;
  -        m_logger = logger;
  -        m_id = 1;
  -    }
  -
  -    /*---------------------------------------------------------------
  -     * ObjectFactory Methods
  -     *-------------------------------------------------------------*/
  -    public Object newInstance() throws Exception
  -    {
  -        Object object = m_clazz.newInstance();
  -        Integer id = new Integer( m_id++ );
  -
  -        m_instances.put( object, id );
  -
  -        if( m_logger.isDebugEnabled() )
  -        {
  -            m_logger.debug( "ClassInstanceObjectFactory.newInstance()  id:" + id );
  -        }
  -
  -        return object;
  -    }
  -
  -    public Class getCreatedClass()
  -    {
  -        return m_clazz;
  -    }
  -
  -    public void dispose( Object object ) throws Exception
  -    {
  -        if( object instanceof Disposable )
  -        {
  -            ( (Disposable)object ).dispose();
  -        }
  -        Integer id = (Integer)m_instances.remove( object );
  -
  -        if( m_logger.isDebugEnabled() )
  -        {
  -            m_logger.debug( "ClassInstanceObjectFactory.decommission(a "
  -                            + object.getClass().getName() + ")  id:" + id );
  -        }
  -    }
  -
  -    public void decommission( Object object ) throws Exception
  -    {
  -        dispose( object );
  -    }
  -}
  -
  +/*
  +
  + ============================================================================
  +                   The Apache Software License, Version 1.1
  + ============================================================================
  +
  + Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  +
  + Redistribution and use in source and binary forms, with or without modifica-
  + tion, are permitted provided that the following conditions are met:
  +
  + 1. Redistributions of  source code must  retain the above copyright  notice,
  +    this list of conditions and the following disclaimer.
  +
  + 2. Redistributions in binary form must reproduce the above copyright notice,
  +    this list of conditions and the following disclaimer in the documentation
  +    and/or other materials provided with the distribution.
  +
  + 3. The end-user documentation included with the redistribution, if any, must
  +    include  the following  acknowledgment:  "This product includes  software
  +    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  +    Alternately, this  acknowledgment may  appear in the software itself,  if
  +    and wherever such third-party acknowledgments normally appear.
  +
  + 4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
  +    must not be used to endorse or promote products derived from this  software
  +    without  prior written permission. For written permission, please contact
  +    apache@apache.org.
  +
  + 5. Products  derived from this software may not  be called "Apache", nor may
  +    "Apache" appear  in their name,  without prior written permission  of the
  +    Apache Software Foundation.
  +
  + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  + FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  + APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  + INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  + DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  + OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  + ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  + (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  +
  + This software  consists of voluntary contributions made  by many individuals
  + on  behalf of the Apache Software  Foundation. For more  information on the
  + Apache Software Foundation, please see <http://www.apache.org/>.
  +
  +*/
  +package org.apache.excalibur.mpool.test;
  +
  +import java.util.HashMap;
  +import org.apache.avalon.framework.activity.Disposable;
  +import org.apache.avalon.framework.logger.Logger;
  +import org.apache.excalibur.mpool.ObjectFactory;
  +
  +/**
  + * @author <a href="mailto:leif@tanukisoftware.com">Leif Mortenson</a>
  + * @version CVS $Revision$ $Date$
  + * @since 4.1
  + */
  +public class ClassInstanceObjectFactory
  +    implements ObjectFactory, org.apache.avalon.excalibur.pool.ObjectFactory
  +{
  +    private HashMap m_instances = new HashMap();
  +    private Logger m_logger;
  +    private Class m_clazz;
  +    private int m_id;
  +
  +    /*---------------------------------------------------------------
  +     * Constructors
  +     *-------------------------------------------------------------*/
  +    /**
  +     * Creates a reproducable log of activity in the provided StringBuffer
  +     */
  +    public ClassInstanceObjectFactory( Class clazz, Logger logger )
  +    {
  +        m_clazz = clazz;
  +        m_logger = logger;
  +        m_id = 1;
  +    }
  +
  +    /*---------------------------------------------------------------
  +     * ObjectFactory Methods
  +     *-------------------------------------------------------------*/
  +    public Object newInstance() throws Exception
  +    {
  +        Object object = m_clazz.newInstance();
  +        Integer id = new Integer( m_id++ );
  +
  +        m_instances.put( object, id );
  +
  +        if( m_logger.isDebugEnabled() )
  +        {
  +            m_logger.debug( "ClassInstanceObjectFactory.newInstance()  id:" + id );
  +        }
  +
  +        return object;
  +    }
  +
  +    public Class getCreatedClass()
  +    {
  +        return m_clazz;
  +    }
  +
  +    public void dispose( Object object ) throws Exception
  +    {
  +        if( object instanceof Disposable )
  +        {
  +            ( (Disposable)object ).dispose();
  +        }
  +        Integer id = (Integer)m_instances.remove( object );
  +
  +        if( m_logger.isDebugEnabled() )
  +        {
  +            m_logger.debug( "ClassInstanceObjectFactory.decommission(a "
  +                            + object.getClass().getName() + ")  id:" + id );
  +        }
  +    }
  +
  +    public void decommission( Object object ) throws Exception
  +    {
  +        dispose( object );
  +    }
  +}
  +
  
  
  
  1.4       +324 -324  jakarta-avalon-excalibur/event/src/test/org/apache/excalibur/mpool/test/MultiThreadedPoolComparisonProfile.java
  
  Index: MultiThreadedPoolComparisonProfile.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/event/src/test/org/apache/excalibur/mpool/test/MultiThreadedPoolComparisonProfile.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- MultiThreadedPoolComparisonProfile.java	8 Aug 2002 00:57:25 -0000	1.3
  +++ MultiThreadedPoolComparisonProfile.java	13 Aug 2002 08:15:21 -0000	1.4
  @@ -1,324 +1,324 @@
  -/*
  -
  - ============================================================================
  -                   The Apache Software License, Version 1.1
  - ============================================================================
  -
  - Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  -
  - Redistribution and use in source and binary forms, with or without modifica-
  - tion, are permitted provided that the following conditions are met:
  -
  - 1. Redistributions of  source code must  retain the above copyright  notice,
  -    this list of conditions and the following disclaimer.
  -
  - 2. Redistributions in binary form must reproduce the above copyright notice,
  -    this list of conditions and the following disclaimer in the documentation
  -    and/or other materials provided with the distribution.
  -
  - 3. The end-user documentation included with the redistribution, if any, must
  -    include  the following  acknowledgment:  "This product includes  software
  -    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  -    Alternately, this  acknowledgment may  appear in the software itself,  if
  -    and wherever such third-party acknowledgments normally appear.
  -
  - 4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
  -    must not be used to endorse or promote products derived from this  software
  -    without  prior written permission. For written permission, please contact
  -    apache@apache.org.
  -
  - 5. Products  derived from this software may not  be called "Apache", nor may
  -    "Apache" appear  in their name,  without prior written permission  of the
  -    Apache Software Foundation.
  -
  - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  - FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  - APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  - INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  - DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  - OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  - ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  - (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  -
  - This software  consists of voluntary contributions made  by many individuals
  - on  behalf of the Apache Software  Foundation. For more  information on the
  - Apache Software Foundation, please see <http://www.apache.org/>.
  -
  -*/
  -package org.apache.excalibur.mpool.test;
  -
  -import org.apache.avalon.excalibur.pool.Poolable;
  -import org.apache.avalon.excalibur.testcase.CascadingAssertionFailedError;
  -import org.apache.avalon.excalibur.testcase.LatchedThreadGroup;
  -import org.apache.avalon.framework.activity.Disposable;
  -import org.apache.avalon.framework.logger.Logger;
  -import org.apache.excalibur.mpool.Pool;
  -
  -/**
  - * This is used to profile and compare various pool implementations
  - *  given a single access thread.
  - *
  - * @author <a href="mailto:leif@tanukisoftware.com">Leif Mortenson</a>
  - * @version $Id$
  - */
  -public class MultiThreadedPoolComparisonProfile
  -    extends PoolComparisonProfileAbstract
  -{
  -    protected static final int THREADS = 100;
  -
  -    private int m_startedCount;
  -    private boolean m_latched;
  -    private int m_completedCount;
  -    private int m_getCount;
  -    private Throwable m_throwable;
  -
  -    /*---------------------------------------------------------------
  -     * Constructors
  -     *-------------------------------------------------------------*/
  -    public MultiThreadedPoolComparisonProfile( String name )
  -    {
  -        super( name );
  -    }
  -
  -    /*---------------------------------------------------------------
  -     * PoolComparisonProfileAbstract Methods
  -     *-------------------------------------------------------------*/
  -    protected long getPoolRunTime( final Pool pool, final int gets )
  -        throws Exception
  -    {
  -        if( gets % THREADS != 0 )
  -        {
  -            m_logger.info( "Invalid: " + gets % THREADS + " gets(" + gets + ") threads(" + THREADS + ")" );
  -            fail( "gets must be evenly divisible by THREADS" );
  -        }
  -
  -        m_getCount = 0;
  -        m_throwable = null;
  -
  -        // Create the runnable
  -        MPoolRunner runnable = new MPoolRunner( pool, gets, m_logger );
  -
  -        LatchedThreadGroup group = new LatchedThreadGroup( runnable, THREADS );
  -        group.enableLogging( m_logger );
  -
  -        long duration;
  -        try
  -        {
  -            duration = group.go();
  -        }
  -        catch( Throwable t )
  -        {
  -            // Throwable could have been thrown by one of the tests.
  -            if( m_throwable == null )
  -            {
  -                m_throwable = t;
  -            }
  -            duration = 0;
  -        }
  -
  -        if( m_throwable != null )
  -        {
  -            throw new CascadingAssertionFailedError( "Exception in test thread.", m_throwable );
  -        }
  -
  -        assertTrue( "m_getCount == 0 (" + m_getCount + ")", m_getCount == 0 );
  -
  -        // Dispose if necessary
  -        if( pool instanceof Disposable )
  -        {
  -            ( (Disposable)pool ).dispose();
  -        }
  -
  -        return duration;
  -    }
  -
  -    /*---------------------------------------------------------------
  -     * PoolComparisonProfileAbstract Methods
  -     *-------------------------------------------------------------*/
  -    protected long getPoolRunTime( final org.apache.avalon.excalibur.pool.Pool pool, final int gets )
  -        throws Exception
  -    {
  -        if( gets % THREADS != 0 )
  -        {
  -            m_logger.info( "Invalid: " + gets % THREADS + " gets(" + gets + ") threads(" + THREADS + ")" );
  -            fail( "gets must be evenly divisible by THREADS" );
  -        }
  -
  -        m_getCount = 0;
  -        m_throwable = null;
  -
  -        // Create the runnable
  -        PoolRunner runnable = new PoolRunner( pool, gets, m_logger );
  -
  -        LatchedThreadGroup group = new LatchedThreadGroup( runnable, THREADS );
  -        group.enableLogging( m_logger );
  -
  -        long duration;
  -        try
  -        {
  -            duration = group.go();
  -        }
  -        catch( Throwable t )
  -        {
  -            // Throwable could have been thrown by one of the tests.
  -            if( m_throwable == null )
  -            {
  -                m_throwable = t;
  -            }
  -            duration = 0;
  -        }
  -
  -        if( m_throwable != null )
  -        {
  -            throw new CascadingAssertionFailedError( "Exception in test thread.", m_throwable );
  -        }
  -
  -        assertTrue( "m_getCount == 0 (" + m_getCount + ")", m_getCount == 0 );
  -
  -        // Dispose if necessary
  -        if( pool instanceof Disposable )
  -        {
  -            ( (Disposable)pool ).dispose();
  -        }
  -
  -        return duration;
  -    }
  -
  -    private static class PoolRunner implements Runnable
  -    {
  -        private Logger m_logger;
  -        private org.apache.avalon.excalibur.pool.Pool m_pool;
  -        private int m_getCount = 0;
  -        private Throwable m_throwable = null;
  -        private int m_gets;
  -
  -        public PoolRunner( org.apache.avalon.excalibur.pool.Pool pool, int gets, Logger logger )
  -        {
  -            m_pool = pool;
  -            m_logger = logger;
  -            m_gets = gets;
  -        }
  -
  -        public int getCount()
  -        {
  -            return m_getCount;
  -        }
  -
  -        public Throwable getThrowable()
  -        {
  -            return m_throwable;
  -        }
  -
  -        public void run()
  -        {
  -            // Perform this threads part of the test.
  -            final int cnt = m_gets / THREADS;
  -            final Poolable[] poolTmp = new Poolable[ cnt ];
  -            final int loops = ( TEST_SIZE / THREADS ) / cnt;
  -            for( int i = 0; i < loops; i++ )
  -            {
  -                // Get some Poolables
  -                for( int j = 0; j < cnt; j++ )
  -                {
  -                    try
  -                    {
  -                        poolTmp[ j ] = m_pool.get();
  -                        m_getCount++;
  -                    }
  -                    catch( Throwable t )
  -                    {
  -                        m_logger.error( "Unexpected error", t );
  -
  -                        if( m_throwable == null )
  -                        {
  -                            m_throwable = t;
  -                        }
  -
  -                        return;
  -                    }
  -                }
  -
  -                // Make the loops hold the poolables longer than they are released, but only slightly.
  -                Thread.yield();
  -
  -                // Put the Poolables back
  -                for( int j = 0; j < cnt; j++ )
  -                {
  -                    m_pool.put( poolTmp[ j ] );
  -                    m_getCount--;
  -                    poolTmp[ j ] = null;
  -                }
  -            }
  -        }
  -    }
  -
  -    private static class MPoolRunner implements Runnable
  -    {
  -        private Logger m_logger;
  -        private Pool m_pool;
  -        private int m_getCount = 0;
  -        private Throwable m_throwable = null;
  -        private final int m_gets;
  -
  -        public MPoolRunner( Pool pool, int gets, Logger logger )
  -        {
  -            m_pool = pool;
  -            m_logger = logger;
  -            m_gets = gets;
  -        }
  -
  -        public int getCount()
  -        {
  -            return m_getCount;
  -        }
  -
  -        public Throwable getThrowable()
  -        {
  -            return m_throwable;
  -        }
  -
  -        public void run()
  -        {
  -            // Perform this threads part of the test.
  -            final int cnt = m_gets / THREADS;
  -            final Object[] poolTmp = new Poolable[ cnt ];
  -            final int loops = ( TEST_SIZE / THREADS ) / cnt;
  -            for( int i = 0; i < loops; i++ )
  -            {
  -                // Get some Poolables
  -                for( int j = 0; j < cnt; j++ )
  -                {
  -                    try
  -                    {
  -                        poolTmp[ j ] = m_pool.acquire();
  -                        m_getCount++;
  -                    }
  -                    catch( Throwable t )
  -                    {
  -                        m_logger.error( "Unexpected error after " + m_getCount +
  -                                        " items retrieved and " + m_gets + " requested", t );
  -
  -                        if( m_throwable == null )
  -                        {
  -                            m_throwable = t;
  -                        }
  -                        return;
  -                    }
  -                }
  -
  -                // Make the loops hold the poolables longer than they are released, but only slightly.
  -                Thread.yield();
  -
  -                // Put the Poolables back
  -                for( int j = 0; j < cnt; j++ )
  -                {
  -                    m_pool.release( poolTmp[ j ] );
  -                    m_getCount--;
  -                    poolTmp[ j ] = null;
  -                }
  -            }
  -        }
  -    }
  -}
  +/*
  +
  + ============================================================================
  +                   The Apache Software License, Version 1.1
  + ============================================================================
  +
  + Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  +
  + Redistribution and use in source and binary forms, with or without modifica-
  + tion, are permitted provided that the following conditions are met:
  +
  + 1. Redistributions of  source code must  retain the above copyright  notice,
  +    this list of conditions and the following disclaimer.
  +
  + 2. Redistributions in binary form must reproduce the above copyright notice,
  +    this list of conditions and the following disclaimer in the documentation
  +    and/or other materials provided with the distribution.
  +
  + 3. The end-user documentation included with the redistribution, if any, must
  +    include  the following  acknowledgment:  "This product includes  software
  +    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  +    Alternately, this  acknowledgment may  appear in the software itself,  if
  +    and wherever such third-party acknowledgments normally appear.
  +
  + 4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
  +    must not be used to endorse or promote products derived from this  software
  +    without  prior written permission. For written permission, please contact
  +    apache@apache.org.
  +
  + 5. Products  derived from this software may not  be called "Apache", nor may
  +    "Apache" appear  in their name,  without prior written permission  of the
  +    Apache Software Foundation.
  +
  + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  + FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  + APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  + INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  + DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  + OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  + ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  + (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  +
  + This software  consists of voluntary contributions made  by many individuals
  + on  behalf of the Apache Software  Foundation. For more  information on the
  + Apache Software Foundation, please see <http://www.apache.org/>.
  +
  +*/
  +package org.apache.excalibur.mpool.test;
  +
  +import org.apache.avalon.excalibur.pool.Poolable;
  +import org.apache.avalon.excalibur.testcase.CascadingAssertionFailedError;
  +import org.apache.avalon.excalibur.testcase.LatchedThreadGroup;
  +import org.apache.avalon.framework.activity.Disposable;
  +import org.apache.avalon.framework.logger.Logger;
  +import org.apache.excalibur.mpool.Pool;
  +
  +/**
  + * This is used to profile and compare various pool implementations
  + *  given a single access thread.
  + *
  + * @author <a href="mailto:leif@tanukisoftware.com">Leif Mortenson</a>
  + * @version $Id$
  + */
  +public class MultiThreadedPoolComparisonProfile
  +    extends PoolComparisonProfileAbstract
  +{
  +    protected static final int THREADS = 100;
  +
  +    private int m_startedCount;
  +    private boolean m_latched;
  +    private int m_completedCount;
  +    private int m_getCount;
  +    private Throwable m_throwable;
  +
  +    /*---------------------------------------------------------------
  +     * Constructors
  +     *-------------------------------------------------------------*/
  +    public MultiThreadedPoolComparisonProfile( String name )
  +    {
  +        super( name );
  +    }
  +
  +    /*---------------------------------------------------------------
  +     * PoolComparisonProfileAbstract Methods
  +     *-------------------------------------------------------------*/
  +    protected long getPoolRunTime( final Pool pool, final int gets )
  +        throws Exception
  +    {
  +        if( gets % THREADS != 0 )
  +        {
  +            m_logger.info( "Invalid: " + gets % THREADS + " gets(" + gets + ") threads(" + THREADS + ")" );
  +            fail( "gets must be evenly divisible by THREADS" );
  +        }
  +
  +        m_getCount = 0;
  +        m_throwable = null;
  +
  +        // Create the runnable
  +        MPoolRunner runnable = new MPoolRunner( pool, gets, m_logger );
  +
  +        LatchedThreadGroup group = new LatchedThreadGroup( runnable, THREADS );
  +        group.enableLogging( m_logger );
  +
  +        long duration;
  +        try
  +        {
  +            duration = group.go();
  +        }
  +        catch( Throwable t )
  +        {
  +            // Throwable could have been thrown by one of the tests.
  +            if( m_throwable == null )
  +            {
  +                m_throwable = t;
  +            }
  +            duration = 0;
  +        }
  +
  +        if( m_throwable != null )
  +        {
  +            throw new CascadingAssertionFailedError( "Exception in test thread.", m_throwable );
  +        }
  +
  +        assertTrue( "m_getCount == 0 (" + m_getCount + ")", m_getCount == 0 );
  +
  +        // Dispose if necessary
  +        if( pool instanceof Disposable )
  +        {
  +            ( (Disposable)pool ).dispose();
  +        }
  +
  +        return duration;
  +    }
  +
  +    /*---------------------------------------------------------------
  +     * PoolComparisonProfileAbstract Methods
  +     *-------------------------------------------------------------*/
  +    protected long getPoolRunTime( final org.apache.avalon.excalibur.pool.Pool pool, final int gets )
  +        throws Exception
  +    {
  +        if( gets % THREADS != 0 )
  +        {
  +            m_logger.info( "Invalid: " + gets % THREADS + " gets(" + gets + ") threads(" + THREADS + ")" );
  +            fail( "gets must be evenly divisible by THREADS" );
  +        }
  +
  +        m_getCount = 0;
  +        m_throwable = null;
  +
  +        // Create the runnable
  +        PoolRunner runnable = new PoolRunner( pool, gets, m_logger );
  +
  +        LatchedThreadGroup group = new LatchedThreadGroup( runnable, THREADS );
  +        group.enableLogging( m_logger );
  +
  +        long duration;
  +        try
  +        {
  +            duration = group.go();
  +        }
  +        catch( Throwable t )
  +        {
  +            // Throwable could have been thrown by one of the tests.
  +            if( m_throwable == null )
  +            {
  +                m_throwable = t;
  +            }
  +            duration = 0;
  +        }
  +
  +        if( m_throwable != null )
  +        {
  +            throw new CascadingAssertionFailedError( "Exception in test thread.", m_throwable );
  +        }
  +
  +        assertTrue( "m_getCount == 0 (" + m_getCount + ")", m_getCount == 0 );
  +
  +        // Dispose if necessary
  +        if( pool instanceof Disposable )
  +        {
  +            ( (Disposable)pool ).dispose();
  +        }
  +
  +        return duration;
  +    }
  +
  +    private static class PoolRunner implements Runnable
  +    {
  +        private Logger m_logger;
  +        private org.apache.avalon.excalibur.pool.Pool m_pool;
  +        private int m_getCount = 0;
  +        private Throwable m_throwable = null;
  +        private int m_gets;
  +
  +        public PoolRunner( org.apache.avalon.excalibur.pool.Pool pool, int gets, Logger logger )
  +        {
  +            m_pool = pool;
  +            m_logger = logger;
  +            m_gets = gets;
  +        }
  +
  +        public int getCount()
  +        {
  +            return m_getCount;
  +        }
  +
  +        public Throwable getThrowable()
  +        {
  +            return m_throwable;
  +        }
  +
  +        public void run()
  +        {
  +            // Perform this threads part of the test.
  +            final int cnt = m_gets / THREADS;
  +            final Poolable[] poolTmp = new Poolable[ cnt ];
  +            final int loops = ( TEST_SIZE / THREADS ) / cnt;
  +            for( int i = 0; i < loops; i++ )
  +            {
  +                // Get some Poolables
  +                for( int j = 0; j < cnt; j++ )
  +                {
  +                    try
  +                    {
  +                        poolTmp[ j ] = m_pool.get();
  +                        m_getCount++;
  +                    }
  +                    catch( Throwable t )
  +                    {
  +                        m_logger.error( "Unexpected error", t );
  +
  +                        if( m_throwable == null )
  +                        {
  +                            m_throwable = t;
  +                        }
  +
  +                        return;
  +                    }
  +                }
  +
  +                // Make the loops hold the poolables longer than they are released, but only slightly.
  +                Thread.yield();
  +
  +                // Put the Poolables back
  +                for( int j = 0; j < cnt; j++ )
  +                {
  +                    m_pool.put( poolTmp[ j ] );
  +                    m_getCount--;
  +                    poolTmp[ j ] = null;
  +                }
  +            }
  +        }
  +    }
  +
  +    private static class MPoolRunner implements Runnable
  +    {
  +        private Logger m_logger;
  +        private Pool m_pool;
  +        private int m_getCount = 0;
  +        private Throwable m_throwable = null;
  +        private final int m_gets;
  +
  +        public MPoolRunner( Pool pool, int gets, Logger logger )
  +        {
  +            m_pool = pool;
  +            m_logger = logger;
  +            m_gets = gets;
  +        }
  +
  +        public int getCount()
  +        {
  +            return m_getCount;
  +        }
  +
  +        public Throwable getThrowable()
  +        {
  +            return m_throwable;
  +        }
  +
  +        public void run()
  +        {
  +            // Perform this threads part of the test.
  +            final int cnt = m_gets / THREADS;
  +            final Object[] poolTmp = new Poolable[ cnt ];
  +            final int loops = ( TEST_SIZE / THREADS ) / cnt;
  +            for( int i = 0; i < loops; i++ )
  +            {
  +                // Get some Poolables
  +                for( int j = 0; j < cnt; j++ )
  +                {
  +                    try
  +                    {
  +                        poolTmp[ j ] = m_pool.acquire();
  +                        m_getCount++;
  +                    }
  +                    catch( Throwable t )
  +                    {
  +                        m_logger.error( "Unexpected error after " + m_getCount +
  +                                        " items retrieved and " + m_gets + " requested", t );
  +
  +                        if( m_throwable == null )
  +                        {
  +                            m_throwable = t;
  +                        }
  +                        return;
  +                    }
  +                }
  +
  +                // Make the loops hold the poolables longer than they are released, but only slightly.
  +                Thread.yield();
  +
  +                // Put the Poolables back
  +                for( int j = 0; j < cnt; j++ )
  +                {
  +                    m_pool.release( poolTmp[ j ] );
  +                    m_getCount--;
  +                    poolTmp[ j ] = null;
  +                }
  +            }
  +        }
  +    }
  +}
  
  
  
  1.3       +686 -686  jakarta-avalon-excalibur/event/src/test/org/apache/excalibur/mpool/test/PoolComparisonProfileAbstract.java
  
  Index: PoolComparisonProfileAbstract.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/event/src/test/org/apache/excalibur/mpool/test/PoolComparisonProfileAbstract.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PoolComparisonProfileAbstract.java	9 Aug 2002 19:22:16 -0000	1.2
  +++ PoolComparisonProfileAbstract.java	13 Aug 2002 08:15:21 -0000	1.3
  @@ -1,686 +1,686 @@
  -/*
  -
  - ============================================================================
  -                   The Apache Software License, Version 1.1
  - ============================================================================
  -
  - Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  -
  - Redistribution and use in source and binary forms, with or without modifica-
  - tion, are permitted provided that the following conditions are met:
  -
  - 1. Redistributions of  source code must  retain the above copyright  notice,
  -    this list of conditions and the following disclaimer.
  -
  - 2. Redistributions in binary form must reproduce the above copyright notice,
  -    this list of conditions and the following disclaimer in the documentation
  -    and/or other materials provided with the distribution.
  -
  - 3. The end-user documentation included with the redistribution, if any, must
  -    include  the following  acknowledgment:  "This product includes  software
  -    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  -    Alternately, this  acknowledgment may  appear in the software itself,  if
  -    and wherever such third-party acknowledgments normally appear.
  -
  - 4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
  -    must not be used to endorse or promote products derived from this  software
  -    without  prior written permission. For written permission, please contact
  -    apache@apache.org.
  -
  - 5. Products  derived from this software may not  be called "Apache", nor may
  -    "Apache" appear  in their name,  without prior written permission  of the
  -    Apache Software Foundation.
  -
  - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  - FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  - APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  - INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  - DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  - OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  - ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  - (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  -
  - This software  consists of voluntary contributions made  by many individuals
  - on  behalf of the Apache Software  Foundation. For more  information on the
  - Apache Software Foundation, please see <http://www.apache.org/>.
  -
  -*/
  -package org.apache.excalibur.mpool.test;
  -
  -import junit.framework.TestCase;
  -import org.apache.avalon.excalibur.pool.ResourceLimitingPool;
  -import org.apache.avalon.framework.logger.LogEnabled;
  -import org.apache.avalon.framework.logger.LogKitLogger;
  -import org.apache.avalon.framework.logger.Logger;
  -import org.apache.excalibur.mpool.FixedSizePool;
  -import org.apache.excalibur.mpool.BlockingFixedSizePool;
  -import org.apache.excalibur.mpool.ObjectFactory;
  -import org.apache.excalibur.mpool.Pool;
  -import org.apache.excalibur.mpool.VariableSizePool;
  -
  -/**
  - * Used as a basis for the PoolComparisonProfile Tests
  - *
  - * @author <a href="mailto:leif@tanukisoftware.com">Leif Mortenson</a>
  - * @version $Id$
  - */
  -public abstract class PoolComparisonProfileAbstract
  -    extends TestCase
  -{
  -    /**
  -     * The TEST_SIZE defines the overall size of the tests.  Decreasing this will
  -     *  decrease the time the test takes to run, but also decrease its efficiency.
  -     */
  -    protected static final int TEST_SIZE = 50000;
  -
  -    protected Logger m_logger;
  -    protected Logger m_poolLogger;
  -
  -    /*---------------------------------------------------------------
  -     * Constructors
  -     *-------------------------------------------------------------*/
  -    public PoolComparisonProfileAbstract( String name )
  -    {
  -        super( name );
  -
  -        // Set to debug to see more useful information.
  -        org.apache.log.Logger logger =
  -            org.apache.log.Hierarchy.getDefaultHierarchy().getLoggerFor( "test" );
  -        logger.setPriority( org.apache.log.Priority.INFO );
  -        m_logger = new LogKitLogger( logger );
  -
  -        // The output from the pools is too much data to be useful, so use a different logger.
  -        org.apache.log.Logger poolLogger =
  -            org.apache.log.Hierarchy.getDefaultHierarchy().getLoggerFor( "pool" );
  -        poolLogger.setPriority( org.apache.log.Priority.INFO );
  -        m_poolLogger = new LogKitLogger( poolLogger );
  -    }
  -
  -    /*---------------------------------------------------------------
  -     * FixedSizePool vs ResourceLimitingPool TestCases
  -     *-------------------------------------------------------------*/
  -    /**
  -     * Compare the FixedSizePool and ResourceLimitingPool when the
  -     *  ResourceLimitingPool is configured to act like a FixedSizePool.
  -     * <p>
  -     * Test will use pools with a max size of 100, while getting up to 100 at a time,
  -     *  Poolables are small objects.
  -     */
  -    public void testCompare_FixedSizePool_And_ResourceLimitingPool_Max100_Gets100_SmallPoolables()
  -        throws Exception
  -    {
  -        String name = "FixedSizePool_And_ResourceLimitingPool_Max100_Gets100_SmallPoolables";
  -
  -        Class poolableClass = SmallPoolable.class;
  -        ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  -        int min = 0;
  -        int max = 100;
  -        boolean maxStrict = true;
  -        boolean blocking = false;
  -        long blockTimeout = 0;
  -        long trimInterval = 0;
  -
  -        FixedSizePool poolA = new FixedSizePool( factory, max );
  -
  -        ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
  -        poolB.enableLogging( m_poolLogger );
  -
  -        generalTest( name, poolA, poolB, 100, factory );
  -    }
  -
  -    /**
  -     * Compare the FixedSizePool and BlockingFixedSizePool when the
  -     *  BlockingFixedSizePool is configured to act like a FixedSizePool.
  -     * <p>
  -     * Test will use pools with a max size of 100, while getting up to 100 at a time,
  -     *  Poolables are medium objects.
  -     */
  -    public void testCompare_FixedSizePool_And_BlockingFixedSizePool_Max100_Gets100_SmallPoolables()
  -        throws Exception
  -    {
  -        String name = "FixedSizePool_And_BlockingFixedSizePool_Max100_Gets100_SmallPoolables";
  -
  -        Class poolableClass = SmallPoolable.class;
  -        ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  -        int min = 0;
  -        int max = 100;
  -        long blockTimeout = 1;
  -
  -        FixedSizePool poolA = new FixedSizePool( factory, max );
  -        BlockingFixedSizePool poolB = new BlockingFixedSizePool( factory, max, blockTimeout );
  -
  -        generalTest( name, poolA, poolB, 100, factory );
  -    }
  -
  -    /**
  -     * Compare the FixedSizePool and BlockingFixedSizePool when the
  -     *  BlockingFixedSizePool is configured to act like a FixedSizePool.
  -     * <p>
  -     * Test will use pools with a max size of 100, while getting up to 100 at a time,
  -     *  Poolables are medium objects.
  -     */
  -    public void testCompare_FixedSizePool_And_BlockingFixedSizePool_Max100_Gets100_MediumPoolables()
  -        throws Exception
  -    {
  -        String name = "FixedSizePool_And_BlockingFixedSizePool_Max100_Gets100_MediumPoolables";
  -
  -        Class poolableClass = MediumPoolable.class;
  -        ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  -        int min = 0;
  -        int max = 100;
  -        long blockTimeout = 1;
  -
  -        FixedSizePool poolA = new FixedSizePool( factory, max );
  -        BlockingFixedSizePool poolB = new BlockingFixedSizePool( factory, max, blockTimeout );
  -
  -        generalTest( name, poolA, poolB, 100, factory );
  -    }
  -
  -    /**
  -     * Compare the FixedSizePool and BlockingFixedSizePool when the
  -     *  BlockingFixedSizePool is configured to act like a FixedSizePool.
  -     * <p>
  -     * Test will use pools with a max size of 100, while getting up to 100 at a time,
  -     *  Poolables are medium objects.
  -     */
  -    public void testCompare_FixedSizePool_And_BlockingFixedSizePool_Max100_Gets100_LargePoolables()
  -        throws Exception
  -    {
  -        String name = "FixedSizePool_And_BlockingFixedSizePool_Max100_Gets100_LargePoolables";
  -
  -        Class poolableClass = LargePoolable.class;
  -        ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  -        int min = 0;
  -        int max = 100;
  -        long blockTimeout = 1;
  -
  -        FixedSizePool poolA = new FixedSizePool( factory, max );
  -        BlockingFixedSizePool poolB = new BlockingFixedSizePool( factory, max, blockTimeout );
  -
  -        generalTest( name, poolA, poolB, 100, factory );
  -    }
  -
  -    /**
  -     * Compare the FixedSizePool and ResourceLimitingPool when the
  -     *  ResourceLimitingPool is configured to act like a FixedSizePool.
  -     * <p>
  -     * Test will use pools with a max size of 100, while getting up to 100 at a time,
  -     *  Poolables are large objects.
  -     */
  -    public void testCompare_FixedSizePool_And_ResourceLimitingPool_Max100_Gets100_LargePoolables()
  -        throws Exception
  -    {
  -        String name = "FixedSizePool_And_ResourceLimitingPool_Max100_Gets100_LargePoolables";
  -
  -        Class poolableClass = LargePoolable.class;
  -        ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  -        int min = 0;
  -        int max = 100;
  -        boolean maxStrict = true;
  -        boolean blocking = false;
  -        long blockTimeout = 0;
  -        long trimInterval = 0;
  -
  -        FixedSizePool poolA = new FixedSizePool( factory, max );
  -
  -        ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
  -        poolB.enableLogging( m_poolLogger );
  -
  -        generalTest( name, poolA, poolB, 100, factory );
  -    }
  -
  -    /*---------------------------------------------------------------
  -     * FixedSizePool vs VariableSizePool TestCases
  -     *-------------------------------------------------------------*/
  -    /**
  -     * Compare the FixedSizePool and VariableSizePool when the
  -     *  VariableSizePool is configured to act like a FixedSizePool.
  -     * <p>
  -     * Test will use pools with a max size of 100, while getting up to 100 at a time,
  -     *  Poolables are small objects.
  -     */
  -    public void testCompare_FixedSizePool_And_VariableSizePool_Max100_Gets100_SmallPoolables()
  -        throws Exception
  -    {
  -        String name = "FixedSizePool_And_VariableSizePool_Max100_Gets100_SmallPoolables";
  -
  -        Class poolableClass = SmallPoolable.class;
  -        ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  -        int max = 100;
  -
  -        FixedSizePool poolA = new FixedSizePool( factory, max );
  -
  -        VariableSizePool poolB = new VariableSizePool( factory, max );
  -
  -        generalTest( name, poolA, poolB, 100, factory );
  -    }
  -
  -    /**
  -     * Compare the FixedSizePool and VariableSizePool when the
  -     *  VariableSizePool is configured to act like a FixedSizePool.
  -     * <p>
  -     * Test will use pools with a max size of 100, while getting up to 100 at a time,
  -     *  Poolables are medium objects.
  -     */
  -    public void testCompare_FixedSizePool_And_VariableSizePool_Max100_Gets100_MediumPoolables()
  -        throws Exception
  -    {
  -        String name = "FixedSizePool_And_VariableSizePool_Max100_Gets100_MediumPoolables";
  -
  -        Class poolableClass = MediumPoolable.class;
  -        ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  -        int max = 100;
  -
  -        FixedSizePool poolA = new FixedSizePool( factory, max );
  -
  -        VariableSizePool poolB = new VariableSizePool( factory, max );
  -
  -        generalTest( name, poolA, poolB, 100, factory );
  -    }
  -
  -    /**
  -     * Compare the FixedSizePool and VariableSizePool when the
  -     *  VariableSizePool is configured to act like a FixedSizePool.
  -     * <p>
  -     * Test will use pools with a max size of 100, while getting up to 100 at a time,
  -     *  Poolables are large objects.
  -     */
  -    public void testCompare_FixedSizePool_And_VariableSizePool_Max100_Gets100_LargePoolables()
  -        throws Exception
  -    {
  -        String name = "FixedSizePool_And_VariableSizePool_Max100_Gets100_LargePoolables";
  -
  -        Class poolableClass = LargePoolable.class;
  -        ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  -        int max = 100;
  -
  -        FixedSizePool poolA = new FixedSizePool( factory, max );
  -
  -        VariableSizePool poolB = new VariableSizePool( factory, max );
  -
  -        generalTest( name, poolA, poolB, 100, factory );
  -    }
  -
  -    /*---------------------------------------------------------------
  -     * Test Classes
  -     *-------------------------------------------------------------*/
  -    public static class SmallPoolable
  -        implements org.apache.avalon.excalibur.pool.Poolable
  -    {
  -        int a;
  -    }
  -
  -    public static class MediumPoolable
  -        implements org.apache.avalon.excalibur.pool.Poolable
  -    {
  -        int[] a = new int[ 100 ];
  -    }
  -
  -    public static class LargePoolable
  -        implements org.apache.avalon.excalibur.pool.Poolable
  -    {
  -        int[][] a = new int[ 10 ][ 100 ];
  -    }
  -
  -    /**
  -     * Dummy class used for timing test cases where no pooling is done.
  -     */
  -    public static class NoPoolingPool
  -        implements Pool, LogEnabled
  -    {
  -        private ObjectFactory m_factory;
  -        private Logger m_logger;
  -
  -        public NoPoolingPool( ObjectFactory factory )
  -        {
  -            m_factory = factory;
  -        }
  -
  -        public void enableLogging( Logger logger )
  -        {
  -            m_logger = logger;
  -        }
  -
  -        public Object acquire() throws Exception
  -        {
  -            return newInstance();
  -        }
  -
  -        public void release( Object poolable )
  -        {
  -            try
  -            {
  -                m_factory.dispose( poolable );
  -            }
  -            catch( Exception e )
  -            {
  -                m_logger.debug( "Error decommissioning object", e );
  -            }
  -        }
  -
  -        public Object newInstance() throws Exception
  -        {
  -            return m_factory.newInstance();
  -        }
  -    }
  -
  -    /*---------------------------------------------------------------
  -     * VariableSizePool vs ResourceLimitingPool TestCases
  -     *-------------------------------------------------------------*/
  -    /**
  -     * Compare the VariableSizePool and ResourceLimitingPool when the
  -     *  ResourceLimitingPool is configured to act like a VariableSizePool.
  -     * <p>
  -     * Test will use pools with a max size of 100, while getting up to 100 at a time,
  -     *  Poolables are small objects.
  -     */
  -    public void testCompare_VariableSizePool_And_ResourceLimitingPool_Max100_Gets100_SmallPoolables()
  -        throws Exception
  -    {
  -        String name = "VariableSizePool_And_ResourceLimitingPool_Max100_Gets100_SmallPoolables";
  -
  -        Class poolableClass = SmallPoolable.class;
  -        ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  -        int min = 0;
  -        int max = 100;
  -        boolean maxStrict = false;
  -        boolean blocking = false;
  -        long blockTimeout = 0;
  -        long trimInterval = 0;
  -
  -        VariableSizePool poolA = new VariableSizePool( factory, max );
  -
  -        ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
  -        poolB.enableLogging( m_poolLogger );
  -
  -        generalTest( name, poolA, poolB, 100, factory );
  -    }
  -
  -    /**
  -     * Compare the VariableSizePool and ResourceLimitingPool when the
  -     *  ResourceLimitingPool is configured to act like a VariableSizePool.
  -     * <p>
  -     * Test will use pools with a max size of 100, while getting up to 200 at a time,
  -     *  Poolables are small objects.
  -     */
  -    public void testCompare_VariableSizePool_And_ResourceLimitingPool_Max100_Gets200_SmallPoolables()
  -        throws Exception
  -    {
  -        String name = "VariableSizePool_And_ResourceLimitingPool_Max100_Gets200_SmallPoolables";
  -
  -        Class poolableClass = SmallPoolable.class;
  -        ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  -        int min = 0;
  -        int max = 100;
  -        boolean maxStrict = false;
  -        boolean blocking = false;
  -        long blockTimeout = 0;
  -        long trimInterval = 0;
  -
  -        VariableSizePool poolA = new VariableSizePool( factory, max );
  -
  -        ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
  -        poolB.enableLogging( m_poolLogger );
  -
  -        generalTest( name, poolA, poolB, 200, factory );
  -    }
  -
  -    /**
  -     * Compare the VariableSizePool and ResourceLimitingPool when the
  -     *  ResourceLimitingPool is configured to act like a VariableSizePool.
  -     * <p>
  -     * Test will use pools with a max size of 100, while getting up to 100 at a time,
  -     *  Poolables are medium objects.
  -     */
  -    public void testCompare_VariableSizePool_And_ResourceLimitingPool_Max100_Gets100_MediumPoolables()
  -        throws Exception
  -    {
  -        String name = "VariableSizePool_And_ResourceLimitingPool_Max10_Gets100_MediumPoolables";
  -
  -        Class poolableClass = MediumPoolable.class;
  -        ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  -        int min = 0;
  -        int max = 100;
  -        boolean maxStrict = false;
  -        boolean blocking = false;
  -        long blockTimeout = 0;
  -        long trimInterval = 0;
  -
  -        VariableSizePool poolA = new VariableSizePool( factory, max );
  -
  -        ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
  -        poolB.enableLogging( m_poolLogger );
  -
  -        generalTest( name, poolA, poolB, 100, factory );
  -    }
  -
  -    /**
  -     * Compare the VariableSizePool and ResourceLimitingPool when the
  -     *  ResourceLimitingPool is configured to act like a VariableSizePool.
  -     * <p>
  -     * Test will use pools with a max size of 100, while getting up to 200 at a time,
  -     *  Poolables are medium objects.
  -     */
  -    public void testCompare_VariableSizePool_And_ResourceLimitingPool_Max100_Gets200_MediumPoolables()
  -        throws Exception
  -    {
  -        String name = "VariableSizePool_And_ResourceLimitingPool_Max100_Gets200_MediumPoolables";
  -
  -        Class poolableClass = MediumPoolable.class;
  -        ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  -        int min = 0;
  -        int max = 100;
  -        boolean maxStrict = false;
  -        boolean blocking = false;
  -        long blockTimeout = 0;
  -        long trimInterval = 0;
  -
  -        VariableSizePool poolA = new VariableSizePool( factory, max );
  -
  -        ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
  -        poolB.enableLogging( m_poolLogger );
  -
  -        generalTest( name, poolA, poolB, 200, factory );
  -    }
  -
  -    /**
  -     * Compare the VariableSizePool and ResourceLimitingPool when the
  -     *  ResourceLimitingPool is configured to act like a VariableSizePool.
  -     * <p>
  -     * Test will use pools with a max size of 100, while getting up to 100 at a time,
  -     *  Poolables are large objects.
  -     */
  -    public void testCompare_VariableSizePool_And_ResourceLimitingPool_Max100_Gets100_LargePoolables()
  -        throws Exception
  -    {
  -        String name = "VariableSizePool_And_ResourceLimitingPool_Max100_Gets100_LargePoolables";
  -
  -        Class poolableClass = LargePoolable.class;
  -        ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  -        int min = 0;
  -        int max = 100;
  -        boolean maxStrict = false;
  -        boolean blocking = false;
  -        long blockTimeout = 0;
  -        long trimInterval = 0;
  -
  -        VariableSizePool poolA = new VariableSizePool( factory, max );
  -
  -        ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
  -        poolB.enableLogging( m_poolLogger );
  -
  -        generalTest( name, poolA, poolB, 100, factory );
  -    }
  -
  -    /**
  -     * Compare the VariableSizePool and ResourceLimitingPool when the
  -     *  ResourceLimitingPool is configured to act like a VariableSizePool.
  -     * <p>
  -     * Test will use pools with a max size of 100, while getting up to 200 at a time,
  -     *  Poolables are large objects.
  -     */
  -    public void testCompare_VariableSizePool_And_ResourceLimitingPool_Max100_Gets200_LargePoolables()
  -        throws Exception
  -    {
  -        String name = "VariableSizePool_And_ResourceLimitingPool_Max100_Gets200_LargePoolables";
  -
  -        Class poolableClass = LargePoolable.class;
  -        ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  -        int min = 0;
  -        int max = 100;
  -        boolean maxStrict = false;
  -        boolean blocking = false;
  -        long blockTimeout = 0;
  -        long trimInterval = 0;
  -
  -        VariableSizePool poolA = new VariableSizePool( factory, max );
  -
  -        ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
  -        poolB.enableLogging( m_poolLogger );
  -
  -        generalTest( name, poolA, poolB, 200, factory );
  -    }
  -
  -    /*---------------------------------------------------------------
  -     * Utility Methods
  -     *-------------------------------------------------------------*/
  -    protected void resetMemory()
  -    {
  -        System.gc();
  -        System.gc();
  -
  -        // Let the system settle down.
  -        try
  -        {
  -            Thread.sleep( 50 );
  -        }
  -        catch( InterruptedException e )
  -        {
  -        }
  -        Runtime runtime = Runtime.getRuntime();
  -        m_logger.debug( "Memory: " + ( runtime.totalMemory() - runtime.freeMemory() ) );
  -    }
  -
  -    protected String getShortClassName( Object o )
  -    {
  -        String name = o.getClass().getName();
  -        int pos = name.lastIndexOf( '.' );
  -        if( pos > 0 )
  -        {
  -            name = name.substring( pos + 1 );
  -        }
  -        return name;
  -    }
  -
  -    protected abstract long getPoolRunTime( Pool pool, int gets )
  -        throws Exception;
  -
  -    protected abstract long getPoolRunTime( org.apache.avalon.excalibur.pool.Pool pool, int gets )
  -        throws Exception;
  -
  -    /**
  -     * The guts of the various test cases.  Will dispose the pools
  -     */
  -    protected void generalTest( String name, Pool poolA, Pool poolB, int gets, ClassInstanceObjectFactory factory )
  -        throws Exception
  -    {
  -        m_logger.info( "Test Case: " + name );
  -
  -        // Get the short class names
  -        final String poolAName = getShortClassName( poolA );
  -        final String poolBName = getShortClassName( poolB );
  -
  -        // Start clean
  -        resetMemory();
  -
  -        // Get a baseline speed for object creation
  -        NoPoolingPool poolBase = new NoPoolingPool( factory );
  -        poolBase.enableLogging( m_poolLogger );
  -        final long noPoolDuration = getPoolRunTime( poolBase, gets );
  -        m_logger.info( "     Unpooled time = " + noPoolDuration + "ms. to use " + TEST_SIZE + " objects." );
  -        resetMemory();
  -
  -
  -        // Get the time for poolA
  -        final long poolADuration = getPoolRunTime( poolA, gets );
  -        m_logger.info( "     " + poolAName + " time = " + poolADuration + "ms. to use " + TEST_SIZE + " objects, " + gets + " at a time." );
  -        resetMemory();
  -
  -
  -        // Get the time for poolB
  -        final long poolBDuration = getPoolRunTime( poolB, gets );
  -        m_logger.info( "     " + poolBName + " time = " + poolBDuration + "ms. to use " + TEST_SIZE + " objects, " + gets + " at a time." );
  -        resetMemory();
  -
  -        // Show a summary
  -        if( m_logger.isInfoEnabled() )
  -        {
  -            double mult;
  -            mult = ( poolADuration > 0 ? ( noPoolDuration * 100 / poolADuration ) / 100.0 : Float.POSITIVE_INFINITY );
  -            m_logger.info( "  => " + poolAName + " is " + mult + " X as fast as not pooling." );
  -
  -            mult = ( poolBDuration > 0 ? ( noPoolDuration * 100 / poolBDuration ) / 100.0 : Float.POSITIVE_INFINITY );
  -            m_logger.info( "  => " + poolBName + " is " + mult + " X as fast as not pooling." );
  -
  -            mult = ( poolBDuration > 0 ? ( poolADuration * 100 / poolBDuration ) / 100.0 : Float.POSITIVE_INFINITY );
  -            m_logger.info( "  => " + poolBName + " is " + mult + " X as fast as " + poolAName + "." );
  -
  -            mult = ( poolADuration > 0 ? ( poolBDuration * 100 / poolADuration ) / 100.0 : Float.POSITIVE_INFINITY );
  -            m_logger.info( "  => " + poolAName + " is " + mult + " X as fast as " + poolBName + "." );
  -        }
  -    }
  -
  -    /**
  -     * The guts of the various test cases.  Will dispose the pools
  -     */
  -    protected void generalTest( String name, Pool poolA, org.apache.avalon.excalibur.pool.Pool poolB, int gets, ClassInstanceObjectFactory factory )
  -        throws Exception
  -    {
  -        m_logger.info( "Test Case: " + name );
  -
  -        // Get the short class names
  -        final String poolAName = getShortClassName( poolA );
  -        final String poolBName = getShortClassName( poolB );
  -
  -        // Start clean
  -        resetMemory();
  -
  -        // Get a baseline speed for object creation
  -        NoPoolingPool poolBase = new NoPoolingPool( factory );
  -        poolBase.enableLogging( m_poolLogger );
  -        final long noPoolDuration = getPoolRunTime( poolBase, gets );
  -        m_logger.info( "     Unpooled time = " + noPoolDuration + "ms. to use " + TEST_SIZE + " objects." );
  -        resetMemory();
  -
  -
  -        // Get the time for poolA
  -        final long poolADuration = getPoolRunTime( poolA, gets );
  -        m_logger.info( "     " + poolAName + " time = " + poolADuration + "ms. to use " + TEST_SIZE + " objects, " + gets + " at a time." );
  -        resetMemory();
  -
  -
  -        // Get the time for poolB
  -        final long poolBDuration = getPoolRunTime( poolB, gets );
  -        m_logger.info( "     " + poolBName + " time = " + poolBDuration + "ms. to use " + TEST_SIZE + " objects, " + gets + " at a time." );
  -        resetMemory();
  -
  -        // Show a summary
  -        if( m_logger.isInfoEnabled() )
  -        {
  -            double mult;
  -            mult = ( poolADuration > 0 ? ( noPoolDuration * 100 / poolADuration ) / 100.0 : Float.POSITIVE_INFINITY );
  -            m_logger.info( "  => " + poolAName + " is " + mult + " X as fast as not pooling." );
  -
  -            mult = ( poolBDuration > 0 ? ( noPoolDuration * 100 / poolBDuration ) / 100.0 : Float.POSITIVE_INFINITY );
  -            m_logger.info( "  => " + poolBName + " is " + mult + " X as fast as not pooling." );
  -
  -            mult = ( poolBDuration > 0 ? ( poolADuration * 100 / poolBDuration ) / 100.0 : Float.POSITIVE_INFINITY );
  -            m_logger.info( "  => " + poolBName + " is " + mult + " X as fast as " + poolAName + "." );
  -
  -            mult = ( poolADuration > 0 ? ( poolBDuration * 100 / poolADuration ) / 100.0 : Float.POSITIVE_INFINITY );
  -            m_logger.info( "  => " + poolAName + " is " + mult + " X as fast as " + poolBName + "." );
  -        }
  -    }
  -}
  +/*
  +
  + ============================================================================
  +                   The Apache Software License, Version 1.1
  + ============================================================================
  +
  + Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  +
  + Redistribution and use in source and binary forms, with or without modifica-
  + tion, are permitted provided that the following conditions are met:
  +
  + 1. Redistributions of  source code must  retain the above copyright  notice,
  +    this list of conditions and the following disclaimer.
  +
  + 2. Redistributions in binary form must reproduce the above copyright notice,
  +    this list of conditions and the following disclaimer in the documentation
  +    and/or other materials provided with the distribution.
  +
  + 3. The end-user documentation included with the redistribution, if any, must
  +    include  the following  acknowledgment:  "This product includes  software
  +    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  +    Alternately, this  acknowledgment may  appear in the software itself,  if
  +    and wherever such third-party acknowledgments normally appear.
  +
  + 4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
  +    must not be used to endorse or promote products derived from this  software
  +    without  prior written permission. For written permission, please contact
  +    apache@apache.org.
  +
  + 5. Products  derived from this software may not  be called "Apache", nor may
  +    "Apache" appear  in their name,  without prior written permission  of the
  +    Apache Software Foundation.
  +
  + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  + FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  + APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  + INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  + DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  + OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  + ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  + (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  +
  + This software  consists of voluntary contributions made  by many individuals
  + on  behalf of the Apache Software  Foundation. For more  information on the
  + Apache Software Foundation, please see <http://www.apache.org/>.
  +
  +*/
  +package org.apache.excalibur.mpool.test;
  +
  +import junit.framework.TestCase;
  +import org.apache.avalon.excalibur.pool.ResourceLimitingPool;
  +import org.apache.avalon.framework.logger.LogEnabled;
  +import org.apache.avalon.framework.logger.LogKitLogger;
  +import org.apache.avalon.framework.logger.Logger;
  +import org.apache.excalibur.mpool.FixedSizePool;
  +import org.apache.excalibur.mpool.BlockingFixedSizePool;
  +import org.apache.excalibur.mpool.ObjectFactory;
  +import org.apache.excalibur.mpool.Pool;
  +import org.apache.excalibur.mpool.VariableSizePool;
  +
  +/**
  + * Used as a basis for the PoolComparisonProfile Tests
  + *
  + * @author <a href="mailto:leif@tanukisoftware.com">Leif Mortenson</a>
  + * @version $Id$
  + */
  +public abstract class PoolComparisonProfileAbstract
  +    extends TestCase
  +{
  +    /**
  +     * The TEST_SIZE defines the overall size of the tests.  Decreasing this will
  +     *  decrease the time the test takes to run, but also decrease its efficiency.
  +     */
  +    protected static final int TEST_SIZE = 50000;
  +
  +    protected Logger m_logger;
  +    protected Logger m_poolLogger;
  +
  +    /*---------------------------------------------------------------
  +     * Constructors
  +     *-------------------------------------------------------------*/
  +    public PoolComparisonProfileAbstract( String name )
  +    {
  +        super( name );
  +
  +        // Set to debug to see more useful information.
  +        org.apache.log.Logger logger =
  +            org.apache.log.Hierarchy.getDefaultHierarchy().getLoggerFor( "test" );
  +        logger.setPriority( org.apache.log.Priority.INFO );
  +        m_logger = new LogKitLogger( logger );
  +
  +        // The output from the pools is too much data to be useful, so use a different logger.
  +        org.apache.log.Logger poolLogger =
  +            org.apache.log.Hierarchy.getDefaultHierarchy().getLoggerFor( "pool" );
  +        poolLogger.setPriority( org.apache.log.Priority.INFO );
  +        m_poolLogger = new LogKitLogger( poolLogger );
  +    }
  +
  +    /*---------------------------------------------------------------
  +     * FixedSizePool vs ResourceLimitingPool TestCases
  +     *-------------------------------------------------------------*/
  +    /**
  +     * Compare the FixedSizePool and ResourceLimitingPool when the
  +     *  ResourceLimitingPool is configured to act like a FixedSizePool.
  +     * <p>
  +     * Test will use pools with a max size of 100, while getting up to 100 at a time,
  +     *  Poolables are small objects.
  +     */
  +    public void testCompare_FixedSizePool_And_ResourceLimitingPool_Max100_Gets100_SmallPoolables()
  +        throws Exception
  +    {
  +        String name = "FixedSizePool_And_ResourceLimitingPool_Max100_Gets100_SmallPoolables";
  +
  +        Class poolableClass = SmallPoolable.class;
  +        ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  +        int min = 0;
  +        int max = 100;
  +        boolean maxStrict = true;
  +        boolean blocking = false;
  +        long blockTimeout = 0;
  +        long trimInterval = 0;
  +
  +        FixedSizePool poolA = new FixedSizePool( factory, max );
  +
  +        ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
  +        poolB.enableLogging( m_poolLogger );
  +
  +        generalTest( name, poolA, poolB, 100, factory );
  +    }
  +
  +    /**
  +     * Compare the FixedSizePool and BlockingFixedSizePool when the
  +     *  BlockingFixedSizePool is configured to act like a FixedSizePool.
  +     * <p>
  +     * Test will use pools with a max size of 100, while getting up to 100 at a time,
  +     *  Poolables are medium objects.
  +     */
  +    public void testCompare_FixedSizePool_And_BlockingFixedSizePool_Max100_Gets100_SmallPoolables()
  +        throws Exception
  +    {
  +        String name = "FixedSizePool_And_BlockingFixedSizePool_Max100_Gets100_SmallPoolables";
  +
  +        Class poolableClass = SmallPoolable.class;
  +        ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  +        int min = 0;
  +        int max = 100;
  +        long blockTimeout = 1;
  +
  +        FixedSizePool poolA = new FixedSizePool( factory, max );
  +        BlockingFixedSizePool poolB = new BlockingFixedSizePool( factory, max, blockTimeout );
  +
  +        generalTest( name, poolA, poolB, 100, factory );
  +    }
  +
  +    /**
  +     * Compare the FixedSizePool and BlockingFixedSizePool when the
  +     *  BlockingFixedSizePool is configured to act like a FixedSizePool.
  +     * <p>
  +     * Test will use pools with a max size of 100, while getting up to 100 at a time,
  +     *  Poolables are medium objects.
  +     */
  +    public void testCompare_FixedSizePool_And_BlockingFixedSizePool_Max100_Gets100_MediumPoolables()
  +        throws Exception
  +    {
  +        String name = "FixedSizePool_And_BlockingFixedSizePool_Max100_Gets100_MediumPoolables";
  +
  +        Class poolableClass = MediumPoolable.class;
  +        ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  +        int min = 0;
  +        int max = 100;
  +        long blockTimeout = 1;
  +
  +        FixedSizePool poolA = new FixedSizePool( factory, max );
  +        BlockingFixedSizePool poolB = new BlockingFixedSizePool( factory, max, blockTimeout );
  +
  +        generalTest( name, poolA, poolB, 100, factory );
  +    }
  +
  +    /**
  +     * Compare the FixedSizePool and BlockingFixedSizePool when the
  +     *  BlockingFixedSizePool is configured to act like a FixedSizePool.
  +     * <p>
  +     * Test will use pools with a max size of 100, while getting up to 100 at a time,
  +     *  Poolables are medium objects.
  +     */
  +    public void testCompare_FixedSizePool_And_BlockingFixedSizePool_Max100_Gets100_LargePoolables()
  +        throws Exception
  +    {
  +        String name = "FixedSizePool_And_BlockingFixedSizePool_Max100_Gets100_LargePoolables";
  +
  +        Class poolableClass = LargePoolable.class;
  +        ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  +        int min = 0;
  +        int max = 100;
  +        long blockTimeout = 1;
  +
  +        FixedSizePool poolA = new FixedSizePool( factory, max );
  +        BlockingFixedSizePool poolB = new BlockingFixedSizePool( factory, max, blockTimeout );
  +
  +        generalTest( name, poolA, poolB, 100, factory );
  +    }
  +
  +    /**
  +     * Compare the FixedSizePool and ResourceLimitingPool when the
  +     *  ResourceLimitingPool is configured to act like a FixedSizePool.
  +     * <p>
  +     * Test will use pools with a max size of 100, while getting up to 100 at a time,
  +     *  Poolables are large objects.
  +     */
  +    public void testCompare_FixedSizePool_And_ResourceLimitingPool_Max100_Gets100_LargePoolables()
  +        throws Exception
  +    {
  +        String name = "FixedSizePool_And_ResourceLimitingPool_Max100_Gets100_LargePoolables";
  +
  +        Class poolableClass = LargePoolable.class;
  +        ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  +        int min = 0;
  +        int max = 100;
  +        boolean maxStrict = true;
  +        boolean blocking = false;
  +        long blockTimeout = 0;
  +        long trimInterval = 0;
  +
  +        FixedSizePool poolA = new FixedSizePool( factory, max );
  +
  +        ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
  +        poolB.enableLogging( m_poolLogger );
  +
  +        generalTest( name, poolA, poolB, 100, factory );
  +    }
  +
  +    /*---------------------------------------------------------------
  +     * FixedSizePool vs VariableSizePool TestCases
  +     *-------------------------------------------------------------*/
  +    /**
  +     * Compare the FixedSizePool and VariableSizePool when the
  +     *  VariableSizePool is configured to act like a FixedSizePool.
  +     * <p>
  +     * Test will use pools with a max size of 100, while getting up to 100 at a time,
  +     *  Poolables are small objects.
  +     */
  +    public void testCompare_FixedSizePool_And_VariableSizePool_Max100_Gets100_SmallPoolables()
  +        throws Exception
  +    {
  +        String name = "FixedSizePool_And_VariableSizePool_Max100_Gets100_SmallPoolables";
  +
  +        Class poolableClass = SmallPoolable.class;
  +        ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  +        int max = 100;
  +
  +        FixedSizePool poolA = new FixedSizePool( factory, max );
  +
  +        VariableSizePool poolB = new VariableSizePool( factory, max );
  +
  +        generalTest( name, poolA, poolB, 100, factory );
  +    }
  +
  +    /**
  +     * Compare the FixedSizePool and VariableSizePool when the
  +     *  VariableSizePool is configured to act like a FixedSizePool.
  +     * <p>
  +     * Test will use pools with a max size of 100, while getting up to 100 at a time,
  +     *  Poolables are medium objects.
  +     */
  +    public void testCompare_FixedSizePool_And_VariableSizePool_Max100_Gets100_MediumPoolables()
  +        throws Exception
  +    {
  +        String name = "FixedSizePool_And_VariableSizePool_Max100_Gets100_MediumPoolables";
  +
  +        Class poolableClass = MediumPoolable.class;
  +        ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  +        int max = 100;
  +
  +        FixedSizePool poolA = new FixedSizePool( factory, max );
  +
  +        VariableSizePool poolB = new VariableSizePool( factory, max );
  +
  +        generalTest( name, poolA, poolB, 100, factory );
  +    }
  +
  +    /**
  +     * Compare the FixedSizePool and VariableSizePool when the
  +     *  VariableSizePool is configured to act like a FixedSizePool.
  +     * <p>
  +     * Test will use pools with a max size of 100, while getting up to 100 at a time,
  +     *  Poolables are large objects.
  +     */
  +    public void testCompare_FixedSizePool_And_VariableSizePool_Max100_Gets100_LargePoolables()
  +        throws Exception
  +    {
  +        String name = "FixedSizePool_And_VariableSizePool_Max100_Gets100_LargePoolables";
  +
  +        Class poolableClass = LargePoolable.class;
  +        ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  +        int max = 100;
  +
  +        FixedSizePool poolA = new FixedSizePool( factory, max );
  +
  +        VariableSizePool poolB = new VariableSizePool( factory, max );
  +
  +        generalTest( name, poolA, poolB, 100, factory );
  +    }
  +
  +    /*---------------------------------------------------------------
  +     * Test Classes
  +     *-------------------------------------------------------------*/
  +    public static class SmallPoolable
  +        implements org.apache.avalon.excalibur.pool.Poolable
  +    {
  +        int a;
  +    }
  +
  +    public static class MediumPoolable
  +        implements org.apache.avalon.excalibur.pool.Poolable
  +    {
  +        int[] a = new int[ 100 ];
  +    }
  +
  +    public static class LargePoolable
  +        implements org.apache.avalon.excalibur.pool.Poolable
  +    {
  +        int[][] a = new int[ 10 ][ 100 ];
  +    }
  +
  +    /**
  +     * Dummy class used for timing test cases where no pooling is done.
  +     */
  +    public static class NoPoolingPool
  +        implements Pool, LogEnabled
  +    {
  +        private ObjectFactory m_factory;
  +        private Logger m_logger;
  +
  +        public NoPoolingPool( ObjectFactory factory )
  +        {
  +            m_factory = factory;
  +        }
  +
  +        public void enableLogging( Logger logger )
  +        {
  +            m_logger = logger;
  +        }
  +
  +        public Object acquire() throws Exception
  +        {
  +            return newInstance();
  +        }
  +
  +        public void release( Object poolable )
  +        {
  +            try
  +            {
  +                m_factory.dispose( poolable );
  +            }
  +            catch( Exception e )
  +            {
  +                m_logger.debug( "Error decommissioning object", e );
  +            }
  +        }
  +
  +        public Object newInstance() throws Exception
  +        {
  +            return m_factory.newInstance();
  +        }
  +    }
  +
  +    /*---------------------------------------------------------------
  +     * VariableSizePool vs ResourceLimitingPool TestCases
  +     *-------------------------------------------------------------*/
  +    /**
  +     * Compare the VariableSizePool and ResourceLimitingPool when the
  +     *  ResourceLimitingPool is configured to act like a VariableSizePool.
  +     * <p>
  +     * Test will use pools with a max size of 100, while getting up to 100 at a time,
  +     *  Poolables are small objects.
  +     */
  +    public void testCompare_VariableSizePool_And_ResourceLimitingPool_Max100_Gets100_SmallPoolables()
  +        throws Exception
  +    {
  +        String name = "VariableSizePool_And_ResourceLimitingPool_Max100_Gets100_SmallPoolables";
  +
  +        Class poolableClass = SmallPoolable.class;
  +        ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  +        int min = 0;
  +        int max = 100;
  +        boolean maxStrict = false;
  +        boolean blocking = false;
  +        long blockTimeout = 0;
  +        long trimInterval = 0;
  +
  +        VariableSizePool poolA = new VariableSizePool( factory, max );
  +
  +        ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
  +        poolB.enableLogging( m_poolLogger );
  +
  +        generalTest( name, poolA, poolB, 100, factory );
  +    }
  +
  +    /**
  +     * Compare the VariableSizePool and ResourceLimitingPool when the
  +     *  ResourceLimitingPool is configured to act like a VariableSizePool.
  +     * <p>
  +     * Test will use pools with a max size of 100, while getting up to 200 at a time,
  +     *  Poolables are small objects.
  +     */
  +    public void testCompare_VariableSizePool_And_ResourceLimitingPool_Max100_Gets200_SmallPoolables()
  +        throws Exception
  +    {
  +        String name = "VariableSizePool_And_ResourceLimitingPool_Max100_Gets200_SmallPoolables";
  +
  +        Class poolableClass = SmallPoolable.class;
  +        ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  +        int min = 0;
  +        int max = 100;
  +        boolean maxStrict = false;
  +        boolean blocking = false;
  +        long blockTimeout = 0;
  +        long trimInterval = 0;
  +
  +        VariableSizePool poolA = new VariableSizePool( factory, max );
  +
  +        ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
  +        poolB.enableLogging( m_poolLogger );
  +
  +        generalTest( name, poolA, poolB, 200, factory );
  +    }
  +
  +    /**
  +     * Compare the VariableSizePool and ResourceLimitingPool when the
  +     *  ResourceLimitingPool is configured to act like a VariableSizePool.
  +     * <p>
  +     * Test will use pools with a max size of 100, while getting up to 100 at a time,
  +     *  Poolables are medium objects.
  +     */
  +    public void testCompare_VariableSizePool_And_ResourceLimitingPool_Max100_Gets100_MediumPoolables()
  +        throws Exception
  +    {
  +        String name = "VariableSizePool_And_ResourceLimitingPool_Max10_Gets100_MediumPoolables";
  +
  +        Class poolableClass = MediumPoolable.class;
  +        ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  +        int min = 0;
  +        int max = 100;
  +        boolean maxStrict = false;
  +        boolean blocking = false;
  +        long blockTimeout = 0;
  +        long trimInterval = 0;
  +
  +        VariableSizePool poolA = new VariableSizePool( factory, max );
  +
  +        ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
  +        poolB.enableLogging( m_poolLogger );
  +
  +        generalTest( name, poolA, poolB, 100, factory );
  +    }
  +
  +    /**
  +     * Compare the VariableSizePool and ResourceLimitingPool when the
  +     *  ResourceLimitingPool is configured to act like a VariableSizePool.
  +     * <p>
  +     * Test will use pools with a max size of 100, while getting up to 200 at a time,
  +     *  Poolables are medium objects.
  +     */
  +    public void testCompare_VariableSizePool_And_ResourceLimitingPool_Max100_Gets200_MediumPoolables()
  +        throws Exception
  +    {
  +        String name = "VariableSizePool_And_ResourceLimitingPool_Max100_Gets200_MediumPoolables";
  +
  +        Class poolableClass = MediumPoolable.class;
  +        ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  +        int min = 0;
  +        int max = 100;
  +        boolean maxStrict = false;
  +        boolean blocking = false;
  +        long blockTimeout = 0;
  +        long trimInterval = 0;
  +
  +        VariableSizePool poolA = new VariableSizePool( factory, max );
  +
  +        ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
  +        poolB.enableLogging( m_poolLogger );
  +
  +        generalTest( name, poolA, poolB, 200, factory );
  +    }
  +
  +    /**
  +     * Compare the VariableSizePool and ResourceLimitingPool when the
  +     *  ResourceLimitingPool is configured to act like a VariableSizePool.
  +     * <p>
  +     * Test will use pools with a max size of 100, while getting up to 100 at a time,
  +     *  Poolables are large objects.
  +     */
  +    public void testCompare_VariableSizePool_And_ResourceLimitingPool_Max100_Gets100_LargePoolables()
  +        throws Exception
  +    {
  +        String name = "VariableSizePool_And_ResourceLimitingPool_Max100_Gets100_LargePoolables";
  +
  +        Class poolableClass = LargePoolable.class;
  +        ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  +        int min = 0;
  +        int max = 100;
  +        boolean maxStrict = false;
  +        boolean blocking = false;
  +        long blockTimeout = 0;
  +        long trimInterval = 0;
  +
  +        VariableSizePool poolA = new VariableSizePool( factory, max );
  +
  +        ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
  +        poolB.enableLogging( m_poolLogger );
  +
  +        generalTest( name, poolA, poolB, 100, factory );
  +    }
  +
  +    /**
  +     * Compare the VariableSizePool and ResourceLimitingPool when the
  +     *  ResourceLimitingPool is configured to act like a VariableSizePool.
  +     * <p>
  +     * Test will use pools with a max size of 100, while getting up to 200 at a time,
  +     *  Poolables are large objects.
  +     */
  +    public void testCompare_VariableSizePool_And_ResourceLimitingPool_Max100_Gets200_LargePoolables()
  +        throws Exception
  +    {
  +        String name = "VariableSizePool_And_ResourceLimitingPool_Max100_Gets200_LargePoolables";
  +
  +        Class poolableClass = LargePoolable.class;
  +        ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  +        int min = 0;
  +        int max = 100;
  +        boolean maxStrict = false;
  +        boolean blocking = false;
  +        long blockTimeout = 0;
  +        long trimInterval = 0;
  +
  +        VariableSizePool poolA = new VariableSizePool( factory, max );
  +
  +        ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
  +        poolB.enableLogging( m_poolLogger );
  +
  +        generalTest( name, poolA, poolB, 200, factory );
  +    }
  +
  +    /*---------------------------------------------------------------
  +     * Utility Methods
  +     *-------------------------------------------------------------*/
  +    protected void resetMemory()
  +    {
  +        System.gc();
  +        System.gc();
  +
  +        // Let the system settle down.
  +        try
  +        {
  +            Thread.sleep( 50 );
  +        }
  +        catch( InterruptedException e )
  +        {
  +        }
  +        Runtime runtime = Runtime.getRuntime();
  +        m_logger.debug( "Memory: " + ( runtime.totalMemory() - runtime.freeMemory() ) );
  +    }
  +
  +    protected String getShortClassName( Object o )
  +    {
  +        String name = o.getClass().getName();
  +        int pos = name.lastIndexOf( '.' );
  +        if( pos > 0 )
  +        {
  +            name = name.substring( pos + 1 );
  +        }
  +        return name;
  +    }
  +
  +    protected abstract long getPoolRunTime( Pool pool, int gets )
  +        throws Exception;
  +
  +    protected abstract long getPoolRunTime( org.apache.avalon.excalibur.pool.Pool pool, int gets )
  +        throws Exception;
  +
  +    /**
  +     * The guts of the various test cases.  Will dispose the pools
  +     */
  +    protected void generalTest( String name, Pool poolA, Pool poolB, int gets, ClassInstanceObjectFactory factory )
  +        throws Exception
  +    {
  +        m_logger.info( "Test Case: " + name );
  +
  +        // Get the short class names
  +        final String poolAName = getShortClassName( poolA );
  +        final String poolBName = getShortClassName( poolB );
  +
  +        // Start clean
  +        resetMemory();
  +
  +        // Get a baseline speed for object creation
  +        NoPoolingPool poolBase = new NoPoolingPool( factory );
  +        poolBase.enableLogging( m_poolLogger );
  +        final long noPoolDuration = getPoolRunTime( poolBase, gets );
  +        m_logger.info( "     Unpooled time = " + noPoolDuration + "ms. to use " + TEST_SIZE + " objects." );
  +        resetMemory();
  +
  +
  +        // Get the time for poolA
  +        final long poolADuration = getPoolRunTime( poolA, gets );
  +        m_logger.info( "     " + poolAName + " time = " + poolADuration + "ms. to use " + TEST_SIZE + " objects, " + gets + " at a time." );
  +        resetMemory();
  +
  +
  +        // Get the time for poolB
  +        final long poolBDuration = getPoolRunTime( poolB, gets );
  +        m_logger.info( "     " + poolBName + " time = " + poolBDuration + "ms. to use " + TEST_SIZE + " objects, " + gets + " at a time." );
  +        resetMemory();
  +
  +        // Show a summary
  +        if( m_logger.isInfoEnabled() )
  +        {
  +            double mult;
  +            mult = ( poolADuration > 0 ? ( noPoolDuration * 100 / poolADuration ) / 100.0 : Float.POSITIVE_INFINITY );
  +            m_logger.info( "  => " + poolAName + " is " + mult + " X as fast as not pooling." );
  +
  +            mult = ( poolBDuration > 0 ? ( noPoolDuration * 100 / poolBDuration ) / 100.0 : Float.POSITIVE_INFINITY );
  +            m_logger.info( "  => " + poolBName + " is " + mult + " X as fast as not pooling." );
  +
  +            mult = ( poolBDuration > 0 ? ( poolADuration * 100 / poolBDuration ) / 100.0 : Float.POSITIVE_INFINITY );
  +            m_logger.info( "  => " + poolBName + " is " + mult + " X as fast as " + poolAName + "." );
  +
  +            mult = ( poolADuration > 0 ? ( poolBDuration * 100 / poolADuration ) / 100.0 : Float.POSITIVE_INFINITY );
  +            m_logger.info( "  => " + poolAName + " is " + mult + " X as fast as " + poolBName + "." );
  +        }
  +    }
  +
  +    /**
  +     * The guts of the various test cases.  Will dispose the pools
  +     */
  +    protected void generalTest( String name, Pool poolA, org.apache.avalon.excalibur.pool.Pool poolB, int gets, ClassInstanceObjectFactory factory )
  +        throws Exception
  +    {
  +        m_logger.info( "Test Case: " + name );
  +
  +        // Get the short class names
  +        final String poolAName = getShortClassName( poolA );
  +        final String poolBName = getShortClassName( poolB );
  +
  +        // Start clean
  +        resetMemory();
  +
  +        // Get a baseline speed for object creation
  +        NoPoolingPool poolBase = new NoPoolingPool( factory );
  +        poolBase.enableLogging( m_poolLogger );
  +        final long noPoolDuration = getPoolRunTime( poolBase, gets );
  +        m_logger.info( "     Unpooled time = " + noPoolDuration + "ms. to use " + TEST_SIZE + " objects." );
  +        resetMemory();
  +
  +
  +        // Get the time for poolA
  +        final long poolADuration = getPoolRunTime( poolA, gets );
  +        m_logger.info( "     " + poolAName + " time = " + poolADuration + "ms. to use " + TEST_SIZE + " objects, " + gets + " at a time." );
  +        resetMemory();
  +
  +
  +        // Get the time for poolB
  +        final long poolBDuration = getPoolRunTime( poolB, gets );
  +        m_logger.info( "     " + poolBName + " time = " + poolBDuration + "ms. to use " + TEST_SIZE + " objects, " + gets + " at a time." );
  +        resetMemory();
  +
  +        // Show a summary
  +        if( m_logger.isInfoEnabled() )
  +        {
  +            double mult;
  +            mult = ( poolADuration > 0 ? ( noPoolDuration * 100 / poolADuration ) / 100.0 : Float.POSITIVE_INFINITY );
  +            m_logger.info( "  => " + poolAName + " is " + mult + " X as fast as not pooling." );
  +
  +            mult = ( poolBDuration > 0 ? ( noPoolDuration * 100 / poolBDuration ) / 100.0 : Float.POSITIVE_INFINITY );
  +            m_logger.info( "  => " + poolBName + " is " + mult + " X as fast as not pooling." );
  +
  +            mult = ( poolBDuration > 0 ? ( poolADuration * 100 / poolBDuration ) / 100.0 : Float.POSITIVE_INFINITY );
  +            m_logger.info( "  => " + poolBName + " is " + mult + " X as fast as " + poolAName + "." );
  +
  +            mult = ( poolADuration > 0 ? ( poolBDuration * 100 / poolADuration ) / 100.0 : Float.POSITIVE_INFINITY );
  +            m_logger.info( "  => " + poolAName + " is " + mult + " X as fast as " + poolBName + "." );
  +        }
  +    }
  +}
  
  
  
  1.2       +149 -149  jakarta-avalon-excalibur/event/src/test/org/apache/excalibur/mpool/test/SingleThreadedPoolComparisonProfile.java
  
  Index: SingleThreadedPoolComparisonProfile.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/event/src/test/org/apache/excalibur/mpool/test/SingleThreadedPoolComparisonProfile.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SingleThreadedPoolComparisonProfile.java	7 Aug 2002 22:44:26 -0000	1.1
  +++ SingleThreadedPoolComparisonProfile.java	13 Aug 2002 08:15:21 -0000	1.2
  @@ -1,149 +1,149 @@
  -/*
  -
  - ============================================================================
  -                   The Apache Software License, Version 1.1
  - ============================================================================
  -
  - Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  -
  - Redistribution and use in source and binary forms, with or without modifica-
  - tion, are permitted provided that the following conditions are met:
  -
  - 1. Redistributions of  source code must  retain the above copyright  notice,
  -    this list of conditions and the following disclaimer.
  -
  - 2. Redistributions in binary form must reproduce the above copyright notice,
  -    this list of conditions and the following disclaimer in the documentation
  -    and/or other materials provided with the distribution.
  -
  - 3. The end-user documentation included with the redistribution, if any, must
  -    include  the following  acknowledgment:  "This product includes  software
  -    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  -    Alternately, this  acknowledgment may  appear in the software itself,  if
  -    and wherever such third-party acknowledgments normally appear.
  -
  - 4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
  -    must not be used to endorse or promote products derived from this  software
  -    without  prior written permission. For written permission, please contact
  -    apache@apache.org.
  -
  - 5. Products  derived from this software may not  be called "Apache", nor may
  -    "Apache" appear  in their name,  without prior written permission  of the
  -    Apache Software Foundation.
  -
  - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  - FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  - APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  - INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  - DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  - OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  - ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  - (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  -
  - This software  consists of voluntary contributions made  by many individuals
  - on  behalf of the Apache Software  Foundation. For more  information on the
  - Apache Software Foundation, please see <http://www.apache.org/>.
  -
  -*/
  -package org.apache.excalibur.mpool.test;
  -
  -import org.apache.avalon.excalibur.pool.Poolable;
  -import org.apache.avalon.framework.activity.Disposable;
  -import org.apache.excalibur.mpool.Pool;
  -
  -/**
  - * This is used to profile and compare various pool implementations
  - *  given a single access thread.
  - *
  - * @author <a href="mailto:leif@tanukisoftware.com">Leif Mortenson</a>
  - * @version $Id$
  - */
  -public class SingleThreadedPoolComparisonProfile
  -    extends PoolComparisonProfileAbstract
  -{
  -    /*---------------------------------------------------------------
  -     * Constructors
  -     *-------------------------------------------------------------*/
  -    public SingleThreadedPoolComparisonProfile( String name )
  -    {
  -        super( name );
  -    }
  -
  -    /*---------------------------------------------------------------
  -     * PoolComparisonProfileAbstract Methods
  -     *-------------------------------------------------------------*/
  -    protected long getPoolRunTime( Pool pool, int gets )
  -        throws Exception
  -    {
  -        // Start clean
  -        resetMemory();
  -
  -        final long startTime = System.currentTimeMillis();
  -        final Object[] poolTmp = new Object[ gets ];
  -        final int loops = TEST_SIZE / gets;
  -        for( int i = 0; i < loops; i++ )
  -        {
  -            // Get some Poolables
  -            for( int j = 0; j < gets; j++ )
  -            {
  -                poolTmp[ j ] = pool.acquire();
  -            }
  -
  -            // Put the Poolables back
  -            for( int j = 0; j < gets; j++ )
  -            {
  -                pool.release( poolTmp[ j ] );
  -                poolTmp[ j ] = null;
  -            }
  -        }
  -        final long duration = System.currentTimeMillis() - startTime;
  -
  -        // Dispose if necessary
  -        if( pool instanceof Disposable )
  -        {
  -            ( (Disposable)pool ).dispose();
  -        }
  -
  -        return duration;
  -    }
  -
  -    /*---------------------------------------------------------------
  -     * PoolComparisonProfileAbstract Methods
  -     *-------------------------------------------------------------*/
  -    protected long getPoolRunTime( org.apache.avalon.excalibur.pool.Pool pool, int gets )
  -        throws Exception
  -    {
  -        // Start clean
  -        resetMemory();
  -
  -        final long startTime = System.currentTimeMillis();
  -        final Poolable[] poolTmp = new Poolable[ gets ];
  -        final int loops = TEST_SIZE / gets;
  -        for( int i = 0; i < loops; i++ )
  -        {
  -            // Get some Poolables
  -            for( int j = 0; j < gets; j++ )
  -            {
  -                poolTmp[ j ] = pool.get();
  -            }
  -
  -            // Put the Poolables back
  -            for( int j = 0; j < gets; j++ )
  -            {
  -                pool.put( poolTmp[ j ] );
  -                poolTmp[ j ] = null;
  -            }
  -        }
  -        final long duration = System.currentTimeMillis() - startTime;
  -
  -        // Dispose if necessary
  -        if( pool instanceof Disposable )
  -        {
  -            ( (Disposable)pool ).dispose();
  -        }
  -
  -        return duration;
  -    }
  -}
  +/*
  +
  + ============================================================================
  +                   The Apache Software License, Version 1.1
  + ============================================================================
  +
  + Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  +
  + Redistribution and use in source and binary forms, with or without modifica-
  + tion, are permitted provided that the following conditions are met:
  +
  + 1. Redistributions of  source code must  retain the above copyright  notice,
  +    this list of conditions and the following disclaimer.
  +
  + 2. Redistributions in binary form must reproduce the above copyright notice,
  +    this list of conditions and the following disclaimer in the documentation
  +    and/or other materials provided with the distribution.
  +
  + 3. The end-user documentation included with the redistribution, if any, must
  +    include  the following  acknowledgment:  "This product includes  software
  +    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  +    Alternately, this  acknowledgment may  appear in the software itself,  if
  +    and wherever such third-party acknowledgments normally appear.
  +
  + 4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
  +    must not be used to endorse or promote products derived from this  software
  +    without  prior written permission. For written permission, please contact
  +    apache@apache.org.
  +
  + 5. Products  derived from this software may not  be called "Apache", nor may
  +    "Apache" appear  in their name,  without prior written permission  of the
  +    Apache Software Foundation.
  +
  + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  + FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  + APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  + INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  + DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  + OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  + ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  + (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  +
  + This software  consists of voluntary contributions made  by many individuals
  + on  behalf of the Apache Software  Foundation. For more  information on the
  + Apache Software Foundation, please see <http://www.apache.org/>.
  +
  +*/
  +package org.apache.excalibur.mpool.test;
  +
  +import org.apache.avalon.excalibur.pool.Poolable;
  +import org.apache.avalon.framework.activity.Disposable;
  +import org.apache.excalibur.mpool.Pool;
  +
  +/**
  + * This is used to profile and compare various pool implementations
  + *  given a single access thread.
  + *
  + * @author <a href="mailto:leif@tanukisoftware.com">Leif Mortenson</a>
  + * @version $Id$
  + */
  +public class SingleThreadedPoolComparisonProfile
  +    extends PoolComparisonProfileAbstract
  +{
  +    /*---------------------------------------------------------------
  +     * Constructors
  +     *-------------------------------------------------------------*/
  +    public SingleThreadedPoolComparisonProfile( String name )
  +    {
  +        super( name );
  +    }
  +
  +    /*---------------------------------------------------------------
  +     * PoolComparisonProfileAbstract Methods
  +     *-------------------------------------------------------------*/
  +    protected long getPoolRunTime( Pool pool, int gets )
  +        throws Exception
  +    {
  +        // Start clean
  +        resetMemory();
  +
  +        final long startTime = System.currentTimeMillis();
  +        final Object[] poolTmp = new Object[ gets ];
  +        final int loops = TEST_SIZE / gets;
  +        for( int i = 0; i < loops; i++ )
  +        {
  +            // Get some Poolables
  +            for( int j = 0; j < gets; j++ )
  +            {
  +                poolTmp[ j ] = pool.acquire();
  +            }
  +
  +            // Put the Poolables back
  +            for( int j = 0; j < gets; j++ )
  +            {
  +                pool.release( poolTmp[ j ] );
  +                poolTmp[ j ] = null;
  +            }
  +        }
  +        final long duration = System.currentTimeMillis() - startTime;
  +
  +        // Dispose if necessary
  +        if( pool instanceof Disposable )
  +        {
  +            ( (Disposable)pool ).dispose();
  +        }
  +
  +        return duration;
  +    }
  +
  +    /*---------------------------------------------------------------
  +     * PoolComparisonProfileAbstract Methods
  +     *-------------------------------------------------------------*/
  +    protected long getPoolRunTime( org.apache.avalon.excalibur.pool.Pool pool, int gets )
  +        throws Exception
  +    {
  +        // Start clean
  +        resetMemory();
  +
  +        final long startTime = System.currentTimeMillis();
  +        final Poolable[] poolTmp = new Poolable[ gets ];
  +        final int loops = TEST_SIZE / gets;
  +        for( int i = 0; i < loops; i++ )
  +        {
  +            // Get some Poolables
  +            for( int j = 0; j < gets; j++ )
  +            {
  +                poolTmp[ j ] = pool.get();
  +            }
  +
  +            // Put the Poolables back
  +            for( int j = 0; j < gets; j++ )
  +            {
  +                pool.put( poolTmp[ j ] );
  +                poolTmp[ j ] = null;
  +            }
  +        }
  +        final long duration = System.currentTimeMillis() - startTime;
  +
  +        // Dispose if necessary
  +        if( pool instanceof Disposable )
  +        {
  +            ( (Disposable)pool ).dispose();
  +        }
  +
  +        return duration;
  +    }
  +}
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message