avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcconn...@apache.org
Subject cvs commit: avalon-excalibur/thread/instrumented/src/test/org/apache/avalon/excalibur/thread/impl/test DefaultThreadPoolTestCase.java ResourceLimitingThreadPoolTestCase.java
Date Mon, 29 Mar 2004 17:22:50 GMT
mcconnell    2004/03/29 09:22:49

  Modified:    thread/api/src/java/org/apache/excalibur/thread
                        ThreadControl.java
               thread/impl/src/java/org/apache/avalon/excalibur/thread/impl
                        BasicThreadPool.java DefaultThreadPool.java
                        ExecutableExecuteable.java
                        ResourceLimitingThreadPool.java
                        SimpleWorkerThread.java
               thread/impl/src/test/org/apache/avalon/excalibur/thread/impl/test
                        DefaultThreadPoolTestCase.java
                        ResourceLimitingThreadPoolTestCase.java
  Added:       thread/impl/src/test/org/apache/avalon/excalibur/thread/impl/test
                        BufferedLogger.java
               thread/instrumented/src/java/org/apache/avalon/excalibur/thread/impl
                        InstrumentedResourceLimitingThreadPool.java
  Removed:     thread/impl/src/java/org/apache/avalon/excalibur/thread/impl
                        WrappedThreadControl.java
               thread/instrumented/src/java/org/apache/avalon/excalibur/thread/impl
                        BasicThreadPool.java DefaultThreadPool.java
                        ExecutableExecuteable.java
                        ResourceLimitingThreadPool.java
                        SimpleWorkerThread.java WrappedThreadControl.java
               thread/api/src/java/org/apache/avalon/excalibur/thread
                        ThreadControl.java ThreadPool.java
               thread/api/src/java/org/apache/avalon/excalibur/thread/impl
                        BasicThreadPool.java DefaultThreadPool.java
                        ExecutableExecuteable.java
                        ResourceLimitingThreadPool.java
                        SimpleWorkerThread.java WrappedThreadControl.java
               thread/api/src/java/org/apache/excalibur/thread/impl
                        AbstractThreadPool.java DefaultThreadControl.java
                        ExecutableRunnable.java WorkerThread.java
               thread/api/src/test/org/apache/avalon/excalibur/thread/impl/test
                        DefaultThreadPoolTestCase.java
                        ResourceLimitingThreadPoolTestCase.java
               thread/impl/src/java/org/apache/avalon/excalibur/thread
                        ThreadControl.java ThreadPool.java
               thread/impl/src/java/org/apache/excalibur/thread
                        Executable.java ThreadControl.java ThreadPool.java
               thread/instrumented/src/java/org/apache/avalon/excalibur/thread
                        ThreadControl.java ThreadPool.java
               thread/instrumented/src/java/org/apache/excalibur/thread
                        Executable.java ThreadControl.java ThreadPool.java
               thread/instrumented/src/java/org/apache/excalibur/thread/impl
                        AbstractThreadPool.java DefaultThreadControl.java
                        ExecutableRunnable.java WorkerThread.java
               thread/instrumented/src/test/org/apache/avalon/excalibur/thread/impl/test
                        DefaultThreadPoolTestCase.java
                        ResourceLimitingThreadPoolTestCase.java
  Log:
  Execute the api impl seperation with full history.
  
  Revision  Changes    Path
  1.6       +0 -1      avalon-excalibur/thread/api/src/java/org/apache/excalibur/thread/ThreadControl.java
  
  Index: ThreadControl.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/thread/api/src/java/org/apache/excalibur/thread/ThreadControl.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ThreadControl.java	28 Feb 2004 11:47:34 -0000	1.5
  +++ ThreadControl.java	29 Mar 2004 17:22:49 -0000	1.6
  @@ -22,7 +22,6 @@
    * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
    */
   public interface ThreadControl
  -    extends org.apache.avalon.excalibur.thread.ThreadControl
   {
       /**
        * Wait for specified time for thread to complete it's work.
  
  
  
  1.6       +3 -2      avalon-excalibur/thread/impl/src/java/org/apache/avalon/excalibur/thread/impl/BasicThreadPool.java
  
  Index: BasicThreadPool.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/thread/impl/src/java/org/apache/avalon/excalibur/thread/impl/BasicThreadPool.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- BasicThreadPool.java	28 Feb 2004 11:47:19 -0000	1.5
  +++ BasicThreadPool.java	29 Mar 2004 17:22:49 -0000	1.6
  @@ -18,12 +18,14 @@
   
   import org.apache.avalon.excalibur.pool.ObjectFactory;
   import org.apache.avalon.excalibur.pool.Pool;
  -import org.apache.avalon.excalibur.thread.ThreadPool;
  +
   import org.apache.avalon.framework.activity.Disposable;
   import org.apache.avalon.framework.activity.Executable;
   import org.apache.avalon.framework.container.ContainerUtil;
   import org.apache.avalon.framework.logger.LogEnabled;
   import org.apache.avalon.framework.logger.Logger;
  +
  +import org.apache.excalibur.thread.ThreadPool;
   import org.apache.excalibur.thread.ThreadControl;
   import org.apache.excalibur.thread.impl.AbstractThreadPool;
   import org.apache.excalibur.thread.impl.WorkerThread;
  @@ -32,7 +34,6 @@
    * The ThreadPool that binds to Legacy Pooling implementation.
    *
    * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
  - * @deprecated Only used by deprecated components. Will remove in the future
    */
   class BasicThreadPool
       extends AbstractThreadPool
  
  
  
  1.6       +5 -10     avalon-excalibur/thread/impl/src/java/org/apache/avalon/excalibur/thread/impl/DefaultThreadPool.java
  
  Index: DefaultThreadPool.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/thread/impl/src/java/org/apache/avalon/excalibur/thread/impl/DefaultThreadPool.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DefaultThreadPool.java	28 Feb 2004 11:47:19 -0000	1.5
  +++ DefaultThreadPool.java	29 Mar 2004 17:22:49 -0000	1.6
  @@ -18,16 +18,16 @@
   
   import org.apache.avalon.excalibur.pool.ObjectFactory;
   import org.apache.avalon.excalibur.pool.SoftResourceLimitingPool;
  -import org.apache.avalon.excalibur.thread.ThreadPool;
  -import org.apache.excalibur.thread.ThreadControl;
  +
   import org.apache.avalon.framework.activity.Disposable;
   import org.apache.avalon.framework.activity.Executable;
   import org.apache.avalon.framework.container.ContainerUtil;
   import org.apache.avalon.framework.logger.LogEnabled;
  -import org.apache.avalon.framework.logger.LogKitLogger;
  -import org.apache.avalon.framework.logger.Loggable;
   import org.apache.avalon.framework.logger.Logger;
   
  +import org.apache.excalibur.thread.ThreadControl;
  +import org.apache.excalibur.thread.ThreadPool;
  +
   /**
    * This class is the public frontend for the thread pool code.
    *
  @@ -35,7 +35,7 @@
    */
   public class DefaultThreadPool
       extends ThreadGroup
  -    implements ObjectFactory, Loggable, LogEnabled, Disposable, ThreadPool
  +    implements ObjectFactory, LogEnabled, Disposable, ThreadPool
   {
       private final BasicThreadPool m_pool;
       private SoftResourceLimitingPool m_underlyingPool;
  @@ -63,11 +63,6 @@
           super( name );
           m_underlyingPool = new SoftResourceLimitingPool( this, min, max );
           m_pool = new BasicThreadPool( this, name, m_underlyingPool );
  -    }
  -
  -    public void setLogger( final org.apache.log.Logger logger )
  -    {
  -        enableLogging( new LogKitLogger( logger ) );
       }
   
       public void enableLogging( final Logger logger )
  
  
  
  1.6       +0 -1      avalon-excalibur/thread/impl/src/java/org/apache/avalon/excalibur/thread/impl/ExecutableExecuteable.java
  
  Index: ExecutableExecuteable.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/thread/impl/src/java/org/apache/avalon/excalibur/thread/impl/ExecutableExecuteable.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ExecutableExecuteable.java	28 Feb 2004 11:47:19 -0000	1.5
  +++ ExecutableExecuteable.java	29 Mar 2004 17:22:49 -0000	1.6
  @@ -23,7 +23,6 @@
    * an {@link Executable} object.
    *
    * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
  - * @deprecated Only Used by deprecated code and will be removed in future
    */
   final class ExecutableExecuteable
       implements Executable
  
  
  
  1.6       +7 -70     avalon-excalibur/thread/impl/src/java/org/apache/avalon/excalibur/thread/impl/ResourceLimitingThreadPool.java
  
  Index: ResourceLimitingThreadPool.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/thread/impl/src/java/org/apache/avalon/excalibur/thread/impl/ResourceLimitingThreadPool.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ResourceLimitingThreadPool.java	28 Feb 2004 11:47:19 -0000	1.5
  +++ ResourceLimitingThreadPool.java	29 Mar 2004 17:22:49 -0000	1.6
  @@ -18,17 +18,18 @@
   
   import org.apache.avalon.excalibur.pool.ObjectFactory;
   import org.apache.avalon.excalibur.pool.ResourceLimitingPool;
  -import org.apache.avalon.excalibur.thread.ThreadPool;
  +
   import org.apache.avalon.framework.activity.Disposable;
   import org.apache.avalon.framework.activity.Executable;
   import org.apache.avalon.framework.container.ContainerUtil;
   import org.apache.avalon.framework.logger.LogEnabled;
   import org.apache.avalon.framework.logger.Logger;
  -import org.apache.excalibur.instrument.Instrument;
  -import org.apache.excalibur.instrument.Instrumentable;
  +
   import org.apache.excalibur.thread.ThreadControl;
  +import org.apache.excalibur.thread.ThreadPool;
   
  -/**
  +/*
  +*
    * A Thread Pool which can be configured to have a hard limit on the maximum number of
threads
    *  which will be allocated.  This is very important for servers to avoid running out of
system
    *  resources.  The pool can be configured to block for a new thread or throw an exception.
  @@ -40,13 +41,10 @@
    */
   public class ResourceLimitingThreadPool
       extends ThreadGroup
  -    implements ObjectFactory, LogEnabled, Disposable, ThreadPool, Instrumentable
  +    implements ObjectFactory, LogEnabled, Disposable, ThreadPool
   {
       private ResourceLimitingPool m_underlyingPool;
   
  -    /** Instrumentable Name assigned to this Instrumentable */
  -    private String m_instrumentableName;
  -
       /**
        * The associated thread pool.
        */
  @@ -119,67 +117,6 @@
               final String message = "Unable to create ThreadPool due to " + e;
               throw new IllegalStateException( message );
           }
  -    }
  -
  -    /*---------------------------------------------------------------
  -     * Instrumentable Methods
  -     *-------------------------------------------------------------*/
  -    /**
  -     * Sets the name for the Instrumentable.  The Instrumentable Name is used
  -     *  to uniquely identify the Instrumentable during the configuration of
  -     *  the InstrumentManager and to gain access to an InstrumentableDescriptor
  -     *  through the InstrumentManager.  The value should be a string which does
  -     *  not contain spaces or periods.
  -     * <p>
  -     * This value may be set by a parent Instrumentable, or by the
  -     *  InstrumentManager using the value of the 'instrumentable' attribute in
  -     *  the configuration of the component.
  -     *
  -     * @param name The name used to identify a Instrumentable.
  -     */
  -    public void setInstrumentableName( String name )
  -    {
  -        m_instrumentableName = name;
  -    }
  -
  -    /**
  -     * Gets the name of the Instrumentable.
  -     *
  -     * @return The name used to identify a Instrumentable.
  -     */
  -    public String getInstrumentableName()
  -    {
  -        return m_instrumentableName;
  -    }
  -
  -    /**
  -     * Obtain a reference to all the Instruments that the Instrumentable object
  -     *  wishes to expose.  All sampling is done directly through the
  -     *  Instruments as opposed to the Instrumentable interface.
  -     *
  -     * @return An array of the Instruments available for profiling.  Should
  -     *         never be null.  If there are no Instruments, then
  -     *         EMPTY_INSTRUMENT_ARRAY can be returned.  This should never be
  -     *         the case though unless there are child Instrumentables with
  -     *         Instruments.
  -     */
  -    public Instrument[] getInstruments()
  -    {
  -        return Instrumentable.EMPTY_INSTRUMENT_ARRAY;
  -    }
  -
  -    /**
  -     * Any Object which implements Instrumentable can also make use of other
  -     *  Instrumentable child objects.  This method is used to tell the
  -     *  InstrumentManager about them.
  -     *
  -     * @return An array of child Instrumentables.  This method should never
  -     *         return null.  If there are no child Instrumentables, then
  -     *         EMPTY_INSTRUMENTABLE_ARRAY can be returned.
  -     */
  -    public Instrumentable[] getChildInstrumentables()
  -    {
  -        return new Instrumentable[]{m_underlyingPool};
       }
   
       /**
  
  
  
  1.6       +2 -1      avalon-excalibur/thread/impl/src/java/org/apache/avalon/excalibur/thread/impl/SimpleWorkerThread.java
  
  Index: SimpleWorkerThread.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/thread/impl/src/java/org/apache/avalon/excalibur/thread/impl/SimpleWorkerThread.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SimpleWorkerThread.java	28 Feb 2004 11:47:19 -0000	1.5
  +++ SimpleWorkerThread.java	29 Mar 2004 17:22:49 -0000	1.6
  @@ -17,8 +17,10 @@
   package org.apache.avalon.excalibur.thread.impl;
   
   import org.apache.avalon.excalibur.pool.Poolable;
  +
   import org.apache.avalon.framework.logger.LogEnabled;
   import org.apache.avalon.framework.logger.Logger;
  +
   import org.apache.excalibur.thread.impl.AbstractThreadPool;
   import org.apache.excalibur.thread.impl.WorkerThread;
   
  @@ -26,7 +28,6 @@
    * This class extends the Thread class to add recyclable functionalities.
    *
    * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
  - * @deprecated Only Used by deprecated code and will be removed in future
    */
   class SimpleWorkerThread
       extends WorkerThread
  
  
  
  1.5       +3 -3      avalon-excalibur/thread/impl/src/test/org/apache/avalon/excalibur/thread/impl/test/DefaultThreadPoolTestCase.java
  
  Index: DefaultThreadPoolTestCase.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/thread/impl/src/test/org/apache/avalon/excalibur/thread/impl/test/DefaultThreadPoolTestCase.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DefaultThreadPoolTestCase.java	28 Feb 2004 11:47:34 -0000	1.4
  +++ DefaultThreadPoolTestCase.java	29 Mar 2004 17:22:49 -0000	1.5
  @@ -1,5 +1,5 @@
   /* 
  - * Copyright 2002-2004 The Apache Software Foundation
  + * Copyright 2002-2004 Apache Software Foundation
    * Licensed  under the  Apache License,  Version 2.0  (the "License");
    * you may not use  this file  except in  compliance with the License.
    * You may obtain a copy of the License at 
  @@ -38,7 +38,7 @@
       {
           final DefaultThreadPool pool = new DefaultThreadPool( "default", 10 );
           pool.setDaemon( false );
  -        pool.enableLogging( new ConsoleLogger() );
  +        pool.enableLogging( new ConsoleLogger( ConsoleLogger.LEVEL_INFO ) );
           pool.execute( new DummyRunnable() );
       }
   
  @@ -47,7 +47,7 @@
       {
           final DefaultThreadPool pool = new DefaultThreadPool( "default", 10 );
           pool.setDaemon( false );
  -        pool.enableLogging( new ConsoleLogger() );
  +        pool.enableLogging( new ConsoleLogger( ConsoleLogger.LEVEL_INFO ) );
           pool.execute( new DummyRunnable() );
       }
   
  
  
  
  1.5       +2 -3      avalon-excalibur/thread/impl/src/test/org/apache/avalon/excalibur/thread/impl/test/ResourceLimitingThreadPoolTestCase.java
  
  Index: ResourceLimitingThreadPoolTestCase.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/thread/impl/src/test/org/apache/avalon/excalibur/thread/impl/test/ResourceLimitingThreadPoolTestCase.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ResourceLimitingThreadPoolTestCase.java	28 Feb 2004 11:47:34 -0000	1.4
  +++ ResourceLimitingThreadPoolTestCase.java	29 Mar 2004 17:22:49 -0000	1.5
  @@ -1,5 +1,5 @@
   /* 
  - * Copyright 2002-2004 The Apache Software Foundation
  + * Copyright 2002-2004 Apache Software Foundation
    * Licensed  under the  Apache License,  Version 2.0  (the "License");
    * you may not use  this file  except in  compliance with the License.
    * You may obtain a copy of the License at 
  @@ -18,7 +18,6 @@
   
   import junit.framework.TestCase;
   
  -import org.apache.avalon.excalibur.testcase.BufferedLogger;
   import org.apache.avalon.excalibur.thread.impl.ResourceLimitingThreadPool;
   
   /**
  
  
  
  1.1                  avalon-excalibur/thread/impl/src/test/org/apache/avalon/excalibur/thread/impl/test/BufferedLogger.java
  
  Index: BufferedLogger.java
  ===================================================================
  /* 
   * Copyright 2002-2004 Apache Software Foundation
   * Licensed  under the  Apache License,  Version 2.0  (the "License");
   * you may not use  this file  except in  compliance with the License.
   * You may obtain a copy of the License at 
   * 
   *   http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed  under the  License is distributed on an "AS IS" BASIS,
   * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
   * implied.
   * 
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.avalon.excalibur.thread.impl.test;
  
  import org.apache.avalon.framework.ExceptionUtil;
  import org.apache.avalon.framework.logger.Logger;
  
  /**
   * Simple Logger which logs all information to an internal StringBuffer.
   *  When logging is complete call toString() on the logger to obtain the
   *  logged output.  Useful for testing.
   *
   * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
   * @version CVS $Revision: 1.1 $ $Date: 2004/03/29 17:22:49 $
   * @since 4.0
   */
  public class BufferedLogger
      implements Logger
  {
      private final StringBuffer m_sb = new StringBuffer();
  
      /**
       * Log a debug message.
       *
       * @param message the message
       */
      public void debug( final String message )
      {
          debug( message, null );
      }
  
      /**
       * Log a debug message.
       *
       * @param message the message
       * @param throwable the throwable
       */
      public void debug( final String message, final Throwable throwable )
      {
          append( "DEBUG", message, throwable );
      }
  
      /**
       * Determine if messages of priority "debug" will be logged.
       *
       * @return true if "debug" messages will be logged
       */
      public boolean isDebugEnabled()
      {
          return true;
      }
  
      /**
       * Log a info message.
       *
       * @param message the message
       */
      public void info( final String message )
      {
          info( message, null );
      }
  
      /**
       * Log a info message.
       *
       * @param message the message
       * @param throwable the throwable
       */
      public void info( final String message, final Throwable throwable )
      {
          append( "INFO", message, throwable );
      }
  
      /**
       * Determine if messages of priority "info" will be logged.
       *
       * @return true if "info" messages will be logged
       */
      public boolean isInfoEnabled()
      {
          return true;
      }
  
      /**
       * Log a warn message.
       *
       * @param message the message
       */
      public void warn( final String message )
      {
          warn( message, null );
      }
  
      /**
       * Log a warn message.
       *
       * @param message the message
       * @param throwable the throwable
       */
      public void warn( final String message, final Throwable throwable )
      {
          append( "WARN", message, throwable );
      }
  
      /**
       * Determine if messages of priority "warn" will be logged.
       *
       * @return true if "warn" messages will be logged
       */
      public boolean isWarnEnabled()
      {
          return true;
      }
  
      /**
       * Log a error message.
       *
       * @param message the message
       */
      public void error( final String message )
      {
          error( message, null );
      }
  
      /**
       * Log a error message.
       *
       * @param message the message
       * @param throwable the throwable
       */
      public void error( final String message, final Throwable throwable )
      {
          append( "ERROR", message, throwable );
      }
  
      /**
       * Determine if messages of priority "error" will be logged.
       *
       * @return true if "error" messages will be logged
       */
      public boolean isErrorEnabled()
      {
          return true;
      }
  
      /**
       * Log a fatalError message.
       *
       * @param message the message
       */
      public void fatalError( final String message )
      {
          fatalError( message, null );
      }
  
      /**
       * Log a fatalError message.
       *
       * @param message the message
       * @param throwable the throwable
       */
      public void fatalError( final String message, final Throwable throwable )
      {
          append( "FATAL ERROR", message, throwable );
      }
  
      /**
       * Determine if messages of priority "fatalError" will be logged.
       *
       * @return true if "fatalError" messages will be logged
       */
      public boolean isFatalErrorEnabled()
      {
          return true;
      }
  
      /**
       * Create a new child logger.
       * The name of the child logger is [current-loggers-name].[passed-in-name]
       *
       * @param name the subname of this logger
       * @return the new logger
       */
      public Logger getChildLogger( final String name )
      {
          return this;
      }
  
      /**
       * Returns the contents of the buffer.
       *
       * @return the buffer contents
       *
       */
      public String toString()
      {
          return m_sb.toString();
      }
  
      private void append( final String level,
                           final String message,
                           final Throwable throwable )
      {
          synchronized( m_sb )
          {
              m_sb.append( level );
              m_sb.append( " - " );
              m_sb.append( message );
  
              if( null != throwable )
              {
                  final String stackTrace =
                      ExceptionUtil.printStackTrace( throwable );
                  m_sb.append( " : " );
                  m_sb.append( stackTrace );
              }
              m_sb.append( "\n" );
          }
      }
  }
  
  
  
  1.1                  avalon-excalibur/thread/instrumented/src/java/org/apache/avalon/excalibur/thread/impl/InstrumentedResourceLimitingThreadPool.java
  
  Index: InstrumentedResourceLimitingThreadPool.java
  ===================================================================
  /* 
   * Copyright 2002-2004 The Apache Software Foundation
   * Licensed  under the  Apache License,  Version 2.0  (the "License");
   * you may not use  this file  except in  compliance with the License.
   * You may obtain a copy of the License at 
   * 
   *   http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed  under the  License is distributed on an "AS IS" BASIS,
   * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
   * implied.
   * 
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.avalon.excalibur.thread.impl;
  
  import org.apache.avalon.excalibur.pool.ObjectFactory;
  import org.apache.avalon.excalibur.pool.InstrumentedResourceLimitingPool;
  
  import org.apache.avalon.framework.activity.Disposable;
  import org.apache.avalon.framework.activity.Executable;
  import org.apache.avalon.framework.container.ContainerUtil;
  import org.apache.avalon.framework.logger.LogEnabled;
  import org.apache.avalon.framework.logger.Logger;
  
  import org.apache.excalibur.instrument.Instrument;
  import org.apache.excalibur.instrument.Instrumentable;
  
  import org.apache.excalibur.thread.ThreadControl;
  import org.apache.excalibur.thread.ThreadPool;
  
  /**
   * A Thread Pool which can be configured to have a hard limit on the maximum number of threads
   *  which will be allocated.  This is very important for servers to avoid running out of
system
   *  resources.  The pool can be configured to block for a new thread or throw an exception.
   *  The maximum block time can also be set.
   *
   * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
   * @version CVS $Revision: 1.1 $ $Date: 2004/03/29 17:22:49 $
   * @since 4.1
   */
  public class InstrumentedResourceLimitingThreadPool
      extends ThreadGroup
      implements ObjectFactory, LogEnabled, Disposable, ThreadPool, Instrumentable
  {
      private InstrumentedResourceLimitingPool m_underlyingPool;
  
      /** Instrumentable Name assigned to this Instrumentable */
      private String m_instrumentableName;
  
      /**
       * The associated thread pool.
       */
      private BasicThreadPool m_pool;
  
      /*---------------------------------------------------------------
       * Constructors
       *-------------------------------------------------------------*/
  
      /**
       * Creates a new <code>ResourceLimitingThreadPool</code>.
       *
       * @param max Maximum number of Poolables which can be stored in the pool, 0 implies
no limit.
       */
      public InstrumentedResourceLimitingThreadPool( final int max )
      {
          this( "Worker Pool", max );
      }
  
      /**
       * Creates a new <code>ResourceLimitingThreadPool</code> with maxStrict
enabled,
       *  blocking enabled, no block timeout and a trim interval of 10 seconds.
       *
       * @param name Name which will used as the thread group name as well as the prefix of
the
       *  names of all threads created by the pool.
       * @param max Maximum number of WorkerThreads which can be stored in the pool,
       *  0 implies no limit.
       */
      public InstrumentedResourceLimitingThreadPool( final String name, final int max )
      {
          this( name, max, true, true, 0, 10000 );
      }
  
      /**
       * Creates a new <code>ResourceLimitingThreadPool</code>.
       *
       * @param name Name which will used as the thread group name as well as the prefix of
the
       *  names of all threads created by the pool.
       * @param max Maximum number of WorkerThreads which can be stored in the pool,
       *  0 implies no limit.
       * @param maxStrict true if the pool should never allow more than max WorkerThreads
to
       *  be created.  Will cause an exception to be thrown if more than max WorkerThreads
are
       *  requested and blocking is false.
       * @param blocking true if the pool should cause a thread calling get() to block when
       *  WorkerThreads are not currently available on the pool.
       * @param blockTimeout The maximum amount of time, in milliseconds, that a call to get()
will
       *  block before an exception is thrown.  A value of 0 implies an indefinate wait.
       * @param trimInterval The minimum interval with which old unused WorkerThreads will
be
       *  removed from the pool.  A value of 0 will cause the pool to never trim WorkerThreads.
       */
      public InstrumentedResourceLimitingThreadPool( final String name,
                                         final int max,
                                         final boolean maxStrict,
                                         final boolean blocking,
                                         final long blockTimeout,
                                         final long trimInterval )
      {
          super( name );
  
          m_underlyingPool =
              new InstrumentedResourceLimitingPool( this, max, maxStrict,
                                        blocking, blockTimeout,
                                        trimInterval );
          try
          {
              m_pool = new BasicThreadPool( this, name, m_underlyingPool );
          }
          catch( Exception e )
          {
              final String message = "Unable to create ThreadPool due to " + e;
              throw new IllegalStateException( message );
          }
      }
  
      /*---------------------------------------------------------------
       * Instrumentable Methods
       *-------------------------------------------------------------*/
      /**
       * Sets the name for the Instrumentable.  The Instrumentable Name is used
       *  to uniquely identify the Instrumentable during the configuration of
       *  the InstrumentManager and to gain access to an InstrumentableDescriptor
       *  through the InstrumentManager.  The value should be a string which does
       *  not contain spaces or periods.
       * <p>
       * This value may be set by a parent Instrumentable, or by the
       *  InstrumentManager using the value of the 'instrumentable' attribute in
       *  the configuration of the component.
       *
       * @param name The name used to identify a Instrumentable.
       */
      public void setInstrumentableName( String name )
      {
          m_instrumentableName = name;
      }
  
      /**
       * Gets the name of the Instrumentable.
       *
       * @return The name used to identify a Instrumentable.
       */
      public String getInstrumentableName()
      {
          return m_instrumentableName;
      }
  
      /**
       * Obtain a reference to all the Instruments that the Instrumentable object
       *  wishes to expose.  All sampling is done directly through the
       *  Instruments as opposed to the Instrumentable interface.
       *
       * @return An array of the Instruments available for profiling.  Should
       *         never be null.  If there are no Instruments, then
       *         EMPTY_INSTRUMENT_ARRAY can be returned.  This should never be
       *         the case though unless there are child Instrumentables with
       *         Instruments.
       */
      public Instrument[] getInstruments()
      {
          return Instrumentable.EMPTY_INSTRUMENT_ARRAY;
      }
  
      /**
       * Any Object which implements Instrumentable can also make use of other
       *  Instrumentable child objects.  This method is used to tell the
       *  InstrumentManager about them.
       *
       * @return An array of child Instrumentables.  This method should never
       *         return null.  If there are no child Instrumentables, then
       *         EMPTY_INSTRUMENTABLE_ARRAY can be returned.
       */
      public Instrumentable[] getChildInstrumentables()
      {
          return new Instrumentable[]{m_underlyingPool};
      }
  
      /**
       * Return the number of worker threads in the pool.
       *
       * @return the numebr of worker threads in the pool.
       */
      public int getSize()
      {
          return m_underlyingPool.getSize();
      }
  
      public void enableLogging( final Logger logger )
      {
          ContainerUtil.enableLogging( m_pool, logger );
      }
  
      public void dispose()
      {
          m_pool.dispose();
      }
  
      public Object newInstance()
      {
          return m_pool.newInstance();
      }
  
      public void decommission( final Object object )
      {
          m_pool.decommission( object );
      }
  
      public Class getCreatedClass()
      {
          return m_pool.getCreatedClass();
      }
  
      /**
       * Run work in separate thread.
       * Return a valid ThreadControl to control work thread.
       *
       * @param work the work to be executed.
       * @return the ThreadControl
       */
      public ThreadControl execute( final Executable work )
      {
          return m_pool.execute( work );
      }
  
      /**
       * Run work in separate thread.
       * Return a valid ThreadControl to control work thread.
       *
       * @param work the work to be executed.
       * @return the ThreadControl
       */
      public ThreadControl execute( final Runnable work )
      {
          return m_pool.execute( work );
      }
  
      /**
       * Run work in separate thread.
       * Return a valid ThreadControl to control work thread.
       *
       * @param work the work to be executed.
       * @return the ThreadControl
       */
      public ThreadControl execute( final org.apache.excalibur.thread.Executable work )
      {
          return m_pool.execute( work );
      }
  }
  
  
  

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


Mime
View raw message