avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From craft...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/util ContextManager.java
Date Fri, 19 Jul 2002 15:50:21 GMT
crafterm    2002/07/19 08:50:21

  Modified:    fortress/src/java/org/apache/excalibur/fortress/util
                        ContextManager.java
  Log:
  Added code to create a default command queue registered with a thread
  manager, if not specified by the client. This fixes async component handler
  initialization, but more changes regarding the configuration of handler
  initialization are to come.
  
  Revision  Changes    Path
  1.25      +65 -3     jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/util/ContextManager.java
  
  Index: ContextManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/util/ContextManager.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- ContextManager.java	2 Jul 2002 11:08:42 -0000	1.24
  +++ ContextManager.java	19 Jul 2002 15:50:21 -0000	1.25
  @@ -21,15 +21,19 @@
   import org.apache.avalon.framework.configuration.DefaultConfiguration;
   import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
   import org.apache.avalon.framework.configuration.DefaultConfigurationSerializer;
  +import org.apache.avalon.framework.container.ContainerUtil;
   import org.apache.avalon.framework.context.Context;
   import org.apache.avalon.framework.context.ContextException;
   import org.apache.avalon.framework.context.DefaultContext;
   import org.apache.avalon.framework.logger.ConsoleLogger;
   import org.apache.avalon.framework.logger.Logger;
  +import org.apache.avalon.framework.parameters.Parameters;
   import org.apache.avalon.framework.service.DefaultServiceManager;
   import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.excalibur.event.Queue;
   import org.apache.excalibur.event.command.CommandManager;
  +import org.apache.excalibur.event.command.ThreadManager;
  +import org.apache.excalibur.event.command.TPCThreadManager;
   import org.apache.excalibur.mpool.DefaultPoolManager;
   import org.apache.excalibur.mpool.PoolManager;
   import org.apache.excalibur.source.Source;
  @@ -363,9 +367,67 @@
           {
           }
   
  -        CommandManager cm = new CommandManager();
  +        // No CommandQueue specified, create a default one
  +        childContext.put( COMMAND_QUEUE, createCommandQueue() );
  +    }
  +
  +    /**
  +     * Helper method for creating a default Command Queue 
  +     *
  +     * @return a default command <code>Queue</code>
  +     * @exception Exception if an error occurs
  +     */
  +    private Queue createCommandQueue() throws Exception
  +    {
  +        final CommandManager cm = new CommandManager();
  +        final ThreadManager tm = new TPCThreadManager();
  +
           assumeOwnership( cm );
  -        childContext.put( COMMAND_QUEUE, cm.getCommandQueue() );
  +        assumeOwnership( tm );
  +
  +        ContainerUtil.enableLogging( tm, logger );
  +        ContainerUtil.parameterize( tm, buildCommandQueueConfig() );
  +        ContainerUtil.initialize( tm );
  +
  +        tm.register( cm );
  +
  +        return cm.getCommandQueue();
  +    }
  +
  +    /**
  +     * Helper method for creating ThreadManager configuration.
  +     *
  +     * @return ThreadManager configuration as a <code>Parameters</code> instance
  +     */
  +    private Parameters buildCommandQueueConfig()
  +    {
  +        final Parameters p = new Parameters();
  +        Integer threadsPerProcessor;
  +        Long threadBlockTimeout;
  +
  +        try
  +        {
  +            threadsPerProcessor = (Integer) rootContext.get( THREADS_CPU );
  +        }
  +        catch( ContextException e )
  +        {
  +            threadsPerProcessor = new Integer( 2 );
  +        }
  +
  +        p.setParameter( "threads-per-processor", threadsPerProcessor.toString() );
  +
  +        try
  +        {
  +            threadBlockTimeout = (Long) rootContext.get( THREAD_TIMEOUT );
  +        }
  +        catch( ContextException e )
  +        {
  +            threadBlockTimeout = new Long( 1000 );
  +        }
  +
  +        p.setParameter( "block-timeout", threadBlockTimeout.toString() );
  +
  +        return p;
       }
   
       protected void initializePoolManager() throws Exception
  
  
  

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


Mime
View raw message