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/lookup FortressComponentManager.java FortressComponentSelector.java FortressServiceManager.java FortressServiceSelector.java
Date Tue, 09 Jul 2002 13:32:36 GMT
crafterm    2002/07/09 06:32:36

  Modified:    fortress/src/java/org/apache/excalibur/fortress
                        AbstractContainer.java ContainerConstants.java
               fortress/src/java/org/apache/excalibur/fortress/handler
                        AbstractComponentHandler.java
                        AbstractThreadSafeComponentHandler.java
                        ComponentFactory.java ComponentHandler.java
                        FactoryComponentHandler.java
                        LazyThreadSafeComponentHandler.java
                        PerThreadComponentHandler.java
                        PoolableComponentHandler.java
                        ThreadSafeComponentHandler.java
               fortress/src/java/org/apache/excalibur/fortress/lookup
                        FortressComponentManager.java
                        FortressComponentSelector.java
                        FortressServiceManager.java
                        FortressServiceSelector.java
  Added:       fortress/src/java/org/apache/excalibur/fortress/lifecycle
                        AbstractLifecycleExtension.java
                        AbstractLifecycleExtensionManager.java
                        LifecycleExtension.java
                        LifecycleExtensionManager.java package.html
  Log:
  Initial commit of Lifecycle extensions code.
  
  Revision  Changes    Path
  1.45      +42 -19    jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/AbstractContainer.java
  
  Index: AbstractContainer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/AbstractContainer.java,v
  retrieving revision 1.44
  retrieving revision 1.45
  diff -u -r1.44 -r1.45
  --- AbstractContainer.java	28 Jun 2002 10:03:24 -0000	1.44
  +++ AbstractContainer.java	9 Jul 2002 13:32:35 -0000	1.45
  @@ -36,6 +36,7 @@
   import org.apache.excalibur.event.Queue;
   import org.apache.excalibur.event.command.Command;
   import org.apache.excalibur.fortress.handler.ComponentHandler;
  +import org.apache.excalibur.fortress.lifecycle.LifecycleExtensionManager;
   import org.apache.excalibur.fortress.lookup.FortressComponentManager;
   import org.apache.excalibur.fortress.lookup.FortressComponentSelector;
   import org.apache.excalibur.fortress.lookup.FortressServiceManager;
  @@ -45,8 +46,8 @@
   
   /**
    * The Container is an interface used to mark the Containers in your system.  It
  - * exposes a protected getComponentManager() method so that the Container's
  - * Manager can expose that to the instantiating class.
  + * exposes a protected getComponentManager()/getServiceManager() method so that the
  + * Container's Manager can expose that to the instantiating class.
    *
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
    * @author <a href="mailto:proyal@apache.org">Peter Royal</a>
  @@ -68,6 +69,7 @@
       protected BucketMap m_configs = new BucketMap();
       protected BucketMap m_mapper = new BucketMap();
       protected List m_components = new ArrayList( 10 );
  +    protected LifecycleExtensionManager m_extManager;
   
       /**
        * Wrap this so that ComponentStateValidator functions properly.
  @@ -91,6 +93,22 @@
   
           try
           {
  +            m_extManager = (LifecycleExtensionManager)m_context.get( Container.EXTENSION_MANAGER );
  +        }
  +        catch( ContextException ce )
  +        {
  +            m_extManager = new LifecycleExtensionManager();
  +
  +            if ( getLogger().isDebugEnabled() )
  +            {
  +                getLogger().debug( "No Container.EXTENSION_MANAGER is given, installing default lifecycle extension manager with 0 extensions" );
  +            }
  +        }
  +
  +        m_extManager.enableLogging( getLogger() );
  +
  +        try
  +        {
               m_classLoader = (ClassLoader)m_context.get( Container.CONTEXT_CLASSLOADER );
           }
           catch( ContextException ce )
  @@ -222,7 +240,6 @@
   
       /**
        * Add a Component.
  -     *
        */
       protected void addComponent( final Configuration component, Object hint )
       {
  @@ -252,7 +269,7 @@
               {
                   if( !hintMap.containsKey( "selector" ) )
                   {
  -                    hintMap.put( "selector", new FortressComponentSelector( this, role ) );
  +                    hintMap.put( "selector", new FortressComponentSelector( this, role, m_extManager, m_context ) );
                   }
               }
               else
  @@ -260,6 +277,8 @@
                   hintMap.put( "default", handler );
               }
   
  +	    // FIXME(MC) is this always needed ? should only need to be done if
  +	    // hintMap is not yet in m_mapper ? or is it here due to threading issues ?
               m_mapper.put( role, hintMap );
           }
       }
  @@ -285,10 +304,11 @@
                   configuration,
                   getComponentManager(),
                   getServiceManager(),
  -                m_context
  +                m_context,
  +                m_extManager
               } );
           }
  -        catch( Exception e )
  +        catch( final Exception e )
           {
               if( getLogger().isDebugEnabled() )
               {
  @@ -325,7 +345,7 @@
       public Object get( final String role, final Object hint )
           throws ServiceException
       {
  -        BucketMap hintMap = (BucketMap)m_mapper.get( role );
  +        final BucketMap hintMap = (BucketMap)m_mapper.get( role );
           Object value;
   
           if( null == hintMap )
  @@ -368,7 +388,7 @@
        */
       public boolean has( final String role, final Object hint )
       {
  -        BucketMap hintMap = (BucketMap)m_mapper.get( role );
  +        final BucketMap hintMap = (BucketMap)m_mapper.get( role );
   
           if( null == hintMap )
           {
  @@ -445,14 +465,17 @@
               }
               catch( Exception e )
               {
  -                getLogger().warn( "Could not initialize component", e );
  +                if ( getLogger().isWarnEnabled() )
  +                {
  +                    getLogger().warn( "Could not initialize component", e );
  +                }
                   buffer.add( e );
               }
           }
   
           if( buffer.size() > 0 )
           {
  -            StringBuffer message = new StringBuffer();
  +            final StringBuffer message = new StringBuffer();
   
               while( !buffer.isEmpty() )
               {
  @@ -468,7 +491,7 @@
        */
       public void dispose()
       {
  -        Iterator i = m_components.iterator();
  +        final Iterator i = m_components.iterator();
   
           while( i.hasNext() )
           {
  @@ -483,7 +506,7 @@
   
                       i.remove();
                   }
  -                catch( Exception e )
  +                catch( final Exception e )
                   {
                       if( getLogger().isWarnEnabled() )
                       {
  @@ -507,10 +530,10 @@
       protected final ComponentManager getComponentManager()
       {
           if ( m_componentManager == null && m_serviceManager == null )
  -            return new FortressComponentManager( this );
  +            return new FortressComponentManager( this, m_extManager, m_context );
           return m_componentManager == null ?
  -            new FortressComponentManager( this, m_serviceManager ) :
  -            new FortressComponentManager( this, m_componentManager );
  +            new FortressComponentManager( this, m_serviceManager, m_extManager, m_context ) :
  +            new FortressComponentManager( this, m_componentManager, m_extManager, m_context );
       }
   
       /**
  @@ -522,10 +545,10 @@
       protected final ServiceManager getServiceManager()
       {
           if ( m_componentManager == null && m_serviceManager == null )
  -            return new FortressServiceManager( this );
  +            return new FortressServiceManager( this, m_extManager, m_context );
           return m_serviceManager == null ?
  -            new FortressServiceManager( this, m_componentManager ) :
  -            new FortressServiceManager( this, m_serviceManager );
  +            new FortressServiceManager( this, m_componentManager, m_extManager, m_context ) :
  +            new FortressServiceManager( this, m_serviceManager, m_extManager, m_context );
       }
   
       /**
  
  
  
  1.6       +3 -1      jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/ContainerConstants.java
  
  Index: ContainerConstants.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/ContainerConstants.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ContainerConstants.java	4 Apr 2002 16:04:28 -0000	1.5
  +++ ContainerConstants.java	9 Jul 2002 13:32:36 -0000	1.6
  @@ -33,4 +33,6 @@
   
       String THREADS_CPU = "container.threadsPerCPU";
       String THREAD_TIMEOUT = "container.threadTimeout";
  +
  +    String EXTENSION_MANAGER = "container.extensionManager";
   }
  
  
  
  1.5       +9 -3      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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AbstractComponentHandler.java	18 Jun 2002 18:45:36 -0000	1.4
  +++ AbstractComponentHandler.java	9 Jul 2002 13:32:36 -0000	1.5
  @@ -17,6 +17,7 @@
   import org.apache.avalon.framework.logger.Logger;
   import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.excalibur.fortress.Container;
  +import org.apache.excalibur.fortress.lifecycle.LifecycleExtensionManager;
   import org.apache.excalibur.fortress.util.RoleManager;
   
   /**
  @@ -48,6 +49,9 @@
       /** Logger Manager */
       protected LoggerManager m_logkit;
   
  +    /** Context */
  +    protected final Context m_context;
  +
       /**
        * Create a ComponentHandler that takes care of hiding the details of
        * whether a Component is ThreadSafe, Poolable, or SingleThreaded.
  @@ -57,11 +61,13 @@
                                        final Configuration config,
                                        final ComponentManager manager,
                                        final ServiceManager service,
  -                                     final Context context )
  +                                     final Context context,
  +                                     final LifecycleExtensionManager extManager )
           throws Exception
       {
           m_logkit = (LoggerManager)context.get( Container.LOGGER_MANAGER );
  -        m_factory = new ComponentFactory( componentClass, config, manager, service, context, m_logkit );
  +        m_factory = new ComponentFactory( componentClass, config, manager, service, context, m_logkit, extManager );
  +        m_context = context;
       }
   
       public boolean isInitialized()
  
  
  
  1.2       +6 -3      jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/AbstractThreadSafeComponentHandler.java
  
  Index: AbstractThreadSafeComponentHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/AbstractThreadSafeComponentHandler.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractThreadSafeComponentHandler.java	28 Jun 2002 17:11:20 -0000	1.1
  +++ AbstractThreadSafeComponentHandler.java	9 Jul 2002 13:32:36 -0000	1.2
  @@ -15,6 +15,7 @@
   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.lifecycle.LifecycleExtensionManager;
   
   /**
    * The ThreadSafeComponentHandler to make sure components are initialized
  @@ -39,10 +40,11 @@
                                                  final Configuration config,
                                                  final ComponentManager manager,
                                                  final ServiceManager service,
  -                                               final Context context )
  +                                               final Context context,
  +                                               final LifecycleExtensionManager extManager )
           throws Exception
       {
  -        super( componentClass, config, manager, service, context );
  +        super( componentClass, config, manager, service, context, extManager );
       }
   
       /**
  @@ -57,6 +59,7 @@
           throws Exception
       {
           super.get();
  +
           return getInstance();
       }
   
  
  
  
  1.15      +15 -2     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.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- ComponentFactory.java	25 Jun 2002 20:44:26 -0000	1.14
  +++ ComponentFactory.java	9 Jul 2002 13:32:36 -0000	1.15
  @@ -21,6 +21,7 @@
   import org.apache.avalon.framework.parameters.Parameters;
   import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.avalon.framework.thread.ThreadSafe;
  +import org.apache.excalibur.fortress.lifecycle.LifecycleExtensionManager;
   import org.apache.excalibur.mpool.ObjectFactory;
   
   /**
  @@ -66,20 +67,27 @@
        */
       private Logger m_logger;
   
  +    /** Lifecycle extensions manager
  +     */
  +    private final LifecycleExtensionManager m_extManager;
  +
       /**
        * Construct a new component factory for the specified component.
        *
        * @param componentClass the class to instantiate (must have a default constructor).
        * @param configuration the <code>Configuration</code> object to pass to new instances.
        * @param componentManager the component manager to pass to <code>Composable</code>s.
  +     * @param serviceManager the service manager to pass to <code>Serviceable</code>s.
        * @param context the <code>Context</code> to pass to <code>Contexutalizable</code>s.
  +     * @param logkit the logkit manager instance.
        */
       public ComponentFactory( final Class componentClass,
                                final Configuration configuration,
                                final ComponentManager componentManager,
                                final ServiceManager serviceManager,
                                final Context context,
  -                             final LoggerManager logkit )
  +                             final LoggerManager logkit,
  +                             final LifecycleExtensionManager extManager )
       {
           m_componentClass = componentClass;
           m_configuration = configuration;
  @@ -87,6 +95,7 @@
           m_serviceManager = serviceManager;
           m_context = context;
           m_logManager = logkit;
  +        m_extManager = extManager;
           m_logger = m_logManager.getLoggerForCategory( "system.factory" );
   
           m_newInstance = new CounterInstrument( "Create " + getInstrumentableName() );
  @@ -130,6 +139,8 @@
               ContainerUtil.parameterize( component, parameters );
           }
   
  +        m_extManager.executeCreationExtensions( component, m_context );
  +
           ContainerUtil.initialize( component );
           ContainerUtil.start( component );
   
  @@ -158,6 +169,8 @@
           if( getCreatedClass().equals( component.getClass() ) )
           {
               ContainerUtil.shutdown( component );
  +
  +            m_extManager.executeDestructionExtensions( component, m_context );
   
               if( m_dispose.isActive() )
               {
  
  
  
  1.10      +4 -2      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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ComponentHandler.java	18 Jun 2002 18:45:36 -0000	1.9
  +++ ComponentHandler.java	9 Jul 2002 13:32:36 -0000	1.10
  @@ -13,6 +13,7 @@
   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;
   
   /**
    * The ComponentHandler interface marks the ComponentHandler implementations.
  @@ -30,7 +31,8 @@
           Configuration.class,
           ComponentManager.class,
           ServiceManager.class,
  -        Context.class
  +        Context.class,
  +        LifecycleExtensionManager.class
       };
   
       /**
  
  
  
  1.18      +8 -7      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.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- FactoryComponentHandler.java	18 Jun 2002 18:45:36 -0000	1.17
  +++ FactoryComponentHandler.java	9 Jul 2002 13:32:36 -0000	1.18
  @@ -12,6 +12,7 @@
   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;
   
   /**
    * The FactoryComponentHandler to make sure components are initialized
  @@ -34,10 +35,11 @@
                                       final Configuration config,
                                       final ComponentManager manager,
                                       final ServiceManager service,
  -                                    final Context context )
  +                                    final Context context,
  +                                    final LifecycleExtensionManager extManager )
           throws Exception
       {
  -        super( componentClass, config, manager, service, context );
  +        super( componentClass, config, manager, service, context, extManager );
           m_logger = m_logkit.getLoggerForCategory( "system.handler.factory" );
           m_name = "FactoryComponentHandler";
       }
  @@ -81,12 +83,11 @@
           {
               m_factory.dispose( component );
           }
  -        catch( final Exception e )
  +        catch ( Exception e )
           {
  -            if( m_logger.isWarnEnabled() )
  +            if ( m_logger.isWarnEnabled() )
               {
  -                m_logger.warn( "Error decommissioning component: " +
  -                               m_factory.getCreatedClass().getName(), e );
  +                m_logger.warn( "Error disposing component", e );
               }
           }
       }
  
  
  
  1.2       +5 -3      jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/LazyThreadSafeComponentHandler.java
  
  Index: LazyThreadSafeComponentHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/LazyThreadSafeComponentHandler.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LazyThreadSafeComponentHandler.java	28 Jun 2002 17:11:20 -0000	1.1
  +++ LazyThreadSafeComponentHandler.java	9 Jul 2002 13:32:36 -0000	1.2
  @@ -11,6 +11,7 @@
   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;
   
   /**
    * LazyThreadSafeComponentHandler. This class manages thread safe
  @@ -33,10 +34,11 @@
                                              final Configuration config,
                                              final ComponentManager manager,
                                              final ServiceManager service,
  -                                           final Context context )
  +                                           final Context context,
  +                                           final LifecycleExtensionManager extManager )
           throws Exception
       {
  -        super( componentClass, config, manager, service, context );
  +        super( componentClass, config, manager, service, context, extManager );
           m_logger = m_logkit.getLoggerForCategory( "system.handler.threadsafe.lazy" );
           m_name = "LazyThreadSafeComponentHandler";
       }
  
  
  
  1.19      +6 -4      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.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- PerThreadComponentHandler.java	18 Jun 2002 18:45:36 -0000	1.18
  +++ PerThreadComponentHandler.java	9 Jul 2002 13:32:36 -0000	1.19
  @@ -12,6 +12,7 @@
   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;
   
   /**
    * The ThreadSafeComponentHandler to make sure components are initialized
  @@ -36,10 +37,11 @@
                                         final Configuration config,
                                         final ComponentManager manager,
                                         final ServiceManager service,
  -                                      final Context context )
  +                                      final Context context,
  +                                      final LifecycleExtensionManager extManager )
           throws Exception
       {
  -        super( componentClass, config, manager, service, context );
  +        super( componentClass, config, manager, service, context, extManager );
           m_instance = new ThreadLocalComponent( m_factory );
           m_logger = m_logkit.getLoggerForCategory( "system.handler.perthread" );
           m_name = "PerThreadComponentHandler";
  @@ -79,7 +81,7 @@
       {
           super.get();
   
  -        return m_instance.get();
  +	return m_instance.get();
       }
   
       /**
  
  
  
  1.22      +6 -5      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.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- PoolableComponentHandler.java	18 Jun 2002 18:45:36 -0000	1.21
  +++ PoolableComponentHandler.java	9 Jul 2002 13:32:36 -0000	1.22
  @@ -13,6 +13,7 @@
   import org.apache.avalon.framework.context.Context;
   import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.excalibur.fortress.Container;
  +import org.apache.excalibur.fortress.lifecycle.LifecycleExtensionManager;
   import org.apache.excalibur.mpool.Pool;
   import org.apache.excalibur.mpool.PoolManager;
   
  @@ -46,10 +47,11 @@
                                        final Configuration config,
                                        final ComponentManager manager,
                                        final ServiceManager service,
  -                                     final Context context )
  +                                     final Context context,
  +                                     final LifecycleExtensionManager extManager )
           throws Exception
       {
  -        super( componentClass, config, manager, service, context );
  +        super( componentClass, config, manager, service, context, extManager );
           m_poolMin = config.getAttributeAsInteger( "pool-min", 10 );
           m_logger = m_logkit.getLoggerForCategory( "system.handler.poolable" );
           m_poolManager = (PoolManager)context.get( Container.POOL_MANAGER );
  @@ -85,7 +87,7 @@
       {
           super.get();
   
  -        return m_pool.acquire();
  +	return m_pool.acquire();
       }
   
       /**
  @@ -94,7 +96,6 @@
       public void put( final Object component )
       {
           super.put( component );
  -
           m_pool.release( component );
       }
   
  
  
  
  1.18      +5 -3      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.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- ThreadSafeComponentHandler.java	28 Jun 2002 17:11:20 -0000	1.17
  +++ ThreadSafeComponentHandler.java	9 Jul 2002 13:32:36 -0000	1.18
  @@ -11,6 +11,7 @@
   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;
   
   /**
    * The ThreadSafeComponentHandler to make sure components are initialized
  @@ -33,10 +34,11 @@
                                          final Configuration config,
                                          final ComponentManager manager,
                                          final ServiceManager service,
  -                                       final Context context )
  +                                       final Context context,
  +                                       final LifecycleExtensionManager extManager )
           throws Exception
       {
  -        super( componentClass, config, manager, service, context );
  +        super( componentClass, config, manager, service, context, extManager );
           m_logger = m_logkit.getLoggerForCategory( "system.handler.threadsafe" );
           m_name = "ThreadSafeComponentHandler";
       }
  
  
  
  1.1                  jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/lifecycle/AbstractLifecycleExtension.java
  
  Index: AbstractLifecycleExtension.java
  ===================================================================
  /*
  * Copyright (C) The Apache Software Foundation. All rights reserved.
  *
  * This software is published under the terms of the Apache Software License
  * version 1.1, a copy of which has been included with this distribution in
  * the LICENSE.txt file.
  */
  package org.apache.excalibur.fortress.lifecycle;
  
  import org.apache.avalon.framework.context.Context;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  
  /**
   * Abstract lifecycle extension helper class, including empty default
   * methods for available extension callbacks.
   *
   * @author <a href="mailto:crafterm@apache.org">Marcus Crafter</a>
   * @version CVS $Revision: 1.1 $ $Date: 2002/07/09 13:32:36 $
   */
  public abstract class AbstractLifecycleExtension
      extends AbstractLogEnabled 
      implements LifecycleExtension
  {
      /**
       * Create, called when the given component is being 
       * instantiated.
       *
       * @param component a <code>Component</code> instance
       * @param context a <code>Context</code> instance
       * @exception Exception if an error occurs
       */
      public void create( Object component, Context context )
          throws Exception {}
  
      /**
       * Destroy, called when the given component is being
       * decomissioned.
       *
       * @param component a <code>Component</code> instance
       * @param context a <code>Context</code> instance
       * @exception Exception if an error occurs
       */
      public void destroy( Object component, Context context )
          throws Exception {}
  
      /**
       * Access, called when the given component is being
       * accessed (ie. via lookup() or select()).
       *
       * @param component a <code>Component</code> instance
       * @param context a <code>Context</code> instance
       * @exception Exception if an error occurs
       */
      public void access( Object component, Context context )
          throws Exception {}
  
      /**
       * Release, called when the given component is being
       * released (ie. by a CM or CS).
       *
       * @param component a <code>Component</code> instance
       * @param context a <code>Context</code> instance
       * @exception Exception if an error occurs
       */
      public void release( Object component, Context context )
          throws Exception {}
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/lifecycle/AbstractLifecycleExtensionManager.java
  
  Index: AbstractLifecycleExtensionManager.java
  ===================================================================
  /*
  * Copyright (C) The Apache Software Foundation. All rights reserved.
  *
  * This software is published under the terms of the Apache Software License
  * version 1.1, a copy of which has been included with this distribution in
  * the LICENSE.txt file.
  */
  package org.apache.excalibur.fortress.lifecycle;
  
  import java.lang.reflect.Method;
  import org.apache.avalon.framework.component.Component;
  import org.apache.avalon.framework.context.Context;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  
  /**
   * <code>AbstractLifecycleExtensionManager</code> class.
   *
   * @author <a href="mailto:crafterm@apache.org">Marcus Crafter</a>
   * @version CVS $Revision: 1.1 $ $Date: 2002/07/09 13:32:36 $
   */
  public abstract class AbstractLifecycleExtensionManager extends AbstractLogEnabled
  {
      // Lifecycle method constants, these are passed to executeExtensions()
      protected final Method ACCESS;
      protected final Method RELEASE;
      protected final Method CREATION;
      protected final Method DESTRUCTION;
  
      /**
       * Constructor, creates a lifecycle manager, and caches all lifecycle
       * <code>Method</code> objects for later use.
       */
      public AbstractLifecycleExtensionManager()
      {
          final Class[] params = {Object.class, Context.class};
  	final Class clazz = LifecycleExtension.class;
  
  	try
  	{
  	    ACCESS = clazz.getDeclaredMethod( "access", params );
  	    RELEASE = clazz.getDeclaredMethod( "release", params );
  	    CREATION = clazz.getDeclaredMethod( "create", params );
  	    DESTRUCTION = clazz.getDeclaredMethod( "destroy", params );
  	}
  	catch ( NoSuchMethodException e )
  	{
  	    throw new IllegalStateException(
  		"Bad environment, cannot reference LifecycleExtension class: " +
  		e.getMessage()
  	    );
  	}
      }
  
      /**
       * <code>executeExtensions</code> method, executes a given array of lifecycle interfaces
       * on a given component.
       *
       * @param component a <code>Component</code> instance
       * @param context a <code>Context</code> instance
       * @param type a <code>Method</code> instance, referencing which phase the
       * extensions array adheres to.
       * @exception Exception if an error occurs
       */
      protected void executeExtensions(
          Object[] extensions, Object component, Context context, Method type
      )
          throws Exception
      {
          final Object[] params = { component, context };
  
          for ( int i = 0; i < extensions.length; ++i )
          {
              if ( getLogger().isDebugEnabled() )
              {
                  getLogger().debug(
                      "Executing extension " + extensions[i] +
                      " on component " + component +
                      " (" + type.getName() + " phase)"
                  );
              }
  
              type.invoke( ( LifecycleExtension ) extensions[i], params );
          }
      }
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/lifecycle/LifecycleExtension.java
  
  Index: LifecycleExtension.java
  ===================================================================
  /*
  * Copyright (C) The Apache Software Foundation. All rights reserved.
  *
  * This software is published under the terms of the Apache Software License
  * version 1.1, a copy of which has been included with this distribution in
  * the LICENSE.txt file.
  */
  package org.apache.excalibur.fortress.lifecycle;
  
  import org.apache.avalon.framework.context.Context;
  
  /**
   * <code>LifecycleExtension</code> interface. This interface defines the methods that
   * a <code>LifecycleExtensionManager</code> can call on a particular concrete
   * <code>LifecycleExtensionMarker</code> class.
   *
   * @author <a href="mailto:crafterm@apache.org">Marcus Crafter</a>
   * @version CVS $Revision: 1.1 $ $Date: 2002/07/09 13:32:36 $
   */
  public interface LifecycleExtension
  {
      /**
       * Create, called when the given component is being 
       * instantiated.
       *
       * @param component a <code>Component</code> instance
       * @param context a <code>Context</code> instance
       * @exception Exception if an error occurs
       */
      void create( Object component, Context context )
          throws Exception;
  
      /**
       * Destroy, called when the given component is being
       * decomissioned.
       *
       * @param component a <code>Component</code> instance
       * @param context a <code>Context</code> instance
       * @exception Exception if an error occurs
       */
      void destroy( Object component, Context context )
          throws Exception;
  
      /**
       * Access, called when the given component is being
       * accessed (ie. via lookup() or select()).
       *
       * @param component a <code>Component</code> instance
       * @param context a <code>Context</code> instance
       * @exception Exception if an error occurs
       */
      void access( Object component, Context context )
          throws Exception;
  
      /**
       * Release, called when the given component is being
       * released (ie. by a CM or CS).
       *
       * @param component a <code>Component</code> instance
       * @param context a <code>Context</code> instance
       * @exception Exception if an error occurs
       */
      void release( Object component, Context context )
          throws Exception;
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/lifecycle/LifecycleExtensionManager.java
  
  Index: LifecycleExtensionManager.java
  ===================================================================
  /*
  * Copyright (C) The Apache Software Foundation. All rights reserved.
  *
  * This software is published under the terms of the Apache Software License
  * version 1.1, a copy of which has been included with this distribution in
  * the LICENSE.txt file.
  */
  package org.apache.excalibur.fortress.lifecycle;
  
  import java.lang.reflect.Method;
  import java.util.ArrayList;
  import java.util.List;
  import org.apache.avalon.framework.component.Component;
  import org.apache.avalon.framework.context.Context;
  
  /**
   * <code>LifecycleExtensionManager</code> class. This class manages lists
   * of extensions objects that are executed on components during the various
   * stages of their lifecycles.
   *
   * <p>
   * It provides 4 methods for adding extension objects to the system,
   * and 4 methods for executing them on a particular component object. The
   * current context is also passed in to the extension objects to facilitate
   * the communication of any global values.
   * </p>
   *
   * @author <a href="mailto:crafterm@apache.org">Marcus Crafter</a>
   * @version CVS $Revision: 1.1 $ $Date: 2002/07/09 13:32:36 $
   */
  public class LifecycleExtensionManager
      extends AbstractLifecycleExtensionManager
  {
      // extensions objects
      private final List m_accessExtensions = new ArrayList();
      private final List m_releaseExtensions = new ArrayList();
      private final List m_creationExtensions = new ArrayList();
      private final List m_destructionExtensions = new ArrayList();
  
      /**
       * <code>executeAccessExtensions</code> method, executes all <i>access</i>
       * level extensions on the given component.
       *
       * @param component a <code>Component</code> instance
       * @param context a <code>Context</code> instance
       * @exception Exception if an error occurs
       */
      public void executeAccessExtensions( Object component, Context context )
          throws Exception
      {
          executeExtensions( m_accessExtensions.toArray(), component, context, ACCESS );
      }
  
      /**
       * <code>executeReleaseExtensions</code> method, executes all <i>release</i>
       * level extensions on the given component.
       *
       * @param component a <code>Component</code> instance
       * @param context a <code>Context</code> instance
       * @exception Exception if an error occurs
       */
      public void executeReleaseExtensions( Object component, Context context )
          throws Exception
      {
          executeExtensions( m_releaseExtensions.toArray(), component, context, RELEASE );
      }
  
      /**
       * <code>executeCreationExtensions</code> method, executes all <i>creation</i>
       * level extensions on the given component.
       *
       * @param component a <code>Component</code> instance
       * @param context a <code>Context</code> instance
       * @exception Exception if an error occurs
       */
      public void executeCreationExtensions( Object component, Context context )
          throws Exception
      {
          executeExtensions( m_creationExtensions.toArray(), component, context, CREATION );
      }
  
      /**
       * <code>executeDestructionExtensions</code> method, executes all <i>destruction</i>
       * level extensions on the given component.
       *
       * @param component a <code>Component</code> instance
       * @param context a <code>Context</code> instance
       * @exception Exception if an error occurs
       */
      public void executeDestructionExtensions( Object component, Context context )
          throws Exception
      {
          executeExtensions( m_destructionExtensions.toArray(), component, context, DESTRUCTION );
      }
  
      // REVISIT: The methods below breaks encapsulation, but I think most of List's
      // operations are useful, any better ways to do this ?
  
      /**
       * Obtains the access level lifecycle extension this manager manages.
       *
       * @return a <code>List</code> of extensions
       */
      public List getAccessLifecycleExtensions()
      {
          return m_accessExtensions;
      }
  
      /**
       * Obtains the release level lifecycle extensions this manager manages.
       *
       * @return a <code>List</code> of extensions
       */
      public List getReleaseLifecycleExtensions()
      {
          return m_releaseExtensions;
      }
  
      /**
       * Obtains the creation level lifecycle extensions this manager manages.
       *
       * @return a <code>List</code> of extensions
       */
      public List getCreationLifecycleExtensions()
      {
          return m_creationExtensions;
      }
  
      /**
       * Obtains the destruction level lifecycle extensions this manager manages.
       *
       * @return a <code>List</code> of extensions
       */
      public List getDestructionLifecycleExtensions()
      {
          return m_destructionExtensions;
      }
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/lifecycle/package.html
  
  Index: package.html
  ===================================================================
  <body>
  Interfaces and classes supporting the addition of lifecycle extensions to
  a container.
  </body>
  
  
  
  1.5       +9 -7      jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/lookup/FortressComponentManager.java
  
  Index: FortressComponentManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/lookup/FortressComponentManager.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- FortressComponentManager.java	9 Jul 2002 10:40:26 -0000	1.4
  +++ FortressComponentManager.java	9 Jul 2002 13:32:36 -0000	1.5
  @@ -12,10 +12,12 @@
   import org.apache.avalon.framework.component.ComponentException;
   import org.apache.avalon.framework.component.ComponentManager;
   import org.apache.avalon.framework.component.ComponentSelector;
  +import org.apache.avalon.framework.context.Context;
   import org.apache.avalon.framework.service.ServiceException;
   import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.excalibur.fortress.Container;
   import org.apache.excalibur.fortress.handler.ComponentHandler;
  +import org.apache.excalibur.fortress.lifecycle.LifecycleExtensionManager;
   import org.apache.excalibur.fortress.lookup.FortressServiceManager;
   
   /**
  @@ -35,25 +37,25 @@
        * This constructor is for a ContainerComponentManager with no parent
        * ComponentLocator
        */
  -    public FortressComponentManager( final Container container )
  +    public FortressComponentManager( final Container container, final LifecycleExtensionManager extManager, final Context context )
       {
  -        this( container,(ComponentManager)null );
  +        this( container,(ComponentManager)null, extManager, context );
       }
       
       /**
        */
  -    public FortressComponentManager( final Container container, final ServiceManager parent )
  +    public FortressComponentManager( final Container container, final ServiceManager parent, final LifecycleExtensionManager extManager, final Context context )
       {
  -        this( container, new ServiceComponentManager(parent));
  +        this( container, new ServiceComponentManager(parent), extManager, context);
       }
   
       /**
        * This constructor is for a ContainerComponentManager with a parent
        * ComponentLocator
        */
  -    public FortressComponentManager( final Container container, final ComponentManager parent )
  +    public FortressComponentManager( final Container container, final ComponentManager parent, final LifecycleExtensionManager extManager, final Context context )
       {
  -        m_proxy = new FortressServiceManager( container, parent );
  +        m_proxy = new FortressServiceManager( container, parent, extManager, context );
       }
   
       public Component lookup( String role )
  
  
  
  1.4       +5 -3      jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/lookup/FortressComponentSelector.java
  
  Index: FortressComponentSelector.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/lookup/FortressComponentSelector.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- FortressComponentSelector.java	9 Jul 2002 10:40:26 -0000	1.3
  +++ FortressComponentSelector.java	9 Jul 2002 13:32:36 -0000	1.4
  @@ -11,10 +11,12 @@
   import org.apache.avalon.framework.component.Component;
   import org.apache.avalon.framework.component.ComponentException;
   import org.apache.avalon.framework.component.ComponentSelector;
  +import org.apache.avalon.framework.context.Context;
   import org.apache.avalon.framework.service.ServiceException;
   import org.apache.avalon.framework.service.ServiceSelector;
   import org.apache.excalibur.fortress.Container;
   import org.apache.excalibur.fortress.handler.ComponentHandler;
  +import org.apache.excalibur.fortress.lifecycle.LifecycleExtensionManager;
   import org.apache.excalibur.fortress.lookup.FortressServiceSelector;
   
   /**
  @@ -31,9 +33,9 @@
       private final ServiceSelector m_proxy;
       private final String m_role;
   
  -    public FortressComponentSelector( final Container container, final String role )
  +    public FortressComponentSelector( final Container container, final String role, final LifecycleExtensionManager extManager, final Context context )
       {
  -        m_proxy = new FortressServiceSelector( container, role );
  +        m_proxy = new FortressServiceSelector( container, role, extManager, context );
           m_role = role;
       }
   
  
  
  
  1.4       +23 -6     jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/lookup/FortressServiceManager.java
  
  Index: FortressServiceManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/lookup/FortressServiceManager.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- FortressServiceManager.java	9 Jul 2002 10:40:26 -0000	1.3
  +++ FortressServiceManager.java	9 Jul 2002 13:32:36 -0000	1.4
  @@ -10,11 +10,13 @@
   import org.apache.avalon.excalibur.collections.BucketMap;
   import org.apache.avalon.framework.component.ComponentManager;
   import org.apache.avalon.framework.component.ComponentSelector;
  +import org.apache.avalon.framework.context.Context;
   import org.apache.avalon.framework.service.ServiceException;
   import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.avalon.framework.service.ServiceSelector;
   import org.apache.excalibur.fortress.Container;
   import org.apache.excalibur.fortress.handler.ComponentHandler;
  +import org.apache.excalibur.fortress.lifecycle.LifecycleExtensionManager;
   
   /**
    * This is the Default ServiceManager for the Container.  It provides
  @@ -29,33 +31,37 @@
       private final Container m_components;
       private final BucketMap m_used;
       private final ServiceManager m_parent;
  +    private final Context m_context;
  +    private final LifecycleExtensionManager m_extManager;
   
       /**
        * This constructor is for a ContainerComponentManager with no parent
        * ComponentLocator
        */
  -    public FortressServiceManager( final Container container )
  +    public FortressServiceManager( final Container container, final LifecycleExtensionManager extManager, final Context context )
       {
  -        this( container, (ServiceManager)null );
  +        this( container, (ServiceManager)null, extManager, context );
       }
   
       /**
        * This constructor is for a ContainerComponentManager with no parent
        * ComponentLocator
        */
  -    public FortressServiceManager( final Container container, final ComponentManager parent )
  +    public FortressServiceManager( final Container container, final ComponentManager parent, final LifecycleExtensionManager extManager, final Context context )
       {
  -        this( container, (parent != null) ? new ComponentServiceManager( parent ) : null );
  +        this( container, (parent != null) ? new ComponentServiceManager( parent ) : null, extManager, context );
       }
   
       /**
        * This constructor is for a ContainerComponentManager with a parent
        * ComponentLocator
        */
  -    public FortressServiceManager( final Container container, final ServiceManager parent )
  +    public FortressServiceManager( final Container container, final ServiceManager parent, final LifecycleExtensionManager extManager, final Context context )
       {
           m_parent = parent;
           m_components = container;
  +        m_context = context;
  +        m_extManager = extManager;
           m_used = new BucketMap();
       }
   
  @@ -112,6 +118,8 @@
               }
   
               component = handler.get();
  +
  +            m_extManager.executeAccessExtensions( component, m_context );
           }
           catch( ServiceException ce )
           {
  @@ -142,6 +150,15 @@
       public void release( Object component )
       {
           final ComponentHandler handler;
  +
  +        try
  +        {
  +            m_extManager.executeReleaseExtensions( component, m_context );
  +        }
  +        catch ( Exception e )
  +        {
  +            // REVISIT(MC): need to log this somewhere ?
  +        }
   
           handler = (ComponentHandler)m_used.remove( component );
   
  
  
  
  1.3       +19 -2     jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/lookup/FortressServiceSelector.java
  
  Index: FortressServiceSelector.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/lookup/FortressServiceSelector.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FortressServiceSelector.java	8 Jul 2002 11:58:58 -0000	1.2
  +++ FortressServiceSelector.java	9 Jul 2002 13:32:36 -0000	1.3
  @@ -8,10 +8,12 @@
   package org.apache.excalibur.fortress.lookup;
   
   import org.apache.avalon.excalibur.collections.BucketMap;
  +import org.apache.avalon.framework.context.Context;
   import org.apache.avalon.framework.service.ServiceException;
   import org.apache.avalon.framework.service.ServiceSelector;
   import org.apache.excalibur.fortress.Container;
   import org.apache.excalibur.fortress.handler.ComponentHandler;
  +import org.apache.excalibur.fortress.lifecycle.LifecycleExtensionManager;
   
   /**
    * This is the Default ServiceSelector for the Container.  It provides
  @@ -26,11 +28,15 @@
       private final String m_role;
       private final Container m_components;
       private final BucketMap m_used;
  +    private final Context m_context;
  +    private final LifecycleExtensionManager m_extManager;
   
  -    public FortressServiceSelector( final Container container, final String role )
  +    public FortressServiceSelector( final Container container, final String role, final LifecycleExtensionManager extManager, final Context context )
       {
           m_role = role;
           m_components = container;
  +        m_context = context;
  +        m_extManager = extManager;
           m_used = new BucketMap();
       }
   
  @@ -59,6 +65,8 @@
               }
   
               component = handler.get();
  +
  +            m_extManager.executeAccessExtensions( component, m_context );
           }
           catch( ServiceException ce )
           {
  @@ -82,6 +90,15 @@
       public void release( Object component )
       {
           final ComponentHandler handler;
  +
  +        try
  +        {
  +            m_extManager.executeReleaseExtensions( component, m_context );
  +        }
  +        catch ( Exception e )
  +        {
  +            // REVISIT(MC): we need to log this somewhere
  +        }
   
           handler = (ComponentHandler)m_used.remove( component );
   
  
  
  

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