avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From blorit...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/event/src/test/org/apache/excalibur/mpool/test MultiThreadedPoolComparisonProfile.java
Date Thu, 08 Aug 2002 00:57:25 GMT
bloritsch    2002/08/07 17:57:25

  Modified:    event    default.properties
               event/src/java/org/apache/excalibur/mpool FixedSizePool.java
                        Pool.java
               event/src/test QueueTest.java
               event/src/test/org/apache/excalibur/event/test
                        ThreadedQueueTestCase.java
               event/src/test/org/apache/excalibur/mpool/test
                        MultiThreadedPoolComparisonProfile.java
  Log:
  add support for a timeout for the pool
  
  Revision  Changes    Path
  1.15      +130 -130  jakarta-avalon-excalibur/event/default.properties
  
  Index: default.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/event/default.properties,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- default.properties	8 Aug 2002 00:36:26 -0000	1.14
  +++ default.properties	8 Aug 2002 00:57:25 -0000	1.15
  @@ -1,130 +1,130 @@
  -# -------------------------------------------------------------------
  -# B U I L D  P R O P E R T I E S
  -# -------------------------------------------------------------------
  -# Specifies default property values
  -# Overridden by ../default.properties and all ant.properties
  -# Not user-editable; use ant.properties files instead
  -
  -name=excalibur-event
  -Name=Excalibur Event
  -dir-name=event
  -version=1.0a
  -package-version=0.99
  -year=2002
  -
  -# --------------------------------------------------
  -#                REQUIRED LIBRARIES
  -# --------------------------------------------------
  -# ----- Excalibur util, version 1.0 or later -----
  -excalibur-util.home=${basedir}/../util/dist
  -excalibur-util.lib=${excalibur-util.home}
  -excalibur-util.jar=${excalibur-util.lib}/excalibur-util-1.0.jar
  -
  -# ----- Excalibur threadcontext, version 1.0 or later -----
  -excalibur-threadcontext.home=${basedir}/../threadcontext/dist
  -excalibur-threadcontext.lib=${excalibur-threadcontext.home}
  -excalibur-threadcontext.jar=${excalibur-threadcontext.lib}/excalibur-threadcontext-1.0.jar
  -
  -# ----- Excalibur Collections, version 1.0 or later -----
  -excalibur-collections.home=${basedir}/../collections/dist
  -excalibur-collections.lib=${excalibur-collections.home}
  -excalibur-collections.jar=${excalibur-collections.lib}/excalibur-collections-1.0.jar
  -
  -# ----- Excalibur Concurrent, version 1.0 or later -----
  -excalibur-concurrent.home=${basedir}/../concurrent/dist
  -excalibur-concurrent.lib=${excalibur-concurrent.home}
  -excalibur-concurrent.jar=${excalibur-concurrent.lib}/excalibur-concurrent-1.0.jar
  -
  -# ----- Excalibur Util, version 1.0 or later -----
  -excalibur-util.home=${basedir}/../util/build/lib
  -excalibur-util.lib=${excalibur-util.home}
  -excalibur-util.jar=${excalibur-util.lib}/excalibur-util-1.0.jar
  -
  -# ----- Excalibur Core -----
  -excalibur-core.home=${basedir}/../all
  -excalibur-core.lib=${excalibur-core.home}/build/lib
  -excalibur-core.jar=${excalibur-core.lib}/excalibur-core.jar
  -
  -# ----- Avalon Framework, version 4.1 or later -----
  -avalon-framework.home=${basedir}/../../jakarta-avalon
  -avalon-framework.lib=${avalon-framework.home}/build/lib
  -avalon-framework.jar=${avalon-framework.lib}/avalon-framework.jar
  -
  -# --------------------------------------------------
  -#          REQUIRED LIBRARIES FOR UNIT TESTS
  -# --------------------------------------------------
  -
  -# For unit testing
  -
  -# ----- Excalibur Testcase, version 1.0 or later -----
  -excalibur-testcase.home=${basedir}/../testcase/dist
  -excalibur-testcase.lib=${excalibur-testcase.home}
  -excalibur-testcase.jar=${excalibur-testcase.lib}/excalibur-testcase-1.0.jar
  -
  -# ----- Excalibur Pool, version 1.0 or later -----
  -excalibur-pool.home=${basedir}/../pool/dist
  -excalibur-pool.lib=${excalibur-pool.home}
  -excalibur-pool.jar=${excalibur-pool.lib}/excalibur-pool-1.1.jar
  -
  -# ----- Logkit -----
  -logkit.home=${basedir}/../../jakarta-avalon-logkit
  -logkit.lib=${logkit.home}/build/lib
  -logkit.jar=${logkit.lib}/logkit.jar
  -
  -# ----- Excalibur instrument, version 1.0 or later -----
  -excalibur-instrument.home=${basedir}/../instrument/dist
  -excalibur-instrument.lib=${excalibur-instrument.home}
  -excalibur-instrument.jar=${excalibur-instrument.lib}/excalibur-instrument-0.3.jar
  -excalibur-instrument-manager.jar=${excalibur-instrument.lib}/excalibur-instrument-manager-0.3.jar
  -excalibur-instrument-manager-interfaces.jar=${excalibur-instrument.lib}/excalibur-instrument-manager-interfaces-0.3.jar
  -
  -# --------------------------------------------------
  -
  -#  Settings used to configure compile environment
  -build.debug = on
  -build.optimize = off
  -build.deprecation = off
  -build.compress = false
  -junit.failonerror = false
  -
  -#  location of intermediate products
  -build.dir = build
  -build.testsrc = ${build.dir}/testsrc
  -build.testclasses = ${build.dir}/testclasses
  -build.lib = ${build.dir}/lib
  -build.conf = ${build.dir}/conf
  -build.classes = ${build.dir}/classes
  -build.tests = ${build.dir}/tests
  -build.reports = ${build.dir}/reports
  -
  -#  Set the properties for source directories
  -src.dir = src
  -java.dir = ${src.dir}/java
  -conf.dir = ${src.dir}/conf
  -test.dir = ${src.dir}/test
  -
  -#  needed by Cocoon
  -build.context = ${build.dir}/documentation
  -build.docs = ${build.dir}/docs
  -build.xdocs = ${build.dir}/xdocs
  -context.dir = ../../jakarta-avalon/src/documentation
  -tools.dir = ../../jakarta-avalon/tools
  -tools.jar = ${java.home}/../lib/tools.jar
  -docs.dir = docs
  -xdocs.dir = ${src.dir}/xdocs
  -
  -#  Set the properties for distribution directories
  -dist.dir = dist
  -dist.javadocs = ${docs.dir}/api
  -
  -#  name of .zip/.tar.gz/.bz2 files and their top-level directory
  -dist.name = ${name}-${version}
  -
  -#  name of jar file
  -jar.name = ${name}-${version}.jar
  -
  -#  property indicating directory where all distribution archives are placed
  -dist.base = distributions
  -
  -depchecker.prefix=.
  -
  +# -------------------------------------------------------------------
  +# B U I L D  P R O P E R T I E S
  +# -------------------------------------------------------------------
  +# Specifies default property values
  +# Overridden by ../default.properties and all ant.properties
  +# Not user-editable; use ant.properties files instead
  +
  +name=excalibur-event
  +Name=Excalibur Event
  +dir-name=event
  +version=1.0a
  +package-version=0.99
  +year=2002
  +
  +# --------------------------------------------------
  +#                REQUIRED LIBRARIES
  +# --------------------------------------------------
  +# ----- Excalibur util, version 1.0 or later -----
  +excalibur-util.home=${basedir}/../util/dist
  +excalibur-util.lib=${excalibur-util.home}
  +excalibur-util.jar=${excalibur-util.lib}/excalibur-util-1.0.jar
  +
  +# ----- Excalibur threadcontext, version 1.0 or later -----
  +excalibur-threadcontext.home=${basedir}/../threadcontext/dist
  +excalibur-threadcontext.lib=${excalibur-threadcontext.home}
  +excalibur-threadcontext.jar=${excalibur-threadcontext.lib}/excalibur-threadcontext-1.0.jar
  +
  +# ----- Excalibur Collections, version 1.0 or later -----
  +excalibur-collections.home=${basedir}/../collections/dist
  +excalibur-collections.lib=${excalibur-collections.home}
  +excalibur-collections.jar=${excalibur-collections.lib}/excalibur-collections-1.0.jar
  +
  +# ----- Excalibur Concurrent, version 1.0 or later -----
  +excalibur-concurrent.home=${basedir}/../concurrent/dist
  +excalibur-concurrent.lib=${excalibur-concurrent.home}
  +excalibur-concurrent.jar=${excalibur-concurrent.lib}/excalibur-concurrent-1.0.jar
  +
  +# ----- Excalibur Util, version 1.0 or later -----
  +excalibur-util.home=${basedir}/../util/build/lib
  +excalibur-util.lib=${excalibur-util.home}
  +excalibur-util.jar=${excalibur-util.lib}/excalibur-util-1.0.jar
  +
  +# ----- Excalibur Core -----
  +excalibur-core.home=${basedir}/../all
  +excalibur-core.lib=${excalibur-core.home}/build/lib
  +excalibur-core.jar=${excalibur-core.lib}/excalibur-core.jar
  +
  +# ----- Avalon Framework, version 4.1 or later -----
  +avalon-framework.home=${basedir}/../../jakarta-avalon
  +avalon-framework.lib=${avalon-framework.home}/build/lib
  +avalon-framework.jar=${avalon-framework.lib}/avalon-framework.jar
  +
  +# --------------------------------------------------
  +#          REQUIRED LIBRARIES FOR UNIT TESTS
  +# --------------------------------------------------
  +
  +# For unit testing
  +
  +# ----- Excalibur Testcase, version 1.0 or later -----
  +excalibur-testcase.home=${basedir}/../testcase/dist
  +excalibur-testcase.lib=${excalibur-testcase.home}
  +excalibur-testcase.jar=${excalibur-testcase.lib}/excalibur-testcase-1.0.jar
  +
  +# ----- Excalibur Pool, version 1.0 or later -----
  +excalibur-pool.home=${basedir}/../pool/dist
  +excalibur-pool.lib=${excalibur-pool.home}
  +excalibur-pool.jar=${excalibur-pool.lib}/excalibur-pool-1.1.jar
  +
  +# ----- Logkit -----
  +logkit.home=${basedir}/../../jakarta-avalon-logkit
  +logkit.lib=${logkit.home}/build/lib
  +logkit.jar=${logkit.lib}/logkit.jar
  +
  +# ----- Excalibur instrument, version 1.0 or later -----
  +excalibur-instrument.home=${basedir}/../instrument/dist
  +excalibur-instrument.lib=${excalibur-instrument.home}
  +excalibur-instrument.jar=${excalibur-instrument.lib}/excalibur-instrument-0.3.jar
  +excalibur-instrument-manager.jar=${excalibur-instrument.lib}/excalibur-instrument-manager-0.3.jar
  +excalibur-instrument-manager-interfaces.jar=${excalibur-instrument.lib}/excalibur-instrument-manager-interfaces-0.3.jar
  +
  +# --------------------------------------------------
  +
  +#  Settings used to configure compile environment
  +build.debug = on
  +build.optimize = off
  +build.deprecation = off
  +build.compress = false
  +junit.failonerror = false
  +
  +#  location of intermediate products
  +build.dir = build
  +build.testsrc = ${build.dir}/testsrc
  +build.testclasses = ${build.dir}/testclasses
  +build.lib = ${build.dir}/lib
  +build.conf = ${build.dir}/conf
  +build.classes = ${build.dir}/classes
  +build.tests = ${build.dir}/tests
  +build.reports = ${build.dir}/reports
  +
  +#  Set the properties for source directories
  +src.dir = src
  +java.dir = ${src.dir}/java
  +conf.dir = ${src.dir}/conf
  +test.dir = ${src.dir}/test
  +
  +#  needed by Cocoon
  +build.context = ${build.dir}/documentation
  +build.docs = ${build.dir}/docs
  +build.xdocs = ${build.dir}/xdocs
  +context.dir = ../../jakarta-avalon/src/documentation
  +tools.dir = ../../jakarta-avalon/tools
  +tools.jar = ${java.home}/../lib/tools.jar
  +docs.dir = docs
  +xdocs.dir = ${src.dir}/xdocs
  +
  +#  Set the properties for distribution directories
  +dist.dir = dist
  +dist.javadocs = ${docs.dir}/api
  +
  +#  name of .zip/.tar.gz/.bz2 files and their top-level directory
  +dist.name = ${name}-${version}
  +
  +#  name of jar file
  +jar.name = ${name}-${version}.jar
  +
  +#  property indicating directory where all distribution archives are placed
  +dist.base = distributions
  +
  +depchecker.prefix=.
  +
  
  
  
  1.2       +27 -3     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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FixedSizePool.java	7 Aug 2002 22:44:25 -0000	1.1
  +++ FixedSizePool.java	8 Aug 2002 00:57:25 -0000	1.2
  @@ -49,6 +49,7 @@
   */
   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;
  @@ -67,10 +68,18 @@
       private boolean m_disposed = false;
       private final Buffer m_buffer;
       private final ObjectFactory m_factory;
  +    private final long m_timeout;
   
       public FixedSizePool( ObjectFactory factory, int size )
           throws Exception
       {
  +        this( factory, size, 1000L );
  +    }
  +
  +    public FixedSizePool( ObjectFactory factory, int size, long timeout )
  +        throws Exception
  +    {
  +        m_timeout = (timeout < 1) ? 1 : timeout;
           m_buffer = new FixedSizeBuffer( size );
           m_factory = factory;
   
  @@ -89,9 +98,23 @@
   
           Object object = null;
   
  -        synchronized( m_buffer )
  +        long end = System.currentTimeMillis() + m_timeout;
  +
  +        while ( null == object && System.currentTimeMillis() < end)
           {
  -            object = m_buffer.remove();
  +            synchronized( m_buffer )
  +            {
  +                if ( m_buffer.isEmpty() )
  +                {
  +                    try
  +                    {
  +                        m_buffer.wait( m_timeout );
  +                    }
  +                    catch (Exception e) {}
  +                }
  +
  +                object = m_buffer.remove();
  +            }
           }
   
           return object;
  @@ -115,6 +138,7 @@
               synchronized( m_buffer )
               {
                   m_buffer.add( object );
  +                m_buffer.notify();
               }
           }
       }
  
  
  
  1.3       +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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Pool.java	8 Aug 2002 00:36:26 -0000	1.2
  +++ Pool.java	8 Aug 2002 00:57:25 -0000	1.3
  @@ -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.5       +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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- QueueTest.java	7 Aug 2002 23:08:26 -0000	1.4
  +++ QueueTest.java	8 Aug 2002 00:57:25 -0000	1.5
  @@ -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.6       +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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ThreadedQueueTestCase.java	7 Aug 2002 23:08:26 -0000	1.5
  +++ ThreadedQueueTestCase.java	8 Aug 2002 00:57:25 -0000	1.6
  @@ -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.3       +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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MultiThreadedPoolComparisonProfile.java	8 Aug 2002 00:36:26 -0000	1.2
  +++ MultiThreadedPoolComparisonProfile.java	8 Aug 2002 00:57:25 -0000	1.3
  @@ -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;
  +                }
  +            }
  +        }
  +    }
  +}
  
  
  

--
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