crafterm 2002/09/11 02:11:31
Modified: fortress/src/java/org/apache/excalibur/fortress/handler
PerThreadComponentHandler.java
Log:
Added code to log any exceptions that may occur when the ThreadLocal
variable is created, and also to prevent null from being returned from the
handler at lookup time.
Reported by: Corey Jewett <[EMAIL PROTECTED]>
Revision Changes Path
1.27 +19 -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.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- PerThreadComponentHandler.java 13 Aug 2002 07:57:26 -0000 1.26
+++ PerThreadComponentHandler.java 11 Sep 2002 09:11:31 -0000 1.27
@@ -51,6 +51,7 @@
import org.apache.avalon.framework.configuration.Configuration;
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;
@@ -82,8 +83,8 @@
throws Exception
{
super( componentClass, config, service, context, extManager, isLazy );
- m_instance = new ThreadLocalComponent( m_factory );
m_logger = m_logkit.getLoggerForCategory( "system.handler.perthread" );
+ m_instance = new ThreadLocalComponent( m_factory, m_logger );
setInstrumentableName( "PerThreadComponentHandler" );
}
@@ -123,7 +124,14 @@
{
super.get();
- return m_instance.get();
+ Object instance = m_instance.get();
+
+ if ( instance == null )
+ {
+ throw new IllegalStateException( "Instance is unavailable" );
+ }
+
+ return instance;
}
/**
@@ -148,10 +156,12 @@
private static final class ThreadLocalComponent extends ThreadLocal
{
private final ComponentFactory m_factory;
+ private final Logger m_logger;
- protected ThreadLocalComponent( ComponentFactory factory )
+ protected ThreadLocalComponent( ComponentFactory factory, Logger logger )
{
m_factory = factory;
+ m_logger = logger;
}
protected Object initialValue()
@@ -162,6 +172,11 @@
}
catch( Exception e )
{
+ if ( m_logger.isErrorEnabled() )
+ {
+ m_logger.error( "Unable to create new thread local instance", e
);
+ }
+
return null;
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>