You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by Carsten Ziegeler <cz...@s-und-n.de> on 2002/07/05 08:47:31 UTC
[PATCH]: Keeping initialization order of components
Hi,
appended is a patch to the ECM which keeps the order of initialization
as they are defined.
The component handlers are stored during the addComponent() method
into the bucket map and (this is new) into an array.
This array is used during the initialize() method to initialize
the handlers. When everything is initialized the array is cleaned up
and only the bucket map is used from that point on.
I think this patch does not do any harm, but is very helpfull
especially for Cocoon. If noone votes against it, I want to apply
it.
Comments are welcome.
Thanks
Carsten
Index: ExcaliburComponentManager.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/component/src/java/org/apache/avalo
n/excalibur/component/ExcaliburComponentManager.java,v
retrieving revision 1.8
diff -u -r1.8 ExcaliburComponentManager.java
--- ExcaliburComponentManager.java 18 Jun 2002 14:25:47 -0000 1.8
+++ ExcaliburComponentManager.java 5 Jul 2002 06:41:32 -0000
@@ -60,6 +60,11 @@
/** Used to map roles to ComponentHandlers. */
private final BucketMap m_componentHandlers = new BucketMap();
+ /** added component handlers before initialization to maintain
+ * the order of initialization
+ */
+ private final List m_newComponentHandlers = new ArrayList();
+
/** RoleInfos. */
private RoleManager m_roles;
@@ -144,14 +149,10 @@
{
m_initialized = true;
- List keys = new ArrayList( m_componentHandlers.keySet() );
-
- for( int i = 0; i < keys.size(); i++ )
+ for (int i = 0; i < m_newComponentHandlers.size(); i++ )
{
- final Object key = keys.get( i );
final ComponentHandler handler =
- (ComponentHandler)m_componentHandlers.get( key );
-
+ (ComponentHandler)m_newComponentHandlers.get( i );
try
{
handler.initialize();
@@ -164,8 +165,33 @@
"the component handler.", e );
}
}
+ }
+
+ List keys = new ArrayList( m_componentHandlers.keySet() );
+
+ for( int i = 0; i < keys.size(); i++ )
+ {
+ final Object key = keys.get( i );
+ final ComponentHandler handler =
+ (ComponentHandler)m_componentHandlers.get( key );
+ if ( !m_newComponentHandlers.contains( handler ) )
+ {
+ try
+ {
+ handler.initialize();
+ }
+ catch( Exception e )
+ {
+ if( getLogger().isErrorEnabled() )
+ {
+ getLogger().error( "Caught an exception trying
to i
nitialize " +
+ "the component handler.",
e );
+ }
+ }
+ }
}
+ m_newComponentHandlers.clear();
}
}
@@ -645,6 +671,7 @@
handler.setLogger( getLogkitLogger() );
handler.enableLogging( getLogger() );
m_componentHandlers.put( role, handler );
+ m_newComponentHandlers.add( handler );
}
catch( final Exception e )
{
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>