avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From blorit...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system ContainerManager.java
Date Mon, 28 Jan 2002 19:29:48 GMT
bloritsch    02/01/28 11:29:48

  Modified:    src/scratchpad/org/apache/avalon/excalibur/command
                        CommandManager.java TPCThreadManager.java
                        TPSPThreadManager.java
               src/scratchpad/org/apache/avalon/excalibur/pool
                        DefaultPoolManager.java ManagablePool.java
               src/scratchpad/org/apache/avalon/excalibur/system
                        ContainerManager.java
  Log:
  update ContainerManager with new Manager types
  
  Revision  Changes    Path
  1.3       +2 -1      jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/command/CommandManager.java
  
  Index: CommandManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/command/CommandManager.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CommandManager.java	28 Jan 2002 18:42:25 -0000	1.2
  +++ CommandManager.java	28 Jan 2002 19:29:47 -0000	1.3
  @@ -155,8 +155,9 @@
                       if ( command.m_repeatable )
                       {
                           RepeatedCommand cmd = (RepeatedCommand) command.m_command;
  +                        int numRepeats = cmd.getNumberOfRepeats();
   
  -                        if ( cmd.getNumberOfRepeats() < command.m_numExecutions )
  +                        if ( numRepeats < 1 || numRepeats < command.m_numExecutions
)
                           {
                               command.m_nextRunTime = System.currentTimeMillis() +
                                       cmd.getRepeatInterval();
  
  
  
  1.2       +6 -5      jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/command/TPCThreadManager.java
  
  Index: TPCThreadManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/command/TPCThreadManager.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TPCThreadManager.java	28 Jan 2002 18:42:25 -0000	1.1
  +++ TPCThreadManager.java	28 Jan 2002 19:29:47 -0000	1.2
  @@ -26,7 +26,7 @@
    *
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
    */
  -public final class TPCThreadManager implements Runnable
  +public final class TPCThreadManager implements Runnable, ThreadManager
   {
       private final ThreadPool m_threadPool;
       private final Mutex   m_mutex = new Mutex();
  @@ -52,7 +52,8 @@
        */
       public TPCThreadManager(Parameters params)
       {
  -        this( params.getParameterAsInteger( "os.arch.cpus", 1 ) , 1 );
  +        this( params.getParameterAsInteger( "os.arch.cpus", 1 ) ,
  +              params.getParameterAsInteger( "container.threadsPerCPU", 2 ) );
       }
   
       /**
  @@ -91,7 +92,7 @@
       /**
        * Register an EventPipeline with the ThreadManager.
        */
  -    void register( EventPipeline pipeline )
  +    public void register( EventPipeline pipeline )
       {
           try
           {
  @@ -117,7 +118,7 @@
       /**
        * Deregister an EventPipeline with the ThreadManager
        */
  -    void deregister( EventPipeline pipeline )
  +    public void deregister( EventPipeline pipeline )
       {
           try
           {
  @@ -144,7 +145,7 @@
       /**
        * Deregisters all EventPipelines from this ThreadManager
        */
  -    void deregisterAll()
  +    public void deregisterAll()
       {
           try
           {
  
  
  
  1.3       +4 -4      jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/command/TPSPThreadManager.java
  
  Index: TPSPThreadManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/command/TPSPThreadManager.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TPSPThreadManager.java	28 Jan 2002 18:43:55 -0000	1.2
  +++ TPSPThreadManager.java	28 Jan 2002 19:29:47 -0000	1.3
  @@ -26,7 +26,7 @@
    *
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
    */
  -public final class TPSPThreadManager implements Runnable
  +public final class TPSPThreadManager implements Runnable, ThreadManager
   {
       private final ThreadPool m_threadPool;
       private final Mutex   m_mutex = new Mutex();
  @@ -64,7 +64,7 @@
       /**
        * Register an EventPipeline with the ThreadManager.
        */
  -    void register( EventPipeline pipeline )
  +    public void register( EventPipeline pipeline )
       {
           try
           {
  @@ -90,7 +90,7 @@
       /**
        * Deregister an EventPipeline with the ThreadManager
        */
  -    void deregister( EventPipeline pipeline )
  +    public void deregister( EventPipeline pipeline )
       {
           try
           {
  @@ -117,7 +117,7 @@
       /**
        * Deregisters all EventPipelines from this ThreadManager
        */
  -    void deregisterAll()
  +    public void deregisterAll()
       {
           try
           {
  
  
  
  1.5       +87 -11    jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/pool/DefaultPoolManager.java
  
  Index: DefaultPoolManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/pool/DefaultPoolManager.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DefaultPoolManager.java	4 Jan 2002 16:36:49 -0000	1.4
  +++ DefaultPoolManager.java	28 Jan 2002 19:29:47 -0000	1.5
  @@ -8,6 +8,12 @@
   package org.apache.avalon.excalibur.pool;
   
   import java.security.SecureRandom;
  +import org.apache.avalon.excalibur.command.RepeatedCommand;
  +import org.apache.avalon.excalibur.event.Queue;
  +
  +import java.util.HashMap;
  +import java.util.Iterator;
  +import java.util.Map;
   
   /**
    * This interface is for a PoolManager that creates pools that are managed
  @@ -15,26 +21,37 @@
    * the constructor.
    *
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  - * @version CVS $Revision: 1.4 $ $Date: 2002/01/04 16:36:49 $
  + * @version CVS $Revision: 1.5 $ $Date: 2002/01/28 19:29:47 $
    * @since 4.1
    */
   public class DefaultPoolManager implements PoolManager
   {
  -    private final ObjectFactory m_controllerFactory;
       private final long          m_managerKey;
       private final SecureRandom  m_keyGenerator;
  +    private final HashMap       m_keyMap = new HashMap();
  +    private final HashMap       m_factoryMap = new HashMap();
   
  -    public DefaultPoolManager( final Class klass )
  -        throws Exception
  +    public DefaultPoolManager()
  +    {
  +        this( null );
  +    }
  +
  +    public DefaultPoolManager( final Queue commandQueue )
       {
           m_keyGenerator = new SecureRandom();
           m_managerKey = m_keyGenerator.nextLong();
   
  -        m_controllerFactory = new DefaultObjectFactory( klass,
  -                                                        new Class[] {long.class},
  -                                                        new Object[] {
  -                                                            new Long(m_managerKey)
  -                                                        } );
  +        if ( null != commandQueue )
  +        {
  +            try
  +            {
  +                commandQueue.enqueue( new PoolManagerCommand( m_keyMap ) );
  +            }
  +            catch (Exception e)
  +            {
  +                // ignore silently for now
  +            }
  +        }
       }
   
       /**
  @@ -43,9 +60,17 @@
       public Pool getManagedPool( ObjectFactory factory, int initialEntries )
           throws Exception
       {
  -        final long poolKey = getKey();
  +        ManagablePool pool = (ManagablePool) m_factoryMap.get( factory );
   
  -        return new VariableSizePool( factory, initialEntries, poolKey );
  +        if ( null == pool )
  +        {
  +            final long poolKey = getKey();
  +            pool =  new VariableSizePool( factory, initialEntries, poolKey );
  +            m_keyMap.put( pool, new Long( poolKey ) );
  +            m_factoryMap.put( factory, pool );
  +        }
  +
  +        return pool;
       }
   
       /**
  @@ -54,5 +79,56 @@
       private final long getKey()
       {
           return m_keyGenerator.nextLong();
  +    }
  +
  +    private final static class PoolManagerCommand implements RepeatedCommand
  +    {
  +        private final Map m_map;
  +        private final int m_min = 4;
  +        private final int m_max = 256;
  +        private final int m_grow = 4;
  +
  +        protected PoolManagerCommand( Map map )
  +        {
  +            m_map = map;
  +        }
  +
  +        public long getDelayInterval()
  +        {
  +            return 10 * 1000L;
  +        }
  +
  +        public long getRepeatInterval()
  +        {
  +            return 10 * 1000L;
  +        }
  +
  +        public int getNumberOfRepeats()
  +        {
  +            return 0;
  +        }
  +
  +        public void execute()
  +            throws Exception
  +        {
  +            Iterator i = m_map.keySet().iterator();
  +
  +            while (i.hasNext())
  +            {
  +                ManagablePool pool = (ManagablePool) i.next();
  +                long key = ((Long) m_map.get( pool )).longValue();
  +                int size = pool.size( key );
  +
  +                if ( size < m_min )
  +                {
  +                    pool.grow( m_grow, key );
  +                }
  +
  +                if ( size > m_max )
  +                {
  +                    pool.shrink( m_grow, key );
  +                }
  +            }
  +        }
       }
   }
  
  
  
  1.3       +7 -4      jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/pool/ManagablePool.java
  
  Index: ManagablePool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/pool/ManagablePool.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ManagablePool.java	26 Dec 2001 17:59:20 -0000	1.2
  +++ ManagablePool.java	28 Jan 2002 19:29:47 -0000	1.3
  @@ -24,7 +24,7 @@
    * </p>
    *
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  - * @version CVS $Revision: 1.2 $ $Date: 2001/12/26 17:59:20 $
  + * @version CVS $Revision: 1.3 $ $Date: 2002/01/28 19:29:47 $
    * @since 4.1
    */
   public interface ManagablePool extends Pool
  @@ -40,7 +40,8 @@
        * @throws IllegalAccessException if the key does not match the controller's
        *                                key.
        */
  -    void grow( int amount, long key ) throws IllegalAccessException;
  +    void grow( int amount, long key )
  +        throws IllegalAccessException;
   
       /**
        * Shrink the pool by the specified amount.  The pool should trust the
  @@ -55,7 +56,8 @@
        * @throws IllegalAccessException if the key does not match the controller's
        *                                key.
        */
  -    void shrink( int amount, long key ) throws IllegalAccessException;
  +    void shrink( int amount, long key )
  +        throws IllegalAccessException;
   
       /**
        * Determine the pool's current size.  The size is defined as the number of
  @@ -69,5 +71,6 @@
        * @throws IllegalAccessException if the key does not match the controller's
        *                                key.
        */
  -    int size( long key ) throws IllegalAccessException;
  +    int size( long key )
  +        throws IllegalAccessException;
   }
  
  
  
  1.10      +17 -9     jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/ContainerManager.java
  
  Index: ContainerManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/ContainerManager.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ContainerManager.java	25 Jan 2002 21:54:02 -0000	1.9
  +++ ContainerManager.java	28 Jan 2002 19:29:47 -0000	1.10
  @@ -17,6 +17,8 @@
   import org.apache.avalon.excalibur.logger.LogKitLoggerManager;
   import org.apache.avalon.excalibur.util.ComponentStateValidator;
   import org.apache.avalon.excalibur.source.*;
  +import org.apache.avalon.excalibur.command.*;
  +import org.apache.avalon.excalibur.pool.*;
   
   import java.io.File;
   
  @@ -104,11 +106,10 @@
    *     </td>
    *   </tr>
    *   <tr>
  - *     <td><code>MAX_THREADS</code></td>
  + *     <td><code>THREADS_CPU</code></td>
    *     <td>
  - *       <code>Integer</code> that holds the value of the maximum number of
  - *       threads used by the ThreadManager.  This defaults to
  - *       <code>CPU_COUNT * 2</code>.
  + *       <code>Integer</code> that holds the value of the number of threads
used
  + *       by the ThreadManager per CPU.  This defaults to 2.
    *     </td>
    *   </tr>
    *   <tr>
  @@ -122,7 +123,7 @@
    * </table>
    *
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  - * @version CVS $Revision: 1.9 $ $Date: 2002/01/25 21:54:02 $
  + * @version CVS $Revision: 1.10 $ $Date: 2002/01/28 19:29:47 $
    */
   public class ContainerManager
   {
  @@ -132,7 +133,7 @@
       public static final String XML_PARSER        = "container.xmlParser";
       public static final String LOGKIT_CONFIG     = "container.loggerConfig";
       public static final String ROLE_CONFIG       = "container.roles";
  -    public static final String MAX_THREADS       = "container.threadPoolMax";
  +    public static final String THREADS_CPU       = "container.threadsPerCPU";
       public static final String CONTAINER_CONFIG  = "container.configFile";
       public static final String LOG_CATEGORY      = "container.logCategory";
       public static final String CPU_COUNT         = "os.arch.cpus";
  @@ -156,9 +157,9 @@
       private final File                    m_contextDirectory;
       private final File                    m_workDirectory;
       private       LoggerManager           m_logManager;
  -    // private final PoolManager            m_poolManager;
  -    // private final ThreadManager          m_threadManager;
  -    // private final CommandManager         m_commandManager;
  +    private final PoolManager             m_poolManager;
  +    private final ThreadManager           m_threadManager;
  +    private final CommandManager          m_commandManager;
       private       ComponentManager        m_componentManager;
       private       Configuration           m_containerConfig;
       private       Configuration           m_logKitConfig;
  @@ -202,6 +203,10 @@
           m_contextClassLoader = rootClassLoader;
           m_contextDirectory = new File(initialParameters.getParameter( CONTEXT_DIRECTORY,
"./" ) );
           m_workDirectory = new File( initialParameters.getParameter( CONTEXT_DIRECTORY,
"/tmp" ) );
  +        m_commandManager = new CommandManager();
  +        m_threadManager = new TPCThreadManager( initialParameters );
  +        m_threadManager.register( m_commandManager );
  +        m_poolManager = new DefaultPoolManager( m_commandManager.getCommandQueue() );
   
           if ( null != defaultLogManager )
           {
  @@ -376,6 +381,9 @@
               );
               context.put( Container.CONTEXT_CLASSLOADER, m_contextClassLoader );
               context.put( Container.ROLE_MANAGER, getRoleManager() );
  +
  +            context.put( Container.COMMAND_QUEUE, m_commandManager.getCommandQueue() );
  +            context.put( Container.POOL_MANAGER, m_poolManager );
   
               context.makeReadOnly();
               m_containerContext = context;
  
  
  

--
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