avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l...@apache.org
Subject cvs commit: avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/threads AbstractThreadManager.java ResourceLimitingThreadManager-schema.xml ResourceLimitingThreadManager.java DefaultThreadManager.java
Date Sun, 18 May 2003 09:44:47 GMT
leif        2003/05/18 02:44:47

  Modified:    src/java/org/apache/avalon/cornerstone/blocks/threads
                        DefaultThreadManager.java
  Added:       src/java/org/apache/avalon/cornerstone/blocks/threads
                        AbstractThreadManager.java
                        ResourceLimitingThreadManager-schema.xml
                        ResourceLimitingThreadManager.java
  Log:
  Add a ThreadManager implementation which makes use of the
  ResourceLimitingThreadPool.
  
  Revision  Changes    Path
  1.29      +5 -61     avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/threads/DefaultThreadManager.java
  
  Index: DefaultThreadManager.java
  ===================================================================
  RCS file: /home/cvs/avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/threads/DefaultThreadManager.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- DefaultThreadManager.java	11 Apr 2003 06:04:53 -0000	1.28
  +++ DefaultThreadManager.java	18 May 2003 09:44:47 -0000	1.29
  @@ -50,14 +50,10 @@
   
   package org.apache.avalon.cornerstone.blocks.threads;
   
  -import java.util.HashMap;
  -import org.apache.avalon.cornerstone.services.threads.ThreadManager;
  -import org.apache.avalon.excalibur.thread.ThreadPool;
  +import java.util.Map;
   import org.apache.avalon.excalibur.thread.impl.DefaultThreadPool;
  -import org.apache.avalon.framework.configuration.Configurable;
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.ConfigurationException;
  -import org.apache.avalon.framework.logger.AbstractLogEnabled;
   
   /**
    * Default implementation of ThreadManager.
  @@ -68,30 +64,10 @@
    * @author <a href="mailto:peter at apache.org">Peter Donald</a>
    */
   public class DefaultThreadManager
  -    extends AbstractLogEnabled
  -    implements ThreadManager, Configurable
  +    extends AbstractThreadManager
   {
  -    ///Map of thread pools for application
  -    private HashMap m_threadPools = new HashMap();
  -
  -    /**
  -     * Setup thread pools based on configuration data.
  -     *
  -     * @param configuration the configuration data
  -     * @exception ConfigurationException if an error occurs
  -     * @phoenix:configuration-schema type="http://relaxng.org/ns/structure/1.0"
  -     */
  -    public void configure( final Configuration configuration )
  -        throws ConfigurationException
  -    {
  -        final Configuration[] groups = configuration.getChildren( "thread-group" );
  -        for( int i = 0; i < groups.length; i++ )
  -        {
  -            configureThreadPool( groups[ i ] );
  -        }
  -    }
  -
  -    private void configureThreadPool( final Configuration configuration )
  +    protected void configureThreadPool( final Map threadPools,
  +                                        final Configuration configuration )
           throws ConfigurationException
       {
           final String name = configuration.getChild( "name" ).getValue();
  @@ -112,44 +88,12 @@
                   new DefaultThreadPool( name, minThreads, maxThreads );
               threadPool.setDaemon( isDaemon );
               threadPool.enableLogging( getLogger() );
  -            m_threadPools.put( name, threadPool );
  +            threadPools.put( name, threadPool );
           }
           catch( final Exception e )
           {
               final String message = "Error creating ThreadPool named " + name;
               throw new ConfigurationException( message, e );
           }
  -    }
  -
  -    /**
  -     * Retrieve a thread pool by name.
  -     *
  -     * @param name the name of thread pool
  -     * @return the threadpool
  -     * @exception IllegalArgumentException if the name of thread pool is
  -     *            invalid or named pool does not exist
  -     */
  -    public ThreadPool getThreadPool( final String name )
  -        throws IllegalArgumentException
  -    {
  -        final ThreadPool threadPool = (ThreadPool)m_threadPools.get( name );
  -
  -        if( null == threadPool )
  -        {
  -            final String message = "Unable to locate ThreadPool named " + name;
  -            throw new IllegalArgumentException( message );
  -        }
  -
  -        return threadPool;
  -    }
  -
  -    /**
  -     * Retrieve the default thread pool.
  -     *
  -     * @return the thread pool
  -     */
  -    public ThreadPool getDefaultThreadPool()
  -    {
  -        return getThreadPool( "default" );
       }
   }
  
  
  
  1.1                  avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/threads/AbstractThreadManager.java
  
  Index: AbstractThreadManager.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Jakarta", "Apache Avalon", "Avalon Cornerstone", "Avalon
      Framework" and "Apache Software Foundation"  must not be used to endorse
      or promote products derived  from this  software without  prior written
      permission. For written permission, please contact apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  
  package org.apache.avalon.cornerstone.blocks.threads;
  
  import java.util.HashMap;
  import java.util.Map;
  import org.apache.avalon.cornerstone.services.threads.ThreadManager;
  import org.apache.avalon.excalibur.thread.ThreadPool;
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  
  /**
   * Abstract implementation of ThreadManager.
   *
   * @author <a href="mailto:peter at apache.org">Peter Donald</a>
   * @author <a href="mailto:leif at apache.org">Leif Mortenson</a>
   */
  public abstract class AbstractThreadManager
      extends AbstractLogEnabled
      implements ThreadManager, Configurable
  {
      ///Map of thread pools for application
      private HashMap m_threadPools = new HashMap();
  
      /**
       * Setup thread pools based on configuration data.
       *
       * @param configuration the configuration data
       * @exception ConfigurationException if an error occurs
       * @phoenix:configuration-schema type="http://relaxng.org/ns/structure/1.0"
       */
      public void configure( final Configuration configuration )
          throws ConfigurationException
      {
          final Configuration[] groups = configuration.getChildren( "thread-group" );
          for( int i = 0; i < groups.length; i++ )
          {
              configureThreadPool( m_threadPools, groups[ i ] );
          }
      }
  
      protected abstract void configureThreadPool( final Map threadPools,
                                                   final Configuration configuration )
          throws ConfigurationException;
  
      /**
       * Retrieve a thread pool by name.
       *
       * @param name the name of thread pool
       * @return the threadpool
       * @exception IllegalArgumentException if the name of thread pool is
       *            invalid or named pool does not exist
       */
      public ThreadPool getThreadPool( final String name )
          throws IllegalArgumentException
      {
          final ThreadPool threadPool = (ThreadPool)m_threadPools.get( name );
  
          if( null == threadPool )
          {
              final String message = "Unable to locate ThreadPool named " + name;
              throw new IllegalArgumentException( message );
          }
  
          return threadPool;
      }
  
      /**
       * Retrieve the default thread pool.
       *
       * @return the thread pool
       */
      public ThreadPool getDefaultThreadPool()
      {
          return getThreadPool( "default" );
      }
  }
  
  
  
  1.1                  avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/threads/ResourceLimitingThreadManager-schema.xml
  
  Index: ResourceLimitingThreadManager-schema.xml
  ===================================================================
  <?xml version="1.0"?>
  <element
      name="root"
      xmlns="http://relaxng.org/ns/structure/1.0"
      datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"
      xmlns:a="http://jakarta.apache.org/phoenix/schema-annotations/1.0"
  >
      <oneOrMore>
          <element name="thread-group">
              <interleave>
                  <element name="name"><text/></element>
                  <element name="is-daemon"><data type="boolean"/></element>
                  <element name="max-threads"><data type="integer"/></element>
                  <element name="max-strict"><data type="boolean"/></element>
                  <element name="blocking"><data type="boolean"/></element>
                  <element name="block-timeout"><data type="long"/></element>
                  <element name="trim-interval"><data type="long"/></element>
              </interleave>
          </element>
      </oneOrMore>
  </element>
  
  
  
  1.1                  avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/threads/ResourceLimitingThreadManager.java
  
  Index: ResourceLimitingThreadManager.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Jakarta", "Apache Avalon", "Avalon Cornerstone", "Avalon
      Framework" and "Apache Software Foundation"  must not be used to endorse
      or promote products derived  from this  software without  prior written
      permission. For written permission, please contact apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  
  package org.apache.avalon.cornerstone.blocks.threads;
  
  import java.util.Map;
  import org.apache.avalon.excalibur.thread.impl.ResourceLimitingThreadPool;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  
  /**
   * Default implementation of ThreadManager.
   *
   * @phoenix:block
   * @phoenix:service name="org.apache.avalon.cornerstone.services.threads.ThreadManager"
   *
   * @author <a href="mailto:leif at apache.org">Leif Mortenson</a>
   */
  public class ResourceLimitingThreadManager
      extends AbstractThreadManager
  {
      protected void configureThreadPool( final Map threadPools,
                                          final Configuration configuration )
          throws ConfigurationException
      {
          final String name = configuration.getChild( "name" ).getValue();
          final boolean isDaemon = configuration.getChild( "is-daemon" ).getValueAsBoolean(
false );
          
          final int max = configuration.getChild( "max-threads" ).getValueAsInteger( 10 );
          final boolean maxStrict = configuration.getChild( "max-strict" ).getValueAsBoolean(
true );
          final boolean blocking = configuration.getChild( "blocking" ).getValueAsBoolean(
true );
          final long blockTimeout = configuration.getChild( "block-timeout" ).getValueAsLong(
0 );
          final long trimInterval = configuration.getChild( "trim-interval" ).getValueAsLong(
10000 );
  
          try
          {
              final ResourceLimitingThreadPool threadPool = new ResourceLimitingThreadPool(
                  name, max, maxStrict, blocking, blockTimeout, trimInterval );
              threadPool.setDaemon( isDaemon );
              threadPool.enableLogging( getLogger() );
              threadPools.put( name, threadPool );
          }
          catch( final Exception e )
          {
              final String message = "Error creating ThreadPool named " + name;
              throw new ConfigurationException( message, e );
          }
      }
  }
  
  
  

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


Mime
View raw message