You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by le...@apache.org on 2002/02/18 11:14:17 UTC

cvs commit: jakarta-avalon-excalibur/src/test/org/apache/avalon/excalibur/component/test PoolableComponentHandlerTestCase.java PoolableComponentHandlerTestCase.xtest PoolableTestObject.java

leif        02/02/18 02:14:17

  Added:       src/test/org/apache/avalon/excalibur/component/test
                        PoolableComponentHandlerTestCase.java
                        PoolableComponentHandlerTestCase.xtest
                        PoolableTestObject.java
  Log:
  Modified PoolableComponentHandler to make use of the
  ResourceLimitingPool.
  
  Revision  Changes    Path
  1.1                  jakarta-avalon-excalibur/src/test/org/apache/avalon/excalibur/component/test/PoolableComponentHandlerTestCase.java
  
  Index: PoolableComponentHandlerTestCase.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.component.test;
  
  import org.apache.avalon.excalibur.component.PoolableComponentHandler;
  import org.apache.avalon.excalibur.testcase.BufferedLogger;
  import org.apache.avalon.excalibur.testcase.ExcaliburTestCase;
  
  import org.apache.avalon.framework.component.ComponentSelector;
  
  /**
   * Test the PoolableComponentHandler.
   *
   * @author <a href="mailto:leif@silveregg.co.jp">Leif Mortenson</a>
   */
  public class PoolableComponentHandlerTestCase
      extends ExcaliburTestCase
  {
      private Exception m_exception;
      
      /*---------------------------------------------------------------
       * Constructors
       *-------------------------------------------------------------*/
      public PoolableComponentHandlerTestCase( String name )
      {
          super(name);
          
          // Set the priority for default log output.
          m_logPriority = org.apache.log.Priority.INFO;
      }
      
      /*---------------------------------------------------------------
       * TestCase Methods
       *-------------------------------------------------------------*/
      public void setUp() throws Exception {
          super.setUp();
      }	
      
      public void tearDown() throws Exception {
          super.tearDown();
      }
      
      /*---------------------------------------------------------------
       * Test Cases
       *-------------------------------------------------------------*/
      /**
       * Test the default values and make sure that objects are reused as expected.
       */
      public void testDefaults() throws Exception
      {
          String name = "testDefaults";
          getLogger().info("Test: " + name);
          
          int size = PoolableComponentHandler.DEFAULT_MAX_POOL_SIZE + 2;
          
          BufferedLogger logger = new BufferedLogger();
          PoolableTestObject.setStaticLoggger( logger );
          PoolableTestObject.resetInstanceCounter();
          
          PoolableTestObject[] poolables = new PoolableTestObject[size];
          
          // Lookup the components.
          for (int i = 0; i < size; i++)
          {
              poolables[i] =
                  (PoolableTestObject)manager.lookup( PoolableTestObject.ROLE + "_" + name );
          }
          
          // Release the components.
          for (int i = 0; i < size; i++)
          {
              manager.release( poolables[i] );
              poolables[i] = null;
          }
          
          // Lookup the components.
          for (int i = 0; i < size; i++)
          {
              poolables[i] =
                  (PoolableTestObject)manager.lookup( PoolableTestObject.ROLE + "_" + name );
          }
          
          // Release the components.
          for (int i = 0; i < size; i++)
          {
              manager.release( poolables[i] );
              poolables[i] = null;
          }
          
          // The disposal of the objects will not show up in the log until the component manager is
          //  actually disposed.
          // When objects are returned the pool, they are stored in a last in first off list.
          String resultLog = logger.toString();
          String expectedLog =
              "DEBUG - PoolableTestObject #1 initialized.\n" +
              "DEBUG - PoolableTestObject #2 initialized.\n" +
              "DEBUG - PoolableTestObject #3 initialized.\n" +
              "DEBUG - PoolableTestObject #4 initialized.\n" +
              "DEBUG - PoolableTestObject #5 initialized.\n" +
              "DEBUG - PoolableTestObject #6 initialized.\n" +
              "DEBUG - PoolableTestObject #7 initialized.\n" +
              "DEBUG - PoolableTestObject #8 initialized.\n" +
              "DEBUG - PoolableTestObject #9 initialized.\n" +
              "DEBUG - PoolableTestObject #10 initialized.\n" +
              "DEBUG - PoolableTestObject #1 recycled.\n" +
              "DEBUG - PoolableTestObject #1 disposed.\n" +      // Still 9 outstanding
              "DEBUG - PoolableTestObject #2 recycled.\n" +
              "DEBUG - PoolableTestObject #2 disposed.\n" +      // Still 8 outstanding
              "DEBUG - PoolableTestObject #3 recycled.\n" +
              "DEBUG - PoolableTestObject #4 recycled.\n" +
              "DEBUG - PoolableTestObject #5 recycled.\n" +
              "DEBUG - PoolableTestObject #6 recycled.\n" +
              "DEBUG - PoolableTestObject #7 recycled.\n" +
              "DEBUG - PoolableTestObject #8 recycled.\n" +
              "DEBUG - PoolableTestObject #9 recycled.\n" +
              "DEBUG - PoolableTestObject #10 recycled.\n" +
              "DEBUG - PoolableTestObject #11 initialized.\n" +
              "DEBUG - PoolableTestObject #12 initialized.\n" +
              "DEBUG - PoolableTestObject #10 recycled.\n" +     // Gets are in LIFO order.
              "DEBUG - PoolableTestObject #10 disposed.\n" +     // Still 9 outstanding
              "DEBUG - PoolableTestObject #9 recycled.\n" +
              "DEBUG - PoolableTestObject #9 disposed.\n" +      // Still 8 outstanding
              "DEBUG - PoolableTestObject #8 recycled.\n" +
              "DEBUG - PoolableTestObject #7 recycled.\n" +
              "DEBUG - PoolableTestObject #6 recycled.\n" +
              "DEBUG - PoolableTestObject #5 recycled.\n" +
              "DEBUG - PoolableTestObject #4 recycled.\n" +
              "DEBUG - PoolableTestObject #3 recycled.\n" +
              "DEBUG - PoolableTestObject #11 recycled.\n" +
              "DEBUG - PoolableTestObject #12 recycled.\n";
          
          assertEquals( "Log did not contain the expected output.", resultLog, expectedLog );
      }
      
      /**
       * Test a non-default max value.
       */
      public void testMax4() throws Exception
      {
          String name = "testMax4";
          getLogger().info("Test: " + name);
          
          int size = 4 + 1;
          
          BufferedLogger logger = new BufferedLogger();
          PoolableTestObject.setStaticLoggger( logger );
          PoolableTestObject.resetInstanceCounter();
          
          PoolableTestObject[] poolables = new PoolableTestObject[size];
          
          // Lookup the components.
          for (int i = 0; i < size; i++)
          {
              poolables[i] =
                  (PoolableTestObject)manager.lookup( PoolableTestObject.ROLE + "_" + name );
          }
          
          // Release the components.
          for (int i = 0; i < size; i++)
          {
              manager.release( poolables[i] );
              poolables[i] = null;
          }
          
          // Lookup the components.
          for (int i = 0; i < size; i++)
          {
              poolables[i] =
                  (PoolableTestObject)manager.lookup( PoolableTestObject.ROLE + "_" + name );
          }
          
          // Release the components.
          for (int i = 0; i < size; i++)
          {
              manager.release( poolables[i] );
              poolables[i] = null;
          }
          
          // The disposal of the objects will not show up in the log until the component manager is
          //  actually disposed.
          String resultLog = logger.toString();
          String expectedLog =
              "DEBUG - PoolableTestObject #1 initialized.\n" +
              "DEBUG - PoolableTestObject #2 initialized.\n" +
              "DEBUG - PoolableTestObject #3 initialized.\n" +
              "DEBUG - PoolableTestObject #4 initialized.\n" +
              "DEBUG - PoolableTestObject #5 initialized.\n" +
              "DEBUG - PoolableTestObject #1 recycled.\n" +
              "DEBUG - PoolableTestObject #1 disposed.\n" +      // Still 4 outstanding
              "DEBUG - PoolableTestObject #2 recycled.\n" +
              "DEBUG - PoolableTestObject #3 recycled.\n" +
              "DEBUG - PoolableTestObject #4 recycled.\n" +
              "DEBUG - PoolableTestObject #5 recycled.\n" +
              "DEBUG - PoolableTestObject #6 initialized.\n" +
              "DEBUG - PoolableTestObject #5 recycled.\n" +      // Gets are in LIFO order.
              "DEBUG - PoolableTestObject #5 disposed.\n" +      // Still 4 outstanding
              "DEBUG - PoolableTestObject #4 recycled.\n" +
              "DEBUG - PoolableTestObject #3 recycled.\n" +
              "DEBUG - PoolableTestObject #2 recycled.\n" +
              "DEBUG - PoolableTestObject #6 recycled.\n";
          
          assertEquals( "Log did not contain the expected output.", resultLog, expectedLog );
      }
      
      /**
       * Test a non-default max value with a strict max and no blocking
       */
      public void testMax4StrictNoBlocking() throws Exception
      {
          String name = "testMax4StrictNoBlocking";
          getLogger().info("Test: " + name);
          
          int size = 4;
          
          BufferedLogger logger = new BufferedLogger();
          PoolableTestObject.setStaticLoggger( logger );
          PoolableTestObject.resetInstanceCounter();
          
          PoolableTestObject[] poolables = new PoolableTestObject[size];
          
          // Lookup the components.
          for (int i = 0; i < size; i++)
          {
              poolables[i] =
                  (PoolableTestObject)manager.lookup( PoolableTestObject.ROLE + "_" + name );
          }
          
          // Try to get one more.  Should fail.
          try
          {
              manager.lookup( PoolableTestObject.ROLE + "_" + name );
              fail( "Attempt to get more Pollables than are in the pool should have failed." );
          } catch ( Exception e )
          {
              // Passed
          }
          
          // Release the components.
          for (int i = 0; i < size; i++)
          {
              manager.release( poolables[i] );
              poolables[i] = null;
          }
          
          // The disposal of the objects will not show up in the log until the component manager is
          //  actually disposed.
          String resultLog = logger.toString();
          String expectedLog =
              "DEBUG - PoolableTestObject #1 initialized.\n" +
              "DEBUG - PoolableTestObject #2 initialized.\n" +
              "DEBUG - PoolableTestObject #3 initialized.\n" +
              "DEBUG - PoolableTestObject #4 initialized.\n" +
              "DEBUG - PoolableTestObject #1 recycled.\n" +
              "DEBUG - PoolableTestObject #2 recycled.\n" +
              "DEBUG - PoolableTestObject #3 recycled.\n" +
              "DEBUG - PoolableTestObject #4 recycled.\n";
          
          assertEquals( "Log did not contain the expected output.", resultLog, expectedLog );
      }
      
      /**
       * Test a non-default max value with a strict max and blocking with no timeout
       */
      public void testMax4StrictBlocking() throws Exception
      {
          final String name = "testMax4StrictBlocking";
          getLogger().info("Test: " + name);
          
          int size = 3;
          
          // Initialize the exception field.
          m_exception = null;
          
          final BufferedLogger logger = new BufferedLogger();
          PoolableTestObject.setStaticLoggger( logger );
          PoolableTestObject.resetInstanceCounter();
          
          PoolableTestObject[] poolables = new PoolableTestObject[size];
          
          // Lookup the components.
          for (int i = 0; i < size; i++)
          {
              poolables[i] =
                  (PoolableTestObject)manager.lookup( PoolableTestObject.ROLE + "_" + name );
          }
          
          // In another thread, get and release another poolable to cause this one to wait.
          new Thread() {
              public void run() {
                  try
                  {
                      logger.debug( "Lookup in second thread." );
                      PoolableTestObject poolable =
                          (PoolableTestObject)manager.lookup( PoolableTestObject.ROLE + "_" + name );
                      
                      // Give the main thread a chance to block
                      try
                      {
                          Thread.sleep( 500 );
                      }
                      catch ( InterruptedException e ) {}
                      
                      logger.debug( "Release in second thread." );
                      manager.release( poolable );
                  }
                  catch (Exception e)
                  {
                      m_exception = e;
                  }
              }
          }.start();
          
          // Give the second thread a chance to get the 4th poolable
          try
          {
              Thread.sleep( 250 );
          }
          catch ( InterruptedException e ) {}
                  
          // Try to get one more.  Should block until the other thread has put it back.
          logger.debug( "Lookup in main thread." );
          PoolableTestObject poolable =
              (PoolableTestObject)manager.lookup( PoolableTestObject.ROLE + "_" + name );
          
          logger.debug( "Release in main thread." );
          manager.release( poolable );
          
          // Release the components.
          for (int i = 0; i < size; i++)
          {
              manager.release( poolables[i] );
              poolables[i] = null;
          }
          
          // Make sure that the second thread did not throw an exception
          assert( "Unexpected exception in second thread.", m_exception == null );
          
          // The disposal of the objects will not show up in the log until the component manager is
          //  actually disposed.
          String resultLog = logger.toString();
          String expectedLog =
              "DEBUG - PoolableTestObject #1 initialized.\n" +
              "DEBUG - PoolableTestObject #2 initialized.\n" +
              "DEBUG - PoolableTestObject #3 initialized.\n" +
              "DEBUG - Lookup in second thread.\n" +
              "DEBUG - PoolableTestObject #4 initialized.\n" +
              "DEBUG - Lookup in main thread.\n" +
              "DEBUG - Release in second thread.\n" +
              "DEBUG - PoolableTestObject #4 recycled.\n" +
              "DEBUG - Release in main thread.\n" +
              "DEBUG - PoolableTestObject #4 recycled.\n" +
              "DEBUG - PoolableTestObject #1 recycled.\n" +
              "DEBUG - PoolableTestObject #2 recycled.\n" +
              "DEBUG - PoolableTestObject #3 recycled.\n";
          
          assertEquals( "Log did not contain the expected output.", resultLog, expectedLog );
      }
      
      /**
       * Test a non-default max value with a strict max and blocking with a timeout
       */
      public void testMax4StrictBlockingTimeout() throws Exception
      {
          String name = "testMax4StrictBlockingTimeout";
          getLogger().info("Test: " + name);
          
          int size = 4;
          
          BufferedLogger logger = new BufferedLogger();
          PoolableTestObject.setStaticLoggger( logger );
          PoolableTestObject.resetInstanceCounter();
          
          PoolableTestObject[] poolables = new PoolableTestObject[size];
          
          // Lookup the components.
          for (int i = 0; i < size; i++)
          {
              poolables[i] =
                  (PoolableTestObject)manager.lookup( PoolableTestObject.ROLE + "_" + name );
          }
          
          // Try to get one more.  Should fail after 500 milliseconds.
          long start = System.currentTimeMillis();
          try
          {
              manager.lookup( PoolableTestObject.ROLE + "_" + name );
              fail( "Attempt to get more Pollables than are in the pool should have failed." );
          } catch ( Exception e )
          {
              // Passed
          }
          long dur = System.currentTimeMillis() - start;
          assert( "Block timeout was not within 50 milliseconds of the configured 500 milliseconds,",
              dur >= 450 && dur <= 550 );
          
          // Release the components.
          for (int i = 0; i < size; i++)
          {
              manager.release( poolables[i] );
              poolables[i] = null;
          }
          
          // The disposal of the objects will not show up in the log until the component manager is
          //  actually disposed.
          String resultLog = logger.toString();
          String expectedLog =
              "DEBUG - PoolableTestObject #1 initialized.\n" +
              "DEBUG - PoolableTestObject #2 initialized.\n" +
              "DEBUG - PoolableTestObject #3 initialized.\n" +
              "DEBUG - PoolableTestObject #4 initialized.\n" +
              "DEBUG - PoolableTestObject #1 recycled.\n" +
              "DEBUG - PoolableTestObject #2 recycled.\n" +
              "DEBUG - PoolableTestObject #3 recycled.\n" +
              "DEBUG - PoolableTestObject #4 recycled.\n";
          
          assertEquals( "Log did not contain the expected output.", resultLog, expectedLog );
      }
      
      /**
       * Test the trimming features.
       */
      public void testTrimming() throws Exception
      {
          String name = "testTrimming";
          getLogger().info("Test: " + name);
          
          BufferedLogger logger = new BufferedLogger();
          PoolableTestObject.setStaticLoggger( logger );
          PoolableTestObject.resetInstanceCounter();
          
          PoolableTestObject[] poolables = new PoolableTestObject[4];
          
          // Lookup and release all 4 components a couple of times.
          for (int i = 0; i < 4; i++)
          {
              poolables[i] =
                  (PoolableTestObject)manager.lookup( PoolableTestObject.ROLE + "_" + name );
          }
          for (int i = 0; i < 4; i++)
          {
              manager.release( poolables[i] );
              poolables[i] = null;
          }
          for (int i = 0; i < 4; i++)
          {
              poolables[i] =
                  (PoolableTestObject)manager.lookup( PoolableTestObject.ROLE + "_" + name );
          }
          for (int i = 0; i < 4; i++)
          {
              manager.release( poolables[i] );
              poolables[i] = null;
          }
          
          // Now wait for 550 ms to trigger a trim on the next lookup.
          try
          {
              Thread.sleep( 550 );
          }
          catch ( InterruptedException e ) {}
          
          // Lookup and release 2 components to mark them as being recently used.
          for (int i = 0; i < 2; i++)
          {
              poolables[i] =
                  (PoolableTestObject)manager.lookup( PoolableTestObject.ROLE + "_" + name );
          }
          for (int i = 0; i < 2; i++)
          {
              manager.release( poolables[i] );
              poolables[i] = null;
          }
          
          // Now wait for 550 ms to trigger a trim on the next lookup.
          try
          {
              Thread.sleep( 550 );
          }
          catch ( InterruptedException e ) {}
          
          // This next get should cause 2 of the components to be trimmed but the 2 we just lookedup
          //  should stay around.
          // Lookup and release all 4 components to see which ones are left.
          for (int i = 0; i < 4; i++)
          {
              poolables[i] =
                  (PoolableTestObject)manager.lookup( PoolableTestObject.ROLE + "_" + name );
          }
          for (int i = 0; i < 4; i++)
          {
              manager.release( poolables[i] );
              poolables[i] = null;
          }
          
          
          // The disposal of the objects will not show up in the log until the component manager is
          //  actually disposed.
          String resultLog = logger.toString();
          String expectedLog =
              "DEBUG - PoolableTestObject #1 initialized.\n" + // First 4 lookups
              "DEBUG - PoolableTestObject #2 initialized.\n" +
              "DEBUG - PoolableTestObject #3 initialized.\n" +
              "DEBUG - PoolableTestObject #4 initialized.\n" +
              "DEBUG - PoolableTestObject #1 recycled.\n" + // First 4 releases
              "DEBUG - PoolableTestObject #2 recycled.\n" +
              "DEBUG - PoolableTestObject #3 recycled.\n" +
              "DEBUG - PoolableTestObject #4 recycled.\n" +
              "DEBUG - PoolableTestObject #4 recycled.\n" + // Second 4 releases already existed.
              "DEBUG - PoolableTestObject #3 recycled.\n" +
              "DEBUG - PoolableTestObject #2 recycled.\n" +
              "DEBUG - PoolableTestObject #1 recycled.\n" +
              "DEBUG - PoolableTestObject #1 recycled.\n" + // 2 lookups after wait.
              "DEBUG - PoolableTestObject #2 recycled.\n" +
              "DEBUG - PoolableTestObject #4 disposed.\n" + // First lookup after second wait triggers disposal of 2 old Poolables.
              "DEBUG - PoolableTestObject #3 disposed.\n" +
              "DEBUG - PoolableTestObject #5 initialized.\n" + // 4 lookups requred 2 more instances.
              "DEBUG - PoolableTestObject #6 initialized.\n" +
              "DEBUG - PoolableTestObject #2 recycled.\n" + // Final 4 releases
              "DEBUG - PoolableTestObject #1 recycled.\n" +
              "DEBUG - PoolableTestObject #5 recycled.\n" +
              "DEBUG - PoolableTestObject #6 recycled.\n";
          
          assertEquals( "Log did not contain the expected output.", resultLog, expectedLog );
      }
  }
  
  
  
  
  1.1                  jakarta-avalon-excalibur/src/test/org/apache/avalon/excalibur/component/test/PoolableComponentHandlerTestCase.xtest
  
  Index: PoolableComponentHandlerTestCase.xtest
  ===================================================================
  <testcase>
      <annotation>
          <![CDATA[
          <title>PoolableComponentHandler Tests</title>
          <para>
          This series of tests excersizes the PoolableComponentHandler provided by Excalibur.
          The configuration is specified in the file located in
          <parameter>jakarta-avalon-excalibur/src/test/org/apache/avalon/excalibur/component/test/PoolableComponentHandlerTestCase.xtext</parameter>.
          </para>
          ]]>
      </annotation>
      
      <!-- =================================================================== -->
      <!-- LogKit Configuration.                                               -->
      <!-- =================================================================== -->
      <logkit>
          <factories>
              <factory type="stream" 
                  class="org.apache.avalon.excalibur.logger.factory.StreamTargetFactory"/>
              <factory type="file" class="org.apache.avalon.excalibur.logger.factory.FileTargetFactory"/>
          </factories>
          
          <targets>
              <stream id="console">
                  <stream>System.out</stream>
                  <format type="avalon">
                      %7.7{priority} %5.5{time}   [%8.8{category}] (%{context}): %{message}\n%{throwable}
                  </format>
              </stream>
              
              <file id="testDefaults">
                  <filename>TEST-org.apache.avalon.excalibur.datasource.ids.test.TableIdGeneratorJdbcTestCase.log</filename>
                  <format type="extended">
                      %7.7{priority} %5.5{time}   [%8.8{category}] (%{context}): %{message}\n%{throwable}
                  </format>
              </file>
          </targets>
          
          <categories>
              <category name="testDefaults" log-level="DEBUG">
                  <log-target id-ref="console"/>
                  <log-target id-ref="testDefaults"/>
              </category>
          </categories>
      </logkit>
      
      <!-- =================================================================== -->
      <!-- Roles Configuration.                                                -->
      <!-- =================================================================== -->
      <roles>
          <role name="org.apache.avalon.excalibur.component.test.PoolableTestObject_testDefaults"
              shorthand="testDefaults"
              default-class="org.apache.avalon.excalibur.component.test.PoolableTestObject"/>
              
          <role name="org.apache.avalon.excalibur.component.test.PoolableTestObject_testMax4"
              shorthand="testMax4"
              default-class="org.apache.avalon.excalibur.component.test.PoolableTestObject"/>
              
          <role name="org.apache.avalon.excalibur.component.test.PoolableTestObject_testMax4StrictNoBlocking"
              shorthand="testMax4StrictNoBlocking"
              default-class="org.apache.avalon.excalibur.component.test.PoolableTestObject"/>
              
          <role name="org.apache.avalon.excalibur.component.test.PoolableTestObject_testMax4StrictBlocking"
              shorthand="testMax4StrictBlocking"
              default-class="org.apache.avalon.excalibur.component.test.PoolableTestObject"/>
              
          <role name="org.apache.avalon.excalibur.component.test.PoolableTestObject_testMax4StrictBlockingTimeout"
              shorthand="testMax4StrictBlockingTimeout"
              default-class="org.apache.avalon.excalibur.component.test.PoolableTestObject"/>
              
          <role name="org.apache.avalon.excalibur.component.test.PoolableTestObject_testTrimming"
              shorthand="testTrimming"
              default-class="org.apache.avalon.excalibur.component.test.PoolableTestObject"/>
      </roles>
      
      <!-- =================================================================== -->
      <!-- Component Configuration.                                            -->
      <!-- =================================================================== -->
      <components>
          <testDefaults/>
          
          <testMax4 pool-max="4"/>
          
          <testMax4StrictNoBlocking pool-max="4" pool-max-strict="true" pool-blocking="false"/>
          
          <testMax4StrictBlocking pool-max="4" pool-max-strict="true"/>
          
          <testMax4StrictBlockingTimeout pool-max="4" pool-max-strict="true" pool-timeout="500"/>
          
          <testTrimming pool-trim-interval="500"/>
      </components>
  </testcase>
  
  
  
  1.1                  jakarta-avalon-excalibur/src/test/org/apache/avalon/excalibur/component/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.component.test;
  
  import org.apache.avalon.excalibur.pool.Poolable;
  
  import org.apache.avalon.excalibur.pool.Recyclable;
  
  import org.apache.avalon.framework.activity.Initializable;
  import org.apache.avalon.framework.activity.Disposable;
  import org.apache.avalon.framework.component.Component;
  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/18 10:14:17 $
   */
  public class PoolableTestObject
      implements Component, Initializable, Recyclable, Disposable, Poolable
  {
      public static final String ROLE = PoolableTestObject.class.getName();
      
      /** Semaphore used to synchronize access to m_instanceCounter */
      private static Object m_semaphore = new Object();
      
      /** Number of instances created since the last call to resetInstanceCounter() */
      private static int m_instanceCounter = 0;
      
      private static Logger m_logger;
      
      /** Instance Id */
      private int m_instanceId;
      
      /*---------------------------------------------------------------
       * Constructors
       *-------------------------------------------------------------*/
      public PoolableTestObject()
      {
          synchronized(m_semaphore)
          {
              m_instanceCounter++;
              m_instanceId = m_instanceCounter;
          }
      }
      
      /*---------------------------------------------------------------
       * Static Methods
       *-------------------------------------------------------------*/
      /**
       * Resets the instance counter so that the next Poolable will get an instance Id of 1.
       */
      public static void resetInstanceCounter()
      {
          synchronized(m_semaphore)
          {
              m_instanceCounter = 0;
          }
      }
      
      /**
       * Used by tests to change the current logger object.
       */
      public static void setStaticLoggger( Logger logger )
      {
          m_logger = logger;
      }
      
      /*---------------------------------------------------------------
       * Initializable Methods
       *-------------------------------------------------------------*/
      /**
       * Called by the Container to initialize the component.
       */
      public void initialize() {
          m_logger.debug("PoolableTestObject #" + m_instanceId + " initialized.");
      }
      
      /*---------------------------------------------------------------
       * Recyclable Methods
       *-------------------------------------------------------------*/
      /**
       * Called by the Container when the component is recycled.
       */
      public void recycle() {
          m_logger.debug("PoolableTestObject #" + m_instanceId + " recycled.");
      }
      
      /*---------------------------------------------------------------
       * Disposable Methods
       *-------------------------------------------------------------*/
      /**
       * Called by the Container to dispose the component.
       */
      public void dispose() {
          m_logger.debug("PoolableTestObject #" + m_instanceId + " disposed.");
      }
  }
  
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>