donaldp 2002/11/08 23:44:39
Modified: 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
PassThroughInvocationHandler.java
PerThreadComponentHandler.java
PoolableComponentHandler.java ProxyHelper.java
ThreadSafeComponentHandler.java
Log:
Reworked the handlers again so that context is passed in via contextualizable,
initialization is done in initialize() and the names of instrument/logger are
auotmagically derived.
Revision Changes Path
1.7 +14 -9
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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- AbstractContainer.java 9 Nov 2002 07:31:34 -0000 1.6
+++ AbstractContainer.java 9 Nov 2002 07:44:38 -0000 1.7
@@ -296,21 +296,26 @@
final ObjectFactory factory =
createObjectFactory( klass, configuration );
+ final Object[] args = new Object[]
+ {
+ factory,
+ new Boolean( isLazy )
+ };
+
final ComponentHandler targetHandler =
- (ComponentHandler)constructor.newInstance( new Object[]{
- factory,
- m_context,
- new Boolean( isLazy )
- } );
+ (ComponentHandler)constructor.newInstance( args );
+ ContainerUtil.contextualize( targetHandler, m_context );
ContainerUtil.configure( targetHandler, configuration );
+ ContainerUtil.initialize( targetHandler );
if( targetHandler instanceof Instrumentable )
{
- Instrumentable instrumentable = (Instrumentable)targetHandler;
- m_instrumentManager.registerInstrumentable(
- instrumentable, instrumentable.getInstrumentableName() );
+ final Instrumentable instrumentable = (Instrumentable)targetHandler;
+ final String name = instrumentable.getInstrumentableName();
+ m_instrumentManager.registerInstrumentable( instrumentable, name );
}
+
handler =
new LEAwareComponentHandler( targetHandler, m_extManager, m_context
);
}
1.36 +29 -9
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.35
retrieving revision 1.36
diff -u -r1.35 -r1.36
--- AbstractComponentHandler.java 9 Nov 2002 07:31:34 -0000 1.35
+++ AbstractComponentHandler.java 9 Nov 2002 07:44:38 -0000 1.36
@@ -51,8 +51,11 @@
import org.apache.avalon.excalibur.logger.LoggerManager;
import org.apache.avalon.framework.activity.Disposable;
+import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.container.ContainerUtil;
import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.context.ContextException;
+import org.apache.avalon.framework.context.Contextualizable;
import org.apache.avalon.framework.logger.Logger;
import org.apache.excalibur.fortress.ContainerConstants;
import org.apache.excalibur.instrument.AbstractInstrumentable;
@@ -70,7 +73,7 @@
*/
public abstract class AbstractComponentHandler
extends AbstractInstrumentable
- implements Disposable, ComponentHandler
+ implements Contextualizable, Initializable, Disposable, ComponentHandler
{
/**
* The instance of the ComponentFactory that creates and disposes of the
@@ -105,32 +108,49 @@
* It falls back to SingleThreaded if not specified.
*
* @param factory The factory used to create component
- * @param context The Context to pass into a contextualizable
- * 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 Context context,
final Boolean isLazy )
throws Exception
{
m_factory = factory;
m_isLazy = isLazy.booleanValue();
+ }
+
+ public void contextualize( final Context context )
+ throws ContextException
+ {
m_loggerManager =
(LoggerManager)context.get( ContainerConstants.LOGGER_MANAGER );
+ }
+
+ public void initialize()
+ throws Exception
+ {
+ final String classname = getClass().getName();
+ final int index = classname.lastIndexOf( '.' );
+ final String name = classname.substring( index + 1 );
+
+ String loggerName = name.toLowerCase();
+ if( name.endsWith("ComponentHandler") )
+ {
+ final int endIndex = loggerName.length() - 16;
+ loggerName = loggerName.substring( 0, endIndex );
+ }
+
+ final String categoryName = "system.handler." + loggerName;
+ m_logger =
+ m_loggerManager.getLoggerForCategory( categoryName );
if( m_factory instanceof Instrumentable )
{
addChildInstrumentable( (Instrumentable)m_factory );
}
- final String classname = getClass().getName();
- final int index = classname.lastIndexOf( '.' );
- final String name = classname.substring( index + 1 );
- System.out.println( "name = " + name );
setInstrumentableName( name );
}
1.19 +1 -5
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.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- ComponentHandler.java 9 Nov 2002 07:31:34 -0000 1.18
+++ ComponentHandler.java 9 Nov 2002 07:44:38 -0000 1.19
@@ -49,10 +49,7 @@
*/
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;
/**
@@ -69,7 +66,6 @@
Class[] HANDLER_CONSTRUCTOR = new Class[]
{
ObjectFactory.class,
- Context.class,
Boolean.class
};
1.35 +2 -5
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.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
--- FactoryComponentHandler.java 9 Nov 2002 07:31:34 -0000 1.34
+++ FactoryComponentHandler.java 9 Nov 2002 07:44:38 -0000 1.35
@@ -49,7 +49,6 @@
*/
package org.apache.excalibur.fortress.handler;
-import org.apache.avalon.framework.context.Context;
import org.apache.excalibur.mpool.ObjectFactory;
/**
@@ -70,12 +69,10 @@
* It falls back to SingleThreaded if not specified.
*/
public FactoryComponentHandler( final ObjectFactory factory,
- final Context context,
final Boolean isLazy )
throws Exception
{
- super( factory, context, isLazy );
- m_logger = m_loggerManager.getLoggerForCategory( "system.handler.factory" );
+ super( factory, isLazy );
}
/**
1.2 +2 -2
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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- LEAwareComponentHandler.java 9 Nov 2002 06:46:42 -0000 1.1
+++ LEAwareComponentHandler.java 9 Nov 2002 07:44:38 -0000 1.2
@@ -49,8 +49,8 @@
*/
package org.apache.excalibur.fortress.handler;
-import org.apache.excalibur.fortress.lifecycle.LifecycleExtensionManager;
import org.apache.avalon.framework.context.Context;
+import org.apache.excalibur.fortress.lifecycle.LifecycleExtensionManager;
/**
* A ComponentHandler that delegates to underlying handler but also
1.3 +1 -1
jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/PassThroughInvocationHandler.java
Index: PassThroughInvocationHandler.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/PassThroughInvocationHandler.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PassThroughInvocationHandler.java 9 Nov 2002 04:02:15 -0000 1.2
+++ PassThroughInvocationHandler.java 9 Nov 2002 07:44:38 -0000 1.3
@@ -8,8 +8,8 @@
package org.apache.excalibur.fortress.handler;
import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
/**
* InvocationHandler that just passes on all methods to target object.
1.38 +8 -5
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.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- PerThreadComponentHandler.java 9 Nov 2002 07:31:34 -0000 1.37
+++ PerThreadComponentHandler.java 9 Nov 2002 07:44:38 -0000 1.38
@@ -48,7 +48,6 @@
*/
package org.apache.excalibur.fortress.handler;
-import org.apache.avalon.framework.context.Context;
import org.apache.excalibur.mpool.ObjectFactory;
/**
@@ -71,12 +70,16 @@
* It falls back to SingleThreaded if not specified.
*/
public PerThreadComponentHandler( final ObjectFactory factory,
- final Context context,
final Boolean isLazy )
throws Exception
{
- super( factory, context, isLazy );
- m_logger = m_loggerManager.getLoggerForCategory( "system.handler.perthread"
);
+ super( factory, isLazy );
+ }
+
+ public void initialize()
+ throws Exception
+ {
+ super.initialize();
m_instance = new ThreadLocalComponent( this );
}
1.40 +11 -7
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.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- PoolableComponentHandler.java 9 Nov 2002 07:31:34 -0000 1.39
+++ PoolableComponentHandler.java 9 Nov 2002 07:44:38 -0000 1.40
@@ -49,10 +49,11 @@
*/
package org.apache.excalibur.fortress.handler;
-import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.context.ContextException;
import org.apache.excalibur.fortress.ContainerConstants;
import org.apache.excalibur.mpool.ObjectFactory;
import org.apache.excalibur.mpool.Pool;
@@ -72,7 +73,7 @@
implements Configurable
{
/** The instance of the PoolManager to create the Pool for the Handler */
- private final PoolManager m_poolManager;
+ private PoolManager m_poolManager;
/** The pool of components for <code>Poolable</code> Components */
private Pool m_pool;
@@ -86,14 +87,17 @@
* It falls back to SingleThreaded if not specified.
*/
public PoolableComponentHandler( final ObjectFactory factory,
- final Context context,
final Boolean isLazy )
throws Exception
{
- super( factory, context, isLazy );
- m_logger = m_loggerManager.getLoggerForCategory( "system.handler.poolable"
);
+ super( factory, isLazy );
+ }
+
+ public void contextualize( Context context )
+ throws ContextException
+ {
+ super.contextualize( context );
m_poolManager = (PoolManager)context.get( ContainerConstants.POOL_MANAGER );
- setInstrumentableName( "PoolableComponentHandler" );
}
public void configure( final Configuration configuration )
1.2 +10 -10
jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/ProxyHelper.java
Index: ProxyHelper.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/ProxyHelper.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ProxyHelper.java 9 Nov 2002 04:46:18 -0000 1.1
+++ ProxyHelper.java 9 Nov 2002 07:44:38 -0000 1.2
@@ -55,25 +55,25 @@
package org.apache.excalibur.fortress.handler;
+import java.io.Serializable;
import java.lang.reflect.Proxy;
import java.util.ArrayList;
-import java.io.Serializable;
+import org.apache.avalon.framework.activity.Disposable;
+import org.apache.avalon.framework.activity.Initializable;
+import org.apache.avalon.framework.activity.Startable;
+import org.apache.avalon.framework.activity.Suspendable;
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.component.Composable;
import org.apache.avalon.framework.component.Recomposable;
-import org.apache.avalon.framework.logger.Loggable;
-import org.apache.avalon.framework.logger.LogEnabled;
-import org.apache.avalon.framework.context.Contextualizable;
-import org.apache.avalon.framework.context.Recontextualizable;
-import org.apache.avalon.framework.service.Serviceable;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Reconfigurable;
+import org.apache.avalon.framework.context.Contextualizable;
+import org.apache.avalon.framework.context.Recontextualizable;
+import org.apache.avalon.framework.logger.LogEnabled;
+import org.apache.avalon.framework.logger.Loggable;
import org.apache.avalon.framework.parameters.Parameterizable;
import org.apache.avalon.framework.parameters.Reparameterizable;
-import org.apache.avalon.framework.activity.Initializable;
-import org.apache.avalon.framework.activity.Startable;
-import org.apache.avalon.framework.activity.Suspendable;
-import org.apache.avalon.framework.activity.Disposable;
+import org.apache.avalon.framework.service.Serviceable;
/**
* Create a Component proxy. Requires JDK 1.3+
1.38 +2 -4
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.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- ThreadSafeComponentHandler.java 9 Nov 2002 07:31:34 -0000 1.37
+++ ThreadSafeComponentHandler.java 9 Nov 2002 07:44:38 -0000 1.38
@@ -72,12 +72,10 @@
* It falls back to SingleThreaded if not specified.
*/
public ThreadSafeComponentHandler( final ObjectFactory factory,
- final Context context,
final Boolean isLazy )
throws Exception
{
- super( factory, context, isLazy );
- m_logger = m_loggerManager.getLoggerForCategory(
"system.handler.threadsafe" );
+ super( factory, isLazy );
}
/**
--
To unsubscribe, e-mail: <mailto:avalon-cvs-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@;jakarta.apache.org>