crafterm 2002/07/22 10:46:58 Modified: fortress/src/java/org/apache/excalibur/fortress AbstractContainer.java DefaultContainerManager.java fortress/src/java/org/apache/excalibur/fortress/handler AbstractComponentHandler.java AbstractThreadSafeComponentHandler.java ComponentHandler.java FactoryComponentHandler.java LazyThreadSafeComponentHandler.java PerThreadComponentHandler.java PoolableComponentHandler.java ThreadSafeComponentHandler.java Log: Implemented 'activation' attribute on component xconf configuration, allowing components to specify their respective handler's initialization policy. Possible policies are 'startup', indicating that the component's handler will be initialized during container startup, and 'request', which means the handler will be initialized upon first request. Currently, the default is 'startup' if no policy is provided. Revision Changes Path 1.48 +62 -12 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.47 retrieving revision 1.48 diff -u -r1.47 -r1.48 --- AbstractContainer.java 17 Jul 2002 20:44:01 -0000 1.47 +++ AbstractContainer.java 22 Jul 2002 17:46:58 -0000 1.48 @@ -51,6 +51,7 @@ * * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a> * @author <a href="mailto:[EMAIL PROTECTED]">Peter Royal</a> + * @author <a href="mailto:[EMAIL PROTECTED]">Marcus Crafter</a> * @version CVS $Revision$ $Date$ */ public abstract class AbstractContainer @@ -247,8 +248,9 @@ String role = component.getAttribute( "role", null ); String klass = component.getAttribute( "class", null ); + boolean isLazy = isLazyComponentHandler( component ); ComponentHandler handler = getComponentHandler( - component.getAttribute( "handler", null ), klass, component + component.getAttribute( "handler", null ), klass, component, isLazy ); if( null != role && null != klass && null != handler ) @@ -281,12 +283,44 @@ } /** + * Helper method to determine whether a given component handler configuration + * requests a lazy or startup based initialization policy. + * + * @param component <code>Configuration</code> + * @return true if the given handler configuration specifies a lazy init policy, + * false otherwise + * @throws IllegalArgumentException if the handler specifies an unknown init + * policy + */ + private boolean isLazyComponentHandler( Configuration component ) + { + String policy = component.getAttribute( "activation", null ); + + boolean policyUnspecified = policy == null; + boolean isLazy = "request".equalsIgnoreCase( policy ); + boolean isNonLazy = "startup".equalsIgnoreCase( policy ); + + if ( policyUnspecified || isNonLazy ) + return false; + else if ( isLazy ) + return true; + + // policy was not null, but didn't match anything above + String klass = component.getAttribute( "class", null ); + + throw new IllegalArgumentException( + "Unknown activation policy for class " + klass + ": " + policy + ); + } + + /** * Get a ComponentHandler with the standard <code>HANDLER_CONSTRUCTOR</code> * for the component class passed in. */ - private ComponentHandler getComponentHandler( String handlerClassName, - String className, - Configuration configuration ) + private ComponentHandler getComponentHandler( final String handlerClassName, + final String className, + final Configuration configuration, + final boolean isLazy ) { Constructor constructor; ComponentHandler handler = null; @@ -301,7 +335,8 @@ configuration, getServiceManager(), m_context, - m_extManager + m_extManager, + new Boolean( isLazy ) } ); } catch( final Exception e ) @@ -427,16 +462,31 @@ { try { - if( null != m_commandQueue ) + final ComponentHandler handler = (ComponentHandler) i.next(); + + if ( !handler.isLazy() ) { - m_commandQueue.enqueue( - new InitComponentHandlerCommand( (ComponentHandler)i.next(), - getLogger() ) - ); + if( null != m_commandQueue ) + { + m_commandQueue.enqueue( + new InitComponentHandlerCommand( handler, getLogger() ) + ); + } + else + { + handler.initialize(); + } } else { - ( (ComponentHandler)i.next() ).initialize(); + if ( getLogger().isDebugEnabled() ) + { + getLogger().debug( + "ComponentHandler (" + handler + + ") has specified request time initialization policy, " + + "initialization deferred till first use" + ); + } } } catch( Exception e ) 1.15 +2 -2 jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/DefaultContainerManager.java Index: DefaultContainerManager.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/DefaultContainerManager.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- DefaultContainerManager.java 12 Jul 2002 13:40:59 -0000 1.14 +++ DefaultContainerManager.java 22 Jul 2002 17:46:58 -0000 1.15 @@ -190,7 +190,7 @@ { instance = null; - throw new InitializationException("Cannot set up container. Startup lifecycle failure", e ); + throw new InitializationException( "Cannot set up container. Startup lifecycle failure", e ); } containerInstance = instance; 1.8 +12 -2 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.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- AbstractComponentHandler.java 18 Jul 2002 14:37:11 -0000 1.7 +++ AbstractComponentHandler.java 22 Jul 2002 17:46:58 -0000 1.8 @@ -51,6 +51,9 @@ /** Context */ protected final Context m_context; + /** Initialization policy */ + private boolean m_isLazy; + /** * Create a ComponentHandler that takes care of hiding the details of * whether a Component is ThreadSafe, Poolable, or SingleThreaded. @@ -60,17 +63,24 @@ final Configuration config, final ServiceManager service, final Context context, - final LifecycleExtensionManager extManager ) + final LifecycleExtensionManager extManager, + final Boolean isLazy ) throws Exception { m_logkit = (LoggerManager)context.get( Container.LOGGER_MANAGER ); m_factory = new ComponentFactory( componentClass, config, service, context, m_logkit, extManager ); m_context = context; + m_isLazy = isLazy.booleanValue(); } public boolean isInitialized() { return m_initialized; + } + + public boolean isLazy() + { + return m_isLazy; } /** 1.4 +4 -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.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- AbstractThreadSafeComponentHandler.java 12 Jul 2002 12:53:44 -0000 1.3 +++ AbstractThreadSafeComponentHandler.java 22 Jul 2002 17:46:58 -0000 1.4 @@ -39,10 +39,11 @@ final Configuration config, final ServiceManager service, final Context context, - final LifecycleExtensionManager extManager ) + final LifecycleExtensionManager extManager, + final Boolean isLazy ) throws Exception { - super( componentClass, config, service, context, extManager ); + super( componentClass, config, service, context, extManager, isLazy ); } /** 1.12 +12 -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.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- ComponentHandler.java 12 Jul 2002 12:53:44 -0000 1.11 +++ ComponentHandler.java 22 Jul 2002 17:46:58 -0000 1.12 @@ -30,7 +30,8 @@ Configuration.class, ServiceManager.class, Context.class, - LifecycleExtensionManager.class + LifecycleExtensionManager.class, + Boolean.class }; /** @@ -39,6 +40,15 @@ * before attempting to use the the ComponentHandler. */ boolean isInitialized(); + + /** + * Indicates whether this ComponentHandler will be initialized using a + * <i>lazy</i> policy (ie. upon first use), or during container startup. + * + * @return true if ComponentHandler will be initialized <i>lazily</i>, + * false otherwise + */ + boolean isLazy(); /** * Gets the current reference to a Component according to the policy of the 1.20 +4 -3 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.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- FactoryComponentHandler.java 12 Jul 2002 12:53:44 -0000 1.19 +++ FactoryComponentHandler.java 22 Jul 2002 17:46:58 -0000 1.20 @@ -34,10 +34,11 @@ final Configuration config, final ServiceManager service, final Context context, - final LifecycleExtensionManager extManager ) + final LifecycleExtensionManager extManager, + final Boolean isLazy ) throws Exception { - super( componentClass, config, service, context, extManager ); + super( componentClass, config, service, context, extManager, isLazy ); m_logger = m_logkit.getLoggerForCategory( "system.handler.factory" ); m_name = "FactoryComponentHandler"; } 1.4 +4 -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.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- LazyThreadSafeComponentHandler.java 12 Jul 2002 12:53:44 -0000 1.3 +++ LazyThreadSafeComponentHandler.java 22 Jul 2002 17:46:58 -0000 1.4 @@ -33,10 +33,11 @@ final Configuration config, final ServiceManager service, final Context context, - final LifecycleExtensionManager extManager ) + final LifecycleExtensionManager extManager, + final Boolean isLazy ) throws Exception { - super( componentClass, config, service, context, extManager ); + super( componentClass, config, service, context, extManager, isLazy ); m_logger = m_logkit.getLoggerForCategory( "system.handler.threadsafe.lazy" ); m_name = "LazyThreadSafeComponentHandler"; } 1.21 +4 -3 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.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- PerThreadComponentHandler.java 12 Jul 2002 12:53:44 -0000 1.20 +++ PerThreadComponentHandler.java 22 Jul 2002 17:46:58 -0000 1.21 @@ -36,10 +36,11 @@ final Configuration config, final ServiceManager service, final Context context, - final LifecycleExtensionManager extManager ) + final LifecycleExtensionManager extManager, + final Boolean isLazy ) throws Exception { - super( componentClass, config, service, context, extManager ); + super( componentClass, config, service, context, extManager, isLazy ); m_instance = new ThreadLocalComponent( m_factory ); m_logger = m_logkit.getLoggerForCategory( "system.handler.perthread" ); m_name = "PerThreadComponentHandler"; 1.24 +4 -3 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.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- PoolableComponentHandler.java 12 Jul 2002 12:53:44 -0000 1.23 +++ PoolableComponentHandler.java 22 Jul 2002 17:46:58 -0000 1.24 @@ -46,10 +46,11 @@ final Configuration config, final ServiceManager service, final Context context, - final LifecycleExtensionManager extManager ) + final LifecycleExtensionManager extManager, + final Boolean isLazy ) throws Exception { - super( componentClass, config, service, context, extManager ); + super( componentClass, config, service, context, extManager, isLazy ); m_poolMin = config.getAttributeAsInteger( "pool-min", 10 ); m_logger = m_logkit.getLoggerForCategory( "system.handler.poolable" ); m_poolManager = (PoolManager)context.get( Container.POOL_MANAGER ); 1.20 +4 -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.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- ThreadSafeComponentHandler.java 12 Jul 2002 12:53:44 -0000 1.19 +++ ThreadSafeComponentHandler.java 22 Jul 2002 17:46:58 -0000 1.20 @@ -33,10 +33,11 @@ final Configuration config, final ServiceManager service, final Context context, - final LifecycleExtensionManager extManager ) + final LifecycleExtensionManager extManager, + final Boolean isLazy ) throws Exception { - super( componentClass, config, service, context, extManager ); + super( componentClass, config, service, context, extManager, isLazy ); m_logger = m_logkit.getLoggerForCategory( "system.handler.threadsafe" ); m_name = "ThreadSafeComponentHandler"; }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>