donaldp 2002/11/09 00:13:52 Modified: fortress/examples/src/java/org/apache/excalibur/fortress/examples/viewer ComponentViewer.java fortress/src/java/org/apache/excalibur/fortress/container AbstractContainer.java fortress/src/java/org/apache/excalibur/fortress/handler AbstractComponentHandler.java ComponentHandler.java FactoryComponentHandler.java LEAwareComponentHandler.java PerThreadComponentHandler.java PoolableComponentHandler.java ThreadSafeComponentHandler.java Added: fortress/src/java/org/apache/excalibur/fortress/container ComponentHandlerEntry.java Log: Rework the Handler so that assembly data is separated out from the actual ComponentHandler class and stored separately from the handler implementation. Currently there is minimal metadata so only the isLazy flag is used and for convenience sake we wont create a metadata object and will put it directly in runtime object (aka entry). Revision Changes Path 1.6 +4 -3 jakarta-avalon-excalibur/fortress/examples/src/java/org/apache/excalibur/fortress/examples/viewer/ComponentViewer.java Index: ComponentViewer.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/examples/src/java/org/apache/excalibur/fortress/examples/viewer/ComponentViewer.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- ComponentViewer.java 9 Nov 2002 07:29:37 -0000 1.5 +++ ComponentViewer.java 9 Nov 2002 08:13:51 -0000 1.6 @@ -38,7 +38,8 @@ * @author <a href="mailto:crafterm@;apache.org">Marcus Crafter</a> * @version CVS $Revision$ $Date$ */ -public final class ComponentViewer extends DefaultContainer +public final class ComponentViewer + extends DefaultContainer implements Startable, ActionListener { // GUI references @@ -159,7 +160,7 @@ { if( getLogger().isWarnEnabled() ) { - getLogger().warn( "Error looking up component: " + e.getRole(), e ); + getLogger().warn( "Error looking up component: " + e.getKey(), e ); } } finally 1.8 +19 -19 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.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- AbstractContainer.java 9 Nov 2002 07:44:38 -0000 1.7 +++ AbstractContainer.java 9 Nov 2002 08:13:51 -0000 1.8 @@ -110,7 +110,6 @@ protected RoleManager m_roleManager; protected InstrumentManager m_instrumentManager; protected Configuration m_configuration; - protected Map m_configs = new StaticBucketMap(); protected Map m_mapper = new StaticBucketMap(); protected List m_components = new ArrayList( 10 ); protected LifecycleExtensionManager m_extManager; @@ -296,11 +295,7 @@ final ObjectFactory factory = createObjectFactory( klass, configuration ); - final Object[] args = new Object[] - { - factory, - new Boolean( isLazy ) - }; + final Object[] args = new Object[] { factory }; final ComponentHandler targetHandler = (ComponentHandler)constructor.newInstance( args ); @@ -335,8 +330,9 @@ " uses handler " + handlerClassName ); } - m_configs.put( handler, configuration ); - m_components.add( handler ); + final ComponentHandlerEntry entry = + new ComponentHandlerEntry( handler, isLazy ); + m_components.add( entry ); return handler; } @@ -385,7 +381,9 @@ if( null == hintMap ) { - throw new ServiceException( role + "/" + hint, "Component does not exist" ); + final String key = role + "/" + hint; + final String message = "Component does not exist"; + throw new ServiceException( key, message ); } if( null == hint ) @@ -404,7 +402,9 @@ if( null == value ) { - throw new ServiceException( role + "/" + hint, "Component does not exist" ); + final String key = role + "/" + hint; + final String message = "Component does not exist"; + throw new ServiceException( key, message ); } return value; @@ -475,14 +475,15 @@ { try { - final ComponentHandler handler = (ComponentHandler)i.next(); - if( !handler.isLazy() ) + final ComponentHandlerEntry entry = (ComponentHandlerEntry)i.next(); + final ComponentHandler handler = entry.getHandler(); + if( !entry.isLazy() ) { if( null != m_commandQueue ) { - m_commandQueue.enqueue( - new PrepareHandlerCommand( handler, getLogger() ) - ); + final PrepareHandlerCommand element = + new PrepareHandlerCommand( handler, getLogger() ); + m_commandQueue.enqueue( element ); } else { @@ -515,7 +516,6 @@ if( buffer.size() > 0 ) { final StringBuffer message = new StringBuffer(); - while( !buffer.isEmpty() ) { message.append( ( (Exception)buffer.remove() ).getMessage() ); @@ -531,10 +531,10 @@ public void dispose() { final Iterator i = m_components.iterator(); - while( i.hasNext() ) { - final ComponentHandler handler = (ComponentHandler)i.next(); + final ComponentHandlerEntry entry = (ComponentHandlerEntry)i.next(); + final ComponentHandler handler = entry.getHandler(); ContainerUtil.dispose( handler ); } } 1.1 jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/container/ComponentHandlerEntry.java Index: ComponentHandlerEntry.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.container; import org.apache.excalibur.fortress.handler.ComponentHandler; /** * This is the container of runtime information about a * ComponentHandler. * * @author <a href="mailto:peter at apache.org">Peter Donald</a> * @version $Revision: 1.1 $ $Date: 2002/11/09 08:13:51 $ */ public class ComponentHandlerEntry { private final ComponentHandler m_handler; private final boolean m_isLazy; /** * Create an entry for a particular handler. * * @param handler the handler * @param lazy true if handler should be lazily prepared */ public ComponentHandlerEntry( final ComponentHandler handler, final boolean lazy ) { if( null == handler ) { throw new NullPointerException( "handler" ); } m_handler = handler; m_isLazy = lazy; } /** * Return the handler that entry manages. * * @return the handler that entry manages. */ public ComponentHandler getHandler() { return m_handler; } /** * Return true if handler should be lazily prepared. * * @return true if handler should be lazily prepared. */ public boolean isLazy() { return m_isLazy; } } 1.37 +3 -22 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.36 retrieving revision 1.37 diff -u -r1.36 -r1.37 --- AbstractComponentHandler.java 9 Nov 2002 07:44:38 -0000 1.36 +++ AbstractComponentHandler.java 9 Nov 2002 08:13:51 -0000 1.37 @@ -68,6 +68,7 @@ * * @author <a href="mailto:bloritsch@;apache.org">Berin Loritsch</a> * @author <a href="mailto:crafterm@;apache.org">Marcus Crafter</a> + * @author <a href="mailto:peter@;apache.org">Peter Donald</a> * @version CVS $Revision$ $Date$ * @since 4.0 */ @@ -99,26 +100,18 @@ /** Logger Manager */ protected LoggerManager m_loggerManager; - /** 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. * It falls back to SingleThreaded if not specified. * * @param factory The factory used to create component - * @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 ObjectFactory factory, - final Boolean isLazy ) + public AbstractComponentHandler( final ObjectFactory factory ) throws Exception { m_factory = factory; - m_isLazy = isLazy.booleanValue(); } public void contextualize( final Context context ) @@ -152,18 +145,6 @@ } setInstrumentableName( name ); - } - - /** - * Determines whether or not the ComponentHandler has lazy initialization - * or not. - * - * @return <code>true</code> if the ComponentHandler has lazy - * initialization. - */ - public boolean isLazy() - { - return m_isLazy; } /** 1.20 +2 -12 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.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- ComponentHandler.java 9 Nov 2002 07:44:38 -0000 1.19 +++ ComponentHandler.java 9 Nov 2002 08:13:51 -0000 1.20 @@ -65,18 +65,8 @@ { Class[] HANDLER_CONSTRUCTOR = new Class[] { - ObjectFactory.class, - Boolean.class + ObjectFactory.class }; - - /** - * 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(); /** * Actually prepare the handler and make it ready to 1.36 +3 -4 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.35 retrieving revision 1.36 diff -u -r1.35 -r1.36 --- FactoryComponentHandler.java 9 Nov 2002 07:44:38 -0000 1.35 +++ FactoryComponentHandler.java 9 Nov 2002 08:13:51 -0000 1.36 @@ -68,11 +68,10 @@ * whether a Component is ThreadSafe, Poolable, or SingleThreaded. * It falls back to SingleThreaded if not specified. */ - public FactoryComponentHandler( final ObjectFactory factory, - final Boolean isLazy ) + public FactoryComponentHandler( final ObjectFactory factory ) throws Exception { - super( factory, isLazy ); + super( factory ); } /** 1.3 +1 -6 jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/LEAwareComponentHandler.java Index: LEAwareComponentHandler.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/LEAwareComponentHandler.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- LEAwareComponentHandler.java 9 Nov 2002 07:44:38 -0000 1.2 +++ LEAwareComponentHandler.java 9 Nov 2002 08:13:51 -0000 1.3 @@ -88,11 +88,6 @@ m_context = context; } - public boolean isLazy() - { - return m_componentHandler.isLazy(); - } - public void prepareHandler() throws Exception { 1.39 +3 -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.38 retrieving revision 1.39 diff -u -r1.38 -r1.39 --- PerThreadComponentHandler.java 9 Nov 2002 07:44:38 -0000 1.38 +++ PerThreadComponentHandler.java 9 Nov 2002 08:13:51 -0000 1.39 @@ -69,11 +69,10 @@ * whether a Component is ThreadSafe, Poolable, or SingleThreaded. * It falls back to SingleThreaded if not specified. */ - public PerThreadComponentHandler( final ObjectFactory factory, - final Boolean isLazy ) + public PerThreadComponentHandler( final ObjectFactory factory ) throws Exception { - super( factory, isLazy ); + super( factory ); } public void initialize() 1.41 +3 -4 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.40 retrieving revision 1.41 diff -u -r1.40 -r1.41 --- PoolableComponentHandler.java 9 Nov 2002 07:44:38 -0000 1.40 +++ PoolableComponentHandler.java 9 Nov 2002 08:13:52 -0000 1.41 @@ -86,11 +86,10 @@ * whether a Component is ThreadSafe, Poolable, or SingleThreaded. * It falls back to SingleThreaded if not specified. */ - public PoolableComponentHandler( final ObjectFactory factory, - final Boolean isLazy ) + public PoolableComponentHandler( final ObjectFactory factory ) throws Exception { - super( factory, isLazy ); + super( factory ); } public void contextualize( Context context ) 1.39 +3 -5 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.38 retrieving revision 1.39 diff -u -r1.38 -r1.39 --- ThreadSafeComponentHandler.java 9 Nov 2002 07:44:38 -0000 1.38 +++ ThreadSafeComponentHandler.java 9 Nov 2002 08:13:52 -0000 1.39 @@ -49,7 +49,6 @@ */ package org.apache.excalibur.fortress.handler; -import org.apache.avalon.framework.context.Context; import org.apache.excalibur.mpool.ObjectFactory; /** @@ -71,11 +70,10 @@ * whether a Component is ThreadSafe, Poolable, or SingleThreaded. * It falls back to SingleThreaded if not specified. */ - public ThreadSafeComponentHandler( final ObjectFactory factory, - final Boolean isLazy ) + public ThreadSafeComponentHandler( final ObjectFactory factory ) throws Exception { - super( factory, isLazy ); + super( factory ); } /**
-- To unsubscribe, e-mail: <mailto:avalon-cvs-unsubscribe@;jakarta.apache.org> For additional commands, e-mail: <mailto:avalon-cvs-help@;jakarta.apache.org>