avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcconn...@apache.org
Subject cvs commit: avalon-components/cornerstone/threads/tutorial/src/java/org/apache/avalon/cornerstone/threads/tutorial Counter.java ThreadConsumer.java ThreadConsumer.xinfo
Date Mon, 15 Mar 2004 13:06:46 GMT
mcconnell    2004/03/15 05:06:46

  Added:       cornerstone/threads/api .cvsignore project.properties
                        project.xml
               cornerstone/threads/api/src/java/org/apache/avalon/cornerstone/services/threads
                        ThreadManager.java package.html
               cornerstone/threads/impl .cvsignore project.xml
               cornerstone/threads/impl/conf block.xml
               cornerstone/threads/impl/src/java/org/apache/avalon/cornerstone/blocks/threads
                        AbstractThreadManager.java
                        DefaultThreadManager-schema.xml
                        DefaultThreadManager.java
                        DefaultThreadManager.xinfo
                        ResourceLimitingThreadManager-schema.xml
                        ResourceLimitingThreadManager.java
                        ResourceLimitingThreadManager.xinfo package.html
               cornerstone/threads/tutorial .cvsignore maven.xml
                        project.properties project.xml
               cornerstone/threads/tutorial/conf block.xml demo.xml
               cornerstone/threads/tutorial/src/java/org/apache/avalon/cornerstone/threads/tutorial
                        Counter.java ThreadConsumer.java
                        ThreadConsumer.xinfo
  Log:
  Bring cornerstone-threads in line with no references to deprecated excalibur thread or pool
