donaldp     2002/11/08 23:31:35

  Modified:    fortress/src/java/org/apache/excalibur/fortress/container
                        AbstractContainer.java
               fortress/src/java/org/apache/excalibur/fortress/handler
                        AbstractComponentHandler.java ComponentFactory.java
                        ComponentHandler.java FactoryComponentHandler.java
                        PerThreadComponentHandler.java
                        PoolableComponentHandler.java
                        ThreadSafeComponentHandler.java
  Log:
  Reworked handler management so that the ctors are more reasonablly defined.
  
  Also moved lifecycle extension management out of the AbstractComponentHandler and 
into a delegating ComponentHandler. Resulted in a chunk of code being cleaned up.
  
  Revision  Changes    Path
  1.6       +45 -11    
jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/container/AbstractContainer.java
  
  Index: AbstractContainer.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/container/AbstractContainer.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AbstractContainer.java    9 Nov 2002 03:46:39 -0000       1.5
  +++ AbstractContainer.java    9 Nov 2002 07:31:34 -0000       1.6
  @@ -74,6 +74,9 @@
   import org.apache.excalibur.fortress.ContainerConstants;
   import org.apache.excalibur.fortress.container.commands.PrepareHandlerCommand;
   import org.apache.excalibur.fortress.handler.ComponentHandler;
  +import org.apache.excalibur.fortress.handler.ComponentFactory;
  +import org.apache.excalibur.fortress.handler.ProxyObjectFactory;
  +import org.apache.excalibur.fortress.handler.LEAwareComponentHandler;
   import org.apache.excalibur.fortress.lifecycle.LifecycleExtensionManager;
   import org.apache.excalibur.fortress.lookup.FortressServiceManager;
   import org.apache.excalibur.fortress.lookup.FortressServiceSelector;
  @@ -82,6 +85,7 @@
   import org.apache.excalibur.instrument.InstrumentManager;
   import org.apache.excalibur.instrument.Instrumentable;
   import org.apache.excalibur.mpool.PoolManager;
  +import org.apache.excalibur.mpool.ObjectFactory;
   
   /**
    * The Container is an interface used to mark the Containers in your system.
  @@ -288,21 +292,27 @@
               Class klass = m_classLoader.loadClass( className );
               Class handlerKlass = m_classLoader.loadClass( handlerClassName );
               constructor = handlerKlass.getConstructor( 
ComponentHandler.HANDLER_CONSTRUCTOR );
  -            handler = (ComponentHandler)constructor.newInstance( new Object[]{
  -                klass,
  -                configuration,
  -                getServiceManager(),
  -                m_context,
  -                m_extManager,
  -                new Boolean( isLazy )
  -            } );
   
  -            if( handler instanceof Instrumentable )
  +            final ObjectFactory factory =
  +                createObjectFactory( klass, configuration );
  +
  +            final ComponentHandler targetHandler =
  +                (ComponentHandler)constructor.newInstance( new Object[]{
  +                    factory,
  +                    m_context,
  +                    new Boolean( isLazy )
  +                } );
  +
  +            ContainerUtil.configure( targetHandler, configuration );
  +
  +            if( targetHandler instanceof Instrumentable )
               {
  -                Instrumentable instrumentable = (Instrumentable)handler;
  +                Instrumentable instrumentable = (Instrumentable)targetHandler;
                   m_instrumentManager.registerInstrumentable(
                       instrumentable, instrumentable.getInstrumentableName() );
               }
  +            handler =
  +                new LEAwareComponentHandler( targetHandler, m_extManager, m_context 
);
           }
           catch( final Exception e )
           {
  @@ -324,6 +334,30 @@
           m_components.add( handler );
   
           return handler;
  +    }
  +
  +    /**
  +     * Create an objectFactory for specified Object configuration.
  +     *
  +     * @param clazz the class of object
  +     * @param configuration the objests configuration
  +     * @return the ObjectFactory
  +     * @throws Exception if unable to create object factory
  +     */
  +    protected ObjectFactory createObjectFactory( final Class clazz,
  +                                                 final Configuration configuration )
  +        throws Exception
  +    {
  +        final LoggerManager loggerManager =
  +            (LoggerManager)m_context.get( ContainerConstants.LOGGER_MANAGER );
  +        final InstrumentManager instrumentManager =
  +            (InstrumentManager)m_context.get( ContainerConstants.INSTRUMENT_MANAGER 
);
  +        final ComponentFactory componentFactory =
  +            new ComponentFactory( clazz, configuration,
  +                                  getServiceManager(), m_context,
  +                                  loggerManager, m_extManager,
  +                                  instrumentManager );
  +        return new ProxyObjectFactory( componentFactory );
       }
   
       /**
  
  
  
  1.35      +16 -43    
jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/AbstractComponentHandler.java
  
  Index: AbstractComponentHandler.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/AbstractComponentHandler.java,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- AbstractComponentHandler.java     9 Nov 2002 05:49:59 -0000       1.34
  +++ AbstractComponentHandler.java     9 Nov 2002 07:31:34 -0000       1.35
  @@ -51,15 +51,11 @@
   
   import org.apache.avalon.excalibur.logger.LoggerManager;
   import org.apache.avalon.framework.activity.Disposable;
  -import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.container.ContainerUtil;
   import org.apache.avalon.framework.context.Context;
   import org.apache.avalon.framework.logger.Logger;
  -import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.excalibur.fortress.ContainerConstants;
  -import org.apache.excalibur.fortress.lifecycle.LifecycleExtensionManager;
   import org.apache.excalibur.instrument.AbstractInstrumentable;
  -import org.apache.excalibur.instrument.InstrumentManager;
   import org.apache.excalibur.instrument.Instrumentable;
   import org.apache.excalibur.mpool.ObjectFactory;
   
  @@ -98,56 +94,44 @@
       protected Logger m_logger;
   
       /** Logger Manager */
  -    protected LoggerManager m_logkit;
  -
  -    /** Context */
  -    protected final Context m_context;
  +    protected LoggerManager m_loggerManager;
   
       /** Initialization policy */
       private boolean m_isLazy;
  -    private LifecycleExtensionManager m_extManager;
   
       /**
        * Create a ComponentHandler that takes care of hiding the details of
        * whether a Component is ThreadSafe, Poolable, or SingleThreaded.
        * It falls back to SingleThreaded if not specified.
        *
  -     * @param componentClass  The class used to instantiate the component
  -     * @param config          The configuration to pass into a configurable
  -     *                        component.
  -     * @param service         The Servicemanager to pass into a serviceable
  -     *                        compoennt.
  +     * @param factory         The factory used to create component
        * @param context         The Context to pass into a contextualizable
        *                        component.
  -     * @param extManager      The lifecycle extension manager that is invoked
  -     *                        for additional lifecycle stages.
        * @param isLazy          Determines whether this component will be
        *                        instantiated on startup or on demand.
        *
        * @throws Exception if any of the passed in members are invalid.
        */
  -    public AbstractComponentHandler( final Class componentClass,
  -                                     final Configuration config,
  -                                     final ServiceManager service,
  +    public AbstractComponentHandler( final ObjectFactory factory,
                                        final Context context,
  -                                     final LifecycleExtensionManager extManager,
                                        final Boolean isLazy )
           throws Exception
       {
  -        m_logkit = (LoggerManager)context.get( ContainerConstants.LOGGER_MANAGER );
  -        InstrumentManager instrumentManager =
  -            (InstrumentManager)context.get( ContainerConstants.INSTRUMENT_MANAGER );
  -        final ComponentFactory componentFactory =
  -            new ComponentFactory( componentClass, config, service, context, 
m_logkit,
  -                                  extManager, instrumentManager );
  -        m_factory = new ProxyObjectFactory( componentFactory );
  -        m_extManager = extManager;
  +        m_factory = factory;
  +        m_isLazy = isLazy.booleanValue();
  +        m_loggerManager =
  +            (LoggerManager)context.get( ContainerConstants.LOGGER_MANAGER );
  +
           if( m_factory instanceof Instrumentable )
           {
               addChildInstrumentable( (Instrumentable)m_factory );
           }
  -        m_context = context;
  -        m_isLazy = isLazy.booleanValue();
  +
  +        final String classname = getClass().getName();
  +        final int index = classname.lastIndexOf( '.' );
  +        final String name = classname.substring( index + 1 );
  +        System.out.println( "name = " + name );
  +        setInstrumentableName( name );
       }
   
       /**
  @@ -218,9 +202,7 @@
               throw new IllegalStateException( message );
           }
   
  -        final Object result = doGet();
  -        m_extManager.executeAccessExtensions( result, m_context );
  -        return result;
  +        return doGet();
       }
   
       /**
  @@ -243,15 +225,6 @@
               final String message =
                   "You cannot put a component in an uninitialized holder";
               throw new IllegalStateException( message );
  -        }
  -
  -        try
  -        {
  -            m_extManager.executeReleaseExtensions( component, m_context );
  -        }
  -        catch( Exception e )
  -        {
  -            // REVISIT(MC): we need to log this somewhere
           }
   
           doPut( component );
  
  
  
  1.28      +5 -3      
jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/ComponentFactory.java
  
  Index: ComponentFactory.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/ComponentFactory.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- ComponentFactory.java     7 Nov 2002 23:23:00 -0000       1.27
  +++ ComponentFactory.java     9 Nov 2002 07:31:34 -0000       1.28
  @@ -200,7 +200,7 @@
   
           if( component instanceof Instrumentable )
           {
  -            Instrumentable instrumentable = (Instrumentable)component;
  +            final Instrumentable instrumentable = (Instrumentable)component;
               instrumentable.setInstrumentableName( m_instrumentableName );
               m_instrumentManager.registerInstrumentable(
                   (Instrumentable)component, m_instrumentableName );
  @@ -243,7 +243,9 @@
           }
           else
           {
  -            throw new IllegalArgumentException( "The object given to be disposed 
does not come from this ObjectFactory" );
  +            final String message = "The object given to be disposed does " +
  +                "not come from this ObjectFactory";
  +            throw new IllegalArgumentException( message );
           }
       }
   
  
  
  
  1.18      +5 -6      
jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/ComponentHandler.java
  
  Index: ComponentHandler.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/ComponentHandler.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- ComponentHandler.java     9 Nov 2002 03:46:39 -0000       1.17
  +++ ComponentHandler.java     9 Nov 2002 07:31:34 -0000       1.18
  @@ -53,6 +53,7 @@
   import org.apache.avalon.framework.context.Context;
   import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.excalibur.fortress.lifecycle.LifecycleExtensionManager;
  +import org.apache.excalibur.mpool.ObjectFactory;
   
   /**
    * The ComponentHandler interface marks the ComponentHandler implementations.
  @@ -65,12 +66,10 @@
    */
   public interface ComponentHandler
   {
  -    Class[] HANDLER_CONSTRUCTOR = new Class[]{
  -        Class.class,
  -        Configuration.class,
  -        ServiceManager.class,
  +    Class[] HANDLER_CONSTRUCTOR = new Class[]
  +    {
  +        ObjectFactory.class,
           Context.class,
  -        LifecycleExtensionManager.class,
           Boolean.class
       };
   
  
  
  
  1.34      +5 -11     
jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/FactoryComponentHandler.java
  
  Index: FactoryComponentHandler.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/FactoryComponentHandler.java,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- FactoryComponentHandler.java      8 Nov 2002 00:33:41 -0000       1.33
  +++ FactoryComponentHandler.java      9 Nov 2002 07:31:34 -0000       1.34
  @@ -49,10 +49,8 @@
   */
   package org.apache.excalibur.fortress.handler;
   
  -import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.context.Context;
  -import org.apache.avalon.framework.service.ServiceManager;
  -import org.apache.excalibur.fortress.lifecycle.LifecycleExtensionManager;
  +import org.apache.excalibur.mpool.ObjectFactory;
   
   /**
    * The FactoryComponentHandler to make sure components are initialized
  @@ -71,17 +69,13 @@
        * whether a Component is ThreadSafe, Poolable, or SingleThreaded.
        * It falls back to SingleThreaded if not specified.
        */
  -    public FactoryComponentHandler( final Class componentClass,
  -                                    final Configuration config,
  -                                    final ServiceManager service,
  +    public FactoryComponentHandler( final ObjectFactory factory,
                                       final Context context,
  -                                    final LifecycleExtensionManager extManager,
                                       final Boolean isLazy )
           throws Exception
       {
  -        super( componentClass, config, service, context, extManager, isLazy );
  -        m_logger = m_logkit.getLoggerForCategory( "system.handler.factory" );
  -        setInstrumentableName( "FactoryComponentHandler" );
  +        super( factory, context, isLazy );
  +        m_logger = m_loggerManager.getLoggerForCategory( "system.handler.factory" );
       }
   
       /**
  
  
  
  1.37      +5 -11     
jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/PerThreadComponentHandler.java
  
  Index: PerThreadComponentHandler.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/PerThreadComponentHandler.java,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- PerThreadComponentHandler.java    8 Nov 2002 00:33:41 -0000       1.36
  +++ PerThreadComponentHandler.java    9 Nov 2002 07:31:34 -0000       1.37
  @@ -48,10 +48,8 @@
   */
   package org.apache.excalibur.fortress.handler;
   
  -import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.context.Context;
  -import org.apache.avalon.framework.service.ServiceManager;
  -import org.apache.excalibur.fortress.lifecycle.LifecycleExtensionManager;
  +import org.apache.excalibur.mpool.ObjectFactory;
   
   /**
    * The ThreadSafeComponentHandler to make sure components are initialized
  @@ -72,18 +70,14 @@
        * whether a Component is ThreadSafe, Poolable, or SingleThreaded.
        * It falls back to SingleThreaded if not specified.
        */
  -    public PerThreadComponentHandler( final Class componentClass,
  -                                      final Configuration config,
  -                                      final ServiceManager service,
  +    public PerThreadComponentHandler( final ObjectFactory factory,
                                         final Context context,
  -                                      final LifecycleExtensionManager extManager,
                                         final Boolean isLazy )
           throws Exception
       {
  -        super( componentClass, config, service, context, extManager, isLazy );
  -        m_logger = m_logkit.getLoggerForCategory( "system.handler.perthread" );
  +        super( factory, context, isLazy );
  +        m_logger = m_loggerManager.getLoggerForCategory( "system.handler.perthread" 
);
           m_instance = new ThreadLocalComponent( this );
  -        setInstrumentableName( "PerThreadComponentHandler" );
       }
   
       /**
  
  
  
  1.39      +16 -12    
jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/PoolableComponentHandler.java
  
  Index: PoolableComponentHandler.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/PoolableComponentHandler.java,v
  retrieving revision 1.38
  retrieving revision 1.39
  diff -u -r1.38 -r1.39
  --- PoolableComponentHandler.java     9 Nov 2002 03:46:39 -0000       1.38
  +++ PoolableComponentHandler.java     9 Nov 2002 07:31:34 -0000       1.39
  @@ -49,11 +49,12 @@
   */
   package org.apache.excalibur.fortress.handler;
   
  -import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.context.Context;
  -import org.apache.avalon.framework.service.ServiceManager;
  +import org.apache.avalon.framework.configuration.Configurable;
  +import org.apache.avalon.framework.configuration.Configuration;
  +import org.apache.avalon.framework.configuration.ConfigurationException;
   import org.apache.excalibur.fortress.ContainerConstants;
  -import org.apache.excalibur.fortress.lifecycle.LifecycleExtensionManager;
  +import org.apache.excalibur.mpool.ObjectFactory;
   import org.apache.excalibur.mpool.Pool;
   import org.apache.excalibur.mpool.PoolManager;
   
  @@ -68,6 +69,7 @@
    */
   public final class PoolableComponentHandler
       extends AbstractComponentHandler
  +    implements Configurable
   {
       /** The instance of the PoolManager to create the Pool for the Handler */
       private final PoolManager m_poolManager;
  @@ -76,26 +78,28 @@
       private Pool m_pool;
   
       /** The Config element for the poolable */
  -    private final int m_poolMin;
  +    private int m_poolMin;
   
       /**
        * Create a ComponentHandler that takes care of hiding the details of
        * whether a Component is ThreadSafe, Poolable, or SingleThreaded.
        * It falls back to SingleThreaded if not specified.
        */
  -    public PoolableComponentHandler( final Class componentClass,
  -                                     final Configuration config,
  -                                     final ServiceManager service,
  +    public PoolableComponentHandler( final ObjectFactory factory,
                                        final Context context,
  -                                     final LifecycleExtensionManager extManager,
                                        final Boolean isLazy )
           throws Exception
       {
  -        super( componentClass, config, service, context, extManager, isLazy );
  -        m_poolMin = config.getAttributeAsInteger( "pool-min", 10 );
  -        m_logger = m_logkit.getLoggerForCategory( "system.handler.poolable" );
  +        super( factory, context, isLazy );
  +        m_logger = m_loggerManager.getLoggerForCategory( "system.handler.poolable" 
);
           m_poolManager = (PoolManager)context.get( ContainerConstants.POOL_MANAGER );
           setInstrumentableName( "PoolableComponentHandler" );
  +    }
  +
  +    public void configure( final Configuration configuration )
  +        throws ConfigurationException
  +    {
  +        m_poolMin = configuration.getAttributeAsInteger( "pool-min", 10 );
       }
   
       /**
  
  
  
  1.37      +5 -11     
jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/ThreadSafeComponentHandler.java
  
  Index: ThreadSafeComponentHandler.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/ThreadSafeComponentHandler.java,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- ThreadSafeComponentHandler.java   9 Nov 2002 03:46:39 -0000       1.36
  +++ ThreadSafeComponentHandler.java   9 Nov 2002 07:31:34 -0000       1.37
  @@ -49,10 +49,8 @@
   */
   package org.apache.excalibur.fortress.handler;
   
  -import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.context.Context;
  -import org.apache.avalon.framework.service.ServiceManager;
  -import org.apache.excalibur.fortress.lifecycle.LifecycleExtensionManager;
  +import org.apache.excalibur.mpool.ObjectFactory;
   
   /**
    * The ThreadSafeComponentHandler to make sure components are initialized
  @@ -73,17 +71,13 @@
        * whether a Component is ThreadSafe, Poolable, or SingleThreaded.
        * It falls back to SingleThreaded if not specified.
        */
  -    public ThreadSafeComponentHandler( final Class componentClass,
  -                                       final Configuration config,
  -                                       final ServiceManager service,
  +    public ThreadSafeComponentHandler( final ObjectFactory factory,
                                          final Context context,
  -                                       final LifecycleExtensionManager extManager,
                                          final Boolean isLazy )
           throws Exception
       {
  -        super( componentClass, config, service, context, extManager, isLazy );
  -        m_logger = m_logkit.getLoggerForCategory( "system.handler.threadsafe" );
  -        setInstrumentableName( "ThreadSafeComponentHandler" );
  +        super( factory, context, isLazy );
  +        m_logger = m_loggerManager.getLoggerForCategory( 
"system.handler.threadsafe" );
       }
   
       /**
  
  
  

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

Reply via email to