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/src/scratchpad/org/apache/avalon/excalibur/system/handler ComponentFactory.java FactoryComponentHandler.java PerThreadComponentHandler.java PoolableComponentHandler.java ThreadSafeComponentHandler.java
Date Tue, 12 Feb 2002 21:30:44 GMT
bloritsch    02/02/12 13:30:44

  Modified:    src/scratchpad/org/apache/avalon/excalibur/pool/test
                        MultiThreadedPoolComparisonProfile.java
                        PoolComparisonProfileAbstract.java
                        SingleThreadedPoolComparisonProfile.java
               src/scratchpad/org/apache/avalon/excalibur/system
                        AbstractContainer.java ContainerManager.java
               src/scratchpad/org/apache/avalon/excalibur/system/handler
                        ComponentFactory.java FactoryComponentHandler.java
                        PerThreadComponentHandler.java
                        PoolableComponentHandler.java
                        ThreadSafeComponentHandler.java
  Added:       src/scratchpad/org/apache/avalon/excalibur/mpool
                        DefaultPoolManager.java FixedSizePool.java
                        ManagablePool.java PoolManager.java
                        VariableSizePool.java
               src/scratchpad/org/apache/avalon/excalibur/mpool/test
                        ClassInstanceObjectFactory.java
                        MultiThreadedPoolComparisonProfile.java
                        PoolComparisonProfileAbstract.java
                        PoolableTestObject.java
                        ResourceLimitingPoolMultithreadMaxStrictBlockTestCase.java
                        ResourceLimitingPoolMultithreadMaxStrictTestCase.java
                        ResourceLimitingPoolMultithreadMaxTestCase.java
                        ResourceLimitingPoolMultithreadTestCase.java
                        ResourceLimitingPoolTestCase.java
                        SingleThreadedPoolComparisonProfile.java
  Removed:     src/scratchpad/org/apache/avalon/excalibur/pool
                        DefaultPoolManager.java FixedSizePool.java
                        ManagablePool.java PoolManager.java
                        VariableSizePool.java
  Log:
  Separate Managed Pool stuff into the mpool package, and migrate tests
  
  Revision  Changes    Path
  1.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/mpool/DefaultPoolManager.java
  
  Index: DefaultPoolManager.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.excalibur.mpool;
  
  import org.apache.avalon.excalibur.command.RepeatedCommand;
  import org.apache.avalon.excalibur.event.Queue;
  
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Map;
  import java.util.Random;
  
  /**
   * 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: 1.1 $ $Date: 2002/02/12 21:30:42 $
   * @since 4.1
   */
  public class DefaultPoolManager implements PoolManager
  {
      private final long          m_managerKey;
      private final Random        m_keyGenerator;
      private final HashMap       m_keyMap = new HashMap();
      private final HashMap       m_factoryMap = new HashMap();
  
      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 final static class PoolManagerCommand implements RepeatedCommand
      {
          private final Map m_map;
          private final int m_min = 4;
          private final int m_max = 256;
          private final int m_grow = 4;
  
          protected PoolManagerCommand( Map 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.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/mpool/FixedSizePool.java
  
  Index: FixedSizePool.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.excalibur.mpool;
  
  import org.apache.avalon.framework.activity.Disposable;
  import org.apache.avalon.excalibur.collections.Buffer;
  import org.apache.avalon.excalibur.collections.FixedSizeBuffer;
  
  /**
   * 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: 1.1 $ $Date: 2002/02/12 21:30:42 $
   * @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 );
              }
          }
      }
  
      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.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/mpool/ManagablePool.java
  
  Index: ManagablePool.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.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: 1.1 $ $Date: 2002/02/12 21:30:42 $
   * @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.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/mpool/PoolManager.java
  
  Index: PoolManager.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.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: 1.1 $ $Date: 2002/02/12 21:30:42 $
   * @since 4.1
   */
  public interface PoolManager
  {
      /**
       * Return a managed pool that has a controller.
       */
      Pool getManagedPool( ObjectFactory factory, int initialEntries )
          throws Exception;
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/mpool/VariableSizePool.java
  
  Index: VariableSizePool.java
  ===================================================================
  
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.excalibur.mpool;
  
  import org.apache.avalon.framework.activity.Disposable;
  import org.apache.avalon.excalibur.collections.Buffer;
  import org.apache.avalon.excalibur.collections.VariableSizeBuffer;
  
  /**
   * 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: 1.1 $ $Date: 2002/02/12 21:30:42 $
   * @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;
  
          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;
  
          synchronized ( m_buffer )
          {
              object = m_buffer.remove();
          }
  
          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.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/mpool/test/ClassInstanceObjectFactory.java
  
  Index: ClassInstanceObjectFactory.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.excalibur.mpool.test;
  
  import java.util.HashMap;
  
  import org.apache.avalon.excalibur.mpool.ObjectFactory;
  import org.apache.avalon.framework.activity.Disposable;
  import org.apache.avalon.framework.logger.Logger;
  
  /**
   * @author <a href="mailto:leif@silveregg.co.jp">Leif Mortenson</a>
   * @version CVS $Revision: 1.1 $ $Date: 2002/02/12 21:30:42 $
   * @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.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/mpool/test/MultiThreadedPoolComparisonProfile.java
  
  Index: MultiThreadedPoolComparisonProfile.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.excalibur.mpool.test;
  
  import junit.framework.TestCase;
  
  import org.apache.avalon.excalibur.mpool.FixedSizePool;
  import org.apache.avalon.excalibur.pool.HardResourceLimitingPool;
  import org.apache.avalon.excalibur.pool.ObjectFactory;
  import org.apache.avalon.excalibur.mpool.Pool;
  import org.apache.avalon.excalibur.pool.Poolable;
  import org.apache.avalon.excalibur.pool.ResourceLimitingPool;
  import org.apache.avalon.excalibur.pool.SingleThreadedPool;
  import org.apache.avalon.excalibur.pool.SoftResourceLimitingPool;
  import org.apache.avalon.excalibur.mpool.VariableSizePool;
  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.LogEnabled;
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.avalon.framework.logger.LogKitLogger;
  
  /**
   * This is used to profile and compare various pool implementations
   *  given a single access thread.
   *
   * @author <a href="mailto:leif@silveregg.co.jp">Leif Mortenson</a>
   * @version $Id: MultiThreadedPoolComparisonProfile.java,v 1.1 2002/02/12 21:30:42 bloritsch Exp $
   */
  public class MultiThreadedPoolComparisonProfile
      extends PoolComparisonProfileAbstract
  {
      protected static final int THREADS = 10;
  
      private Object    m_semaphore = new Object();
      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 )
          {
              fail( "gets must be evenly divisible by THREADS");
          }
  
          m_getCount = 0;
          m_throwable = null;
  
          // Create the runnable
          Runnable runnable = new Runnable()
          {
              public void run()
              {
                  // Perform this threads part of the test.
                  final int cnt = gets / THREADS;
                  final Object[] poolTmp = new Object[cnt];
                  final int loops = TEST_SIZE / gets;
                  for( int i = 0; i < loops; i++ )
                  {
                      // Get some Poolables
                      for ( int j = 0; j < cnt; j++ )
                      {
                          try
                          {
                              poolTmp[j] = pool.acquire();
                              synchronized(m_semaphore)
                              {
                                  m_getCount++;
                              }
                          }
                          catch ( Throwable t )
                          {
                              m_poolLogger.error( "Unexpected error", t );
  
                              synchronized(m_semaphore)
                              {
                                  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++ )
                      {
                          pool.release( poolTmp[j] );
                          synchronized(m_semaphore)
                          {
                              m_getCount--;
                          }
                          poolTmp[j] = null;
                      }
                  }
              }
          };
  
          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 )
          {
              fail( "gets must be evenly divisible by THREADS");
          }
  
          m_getCount = 0;
          m_throwable = null;
  
          // Create the runnable
          Runnable runnable = new Runnable()
          {
              public void run()
              {
                  // Perform this threads part of the test.
                  final int cnt = gets / THREADS;
                  final Poolable[] poolTmp = new Poolable[cnt];
                  final int loops = TEST_SIZE / gets;
                  for( int i = 0; i < loops; i++ )
                  {
                      // Get some Poolables
                      for ( int j = 0; j < cnt; j++ )
                      {
                          try
                          {
                              poolTmp[j] = pool.get();
                              synchronized(m_semaphore)
                              {
                                  m_getCount++;
                              }
                          }
                          catch ( Throwable t )
                          {
                              m_poolLogger.error( "Unexpected error", t );
  
                              synchronized(m_semaphore)
                              {
                                  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++ )
                      {
                          pool.put( poolTmp[j] );
                          synchronized(m_semaphore)
                          {
                              m_getCount--;
                          }
                          poolTmp[j] = null;
                      }
                  }
              }
          };
  
          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;
      }
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/mpool/test/PoolComparisonProfileAbstract.java
  
  Index: PoolComparisonProfileAbstract.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.excalibur.mpool.test;
  
  import junit.framework.TestCase;
  
  import org.apache.avalon.excalibur.mpool.FixedSizePool;
  import org.apache.avalon.excalibur.pool.HardResourceLimitingPool;
  import org.apache.avalon.excalibur.mpool.ObjectFactory;
  import org.apache.avalon.excalibur.mpool.Pool;
  import org.apache.avalon.excalibur.pool.ResourceLimitingPool;
  import org.apache.avalon.excalibur.pool.SingleThreadedPool;
  import org.apache.avalon.excalibur.pool.SoftResourceLimitingPool;
  import org.apache.avalon.excalibur.mpool.VariableSizePool;
  
  import org.apache.avalon.framework.activity.Disposable;
  import org.apache.avalon.framework.logger.LogEnabled;
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.avalon.framework.logger.LogKitLogger;
  
  /**
   * Used as a basis for the PoolComparisonProfile Tests
   *
   * @author <a href="mailto:leif@silveregg.co.jp">Leif Mortenson</a>
   * @version $Id: PoolComparisonProfileAbstract.java,v 1.1 2002/02/12 21:30:42 bloritsch Exp $
   */
  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 );
      }
  
      /*---------------------------------------------------------------
       * SoftResourceLimitingPool vs ResourceLimitingPool TestCases
       *-------------------------------------------------------------*/
      /**
       * Compare the SoftResourceLimitingPool and ResourceLimitingPool when the
       *  ResourceLimitingPool is configured to act like a SoftResourceLimitingPool.
       * <p>
       * Test will use pools with a max size of 10, while getting up to 10 at a time,
       *  Poolables are small objects.
       */
      public void testCompare_SoftResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets10_SmallPoolables()
          throws Exception
      {
          String name = "SoftResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets10_SmallPoolables";
  
          Class         poolableClass = SmallPoolable.class;
          ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
          int           min          = 0;
          int           max          = 10;
          boolean       maxStrict    = false;
          boolean       blocking     = false;
          long          blockTimeout = 0;
          long          trimInterval = 0;
  
          SoftResourceLimitingPool poolA = new SoftResourceLimitingPool( factory, min, max );
          poolA.enableLogging( m_poolLogger );
          poolA.initialize();
  
          ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
          poolB.enableLogging( m_poolLogger );
  
          generalTest( name, poolA, poolB, 10, factory );
      }
  
      /**
       * Compare the SoftResourceLimitingPool and ResourceLimitingPool when the
       *  ResourceLimitingPool is configured to act like a SoftResourceLimitingPool.
       * <p>
       * Test will use pools with a max size of 10, while getting up to 20 at a time,
       *  Poolables are small objects.
       */
      public void testCompare_SoftResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets20_SmallPoolables()
          throws Exception
      {
          String name = "SoftResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets20_SmallPoolables";
  
          Class         poolableClass = SmallPoolable.class;
          ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
          int           min          = 0;
          int           max          = 10;
          boolean       maxStrict    = false;
          boolean       blocking     = false;
          long          blockTimeout = 0;
          long          trimInterval = 0;
  
          SoftResourceLimitingPool poolA = new SoftResourceLimitingPool( factory, min, max );
          poolA.enableLogging( m_poolLogger );
          poolA.initialize();
  
          ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
          poolB.enableLogging( m_poolLogger );
  
          generalTest( name, poolA, poolB, 20, factory );
      }
  
      /**
       * Compare the SoftResourceLimitingPool and ResourceLimitingPool when the
       *  ResourceLimitingPool is configured to act like a SoftResourceLimitingPool.
       * <p>
       * Test will use pools with a max size of 10, while getting up to 10 at a time,
       *  Poolables are medium objects.
       */
      public void testCompare_SoftResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets10_MediumPoolables()
          throws Exception
      {
          String name = "SoftResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets10_MediumPoolables";
  
          Class         poolableClass = MediumPoolable.class;
          ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
          int           min          = 0;
          int           max          = 10;
          boolean       maxStrict    = false;
          boolean       blocking     = false;
          long          blockTimeout = 0;
          long          trimInterval = 0;
  
          SoftResourceLimitingPool poolA = new SoftResourceLimitingPool( factory, min, max );
          poolA.enableLogging( m_poolLogger );
          poolA.initialize();
  
          ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
          poolB.enableLogging( m_poolLogger );
  
          generalTest( name, poolA, poolB, 10, factory );
      }
  
      /**
       * Compare the SoftResourceLimitingPool and ResourceLimitingPool when the
       *  ResourceLimitingPool is configured to act like a SoftResourceLimitingPool.
       * <p>
       * Test will use pools with a max size of 10, while getting up to 20 at a time,
       *  Poolables are medium objects.
       */
      public void testCompare_SoftResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets20_MediumPoolables()
          throws Exception
      {
          String name = "SoftResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets20_MediumPoolables";
  
          Class         poolableClass = MediumPoolable.class;
          ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
          int           min          = 0;
          int           max          = 10;
          boolean       maxStrict    = false;
          boolean       blocking     = false;
          long          blockTimeout = 0;
          long          trimInterval = 0;
  
          SoftResourceLimitingPool poolA = new SoftResourceLimitingPool( factory, min, max );
          poolA.enableLogging( m_poolLogger );
          poolA.initialize();
  
          ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
          poolB.enableLogging( m_poolLogger );
  
          generalTest( name, poolA, poolB, 20, factory );
      }
  
      /**
       * Compare the SoftResourceLimitingPool and ResourceLimitingPool when the
       *  ResourceLimitingPool is configured to act like a SoftResourceLimitingPool.
       * <p>
       * Test will use pools with a max size of 10, while getting up to 10 at a time,
       *  Poolables are large objects.
       */
      public void testCompare_SoftResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets10_LargePoolables()
          throws Exception
      {
          String name = "SoftResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets10_LargePoolables";
  
          Class         poolableClass = LargePoolable.class;
          ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
          int           min          = 0;
          int           max          = 10;
          boolean       maxStrict    = false;
          boolean       blocking     = false;
          long          blockTimeout = 0;
          long          trimInterval = 0;
  
          SoftResourceLimitingPool poolA = new SoftResourceLimitingPool( factory, min, max );
          poolA.enableLogging( m_poolLogger );
          poolA.initialize();
  
          ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
          poolB.enableLogging( m_poolLogger );
  
          generalTest( name, poolA, poolB, 10, factory );
      }
  
      /**
       * Compare the SoftResourceLimitingPool and ResourceLimitingPool when the
       *  ResourceLimitingPool is configured to act like a SoftResourceLimitingPool.
       * <p>
       * Test will use pools with a max size of 10, while getting up to 20 at a time,
       *  Poolables are large objects.
       */
      public void testCompare_SoftResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets20_LargePoolables()
          throws Exception
      {
          String name = "SoftResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets20_LargePoolables";
  
          Class         poolableClass = LargePoolable.class;
          ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
          int           min          = 0;
          int           max          = 10;
          boolean       maxStrict    = false;
          boolean       blocking     = false;
          long          blockTimeout = 0;
          long          trimInterval = 0;
  
          SoftResourceLimitingPool poolA = new SoftResourceLimitingPool( factory, min, max );
          poolA.enableLogging( m_poolLogger );
          poolA.initialize();
  
          ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
          poolB.enableLogging( m_poolLogger );
  
          generalTest( name, poolA, poolB, 20, factory );
      }
  
      /*---------------------------------------------------------------
       * HardResourceLimitingPool vs ResourceLimitingPool TestCases
       *-------------------------------------------------------------*/
      /**
       * Compare the HardResourceLimitingPool and ResourceLimitingPool when the
       *  ResourceLimitingPool is configured to act like a HardResourceLimitingPool.
       * <p>
       * Test will use pools with a max size of 10, while getting up to 10 at a time,
       *  Poolables are small objects.
       */
      public void testCompare_HardResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets10_SmallPoolables()
          throws Exception
      {
          String name = "HardResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets10_SmallPoolables";
  
          Class         poolableClass = SmallPoolable.class;
          ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
          int           min          = 0;
          int           max          = 10;
          boolean       maxStrict    = true;
          boolean       blocking     = false;
          long          blockTimeout = 0;
          long          trimInterval = 0;
  
          HardResourceLimitingPool poolA = new HardResourceLimitingPool( factory, min, max );
          poolA.enableLogging( m_poolLogger );
          poolA.initialize();
  
          ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
          poolB.enableLogging( m_poolLogger );
  
          generalTest( name, poolA, poolB, 10, factory );
      }
  
      /**
       * Compare the HardResourceLimitingPool and ResourceLimitingPool when the
       *  ResourceLimitingPool is configured to act like a HardResourceLimitingPool.
       * <p>
       * Test will use pools with a max size of 10, while getting up to 10 at a time,
       *  Poolables are medium objects.
       */
      public void testCompare_HardResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets10_MediumPoolables()
          throws Exception
      {
          String name = "HardResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets10_MediumPoolables";
  
          Class         poolableClass = MediumPoolable.class;
          ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
          int           min          = 0;
          int           max          = 10;
          boolean       maxStrict    = true;
          boolean       blocking     = false;
          long          blockTimeout = 0;
          long          trimInterval = 0;
  
          HardResourceLimitingPool poolA = new HardResourceLimitingPool( factory, min, max );
          poolA.enableLogging( m_poolLogger );
          poolA.initialize();
  
          ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
          poolB.enableLogging( m_poolLogger );
  
          generalTest( name, poolA, poolB, 10, factory );
      }
  
      /**
       * Compare the HardResourceLimitingPool and ResourceLimitingPool when the
       *  ResourceLimitingPool is configured to act like a HardResourceLimitingPool.
       * <p>
       * Test will use pools with a max size of 10, while getting up to 10 at a time,
       *  Poolables are large objects.
       */
      public void testCompare_HardResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets10_LargePoolables()
          throws Exception
      {
          String name = "HardResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets10_LargePoolables";
  
          Class         poolableClass = LargePoolable.class;
          ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
          int           min          = 0;
          int           max          = 10;
          boolean       maxStrict    = true;
          boolean       blocking     = false;
          long          blockTimeout = 0;
          long          trimInterval = 0;
  
          HardResourceLimitingPool poolA = new HardResourceLimitingPool( factory, min, max );
          poolA.enableLogging( m_poolLogger );
          poolA.initialize();
  
          ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
          poolB.enableLogging( m_poolLogger );
  
          generalTest( name, poolA, poolB, 10, factory );
      }
  
      /*---------------------------------------------------------------
       * 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 10, while getting up to 10 at a time,
       *  Poolables are small objects.
       */
      public void testCompare_FixedSizePool_And_ResourceLimitingPool_Max10_Gets10_SmallPoolables()
          throws Exception
      {
          String name = "FixedSizePool_And_ResourceLimitingPool_Max10_Gets10_SmallPoolables";
  
          Class         poolableClass = SmallPoolable.class;
          ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
          int           min          = 0;
          int           max          = 10;
          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, 10, 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 10, while getting up to 10 at a time,
       *  Poolables are medium objects.
       */
      public void testCompare_FixedSizePool_And_ResourceLimitingPool_Max10_Gets10_MediumPoolables()
          throws Exception
      {
          String name = "FixedSizePool_And_ResourceLimitingPool_Max10_Gets10_MediumPoolables";
  
          Class         poolableClass = MediumPoolable.class;
          ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
          int           min          = 0;
          int           max          = 10;
          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, 10, 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 10, while getting up to 10 at a time,
       *  Poolables are large objects.
       */
      public void testCompare_FixedSizePool_And_ResourceLimitingPool_Max10_Gets10_LargePoolables()
          throws Exception
      {
          String name = "FixedSizePool_And_ResourceLimitingPool_Max10_Gets10_LargePoolables";
  
          Class         poolableClass = LargePoolable.class;
          ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
          int           min          = 0;
          int           max          = 10;
          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, 10, 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[100][50];
      }
  
      /**
       * 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();
          }
      }
  
      /*---------------------------------------------------------------
       * 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 + "." );
          }
      }
  
      /**
       * 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 + "." );
          }
      }
  
      /**
       * The guts of the various test cases.  Will dispose the pools
       */
      protected void generalTest(String name, org.apache.avalon.excalibur.pool.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 + "." );
          }
      }
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/mpool/test/PoolableTestObject.java
  
  Index: PoolableTestObject.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.excalibur.mpool.test;
  
  import org.apache.avalon.excalibur.pool.Poolable;
  
  /**
   * @author <a href="mailto:leif@silveregg.co.jp">Leif Mortenson</a>
   * @version CVS $Revision: 1.1 $ $Date: 2002/02/12 21:30:42 $
   * @since 4.1
   */
  public class PoolableTestObject implements Poolable
  {
  }
  
  
  
  
  1.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/mpool/test/ResourceLimitingPoolMultithreadMaxStrictBlockTestCase.java
  
  Index: ResourceLimitingPoolMultithreadMaxStrictBlockTestCase.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.excalibur.mpool.test;
  
  import com.clarkware.junitperf.ConstantTimer;
  import com.clarkware.junitperf.LoadTest;
  import com.clarkware.junitperf.TimedTest;
  import com.clarkware.junitperf.Timer;
  
  import junit.extensions.TestSetup;
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  import org.apache.avalon.excalibur.logger.BufferedLogger;
  import org.apache.avalon.excalibur.pool.Poolable;
  import org.apache.avalon.excalibur.pool.ResourceLimitingPool;
  
  /**
   * @author <a href="mailto:leif@silveregg.co.jp">Leif Mortenson</a>
   * @version CVS $Revision: 1.1 $ $Date: 2002/02/12 21:30:42 $
   * @since 4.1
   */
  public final class ResourceLimitingPoolMultithreadMaxStrictBlockTestCase extends TestCase
  {
      private static BufferedLogger m_logger;
      private static ClassInstanceObjectFactory m_factory;
      private static ResourceLimitingPool m_pool;
  
      /*---------------------------------------------------------------
       * Constructors
       *-------------------------------------------------------------*/
      public ResourceLimitingPoolMultithreadMaxStrictBlockTestCase()
      {
          this( "ResourceLimitingPool Multithreaded Max Size Strict Blocking Test Case" );
      }
  
      public ResourceLimitingPoolMultithreadMaxStrictBlockTestCase( final String name )
      {
          super( name );
      }
  
      /*---------------------------------------------------------------
       * Suite
       *-------------------------------------------------------------*/
      public static Test suite()
      {
          TestSuite suite = new TestSuite();
  
          Timer timer = new ConstantTimer( 100 );
          int maxUsers = 10;
          int iterations = 10;
          long maxElapsedTime = 20000;
  
          Test testCase = new ResourceLimitingPoolMultithreadMaxStrictBlockTestCase( "testGetPut" );
          Test loadTest = new LoadTest( testCase, maxUsers, iterations, timer );
          Test timedTest = new TimedTest( loadTest, maxElapsedTime );
          suite.addTest( timedTest );
  
          TestSetup wrapper= new TestSetup(suite)
          {
              public void setUp()
              {
                  oneTimeSetUp();
              }
              public void tearDown() throws Exception
              {
                  oneTimeTearDown();
              }
          };
  
          return wrapper;
      }
  
      public static void oneTimeSetUp()
      {
          m_logger = new BufferedLogger();
          m_factory = new ClassInstanceObjectFactory( PoolableTestObject.class, m_logger );
          m_pool = new ResourceLimitingPool( m_factory, 3, true, true, 0, 0 );
  
          m_pool.enableLogging( m_logger );
      }
  
      public static void oneTimeTearDown() throws Exception
      {
          // The timing of this test makes it so the pool should grow to 4 elements
          assertEquals( "1) Pool Ready Size", 3, m_pool.getReadySize() );
          assertEquals( "1) Pool Size", 3, m_pool.getSize() );
  
          // Make sure that each of the objects are uniqe by checking them all back out.
          Poolable p1 = m_pool.get();
          Poolable p2 = m_pool.get();
          Poolable p3 = m_pool.get();
  
          assertEquals( "2) Pool Ready Size", 0, m_pool.getReadySize() );
          assertEquals( "2) Pool Size", 3, m_pool.getSize() );
  
          assertTrue( "p1 != p2", p1 != p2 );
          assertTrue( "p1 != p3", p1 != p3 );
          assertTrue( "p2 != p3", p2 != p3 );
  
          m_pool.put( p1 );
          m_pool.put( p2 );
          m_pool.put( p3 );
  
          assertEquals( "3) Pool Ready Size", 3, m_pool.getReadySize() );
          assertEquals( "3) Pool Size", 3, m_pool.getSize() );
  
          m_pool.dispose();
  
          assertEquals( "4) Pool Ready Size", 0, m_pool.getReadySize() );
          assertEquals( "4) Pool Size", 0, m_pool.getSize() );
      }
  
      /*---------------------------------------------------------------
       * TestCases
       *-------------------------------------------------------------*/
      public void testGetPut() throws Exception
      {
          Poolable p = m_pool.get();
  
          // We can't check the exact pool size, but make sure that it never gets over 3
          assertTrue( "Pool size <= 3", m_pool.getSize() <= 3 );
  
          try
          {
              Thread.sleep( 33 );
          }
          catch (InterruptedException e) {}
          m_pool.put( p );
      }
  }
  
  
  
  
  1.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/mpool/test/ResourceLimitingPoolMultithreadMaxStrictTestCase.java
  
  Index: ResourceLimitingPoolMultithreadMaxStrictTestCase.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.excalibur.mpool.test;
  
  import com.clarkware.junitperf.ConstantTimer;
  import com.clarkware.junitperf.LoadTest;
  import com.clarkware.junitperf.TimedTest;
  import com.clarkware.junitperf.Timer;
  
  import junit.extensions.TestSetup;
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  import org.apache.avalon.excalibur.logger.BufferedLogger;
  import org.apache.avalon.excalibur.pool.Poolable;
  import org.apache.avalon.excalibur.pool.ResourceLimitingPool;
  
  /**
   * @author <a href="mailto:leif@silveregg.co.jp">Leif Mortenson</a>
   * @version CVS $Revision: 1.1 $ $Date: 2002/02/12 21:30:42 $
   * @since 4.1
   */
  public final class ResourceLimitingPoolMultithreadMaxStrictTestCase extends TestCase
  {
      private static BufferedLogger m_logger;
      private static ClassInstanceObjectFactory m_factory;
      private static ResourceLimitingPool m_pool;
  
      /*---------------------------------------------------------------
       * Constructors
       *-------------------------------------------------------------*/
      public ResourceLimitingPoolMultithreadMaxStrictTestCase()
      {
          this( "ResourceLimitingPool Multithreaded Max Size Strict Test Case" );
      }
  
      public ResourceLimitingPoolMultithreadMaxStrictTestCase( final String name )
      {
          super( name );
      }
  
      /*---------------------------------------------------------------
       * Suite
       *-------------------------------------------------------------*/
      public static Test suite()
      {
          TestSuite suite = new TestSuite();
  
          Timer timer = new ConstantTimer( 100 );
          int maxUsers = 50;
          int iterations = 10;
          long maxElapsedTime = 20000;
  
          Test testCase = new ResourceLimitingPoolMultithreadMaxStrictTestCase( "testGetPut" );
          Test loadTest = new LoadTest( testCase, maxUsers, iterations, timer );
          Test timedTest = new TimedTest( loadTest, maxElapsedTime );
          suite.addTest( timedTest );
  
          TestSetup wrapper= new TestSetup( suite )
          {
              public void setUp()
              {
                  oneTimeSetUp();
              }
              public void tearDown() throws Exception
              {
                  oneTimeTearDown();
              }
          };
  
          return wrapper;
      }
  
      public static void oneTimeSetUp()
      {
          m_logger = new BufferedLogger();
          m_factory = new ClassInstanceObjectFactory( PoolableTestObject.class, m_logger );
          m_pool = new ResourceLimitingPool( m_factory, 3, true, false, 0, 0 );
  
          m_pool.enableLogging( m_logger );
      }
  
      public static void oneTimeTearDown() throws Exception
      {
          // The timing of this test makes it so the pool should grow to 4 elements
          assertEquals( "1) Pool Ready Size", 3, m_pool.getReadySize() );
          assertEquals( "1) Pool Size", 3, m_pool.getSize() );
  
          // Make sure that each of the objects are uniqe by checking them all back out.
          Poolable p1 = m_pool.get();
          Poolable p2 = m_pool.get();
          Poolable p3 = m_pool.get();
  
          assertEquals( "2) Pool Ready Size", 0, m_pool.getReadySize() );
          assertEquals( "2) Pool Size", 3, m_pool.getSize() );
  
          assertTrue( "p1 != p2", p1 != p2 );
          assertTrue( "p1 != p3", p1 != p3 );
          assertTrue( "p2 != p3", p2 != p3 );
  
          m_pool.put( p1 );
          m_pool.put( p2 );
          m_pool.put( p3 );
  
          assertEquals( "3) Pool Ready Size", 3, m_pool.getReadySize() );
          assertEquals( "3) Pool Size", 3, m_pool.getSize() );
  
          m_pool.dispose();
  
          assertEquals( "4) Pool Ready Size", 0, m_pool.getReadySize() );
          assertEquals( "4) Pool Size", 0, m_pool.getSize() );
      }
  
      /*---------------------------------------------------------------
       * TestCases
       *-------------------------------------------------------------*/
      public void testGetPut() throws Exception
      {
          Poolable p;
          try
          {
              p = m_pool.get();
          }
          catch ( Exception e )
          {
              // We will sometimes fail to get an object
              assertEquals( "Exception calling get()",
                  "Could not create enough Components to service your request.",
                  e.getMessage() );
              return;
          }
  
          // We can't check the exact pool size, but make sure that it never gets over 3
          assertTrue( "Pool size <= 3", m_pool.getSize() <= 3 );
  
          try
          {
              Thread.sleep( 33 );
          } catch ( InterruptedException e ) {}
          m_pool.put( p );
      }
  }
  
  
  
  
  1.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/mpool/test/ResourceLimitingPoolMultithreadMaxTestCase.java
  
  Index: ResourceLimitingPoolMultithreadMaxTestCase.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.excalibur.mpool.test;
  
  import com.clarkware.junitperf.ConstantTimer;
  import com.clarkware.junitperf.LoadTest;
  import com.clarkware.junitperf.TimedTest;
  import com.clarkware.junitperf.Timer;
  
  import junit.extensions.TestSetup;
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  import org.apache.avalon.excalibur.logger.BufferedLogger;
  import org.apache.avalon.excalibur.pool.Poolable;
  import org.apache.avalon.excalibur.pool.ResourceLimitingPool;
  
  /**
   * @author <a href="mailto:leif@silveregg.co.jp">Leif Mortenson</a>
   * @version CVS $Revision: 1.1 $ $Date: 2002/02/12 21:30:42 $
   * @since 4.1
   */
  public final class ResourceLimitingPoolMultithreadMaxTestCase
      extends TestCase
  {
      private static BufferedLogger m_logger;
      private static ClassInstanceObjectFactory m_factory;
      private static ResourceLimitingPool m_pool;
  
      /*---------------------------------------------------------------
       * Constructors
       *-------------------------------------------------------------*/
      public ResourceLimitingPoolMultithreadMaxTestCase()
      {
          this( "ResourceLimitingPool Multithreaded Max Size Test Case" );
      }
  
      public ResourceLimitingPoolMultithreadMaxTestCase( final String name )
      {
          super( name );
      }
  
      /*---------------------------------------------------------------
       * Suite
       *-------------------------------------------------------------*/
      public static Test suite()
      {
          TestSuite suite = new TestSuite();
  
          Timer timer = new ConstantTimer( 100 );
          int maxUsers = 50;
          int iterations = 10;
          long maxElapsedTime = 20000;
  
          Test testCase = new ResourceLimitingPoolMultithreadMaxTestCase( "testGetPut" );
          Test loadTest = new LoadTest( testCase, maxUsers, iterations, timer );
          Test timedTest = new TimedTest( loadTest, maxElapsedTime );
          suite.addTest( timedTest );
  
          TestSetup wrapper= new TestSetup( suite )
          {
              public void setUp()
              {
                  oneTimeSetUp();
              }
              public void tearDown() throws Exception
              {
                  oneTimeTearDown();
              }
          };
  
          return wrapper;
      }
  
      public static void oneTimeSetUp()
      {
          m_logger = new BufferedLogger();
          m_factory = new ClassInstanceObjectFactory( PoolableTestObject.class, m_logger );
          m_pool = new ResourceLimitingPool( m_factory, 3, false, false, 0, 0 );
  
          m_pool.enableLogging( m_logger );
      }
  
      public static void oneTimeTearDown() throws Exception
      {
          // The timing of this test makes it so the pool should grow to 4 elements
          assertEquals( "1) Pool Ready Size", 3, m_pool.getReadySize() );
          assertEquals( "1) Pool Size", 3, m_pool.getSize() );
  
          // Make sure that each of the objects are uniqe by checking them all back out.
          Poolable p1 = m_pool.get();
          Poolable p2 = m_pool.get();
          Poolable p3 = m_pool.get();
  
          assertEquals( "2) Pool Ready Size", 0, m_pool.getReadySize() );
          assertEquals( "2) Pool Size", 3, m_pool.getSize() );
  
          assertTrue( "p1 != p2", p1 != p2 );
          assertTrue( "p1 != p3", p1 != p3 );
          assertTrue( "p2 != p3", p2 != p3 );
  
          m_pool.put( p1 );
          m_pool.put( p2 );
          m_pool.put( p3 );
  
          assertEquals( "3) Pool Ready Size", 3, m_pool.getReadySize() );
          assertEquals( "3) Pool Size", 3, m_pool.getSize() );
  
          m_pool.dispose();
  
          assertEquals( "4) Pool Ready Size", 0, m_pool.getReadySize() );
          assertEquals( "4) Pool Size", 0, m_pool.getSize() );
      }
  
      /*---------------------------------------------------------------
       * TestCases
       *-------------------------------------------------------------*/
      public void testGetPut() throws Exception
      {
          Poolable p = m_pool.get();
  
          try
          {
              Thread.sleep(33);
          } catch ( InterruptedException e ) {}
          m_pool.put( p );
      }
  }
  
  
  
  
  1.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/mpool/test/ResourceLimitingPoolMultithreadTestCase.java
  
  Index: ResourceLimitingPoolMultithreadTestCase.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.excalibur.mpool.test;
  
  import com.clarkware.junitperf.ConstantTimer;
  import com.clarkware.junitperf.LoadTest;
  import com.clarkware.junitperf.TimedTest;
  import com.clarkware.junitperf.Timer;
  
  import junit.extensions.TestSetup;
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  import org.apache.avalon.excalibur.logger.BufferedLogger;
  import org.apache.avalon.excalibur.pool.Poolable;
  import org.apache.avalon.excalibur.pool.ResourceLimitingPool;
  
  /**
   * @author <a href="mailto:leif@silveregg.co.jp">Leif Mortenson</a>
   * @version CVS $Revision: 1.1 $ $Date: 2002/02/12 21:30:42 $
   * @since 4.1
   */
  public final class ResourceLimitingPoolMultithreadTestCase
      extends TestCase
  {
      private static BufferedLogger m_logger;
      private static ClassInstanceObjectFactory m_factory;
      private static ResourceLimitingPool m_pool;
  
      /*---------------------------------------------------------------
       * Constructors
       *-------------------------------------------------------------*/
      public ResourceLimitingPoolMultithreadTestCase()
      {
          this( "ResourceLimitingPool Multithreaded Test Case" );
      }
  
      public ResourceLimitingPoolMultithreadTestCase( final String name )
      {
          super( name );
      }
  
      /*---------------------------------------------------------------
       * Suite
       *-------------------------------------------------------------*/
      public static Test suite()
      {
          TestSuite suite = new TestSuite();
  
          Timer timer = new ConstantTimer( 100 );
          int maxUsers = 10;
          int iterations = 10;
          long maxElapsedTime = 20000;
  
          Test testCase = new ResourceLimitingPoolMultithreadTestCase( "testGetPut" );
          Test loadTest = new LoadTest( testCase, maxUsers, iterations, timer );
          Test timedTest = new TimedTest( loadTest, maxElapsedTime );
          suite.addTest( timedTest );
  
          TestSetup wrapper= new TestSetup( suite )
          {
              public void setUp()
              {
                  oneTimeSetUp();
              }
              public void tearDown() throws Exception
              {
                  oneTimeTearDown();
              }
          };
  
          return wrapper;
      }
  
      public static void oneTimeSetUp()
      {
          m_logger = new BufferedLogger();
          m_factory = new ClassInstanceObjectFactory( PoolableTestObject.class, m_logger );
          m_pool = new ResourceLimitingPool( m_factory, 0, false, false, 0, 0 );
  
          m_pool.enableLogging( m_logger );
      }
  
      public static void oneTimeTearDown() throws Exception
      {
          // The timing of this test makes it so the pool should grow to 4 elements
          assertEquals( "1) Pool Ready Size", 4, m_pool.getReadySize() );
          assertEquals( "1) Pool Size", 4, m_pool.getSize() );
  
          // Make sure that each of the objects are uniqe by checking them all back out.
          Poolable p1 = m_pool.get();
          Poolable p2 = m_pool.get();
          Poolable p3 = m_pool.get();
          Poolable p4 = m_pool.get();
  
          assertEquals( "2) Pool Ready Size", 0, m_pool.getReadySize() );
          assertEquals( "2) Pool Size", 4, m_pool.getSize() );
  
          assertTrue( "p1 != p2", p1 != p2 );
          assertTrue( "p1 != p3", p1 != p3 );
          assertTrue( "p1 != p4", p1 != p4 );
          assertTrue( "p2 != p3", p2 != p3 );
          assertTrue( "p2 != p4", p2 != p4 );
          assertTrue( "p3 != p4", p3 != p4 );
  
          m_pool.put( p1 );
          m_pool.put( p2 );
          m_pool.put( p3 );
          m_pool.put( p4 );
  
          assertEquals( "3) Pool Ready Size", 4, m_pool.getReadySize() );
          assertEquals( "3) Pool Size", 4, m_pool.getSize() );
  
          m_pool.dispose();
  
          assertEquals( "4) Pool Ready Size", 0, m_pool.getReadySize() );
          assertEquals( "4) Pool Size", 0, m_pool.getSize() );
      }
  
      /*---------------------------------------------------------------
       * TestCases
       *-------------------------------------------------------------*/
      public void testGetPut() throws Exception
      {
          Poolable p = m_pool.get();
          try
          {
              Thread.sleep(33);
          }
          catch ( InterruptedException e ) {}
          m_pool.put( p );
      }
  }
  
  
  
  
  1.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/mpool/test/ResourceLimitingPoolTestCase.java
  
  Index: ResourceLimitingPoolTestCase.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.excalibur.mpool.test;
  
  import junit.framework.TestCase;
  
  import org.apache.avalon.excalibur.logger.BufferedLogger;
  import org.apache.avalon.excalibur.pool.Poolable;
  import org.apache.avalon.excalibur.pool.ResourceLimitingPool;
  
  /**
   * @author <a href="mailto:leif@silveregg.co.jp">Leif Mortenson</a>
   * @version CVS $Revision: 1.1 $ $Date: 2002/02/12 21:30:42 $
   * @since 4.1
   */
  public final class ResourceLimitingPoolTestCase extends TestCase
  {
      /*---------------------------------------------------------------
       * Constructors
       *-------------------------------------------------------------*/
      public ResourceLimitingPoolTestCase()
      {
          this( "ResourceLimitingPool Test Case" );
      }
  
      public ResourceLimitingPoolTestCase( final String name )
      {
          super( name );
      }
  
      /*---------------------------------------------------------------
       * TestCases
       *-------------------------------------------------------------*/
      public void testCreateDestroy()
      {
          BufferedLogger logger = new BufferedLogger();
          ClassInstanceObjectFactory factory =
              new ClassInstanceObjectFactory( PoolableTestObject.class, logger );
          ResourceLimitingPool pool = new ResourceLimitingPool( factory, 0, false, false, 0, 0 );
  
          pool.enableLogging( logger );
          pool.dispose();
  
          // Make sure the logger output check out.
          assertEquals(
              logger.toString(),
              ""
              );
      }
  
      public void testSingleGetPut() throws Exception
      {
          BufferedLogger logger = new BufferedLogger();
          ClassInstanceObjectFactory factory =
              new ClassInstanceObjectFactory( PoolableTestObject.class, logger );
          ResourceLimitingPool pool = new ResourceLimitingPool( factory, 0, false, false, 0, 0 );
  
          pool.enableLogging( logger );
  
          assertEquals( "1) Pool Ready Size", 0, pool.getReadySize() );
          assertEquals( "1) Pool Size", 0, pool.getSize() );
  
          Poolable p = pool.get();
  
          assertEquals( "2) Pool Ready Size", 0, pool.getReadySize() );
          assertEquals( "2) Pool Size", 1, pool.getSize() );
  
          pool.put(p);
  
          assertEquals( "3) Pool Ready Size", 1, pool.getReadySize() );
          assertEquals( "3) Pool Size", 1, pool.getSize() );
  
          pool.dispose();
  
          // Make sure the logger output check out.
          assertEquals( "Logger output",
              "DEBUG - ClassInstanceObjectFactory.newInstance()  id:1\n" +
              "DEBUG - Created a new org.apache.avalon.excalibur.pool.test.PoolableTestObject from the object factory.\n" +
              "DEBUG - Got a org.apache.avalon.excalibur.pool.test.PoolableTestObject from the pool.\n" +
              "DEBUG - Put a org.apache.avalon.excalibur.pool.test.PoolableTestObject back into the pool.\n" +
              "DEBUG - ClassInstanceObjectFactory.decommission(a org.apache.avalon.excalibur.pool.test.PoolableTestObject)  id:1\n",
              logger.toString()
              );
      }
  
      public void testSingleGetPutPoolCheck() throws Exception
      {
          BufferedLogger logger = new BufferedLogger();
          ClassInstanceObjectFactory factory =
              new ClassInstanceObjectFactory( PoolableTestObject.class, logger );
          ResourceLimitingPool pool = new ResourceLimitingPool( factory, 0, false, false, 0, 0 );
  
          pool.enableLogging( logger );
  
          assertEquals( "1) Pool Ready Size", 0, pool.getReadySize() );
          assertEquals( "1) Pool Size", 0, pool.getSize() );
  
          Poolable p1 = pool.get();
  
          assertEquals( "2) Pool Ready Size", 0, pool.getReadySize() );
          assertEquals( "2) Pool Size", 1, pool.getSize() );
  
          pool.put( p1 );
  
          assertEquals( "3) Pool Ready Size", 1, pool.getReadySize() );
          assertEquals( "3) Pool Size", 1, pool.getSize() );
  
          Poolable p2 = pool.get();
  
          assertEquals( "4) Pool Ready Size", 0, pool.getReadySize() );
          assertEquals( "4) Pool Size", 1, pool.getSize() );
  
          assertEquals( "Pooled Object reuse check", p1, p2 );
  
          pool.put( p2 );
  
          assertEquals( "5) Pool Ready Size", 1, pool.getReadySize() );
          assertEquals( "5) Pool Size", 1, pool.getSize() );
  
          pool.dispose();
  
          // Make sure the logger output check out.
          assertEquals( "Logger output",
              "DEBUG - ClassInstanceObjectFactory.newInstance()  id:1\n" +
              "DEBUG - Created a new org.apache.avalon.excalibur.pool.test.PoolableTestObject from the object factory.\n" +
              "DEBUG - Got a org.apache.avalon.excalibur.pool.test.PoolableTestObject from the pool.\n" +
              "DEBUG - Put a org.apache.avalon.excalibur.pool.test.PoolableTestObject back into the pool.\n" +
              "DEBUG - Got a org.apache.avalon.excalibur.pool.test.PoolableTestObject from the pool.\n" +
              "DEBUG - Put a org.apache.avalon.excalibur.pool.test.PoolableTestObject back into the pool.\n" +
              "DEBUG - ClassInstanceObjectFactory.decommission(a org.apache.avalon.excalibur.pool.test.PoolableTestObject)  id:1\n",
              logger.toString()
              );
      }
  
      public void testMultipleGetPut() throws Exception
      {
          BufferedLogger logger = new BufferedLogger();
          ClassInstanceObjectFactory factory =
              new ClassInstanceObjectFactory( PoolableTestObject.class, logger );
          ResourceLimitingPool pool = new ResourceLimitingPool( factory, 0, false, false, 0, 0 );
  
          pool.enableLogging( logger );
  
          assertEquals( "1) Pool Ready Size", 0, pool.getReadySize() );
          assertEquals( "1) Pool Size", 0, pool.getSize() );
  
          Poolable p1 = pool.get();
  
          assertEquals( "2) Pool Ready Size", 0, pool.getReadySize() );
          assertEquals( "2) Pool Size", 1, pool.getSize() );
  
          Poolable p2 = pool.get();
  
          assertEquals( "3) Pool Ready Size", 0, pool.getReadySize() );
          assertEquals( "3) Pool Size", 2, pool.getSize() );
  
          pool.put( p1 );
  
          assertEquals( "4) Pool Ready Size", 1, pool.getReadySize() );
          assertEquals( "4) Pool Size", 2, pool.getSize() );
  
          pool.put( p2 );
  
          assertEquals( "5) Pool Ready Size", 2, pool.getReadySize() );
          assertEquals( "5) Pool Size", 2, pool.getSize() );
  
          pool.dispose();
  
          // Make sure the logger output check out.
          assertEquals( "Logger output",
              "DEBUG - ClassInstanceObjectFactory.newInstance()  id:1\n" +
              "DEBUG - Created a new org.apache.avalon.excalibur.pool.test.PoolableTestObject from the object factory.\n" +
              "DEBUG - Got a org.apache.avalon.excalibur.pool.test.PoolableTestObject from the pool.\n" +
              "DEBUG - ClassInstanceObjectFactory.newInstance()  id:2\n" +
              "DEBUG - Created a new org.apache.avalon.excalibur.pool.test.PoolableTestObject from the object factory.\n" +
              "DEBUG - Got a org.apache.avalon.excalibur.pool.test.PoolableTestObject from the pool.\n" +
              "DEBUG - Put a org.apache.avalon.excalibur.pool.test.PoolableTestObject back into the pool.\n" +
              "DEBUG - Put a org.apache.avalon.excalibur.pool.test.PoolableTestObject back into the pool.\n" +
              "DEBUG - ClassInstanceObjectFactory.decommission(a org.apache.avalon.excalibur.pool.test.PoolableTestObject)  id:1\n" +
              "DEBUG - ClassInstanceObjectFactory.decommission(a org.apache.avalon.excalibur.pool.test.PoolableTestObject)  id:2\n",
              logger.toString()
              );
      }
  }
  
  
  
  
  1.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/mpool/test/SingleThreadedPoolComparisonProfile.java
  
  Index: SingleThreadedPoolComparisonProfile.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.excalibur.mpool.test;
  
  import junit.framework.TestCase;
  
  import org.apache.avalon.excalibur.mpool.FixedSizePool;
  import org.apache.avalon.excalibur.pool.HardResourceLimitingPool;
  import org.apache.avalon.excalibur.pool.ObjectFactory;
  import org.apache.avalon.excalibur.mpool.Pool;
  import org.apache.avalon.excalibur.pool.Poolable;
  import org.apache.avalon.excalibur.pool.ResourceLimitingPool;
  import org.apache.avalon.excalibur.pool.SingleThreadedPool;
  import org.apache.avalon.excalibur.pool.SoftResourceLimitingPool;
  import org.apache.avalon.excalibur.mpool.VariableSizePool;
  
  import org.apache.avalon.framework.activity.Disposable;
  import org.apache.avalon.framework.logger.LogEnabled;
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.avalon.framework.logger.LogKitLogger;
  
  /**
   * This is used to profile and compare various pool implementations
   *  given a single access thread.
   *
   * @author <a href="mailto:leif@silveregg.co.jp">Leif Mortenson</a>
   * @version $Id: SingleThreadedPoolComparisonProfile.java,v 1.1 2002/02/12 21:30:42 bloritsch Exp $
   */
  public class SingleThreadedPoolComparisonProfile
      extends PoolComparisonProfileAbstract
  {
      /*---------------------------------------------------------------
       * Constructors
       *-------------------------------------------------------------*/
      public SingleThreadedPoolComparisonProfile(String name)
      {
          super(name);
      }
  
      /*---------------------------------------------------------------
       * SingleThreadedPool vs ResourceLimitingPool TestCases
       *-------------------------------------------------------------*/
      /**
       * Compare the SingleThreadedPool and ResourceLimitingPool when the
       *  ResourceLimitingPool is configured to act like a SingleThreadedPool.
       * <p>
       * Test will use pools with a max size of 10, while getting up to 10 at a time,
       *  Poolables are small objects.
       */
      public void testCompare_SingleThreadedPool_And_ResourceLimitingPool_Max10_Gets10_SmallPoolables()
          throws Exception
      {
          String name = "SingleThreadedPool_And_ResourceLimitingPool_Max10_Gets10_SmallPoolables";
  
          Class         poolableClass = SmallPoolable.class;
          ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
          int           min          = 0;
          int           max          = 10;
          boolean       maxStrict    = false;
          boolean       blocking     = false;
          long          blockTimeout = 0;
          long          trimInterval = 0;
  
          SingleThreadedPool poolA = new SingleThreadedPool( factory, min, max );
          poolA.enableLogging( m_poolLogger );
          poolA.initialize();
  
          ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
          poolB.enableLogging( m_poolLogger );
  
          generalTest( name, poolA, poolB, 10, factory );
      }
  
      /**
       * Compare the SingleThreadedPool and ResourceLimitingPool when the
       *  ResourceLimitingPool is configured to act like a SingleThreadedPool.
       * <p>
       * Test will use pools with a max size of 10, while getting up to 20 at a time,
       *  Poolables are small objects.
       */
      public void testCompare_SingleThreadedPool_And_ResourceLimitingPool_Max10_Gets20_SmallPoolables()
          throws Exception
      {
          String name = "SingleThreadedPool_And_ResourceLimitingPool_Max10_Gets20_SmallPoolables";
  
          Class         poolableClass = SmallPoolable.class;
          ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
          int           min          = 0;
          int           max          = 10;
          boolean       maxStrict    = false;
          boolean       blocking     = false;
          long          blockTimeout = 0;
          long          trimInterval = 0;
  
          SingleThreadedPool poolA = new SingleThreadedPool( factory, min, max );
          poolA.enableLogging( m_poolLogger );
          poolA.initialize();
  
          ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
          poolB.enableLogging( m_poolLogger );
  
          generalTest( name, poolA, poolB, 20, factory );
      }
  
      /**
       * Compare the SingleThreadedPool and ResourceLimitingPool when the
       *  ResourceLimitingPool is configured to act like a SingleThreadedPool.
       * <p>
       * Test will use pools with a max size of 10, while getting up to 10 at a time,
       *  Poolables are medium objects.
       */
      public void testCompare_SingleThreadedPool_And_ResourceLimitingPool_Max10_Gets10_MediumPoolables()
          throws Exception
      {
          String name = "SingleThreadedPool_And_ResourceLimitingPool_Max10_Gets10_MediumPoolables";
  
          Class         poolableClass = MediumPoolable.class;
          ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
          int           min          = 0;
          int           max          = 10;
          boolean       maxStrict    = false;
          boolean       blocking     = false;
          long          blockTimeout = 0;
          long          trimInterval = 0;
  
          SingleThreadedPool poolA = new SingleThreadedPool( factory, min, max );
          poolA.enableLogging( m_poolLogger );
          poolA.initialize();
  
          ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
          poolB.enableLogging( m_poolLogger );
  
          generalTest( name, poolA, poolB, 10, factory );
      }
  
      /**
       * Compare the SingleThreadedPool and ResourceLimitingPool when the
       *  ResourceLimitingPool is configured to act like a SingleThreadedPool.
       * <p>
       * Test will use pools with a max size of 10, while getting up to 20 at a time,
       *  Poolables are medium objects.
       */
      public void testCompare_SingleThreadedPool_And_ResourceLimitingPool_Max10_Gets20_MediumPoolables()
          throws Exception
      {
          String name = "SingleThreadedPool_And_ResourceLimitingPool_Max10_Gets20_MediumPoolables";
  
          Class         poolableClass = MediumPoolable.class;
          ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
          int           min          = 0;
          int           max          = 10;
          boolean       maxStrict    = false;
          boolean       blocking     = false;
          long          blockTimeout = 0;
          long          trimInterval = 0;
  
          SingleThreadedPool poolA = new SingleThreadedPool( factory, min, max );
          poolA.enableLogging( m_poolLogger );
          poolA.initialize();
  
          ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
          poolB.enableLogging( m_poolLogger );
  
          generalTest( name, poolA, poolB, 20, factory );
      }
  
      /**
       * Compare the SingleThreadedPool and ResourceLimitingPool when the
       *  ResourceLimitingPool is configured to act like a SingleThreadedPool.
       * <p>
       * Test will use pools with a max size of 10, while getting up to 10 at a time,
       *  Poolables are large objects.
       */
      public void testCompare_SingleThreadedPool_And_ResourceLimitingPool_Max10_Gets10_LargePoolables()
          throws Exception
      {
          String name = "SingleThreadedPool_And_ResourceLimitingPool_Max10_Gets10_LargePoolables";
  
          Class         poolableClass = LargePoolable.class;
          ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
          int           min          = 0;
          int           max          = 10;
          boolean       maxStrict    = false;
          boolean       blocking     = false;
          long          blockTimeout = 0;
          long          trimInterval = 0;
  
          SingleThreadedPool poolA = new SingleThreadedPool( factory, min, max );
          poolA.enableLogging( m_poolLogger );
          poolA.initialize();
  
          ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
          poolB.enableLogging( m_poolLogger );
  
          generalTest( name, poolA, poolB, 10, factory );
      }
  
      /**
       * Compare the SingleThreadedPool and ResourceLimitingPool when the
       *  ResourceLimitingPool is configured to act like a SingleThreadedPool.
       * <p>
       * Test will use pools with a max size of 10, while getting up to 20 at a time,
       *  Poolables are large objects.
       */
      public void testCompare_SingleThreadedPool_And_ResourceLimitingPool_Max10_Gets20_LargePoolables()
          throws Exception
      {
          String name = "SingleThreadedPool_And_ResourceLimitingPool_Max10_Gets20_LargePoolables";
  
          Class         poolableClass = LargePoolable.class;
          ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
          int           min          = 0;
          int           max          = 10;
          boolean       maxStrict    = false;
          boolean       blocking     = false;
          long          blockTimeout = 0;
          long          trimInterval = 0;
  
          SingleThreadedPool poolA = new SingleThreadedPool( factory, min, max );
          poolA.enableLogging( m_poolLogger );
          poolA.initialize();
  
          ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
          poolB.enableLogging( m_poolLogger );
  
          generalTest( name, poolA, poolB, 20, factory );
      }
  
      /*---------------------------------------------------------------
       * 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 10, while getting up to 10 at a time,
       *  Poolables are small objects.
       */
      public void testCompare_VariableSizePool_And_ResourceLimitingPool_Max10_Gets10_SmallPoolables()
          throws Exception
      {
          String name = "VariableSizePool_And_ResourceLimitingPool_Max10_Gets10_SmallPoolables";
  
          Class         poolableClass = SmallPoolable.class;
          ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
          int           min          = 0;
          int           max          = 10;
          boolean       maxStrict    = true;
          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, 10, 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 10, while getting up to 10 at a time,
       *  Poolables are medium objects.
       */
      public void testCompare_VariableSizePool_And_ResourceLimitingPool_Max10_Gets10_MediumPoolables()
          throws Exception
      {
          String name = "VariableSizePool_And_ResourceLimitingPool_Max10_Gets10_MediumPoolables";
  
          Class         poolableClass = MediumPoolable.class;
          ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
          int           min          = 0;
          int           max          = 10;
          boolean       maxStrict    = true;
          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, 10, 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 10, while getting up to 10 at a time,
       *  Poolables are large objects.
       */
      public void testCompare_VariableSizePool_And_ResourceLimitingPool_Max10_Gets10_LargePoolables()
          throws Exception
      {
          String name = "VariableSizePool_And_ResourceLimitingPool_Max10_Gets10_LargePoolables";
  
          Class         poolableClass = LargePoolable.class;
          ClassInstanceObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
          int           min          = 0;
          int           max          = 10;
          boolean       maxStrict    = true;
          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, 10, factory );
      }
  
      /*---------------------------------------------------------------
       * 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;
      }
  }
  
  
  
  1.3       +14 -16    jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/pool/test/MultiThreadedPoolComparisonProfile.java
  
  Index: MultiThreadedPoolComparisonProfile.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/pool/test/MultiThreadedPoolComparisonProfile.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MultiThreadedPoolComparisonProfile.java	12 Feb 2002 06:37:11 -0000	1.2
  +++ MultiThreadedPoolComparisonProfile.java	12 Feb 2002 21:30:43 -0000	1.3
  @@ -9,7 +9,6 @@
   
   import junit.framework.TestCase;
   
  -import org.apache.avalon.excalibur.pool.FixedSizePool;
   import org.apache.avalon.excalibur.pool.HardResourceLimitingPool;
   import org.apache.avalon.excalibur.pool.ObjectFactory;
   import org.apache.avalon.excalibur.pool.Pool;
  @@ -17,7 +16,6 @@
   import org.apache.avalon.excalibur.pool.ResourceLimitingPool;
   import org.apache.avalon.excalibur.pool.SingleThreadedPool;
   import org.apache.avalon.excalibur.pool.SoftResourceLimitingPool;
  -import org.apache.avalon.excalibur.pool.VariableSizePool;
   import org.apache.avalon.excalibur.testcase.CascadingAssertionFailedError;
   import org.apache.avalon.excalibur.testcase.LatchedThreadGroup;
   
  @@ -31,20 +29,20 @@
    *  given a single access thread.
    *
    * @author <a href="mailto:leif@silveregg.co.jp">Leif Mortenson</a>
  - * @version $Id: MultiThreadedPoolComparisonProfile.java,v 1.2 2002/02/12 06:37:11 leif Exp $
  + * @version $Id: MultiThreadedPoolComparisonProfile.java,v 1.3 2002/02/12 21:30:43 bloritsch Exp $
    */
   public class MultiThreadedPoolComparisonProfile
       extends PoolComparisonProfileAbstract
   {
       protected static final int THREADS = 10;
  -    
  +
       private Object    m_semaphore = new Object();
       private int       m_startedCount;
       private boolean   m_latched;
       private int       m_completedCount;
       private int       m_getCount;
       private Throwable m_throwable;
  -    
  +
       /*---------------------------------------------------------------
        * Constructors
        *-------------------------------------------------------------*/
  @@ -52,7 +50,7 @@
       {
           super(name);
       }
  -    
  +
       /*---------------------------------------------------------------
        * PoolComparisonProfileAbstract Methods
        *-------------------------------------------------------------*/
  @@ -63,10 +61,10 @@
           {
               fail( "gets must be evenly divisible by THREADS");
           }
  -        
  +
           m_getCount = 0;
           m_throwable = null;
  -        
  +
           // Create the runnable
           Runnable runnable = new Runnable()
           {
  @@ -92,7 +90,7 @@
                           catch ( Throwable t )
                           {
                               m_poolLogger.error( "Unexpected error", t );
  -                            
  +
                               synchronized(m_semaphore)
                               {
                                   if (m_throwable == null) {
  @@ -102,10 +100,10 @@
                               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++ )
                       {
  @@ -119,7 +117,7 @@
                   }
               }
           };
  -        
  +
           LatchedThreadGroup group = new LatchedThreadGroup( runnable, THREADS );
           group.enableLogging( m_logger );
   
  @@ -136,19 +134,19 @@
               }
               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;
       }
   }
  
  
  
  1.2       +52 -144   jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/pool/test/PoolComparisonProfileAbstract.java
  
  Index: PoolComparisonProfileAbstract.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/pool/test/PoolComparisonProfileAbstract.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PoolComparisonProfileAbstract.java	2 Feb 2002 17:31:32 -0000	1.1
  +++ PoolComparisonProfileAbstract.java	12 Feb 2002 21:30:43 -0000	1.2
  @@ -9,7 +9,6 @@
   
   import junit.framework.TestCase;
   
  -import org.apache.avalon.excalibur.pool.FixedSizePool;
   import org.apache.avalon.excalibur.pool.HardResourceLimitingPool;
   import org.apache.avalon.excalibur.pool.ObjectFactory;
   import org.apache.avalon.excalibur.pool.Pool;
  @@ -17,7 +16,6 @@
   import org.apache.avalon.excalibur.pool.ResourceLimitingPool;
   import org.apache.avalon.excalibur.pool.SingleThreadedPool;
   import org.apache.avalon.excalibur.pool.SoftResourceLimitingPool;
  -import org.apache.avalon.excalibur.pool.VariableSizePool;
   
   import org.apache.avalon.framework.activity.Disposable;
   import org.apache.avalon.framework.logger.LogEnabled;
  @@ -28,7 +26,7 @@
    * Used as a basis for the PoolComparisonProfile Tests
    *
    * @author <a href="mailto:leif@silveregg.co.jp">Leif Mortenson</a>
  - * @version $Id: PoolComparisonProfileAbstract.java,v 1.1 2002/02/02 17:31:32 leif Exp $
  + * @version $Id: PoolComparisonProfileAbstract.java,v 1.2 2002/02/12 21:30:43 bloritsch Exp $
    */
   public abstract class PoolComparisonProfileAbstract
       extends TestCase
  @@ -41,7 +39,7 @@
   
       protected Logger m_logger;
       protected Logger m_poolLogger;
  -    
  +
       /*---------------------------------------------------------------
        * Constructors
        *-------------------------------------------------------------*/
  @@ -50,18 +48,18 @@
           super(name);
   
           // Set to debug to see more useful information.
  -        org.apache.log.Logger logger = 
  +        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 );
       }
  -    
  +
       /*---------------------------------------------------------------
        * SoftResourceLimitingPool vs ResourceLimitingPool TestCases
        *-------------------------------------------------------------*/
  @@ -76,7 +74,7 @@
           throws Exception
       {
           String name = "SoftResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets10_SmallPoolables";
  -        
  +
           Class         poolableClass = SmallPoolable.class;
           ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
           int           min          = 0;
  @@ -85,11 +83,11 @@
           boolean       blocking     = false;
           long          blockTimeout = 0;
           long          trimInterval = 0;
  -        
  +
           SoftResourceLimitingPool poolA = new SoftResourceLimitingPool( factory, min, max );
           poolA.enableLogging( m_poolLogger );
           poolA.initialize();
  -        
  +
           ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
           poolB.enableLogging( m_poolLogger );
   
  @@ -107,7 +105,7 @@
           throws Exception
       {
           String name = "SoftResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets20_SmallPoolables";
  -        
  +
           Class         poolableClass = SmallPoolable.class;
           ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
           int           min          = 0;
  @@ -116,11 +114,11 @@
           boolean       blocking     = false;
           long          blockTimeout = 0;
           long          trimInterval = 0;
  -        
  +
           SoftResourceLimitingPool poolA = new SoftResourceLimitingPool( factory, min, max );
           poolA.enableLogging( m_poolLogger );
           poolA.initialize();
  -        
  +
           ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
           poolB.enableLogging( m_poolLogger );
   
  @@ -138,7 +136,7 @@
           throws Exception
       {
           String name = "SoftResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets10_MediumPoolables";
  -        
  +
           Class         poolableClass = MediumPoolable.class;
           ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
           int           min          = 0;
  @@ -147,11 +145,11 @@
           boolean       blocking     = false;
           long          blockTimeout = 0;
           long          trimInterval = 0;
  -        
  +
           SoftResourceLimitingPool poolA = new SoftResourceLimitingPool( factory, min, max );
           poolA.enableLogging( m_poolLogger );
           poolA.initialize();
  -        
  +
           ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
           poolB.enableLogging( m_poolLogger );
   
  @@ -169,7 +167,7 @@
           throws Exception
       {
           String name = "SoftResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets20_MediumPoolables";
  -        
  +
           Class         poolableClass = MediumPoolable.class;
           ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
           int           min          = 0;
  @@ -178,11 +176,11 @@
           boolean       blocking     = false;
           long          blockTimeout = 0;
           long          trimInterval = 0;
  -        
  +
           SoftResourceLimitingPool poolA = new SoftResourceLimitingPool( factory, min, max );
           poolA.enableLogging( m_poolLogger );
           poolA.initialize();
  -        
  +
           ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
           poolB.enableLogging( m_poolLogger );
   
  @@ -200,7 +198,7 @@
           throws Exception
       {
           String name = "SoftResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets10_LargePoolables";
  -        
  +
           Class         poolableClass = LargePoolable.class;
           ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
           int           min          = 0;
  @@ -209,11 +207,11 @@
           boolean       blocking     = false;
           long          blockTimeout = 0;
           long          trimInterval = 0;
  -        
  +
           SoftResourceLimitingPool poolA = new SoftResourceLimitingPool( factory, min, max );
           poolA.enableLogging( m_poolLogger );
           poolA.initialize();
  -        
  +
           ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
           poolB.enableLogging( m_poolLogger );
   
  @@ -231,7 +229,7 @@
           throws Exception
       {
           String name = "SoftResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets20_LargePoolables";
  -        
  +
           Class         poolableClass = LargePoolable.class;
           ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
           int           min          = 0;
  @@ -240,11 +238,11 @@
           boolean       blocking     = false;
           long          blockTimeout = 0;
           long          trimInterval = 0;
  -        
  +
           SoftResourceLimitingPool poolA = new SoftResourceLimitingPool( factory, min, max );
           poolA.enableLogging( m_poolLogger );
           poolA.initialize();
  -        
  +
           ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
           poolB.enableLogging( m_poolLogger );
   
  @@ -265,7 +263,7 @@
           throws Exception
       {
           String name = "HardResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets10_SmallPoolables";
  -        
  +
           Class         poolableClass = SmallPoolable.class;
           ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
           int           min          = 0;
  @@ -274,11 +272,11 @@
           boolean       blocking     = false;
           long          blockTimeout = 0;
           long          trimInterval = 0;
  -        
  +
           HardResourceLimitingPool poolA = new HardResourceLimitingPool( factory, min, max );
           poolA.enableLogging( m_poolLogger );
           poolA.initialize();
  -        
  +
           ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
           poolB.enableLogging( m_poolLogger );
   
  @@ -296,7 +294,7 @@
           throws Exception
       {
           String name = "HardResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets10_MediumPoolables";
  -        
  +
           Class         poolableClass = MediumPoolable.class;
           ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
           int           min          = 0;
  @@ -305,11 +303,11 @@
           boolean       blocking     = false;
           long          blockTimeout = 0;
           long          trimInterval = 0;
  -        
  +
           HardResourceLimitingPool poolA = new HardResourceLimitingPool( factory, min, max );
           poolA.enableLogging( m_poolLogger );
           poolA.initialize();
  -        
  +
           ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
           poolB.enableLogging( m_poolLogger );
   
  @@ -327,7 +325,7 @@
           throws Exception
       {
           String name = "HardResourceLimitingPool_And_ResourceLimitingPool_Max10_Gets10_LargePoolables";
  -        
  +
           Class         poolableClass = LargePoolable.class;
           ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
           int           min          = 0;
  @@ -336,11 +334,11 @@
           boolean       blocking     = false;
           long          blockTimeout = 0;
           long          trimInterval = 0;
  -        
  +
           HardResourceLimitingPool poolA = new HardResourceLimitingPool( factory, min, max );
           poolA.enableLogging( m_poolLogger );
           poolA.initialize();
  -        
  +
           ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
           poolB.enableLogging( m_poolLogger );
   
  @@ -348,96 +346,6 @@
       }
   
       /*---------------------------------------------------------------
  -     * 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 10, while getting up to 10 at a time,
  -     *  Poolables are small objects.
  -     */
  -    public void testCompare_FixedSizePool_And_ResourceLimitingPool_Max10_Gets10_SmallPoolables()
  -        throws Exception
  -    {
  -        String name = "FixedSizePool_And_ResourceLimitingPool_Max10_Gets10_SmallPoolables";
  -        
  -        Class         poolableClass = SmallPoolable.class;
  -        ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  -        int           min          = 0;
  -        int           max          = 10;
  -        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, 10, 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 10, while getting up to 10 at a time,
  -     *  Poolables are medium objects.
  -     */
  -    public void testCompare_FixedSizePool_And_ResourceLimitingPool_Max10_Gets10_MediumPoolables()
  -        throws Exception
  -    {
  -        String name = "FixedSizePool_And_ResourceLimitingPool_Max10_Gets10_MediumPoolables";
  -        
  -        Class         poolableClass = MediumPoolable.class;
  -        ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  -        int           min          = 0;
  -        int           max          = 10;
  -        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, 10, 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 10, while getting up to 10 at a time,
  -     *  Poolables are large objects.
  -     */
  -    public void testCompare_FixedSizePool_And_ResourceLimitingPool_Max10_Gets10_LargePoolables()
  -        throws Exception
  -    {
  -        String name = "FixedSizePool_And_ResourceLimitingPool_Max10_Gets10_LargePoolables";
  -        
  -        Class         poolableClass = LargePoolable.class;
  -        ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  -        int           min          = 0;
  -        int           max          = 10;
  -        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, 10, factory );
  -    }
  -    
  -    /*---------------------------------------------------------------
        * Test Classes
        *-------------------------------------------------------------*/
       public static class SmallPoolable
  @@ -457,7 +365,7 @@
       {
           int[][] a = new int[100][50];
       }
  -    
  +
       /**
        * Dummy class used for timing test cases where no pooling is done.
        */
  @@ -466,22 +374,22 @@
       {
           private ObjectFactory m_factory;
           private Logger        m_logger;
  -        
  +
           public NoPoolingPool( ObjectFactory factory )
           {
               m_factory = factory;
           }
  -        
  +
           public void enableLogging( Logger logger )
           {
               m_logger = logger;
           }
  -        
  +
           public Poolable get() throws Exception
           {
               return (Poolable)m_factory.newInstance();
           }
  -        
  +
           public void put( Poolable poolable )
           {
               try {
  @@ -493,7 +401,7 @@
               }
           }
       }
  -    
  +
       /*---------------------------------------------------------------
        * Utility Methods
        *-------------------------------------------------------------*/
  @@ -501,7 +409,7 @@
       {
           System.gc();
           System.gc();
  -        
  +
           // Let the system settle down.
           try
           {
  @@ -511,7 +419,7 @@
           Runtime runtime = Runtime.getRuntime();
           m_logger.debug( "Memory: " + ( runtime.totalMemory() - runtime.freeMemory() ) );
       }
  -    
  +
       protected String getShortClassName( Object o )
       {
           String name = o.getClass().getName();
  @@ -522,10 +430,10 @@
           }
           return name;
       }
  -    
  +
       protected abstract long getPoolRunTime( Pool pool, int gets )
           throws Exception;
  -    
  +
       /**
        * The guts of the various test cases.  Will dispose the pools
        */
  @@ -533,43 +441,43 @@
           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 + "." );
           }
  
  
  
  1.4       +25 -117   jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/pool/test/SingleThreadedPoolComparisonProfile.java
  
  Index: SingleThreadedPoolComparisonProfile.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/pool/test/SingleThreadedPoolComparisonProfile.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SingleThreadedPoolComparisonProfile.java	2 Feb 2002 17:31:32 -0000	1.3
  +++ SingleThreadedPoolComparisonProfile.java	12 Feb 2002 21:30:43 -0000	1.4
  @@ -9,7 +9,6 @@
   
   import junit.framework.TestCase;
   
  -import org.apache.avalon.excalibur.pool.FixedSizePool;
   import org.apache.avalon.excalibur.pool.HardResourceLimitingPool;
   import org.apache.avalon.excalibur.pool.ObjectFactory;
   import org.apache.avalon.excalibur.pool.Pool;
  @@ -17,7 +16,6 @@
   import org.apache.avalon.excalibur.pool.ResourceLimitingPool;
   import org.apache.avalon.excalibur.pool.SingleThreadedPool;
   import org.apache.avalon.excalibur.pool.SoftResourceLimitingPool;
  -import org.apache.avalon.excalibur.pool.VariableSizePool;
   
   import org.apache.avalon.framework.activity.Disposable;
   import org.apache.avalon.framework.logger.LogEnabled;
  @@ -29,7 +27,7 @@
    *  given a single access thread.
    *
    * @author <a href="mailto:leif@silveregg.co.jp">Leif Mortenson</a>
  - * @version $Id: SingleThreadedPoolComparisonProfile.java,v 1.3 2002/02/02 17:31:32 leif Exp $
  + * @version $Id: SingleThreadedPoolComparisonProfile.java,v 1.4 2002/02/12 21:30:43 bloritsch Exp $
    */
   public class SingleThreadedPoolComparisonProfile
       extends PoolComparisonProfileAbstract
  @@ -41,7 +39,7 @@
       {
           super(name);
       }
  -    
  +
       /*---------------------------------------------------------------
        * SingleThreadedPool vs ResourceLimitingPool TestCases
        *-------------------------------------------------------------*/
  @@ -56,7 +54,7 @@
           throws Exception
       {
           String name = "SingleThreadedPool_And_ResourceLimitingPool_Max10_Gets10_SmallPoolables";
  -        
  +
           Class         poolableClass = SmallPoolable.class;
           ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
           int           min          = 0;
  @@ -65,11 +63,11 @@
           boolean       blocking     = false;
           long          blockTimeout = 0;
           long          trimInterval = 0;
  -        
  +
           SingleThreadedPool poolA = new SingleThreadedPool( factory, min, max );
           poolA.enableLogging( m_poolLogger );
           poolA.initialize();
  -        
  +
           ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
           poolB.enableLogging( m_poolLogger );
   
  @@ -87,7 +85,7 @@
           throws Exception
       {
           String name = "SingleThreadedPool_And_ResourceLimitingPool_Max10_Gets20_SmallPoolables";
  -        
  +
           Class         poolableClass = SmallPoolable.class;
           ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
           int           min          = 0;
  @@ -96,11 +94,11 @@
           boolean       blocking     = false;
           long          blockTimeout = 0;
           long          trimInterval = 0;
  -        
  +
           SingleThreadedPool poolA = new SingleThreadedPool( factory, min, max );
           poolA.enableLogging( m_poolLogger );
           poolA.initialize();
  -        
  +
           ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
           poolB.enableLogging( m_poolLogger );
   
  @@ -118,7 +116,7 @@
           throws Exception
       {
           String name = "SingleThreadedPool_And_ResourceLimitingPool_Max10_Gets10_MediumPoolables";
  -        
  +
           Class         poolableClass = MediumPoolable.class;
           ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
           int           min          = 0;
  @@ -127,11 +125,11 @@
           boolean       blocking     = false;
           long          blockTimeout = 0;
           long          trimInterval = 0;
  -        
  +
           SingleThreadedPool poolA = new SingleThreadedPool( factory, min, max );
           poolA.enableLogging( m_poolLogger );
           poolA.initialize();
  -        
  +
           ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
           poolB.enableLogging( m_poolLogger );
   
  @@ -149,7 +147,7 @@
           throws Exception
       {
           String name = "SingleThreadedPool_And_ResourceLimitingPool_Max10_Gets20_MediumPoolables";
  -        
  +
           Class         poolableClass = MediumPoolable.class;
           ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
           int           min          = 0;
  @@ -158,11 +156,11 @@
           boolean       blocking     = false;
           long          blockTimeout = 0;
           long          trimInterval = 0;
  -        
  +
           SingleThreadedPool poolA = new SingleThreadedPool( factory, min, max );
           poolA.enableLogging( m_poolLogger );
           poolA.initialize();
  -        
  +
           ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
           poolB.enableLogging( m_poolLogger );
   
  @@ -180,7 +178,7 @@
           throws Exception
       {
           String name = "SingleThreadedPool_And_ResourceLimitingPool_Max10_Gets10_LargePoolables";
  -        
  +
           Class         poolableClass = LargePoolable.class;
           ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
           int           min          = 0;
  @@ -189,11 +187,11 @@
           boolean       blocking     = false;
           long          blockTimeout = 0;
           long          trimInterval = 0;
  -        
  +
           SingleThreadedPool poolA = new SingleThreadedPool( factory, min, max );
           poolA.enableLogging( m_poolLogger );
           poolA.initialize();
  -        
  +
           ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
           poolB.enableLogging( m_poolLogger );
   
  @@ -211,7 +209,7 @@
           throws Exception
       {
           String name = "SingleThreadedPool_And_ResourceLimitingPool_Max10_Gets20_LargePoolables";
  -        
  +
           Class         poolableClass = LargePoolable.class;
           ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
           int           min          = 0;
  @@ -220,107 +218,17 @@
           boolean       blocking     = false;
           long          blockTimeout = 0;
           long          trimInterval = 0;
  -        
  +
           SingleThreadedPool poolA = new SingleThreadedPool( factory, min, max );
           poolA.enableLogging( m_poolLogger );
           poolA.initialize();
  -        
  +
           ResourceLimitingPool poolB = new ResourceLimitingPool( factory, max, maxStrict, blocking, blockTimeout, trimInterval );
           poolB.enableLogging( m_poolLogger );
   
           generalTest( name, poolA, poolB, 20, factory );
       }
  -    
  -    /*---------------------------------------------------------------
  -     * 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 10, while getting up to 10 at a time,
  -     *  Poolables are small objects.
  -     */
  -    public void testCompare_VariableSizePool_And_ResourceLimitingPool_Max10_Gets10_SmallPoolables()
  -        throws Exception
  -    {
  -        String name = "VariableSizePool_And_ResourceLimitingPool_Max10_Gets10_SmallPoolables";
  -        
  -        Class         poolableClass = SmallPoolable.class;
  -        ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  -        int           min          = 0;
  -        int           max          = 10;
  -        boolean       maxStrict    = true;
  -        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, 10, 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 10, while getting up to 10 at a time,
  -     *  Poolables are medium objects.
  -     */
  -    public void testCompare_VariableSizePool_And_ResourceLimitingPool_Max10_Gets10_MediumPoolables()
  -        throws Exception
  -    {
  -        String name = "VariableSizePool_And_ResourceLimitingPool_Max10_Gets10_MediumPoolables";
  -        
  -        Class         poolableClass = MediumPoolable.class;
  -        ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  -        int           min          = 0;
  -        int           max          = 10;
  -        boolean       maxStrict    = true;
  -        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, 10, 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 10, while getting up to 10 at a time,
  -     *  Poolables are large objects.
  -     */
  -    public void testCompare_VariableSizePool_And_ResourceLimitingPool_Max10_Gets10_LargePoolables()
  -        throws Exception
  -    {
  -        String name = "VariableSizePool_And_ResourceLimitingPool_Max10_Gets10_LargePoolables";
  -        
  -        Class         poolableClass = LargePoolable.class;
  -        ObjectFactory factory = new ClassInstanceObjectFactory( poolableClass, m_poolLogger );
  -        int           min          = 0;
  -        int           max          = 10;
  -        boolean       maxStrict    = true;
  -        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, 10, factory );
  -    }
  -    
  +
       /*---------------------------------------------------------------
        * PoolComparisonProfileAbstract Methods
        *-------------------------------------------------------------*/
  @@ -329,7 +237,7 @@
       {
           // Start clean
           resetMemory();
  -        
  +
           final long startTime = System.currentTimeMillis();
           final Poolable[] poolTmp = new Poolable[gets];
           final int loops = TEST_SIZE / gets;
  @@ -340,7 +248,7 @@
               {
                   poolTmp[j] = pool.get();
               }
  -            
  +
               // Put the Poolables back
               for ( int j = 0; j < gets; j++ )
               {
  @@ -349,12 +257,12 @@
               }
           }
           final long duration = System.currentTimeMillis() - startTime;
  -        
  +
           // Dispose if necessary
           if ( pool instanceof Disposable ) {
               ((Disposable)pool).dispose();
           }
  -        
  +
           return duration;
       }
   }
  
  
  
  1.19      +2 -2      jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/AbstractContainer.java
  
  Index: AbstractContainer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/AbstractContainer.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- AbstractContainer.java	8 Feb 2002 18:09:41 -0000	1.18
  +++ AbstractContainer.java	12 Feb 2002 21:30:43 -0000	1.19
  @@ -18,7 +18,7 @@
   import org.apache.avalon.excalibur.system.handler.*;
   import org.apache.avalon.excalibur.logger.LoggerManager;
   import org.apache.avalon.excalibur.event.Queue;
  -import org.apache.avalon.excalibur.pool.PoolManager;
  +import org.apache.avalon.excalibur.mpool.PoolManager;
   
   import java.util.ArrayList;
   import java.util.Collections;
  @@ -35,7 +35,7 @@
    * Manager can expose that to the instantiating class.
    *
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  - * @version CVS $Revision: 1.18 $ $Date: 2002/02/08 18:09:41 $
  + * @version CVS $Revision: 1.19 $ $Date: 2002/02/12 21:30:43 $
    */
   public abstract class AbstractContainer
      extends AbstractLogEnabled
  
  
  
  1.22      +2 -2      jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/ContainerManager.java
  
  Index: ContainerManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/ContainerManager.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- ContainerManager.java	11 Feb 2002 21:51:12 -0000	1.21
  +++ ContainerManager.java	12 Feb 2002 21:30:43 -0000	1.22
  @@ -20,7 +20,7 @@
   import org.apache.avalon.excalibur.util.SystemUtil;
   import org.apache.avalon.excalibur.source.*;
   import org.apache.avalon.excalibur.command.*;
  -import org.apache.avalon.excalibur.pool.*;
  +import org.apache.avalon.excalibur.mpool.*;
   
   import java.io.File;
   
  @@ -109,7 +109,7 @@
    * </table>
    *
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  - * @version CVS $Revision: 1.21 $ $Date: 2002/02/11 21:51:12 $
  + * @version CVS $Revision: 1.22 $ $Date: 2002/02/12 21:30:43 $
    */
   public class ContainerManager implements Disposable
   {
  
  
  
  1.2       +16 -9     jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/handler/ComponentFactory.java
  
  Index: ComponentFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/handler/ComponentFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ComponentFactory.java	28 Jan 2002 20:54:01 -0000	1.1
  +++ ComponentFactory.java	12 Feb 2002 21:30:43 -0000	1.2
  @@ -22,7 +22,7 @@
   import org.apache.avalon.framework.logger.Logger;
   import org.apache.avalon.framework.logger.LogEnabled;
   import org.apache.avalon.framework.thread.ThreadSafe;
  -import org.apache.avalon.excalibur.pool.ObjectFactory;
  +import org.apache.avalon.excalibur.mpool.ObjectFactory;
   import org.apache.avalon.excalibur.logger.LoggerManager;
   
   /**
  @@ -30,7 +30,7 @@
    *
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
    * @author <a href="mailto:paul@luminas.co.uk">Paul Russell</a>
  - * @version CVS $Revision: 1.1 $ $Date: 2002/01/28 20:54:01 $
  + * @version CVS $Revision: 1.2 $ $Date: 2002/02/12 21:30:43 $
    * @since 4.0
    */
   public class ComponentFactory
  @@ -155,23 +155,30 @@
           return m_componentClass;
       }
   
  -    public final void decommission( final Object component )
  +    public final void dispose( final Object component )
           throws Exception
       {
           if (m_logger.isDebugEnabled())
           {
               m_logger.debug( "ComponentFactory decommissioning instance of " +
  -                               m_componentClass.getName() + "." );
  +                               getCreatedClass().getName() + "." );
           }
   
  -        if( component instanceof Startable )
  +        if ( getCreatedClass().equals( component.getClass() ) )
           {
  -            ((Startable)component).stop();
  -        }
  +            if( component instanceof Startable )
  +            {
  +                ((Startable)component).stop();
  +            }
   
  -        if( component instanceof Disposable )
  +            if( component instanceof Disposable )
  +            {
  +                ((Disposable)component).dispose();
  +            }
  +        }
  +        else
           {
  -            ((Disposable)component).dispose();
  +            throw new IllegalArgumentException("The object given to be disposed does not come from this ObjectFactory");
           }
       }
   }
  
  
  
  1.5       +2 -2      jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/handler/FactoryComponentHandler.java
  
  Index: FactoryComponentHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/handler/FactoryComponentHandler.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- FactoryComponentHandler.java	7 Feb 2002 21:58:19 -0000	1.4
  +++ FactoryComponentHandler.java	12 Feb 2002 21:30:43 -0000	1.5
  @@ -23,7 +23,7 @@
    * and destroyed correctly.
    *
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  - * @version CVS $Revision: 1.4 $ $Date: 2002/02/07 21:58:19 $
  + * @version CVS $Revision: 1.5 $ $Date: 2002/02/12 21:30:43 $
    * @since 4.0
    */
   public final class FactoryComponentHandler
  @@ -112,7 +112,7 @@
   
           try
           {
  -            m_factory.decommission( component );
  +            m_factory.dispose( component );
           }
           catch( final Exception e )
           {
  
  
  
  1.5       +2 -2      jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/handler/PerThreadComponentHandler.java
  
  Index: PerThreadComponentHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/handler/PerThreadComponentHandler.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- PerThreadComponentHandler.java	7 Feb 2002 21:58:19 -0000	1.4
  +++ PerThreadComponentHandler.java	12 Feb 2002 21:30:43 -0000	1.5
  @@ -23,7 +23,7 @@
    * and destroyed correctly.
    *
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  - * @version CVS $Revision: 1.4 $ $Date: 2002/02/07 21:58:19 $
  + * @version CVS $Revision: 1.5 $ $Date: 2002/02/12 21:30:43 $
    * @since 4.0
    */
   public final class PerThreadComponentHandler implements ComponentHandler {
  @@ -119,7 +119,7 @@
       public void dispose()
       {
           try {
  -            m_factory.decommission( m_instance.getComponent() );
  +            m_factory.dispose( m_instance.getComponent() );
   
               m_instance = null;
           }
  
  
  
  1.5       +7 -8      jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/handler/PoolableComponentHandler.java
  
  Index: PoolableComponentHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/handler/PoolableComponentHandler.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- PoolableComponentHandler.java	7 Feb 2002 21:58:19 -0000	1.4
  +++ PoolableComponentHandler.java	12 Feb 2002 21:30:43 -0000	1.5
  @@ -14,9 +14,8 @@
   import org.apache.avalon.framework.component.ComponentManager;
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.context.Context;
  -import org.apache.avalon.excalibur.pool.Pool;
  -import org.apache.avalon.excalibur.pool.Poolable;
  -import org.apache.avalon.excalibur.pool.PoolManager;
  +import org.apache.avalon.excalibur.mpool.Pool;
  +import org.apache.avalon.excalibur.mpool.PoolManager;
   import org.apache.avalon.excalibur.logger.LoggerManager;
   import org.apache.avalon.framework.logger.Logger;
   import org.apache.log.Hierarchy;
  @@ -26,15 +25,15 @@
    * and destroyed correctly.
    *
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  - * @version CVS $Revision: 1.4 $ $Date: 2002/02/07 21:58:19 $
  + * @version CVS $Revision: 1.5 $ $Date: 2002/02/12 21:30:43 $
    * @since 4.0
    */
   public final class PoolableComponentHandler implements ComponentHandler {
       /** The instance of the ComponentFactory that creates and disposes of the Component */
  -    private final ComponentFactory    m_factory;
  +    private final ComponentFactory     m_factory;
   
       /** The pool of components for <code>Poolable</code> Components */
  -    private final Pool                m_pool;
  +    private final Pool                 m_pool;
   
       /** State management boolean stating whether the Handler is initialized or not */
       private boolean                    m_initialized   = false;
  @@ -109,7 +108,7 @@
                                                "a disposed holder" );
           }
   
  -        return (Component)m_pool.get();
  +        return (Component)m_pool.acquire();
       }
   
       /**
  @@ -123,7 +122,7 @@
                                                "an uninitialized holder." );
           }
   
  -        m_pool.put( (Poolable)component );
  +        m_pool.release( component );
       }
   
       /**
  
  
  
  1.5       +2 -2      jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/handler/ThreadSafeComponentHandler.java
  
  Index: ThreadSafeComponentHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/handler/ThreadSafeComponentHandler.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ThreadSafeComponentHandler.java	7 Feb 2002 21:58:19 -0000	1.4
  +++ ThreadSafeComponentHandler.java	12 Feb 2002 21:30:43 -0000	1.5
  @@ -23,7 +23,7 @@
    * and destroyed correctly.
    *
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  - * @version CVS $Revision: 1.4 $ $Date: 2002/02/07 21:58:19 $
  + * @version CVS $Revision: 1.5 $ $Date: 2002/02/12 21:30:43 $
    * @since 4.0
    */
   public final class ThreadSafeComponentHandler implements ComponentHandler {
  @@ -125,7 +125,7 @@
           try {
               if( null != m_factory )
               {
  -                m_factory.decommission( m_instance );
  +                m_factory.dispose( m_instance );
               }
               else
               {
  
  
  

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