content.
  
  Revision  Changes    Path
  1.1                  avalon-components/cornerstone/threads/api/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  maven.log
  velocity.log
  build.properties
  target
  maven.log
  
  
  1.1                  avalon-components/cornerstone/threads/api/project.properties
  
  Index: project.properties
  ===================================================================
  
  #
  # Override the standard Maven site script.
  #
  maven.xdoc.jsl = file:/${basedir}/../../src/etc/site.jsl
  
  #
  # Declaration of the remote links to assign on javadoc generation.
  # Link declarations can be overriden in the user's build.properties
  # file.
  #
  
  excalibur.thread.link = http://avalon.apache.org/excalibur/thread/api/
  excalibur.event.link = http://avalon.apache.org/excalibur/event/api/
  
  maven.javadoc.links = ${sun.j2se.link},${avalon.framework.link},${excalibur.thread.link},${excalibur.event.link}
  
  
  
  1.1                  avalon-components/cornerstone/threads/api/project.xml
  
  Index: project.xml
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?>
  
  <project>
  
    <extend>${basedir}/../../project.xml</extend>
  
    <groupId>cornerstone-threads</groupId>
    <id>cornerstone-threads-api</id>
    <name>Cornerstone Threads API</name>
    <currentVersion>SNAPSHOT</currentVersion>
    <package>org.apache.avalon.cornerstone.services.threads</package>
    <inceptionYear>2001</inceptionYear>
    <shortDescription>Cornerstone Threads API</shortDescription>
  
    <dependencies>
  
      <!-- excalibur dependencies -->
  
      <dependency>
        <groupId>excalibur-thread</groupId>
        <artifactId>excalibur-thread-api</artifactId>
        <version>SNAPSHOT</version>
      </dependency>
  
    </dependencies>
    
  </project>
  
  
  
  1.1                  avalon-components/cornerstone/threads/api/src/java/org/apache/avalon/cornerstone/services/threads/ThreadManager.java
  
  Index: ThreadManager.java
  ===================================================================
  /* 
   * Copyright 1999-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.cornerstone.services.threads;
  
  import org.apache.excalibur.thread.ThreadPool;
  
  /**
   * Manage a set of ThreadPools.
   *
   * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
   * @version $Revision: 1.1 $ $Date: 2004/03/15 13:06:46 $
   */
  public interface ThreadManager
  {
      String ROLE = ThreadManager.class.getName();
  
      /**
       * 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
       */
      ThreadPool getThreadPool( String name )
          throws IllegalArgumentException;
  
      /**
       * Retrieve the default thread pool.
       *
       * @return the thread pool
       */
      ThreadPool getDefaultThreadPool();
  }
  
  
  
  1.1                  avalon-components/cornerstone/threads/api/src/java/org/apache/avalon/cornerstone/services/threads/package.html
  
  Index: package.html
  ===================================================================
  <body>
  Defintion of the thread pool service.
  </body>
  
  
  
  1.1                  avalon-components/cornerstone/threads/impl/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  maven.log
  velocity.log
  build.properties
  target
  maven.log
  
  
  1.1                  avalon-components/cornerstone/threads/impl/project.xml
  
  Index: project.xml
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?>
  
  <project>
  
    <extend>${basedir}/../../project.xml</extend>
  
    <groupId>cornerstone-threads</groupId>
    <id>cornerstone-threads-impl</id>
    <name>Cornerstone Thread Manager Implementation</name>
    <currentVersion>SNAPSHOT</currentVersion>
    <package>org.apache.avalon.cornerstone.blocks.threads</package>
  
    <inceptionYear>2001</inceptionYear>
    <shortDescription>Cornerstone Threads</shortDescription>
  
    <dependencies>
  
      <!-- cornerstone api dependencies -->
  
      <dependency>
        <groupId>cornerstone-threads</groupId>
        <artifactId>cornerstone-threads-api</artifactId>
        <version>SNAPSHOT</version>
      </dependency>
  
      <!-- avalon dependencies -->
  
      <dependency>
        <groupId>avalon-framework</groupId>
        <artifactId>avalon-framework-api</artifactId>
        <version>4.1.5</version>
      </dependency>
      <dependency>
        <groupId>excalibur-thread</groupId>
        <artifactId>excalibur-thread-api</artifactId>
        <version>SNAPSHOT</version>
      </dependency>
      <dependency>
        <groupId>excalibur-thread</groupId>
        <artifactId>excalibur-thread-impl</artifactId>
        <version>SNAPSHOT</version>
      </dependency>
      <dependency>
        <groupId>excalibur-pool</groupId>
        <artifactId>excalibur-pool-api</artifactId>
        <version>SNAPSHOT</version>
      </dependency>
      <dependency>
        <groupId>excalibur-pool</groupId>
        <artifactId>excalibur-pool-impl</artifactId>
        <version>SNAPSHOT</version>
      </dependency>
      <dependency>
        <groupId>commons-collections</groupId>
        <artifactId>commons-collections</artifactId>
        <version>2.1</version>
      </dependency>
      <dependency>
        <groupId>concurrent</groupId>
        <artifactId>concurrent</artifactId>
        <version>1.3.1</version>
      </dependency>
  
    </dependencies>
    
  </project>
  
  
  
  1.1                  avalon-components/cornerstone/threads/impl/conf/block.xml
  
  Index: block.xml
  ===================================================================
  
  <!--
  Thread Block deployment directive.
  -->
  
  <container name="threads">
  
     <services>
       <service type="org.apache.avalon.cornerstone.services.threads.ThreadManager">
         <source>manager</source>
       </service>
     </services>
  
     <classloader>
       <classpath>
         <repository>
           <resource id="avalon-framework:avalon-framework-api" version="4.1.5"/>
           <resource id="avalon-framework:avalon-framework-impl" version="4.1.5"/>
           <resource id="commons-collections:commons-collections" version="2.1"/>
           <resource id="concurrent:concurrent" version="1.3.1"/>
           <resource id="excalibur-pool:excalibur-pool-api" version="SNAPSHOT"/>
           <resource id="excalibur-pool:excalibur-pool-impl" version="SNAPSHOT"/>
           <resource id="excalibur-thread:excalibur-thread-api" version="SNAPSHOT"/>
           <resource id="excalibur-thread:excalibur-thread-impl" version="SNAPSHOT"/>
           <resource id="cornerstone-threads:cornerstone-threads-api" version="SNAPSHOT"/>
         </repository>
       </classpath>
     </classloader>
  
     <component name="manager" 
          class="org.apache.avalon.cornerstone.blocks.threads.DefaultThreadManager" 
          activation="true">
       <configuration>
         <thread-group>
           <name>default</name>
           <priority>5</priority> 
           <is-daemon>false</is-daemon>
           <max-threads>100</max-threads>
           <min-threads>20</min-threads>
           <min-spare-threads>20</min-spare-threads>
         </thread-group>
       </configuration>
     </component>
  
  </container>
  
  
  
  1.1                  avalon-components/cornerstone/threads/impl/src/java/org/apache/avalon/cornerstone/blocks/threads/AbstractThreadManager.java
  
  Index: AbstractThreadManager.java
  ===================================================================
  /* 
   * Copyright 1999-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.cornerstone.blocks.threads;
  
  import java.util.HashMap;
  import java.util.Map;
  
  import org.apache.avalon.cornerstone.services.threads.ThreadManager;
  
  import org.apache.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:dev@avalon.apache.org">Avalon Development Team</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
       */
      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-components/cornerstone/threads/impl/src/java/org/apache/avalon/cornerstone/blocks/threads/DefaultThreadManager-schema.xml
  
  Index: DefaultThreadManager-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="priority"><data type="integer"/></element>
                  <element name="is-daemon"><data type="boolean"/></element>
                  <element name="min-threads"><data type="integer"/></element>
                  <element name="max-threads"><data type="integer"/></element>
                  <element name="min-spare-threads"><data type="integer"/></element>
              </interleave>
          </element>
      </oneOrMore>
  </element>
  
  
  
  1.1                  avalon-components/cornerstone/threads/impl/src/java/org/apache/avalon/cornerstone/blocks/threads/DefaultThreadManager.java
  
  Index: DefaultThreadManager.java
  ===================================================================
  /* 
   * Copyright 1999-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.cornerstone.blocks.threads;
  
  import java.util.Map;
  
  import org.apache.avalon.excalibur.thread.impl.DefaultThreadPool;
  
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  
  /**
   * Default implementation of ThreadManager.
   *
   * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
   */
  public class DefaultThreadManager
      extends AbstractThreadManager
  {
      protected void configureThreadPool( final Map threadPools,
                                          final Configuration configuration )
          throws ConfigurationException
      {
          final String name = configuration.getChild( "name" ).getValue();
          // NEVER USED!!
          //final int priority = configuration.getChild( "priority" ).getValueAsInteger( 5
);
          final boolean isDaemon = configuration.getChild( "is-daemon" ).getValueAsBoolean(
false );
  
          final int minThreads = configuration.getChild( "min-threads" ).getValueAsInteger(
5 );
          final int maxThreads = configuration.getChild( "max-threads" ).getValueAsInteger(
10 );
  
          // NEVER USED!!
          //final int minSpareThreads = configuration.getChild( "min-spare-threads" ).
          //    getValueAsInteger( maxThreads - minThreads );
  
          try
          {
              final DefaultThreadPool threadPool =
                  new DefaultThreadPool( name, minThreads, maxThreads );
              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 );
          }
      }
  }
  
  
  
  1.1                  avalon-components/cornerstone/threads/impl/src/java/org/apache/avalon/cornerstone/blocks/threads/DefaultThreadManager.xinfo
  
  Index: DefaultThreadManager.xinfo
  ===================================================================
  <?xml version="1.0"?>
  <!DOCTYPE blockinfo PUBLIC "-//PHOENIX/Block Info DTD Version 1.0//EN"
                    "http://jakarta.apache.org/avalon/dtds/phoenix/blockinfo_1_0.dtd">
  
  <blockinfo>
  
    <block>
      <version>1.0</version>
      <schema-type>http://relaxng.org/ns/structure/1.0</schema-type>
    </block>
  
    <services>
      <service name="org.apache.avalon.cornerstone.services.threads.ThreadManager"/>
    </services>
  
  </blockinfo>
  
  
  
  1.1                  avalon-components/cornerstone/threads/impl/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-components/cornerstone/threads/impl/src/java/org/apache/avalon/cornerstone/blocks/threads/ResourceLimitingThreadManager.java
  
  Index: ResourceLimitingThreadManager.java
  ===================================================================
  /* 
   * Copyright 1999-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.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.
   *
   * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</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 );
          }
      }
  }
  
  
  
  1.1                  avalon-components/cornerstone/threads/impl/src/java/org/apache/avalon/cornerstone/blocks/threads/ResourceLimitingThreadManager.xinfo
  
  Index: ResourceLimitingThreadManager.xinfo
  ===================================================================
  <?xml version="1.0"?>
  <!DOCTYPE blockinfo PUBLIC "-//PHOENIX/Block Info DTD Version 1.0//EN"
                    "http://jakarta.apache.org/avalon/dtds/phoenix/blockinfo_1_0.dtd">
  
  <blockinfo>
  
    <block>
      <version>1.0</version>
      <schema-type>http://relaxng.org/ns/structure/1.0</schema-type>
    </block>
  
    <services>
      <service name="org.apache.avalon.cornerstone.services.threads.ThreadManager"/>
    </services>
  
  </blockinfo>
  
  
  
  1.1                  avalon-components/cornerstone/threads/impl/src/java/org/apache/avalon/cornerstone/blocks/threads/package.html
  
  Index: package.html
  ===================================================================
  <body>
  Default implementation of a thread pool manager.
  </body>
  
  
  
  1.1                  avalon-components/cornerstone/threads/tutorial/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  maven.log
  velocity.log
  build.properties
  target
  maven.log
  logs
  
  
  
  1.1                  avalon-components/cornerstone/threads/tutorial/maven.xml
  
  Index: maven.xml
  ===================================================================
  <project default="jar:jar">
  
    <preGoal name="java:compile">
      <attainGoal name="avalon:meta"/>
    </preGoal>
  
  </project>
  
  
  
  1.1                  avalon-components/cornerstone/threads/tutorial/project.properties
  
  	<<Binary file>>
  
  
  1.1                  avalon-components/cornerstone/threads/tutorial/project.xml
  
  Index: project.xml
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?>
  
  <project>
  
    <extend>${basedir}/../../project.xml</extend>
  
    <groupId>cornerstone-threads</groupId>
    <id>cornerstone-threads-tutorial</id>
    <name>Cornerstone Threads Tutorial</name>
    <currentVersion>SNAPSHOT</currentVersion>
    <package>org.apache.avalon.cornerstone.threads.tutorial</package>
  
    <inceptionYear>2001</inceptionYear>
    <shortDescription>Cornerstone Threads</shortDescription>
  
    <dependencies>
  
      <!-- cornerstone api dependencies -->
  
      <dependency>
        <groupId>cornerstone-threads</groupId>
        <artifactId>cornerstone-threads-api</artifactId>
        <version>SNAPSHOT</version>
      </dependency>
  
      <!-- avalon dependencies -->
  
      <dependency>
        <groupId>avalon-framework</groupId>
        <artifactId>avalon-framework-api</artifactId>
        <version>4.1.5</version>
      </dependency>
      <dependency>
        <groupId>avalon-framework</groupId>
        <artifactId>avalon-framework-impl</artifactId>
        <version>4.1.5</version>
      </dependency>
  
      <!-- excalibur dependencies -->
  
      <dependency>
        <groupId>excalibur-thread</groupId>
        <artifactId>excalibur-thread-api</artifactId>
        <version>SNAPSHOT</version>
      </dependency>
  
      <!--
      <dependency>
        <id>excalibur-pool</id>
        <version>1.2</version>
      </dependency>
  
      <dependency>
        <id>excalibur-event</id>
        <version>1.0.3</version>
      </dependency>
  
      <dependency>
        <id>xml-apis</id>
        <version>1.0.b2</version>
        <url>http://xml.apache.org/xerces2-j/</url>
      </dependency>
  
      <dependency>
        <id>xerces</id>
        <version>2.2.1</version>
        <url>http://xml.apache.org/xerces2-j/</url>
      </dependency>
      -->
  
    </dependencies>
    
  </project>
  
  
  
  1.1                  avalon-components/cornerstone/threads/tutorial/conf/block.xml
  
  Index: block.xml
  ===================================================================
  
  <!--
  Thread Tutorial.
  -->
  
  <container name="threads">
  
       <categories>
         <category name="classloader/scanner" priority="ERROR"/>
       </categories>
  
       <classloader>
         <classpath>
           <repository>
             <resource id="avalon-framework:avalon-framework-impl" version="4.1.5"/>
             <resource id="commons-collections:commons-collections" version="2.1"/>
             <resource id="excalibur-pool:excalibur-pool-api" version="SNAPSHOT"/>
             <resource id="excalibur-pool:excalibur-pool-impl" version="SNAPSHOT"/>
             <resource id="excalibur-thread:excalibur-thread-api" version="SNAPSHOT"/>
             <resource id="excalibur-thread:excalibur-thread-impl" version="SNAPSHOT"/>
             <resource id="cornerstone-threads:cornerstone-threads-api" version="SNAPSHOT"/>
             <!--<resource id="excalibur-event:excalibur-event" version="1.0.3"/>-->
           </repository>
         </classpath>
       </classloader>
  
       <component name="manager" 
          class="org.apache.avalon.cornerstone.blocks.threads.DefaultThreadManager">
         <configuration>
           <thread-group>
             <name>default</name>
             <priority>5</priority> 
             <is-daemon>false</is-daemon>
             <max-threads>100</max-threads>
             <min-threads>20</min-threads>
             <min-spare-threads>20</min-spare-threads>
           </thread-group>
         </configuration>
       </component>
  
  </container>
  
  
  
  1.1                  avalon-components/cornerstone/threads/tutorial/conf/demo.xml
  
  Index: demo.xml
  ===================================================================
  
  <!--
  Thread Tutorial. 
  A standalone container definition within which we import the 
  cornerstone threads block.  The classloader only need to include 
  the resources the make up the api published by the block together
  with any jars required for its own implementation.
  -->
  
  <container name="thread-tutorial">
  
     <classloader>
       <classpath>
         <repository>
           <resource id="avalon-framework:avalon-framework-api" version="4.1.5"/>
           <resource id="excalibur-pool:excalibur-pool-api" version="SNAPSHOT"/>
           <resource id="excalibur-thread:excalibur-thread-api" version="SNAPSHOT"/>
           <resource id="cornerstone-threads:cornerstone-threads-api" version="SNAPSHOT"/>
           <resource id="cornerstone-threads:cornerstone-threads-tutorial" version="SNAPSHOT"/>
         </repository>
       </classpath>
     </classloader>
  
     <include name="threads" 
         id="cornerstone-threads:cornerstone-threads-impl" 
         version="SNAPSHOT"/>
  
     <component name="test" 
        class="org.apache.avalon.cornerstone.threads.tutorial.ThreadConsumer" />
  
  </container>
  
  
  
  1.1                  avalon-components/cornerstone/threads/tutorial/src/java/org/apache/avalon/cornerstone/threads/tutorial/Counter.java
  
  Index: Counter.java
  ===================================================================
  /* 
   * Copyright 1999-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.cornerstone.threads.tutorial;
  
  import org.apache.avalon.framework.logger.LogEnabled;
  import org.apache.avalon.framework.logger.Logger;
  
  /**
   * A demonstration runnable object that simply logs a countdown sequence.
   *
   * @author Stephen McConnell
   * @avalon.component name="counter" 
   */
  public class Counter extends Thread implements LogEnabled
  {
     /**
      * The supplied logging channel.
      */
      private Logger m_logger;
  
      private int m_count = 10;
  
      public void enableLogging( Logger logger )
      {
          m_logger = logger;
      }
  
      protected Logger getLogger()
      {
          return m_logger;
      }
  
      public void run()
      {
          while( m_count > 0 )
          {
              getLogger().info( "count: " + m_count );
              m_count--;
              try
              {
                  sleep( 1000 );
              }
              catch( Throwable e )
              {
                  getLogger().info( "I've been interrupted." );
                  m_count = -1;
              }
          }
          getLogger().info( "Time to die." );
          m_logger = null;
      }
  }
  
  
  
  
  1.1                  avalon-components/cornerstone/threads/tutorial/src/java/org/apache/avalon/cornerstone/threads/tutorial/ThreadConsumer.java
  
  Index: ThreadConsumer.java
  ===================================================================
  /* 
   * Copyright 1999-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.cornerstone.threads.tutorial;
  
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  import org.apache.avalon.framework.service.Serviceable;
  import org.apache.avalon.framework.service.ServiceManager;
  import org.apache.avalon.framework.service.ServiceException;
  import org.apache.avalon.framework.activity.Initializable;
  import org.apache.avalon.framework.activity.Disposable;
  
  import org.apache.excalibur.thread.ThreadControl;
  import org.apache.excalibur.thread.ThreadPool;
  
  import org.apache.avalon.cornerstone.services.threads.ThreadManager;
  
  /**
   * ThreadConsumer is a example of a component that uses the ThreadManager
   * service to aquired a thread pool.
   *
   * @avalon.component name="consumer" lifestyle="singleton" version="1.0"
   * @author Stephen McConnell
   */
  public class ThreadConsumer extends AbstractLogEnabled implements
  Serviceable, Initializable, Disposable
  {
     /**
      * The service manager from which serrvices are aquired and released.
      */
      private ServiceManager m_manager;
  
     /**
      * The cornerstone thread manager.
      */
      private ThreadManager m_threads;
  
     /**
      * A thread pool aquired from the thread manager.
      */
      private ThreadPool m_pool;
  
     /**
      * A thread control return from the launching of a new thread.
      */
      private ThreadControl m_control;
  
  
     /**
      * Servicing of the component by the container during which the 
      * component aquires the ThreadManager service.
      * 
      * @param manager the thread manager
      * @exception ServiceException if the thread manager service is 
      *   unresolvable
      * @avalon.dependency key="threads" 
      *   type="org.apache.avalon.cornerstone.services.threads.ThreadManager"
      */
      public void service( ServiceManager manager ) throws ServiceException
      {
          m_manager = manager;
          getLogger().info( "aquiring cornerstone threads service" );
          m_threads = (ThreadManager) m_manager.lookup( "threads" );
      }
  
     /**
      * Initialization of the component by the container during which we 
      * establish a child thread by passing a runnable object to the thread pool.
      * @exception Exception if an initialization stage error occurs
      */
      public void initialize() throws Exception
      {
          getLogger().info( "initialization" );
  
          //
          // get the default thread pool
          //
  
          m_pool = m_threads.getDefaultThreadPool();
  
          //
          // create a runnable object to run
          //
   
          Counter counter = new Counter();
          counter.enableLogging( getLogger().getChildLogger( "counter" ) );
  
          //
          // start a thread and get the thread control reference
          //
  
          m_control = m_pool.execute( counter );
      }
  
     /**
      * Disposal of the component during which he handle the closue of the 
      * child thread we have establshed during the initialization stage.
      */
      public void dispose()
      {
          getLogger().info( "disposal" );
  
          if( ( m_control != null ) && !m_control.isFinished() )
          {
              //
              // interrupt the child 
              //
  
              getLogger().info( "disposal invoked while child thread active" );
              m_control.interrupt();
  
              //
              // Using m_control.join() locks things up - why?  Using a 
              // wait for finished state instead.
              // 
  
              while( !m_control.isFinished() )
              {
                  getLogger().info( "waiting for child" );
                  try
                  {
                      Thread.sleep( 1000 );
                  }
                  catch( InterruptedException ie )
                  {
                      // ignore it
                  }
              }
          }
  
          //
          // check for errors
          //
  
          if( ( m_control != null ) && ( m_control.getThrowable() != null ) )
          {
              getLogger().warn( 
                "thread terminated with exception condition", 
                 m_control.getThrowable() );
          }
  
          if( m_pool != null )
          {
              if( m_pool instanceof Disposable )
              {
                  ((Disposable)m_pool).dispose();
              }
              m_pool = null;
          }
  
          m_manager.release( m_threads );
  
          m_control = null;
          m_threads = null;
          m_manager = null;
  
          getLogger().info( "disposed" );
      }
  }
  
  
  
  
  1.1                  avalon-components/cornerstone/threads/tutorial/src/java/org/apache/avalon/cornerstone/threads/tutorial/ThreadConsumer.xinfo
  
  Index: ThreadConsumer.xinfo
  ===================================================================
  <?xml version="1.0"?>
  <!DOCTYPE type
        PUBLIC "-//AVALON/Type DTD Version 1.0//EN"
               "http://avalon.apache.org/dtds/meta/type_1_1.dtd" >
  <type>
    <info>
      <name>thread-consumer</name>
      <version>1.0</version>
    </info>
    <dependencies>
      <dependency type="org.apache.avalon.cornerstone.services.threads.ThreadManager"
        key="threads"/>
    </dependencies>
  </type>
  
  
  

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


Mime
View raw message