leif 02/04/09 22:39:37
Modified:
instrument-manager/src/java/org/apache/avalon/excalibur/instrument/component
DefaultComponentHandler.java
InstrumentComponentHandler.java
PoolableComponentHandler.java
ThreadSafeComponentHandler.java
Log:
Modify so that handlers now extend their ECM counterparts. This was necessary
to make class casting work correctly. Also reduced duplicate code.
Revision Changes Path
1.3 +67 -101
jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/avalon/excalibur/instrument/component/DefaultComponentHandler.java
Index: DefaultComponentHandler.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/avalon/excalibur/instrument/component/DefaultComponentHandler.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DefaultComponentHandler.java 3 Apr 2002 13:18:29 -0000 1.2
+++ DefaultComponentHandler.java 10 Apr 2002 05:39:37 -0000 1.3
@@ -8,40 +8,28 @@
package org.apache.avalon.excalibur.instrument.component;
import org.apache.avalon.excalibur.component.DefaultComponentFactory;
-import org.apache.avalon.excalibur.component.RoleManager;
import org.apache.avalon.excalibur.instrument.CounterInstrument;
import org.apache.avalon.excalibur.instrument.Instrument;
+import org.apache.avalon.excalibur.instrument.Instrumentable;
import org.apache.avalon.excalibur.instrument.ValueInstrument;
-import org.apache.avalon.excalibur.logger.LogKitManager;
-import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.component.Component;
-import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.context.Context;
-import org.apache.log.Logger;
/**
* The DefaultComponentHandler to make sure components are initialized
* and destroyed correctly.
*
- * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
- * @author <a href="mailto:[EMAIL PROTECTED]">Ryan Shaw</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Leif Mortenson</a>
- * @version CVS $Revision: 1.2 $ $Date: 2002/04/03 13:18:29 $
+ * @version CVS $Revision: 1.3 $ $Date: 2002/04/10 05:39:37 $
* @since 4.0
*/
public class DefaultComponentHandler
- extends InstrumentComponentHandler
+ extends org.apache.avalon.excalibur.component.DefaultComponentHandler
+ implements Instrumentable
{
- /** The instance of the ComponentFactory that creates and disposes of
the Component */
- private final DefaultComponentFactory m_factory;
-
- /** State management boolean stating whether the Handler is initialized
or not */
- private boolean m_initialized = false;
-
- /** State management boolean stating whether the Handler is disposed or
not */
- private boolean m_disposed = false;
+ /** Instrumentable Name assigned to this Instrumentable */
+ private String m_instrumentableName;
/** Instrument used to profile the number of outstanding references. */
private ValueInstrument m_referencesInstrument;
@@ -52,6 +40,9 @@
/** Instrument used to profile the number of puts. */
private CounterInstrument m_putsInstrument;
+ /*---------------------------------------------------------------
+ * Constructors
+ *-------------------------------------------------------------*/
/**
* Create a DefaultComponentHandler which manages a pool of Components
* created by the specified factory object.
@@ -59,12 +50,14 @@
* @param factory The factory object which is responsible for creating
the components
* managed by the ComponentHandler.
* @param config The configuration to use to configure the pool.
+ *
+ * @throws Exception if the handler could not be created.
*/
public DefaultComponentHandler( final DefaultComponentFactory factory,
final Configuration config )
throws Exception
{
- m_factory = factory;
+ super( factory, config );
// Initialize the Instrumentable elements.
m_referencesInstrument = new ValueInstrument( "references" );
@@ -72,51 +65,21 @@
m_putsInstrument = new CounterInstrument( "puts" );
}
+ /*---------------------------------------------------------------
+ * ComponentHandler Methods
+ *-------------------------------------------------------------*/
/**
- * Sets the logger that the ComponentHandler will use.
- */
- public void setLogger( final Logger logger )
- {
- m_factory.setLogger( logger );
-
- super.setLogger( logger );
- }
-
- /**
- * Initialize the ComponentHandler.
- */
- public void initialize()
- {
- if( m_initialized )
- {
- return;
- }
-
- if( getLogger().isDebugEnabled() )
- {
- getLogger().debug( "ComponentHandler initialized for: " +
this.m_factory.getCreatedClass().getName() );
- }
- m_initialized = true;
- }
-
- /**
- * Get a reference of the desired Component
+ * Get a reference of the desired Component.
+ *
+ * @return A component from the handler.
+ *
+ * @throws Exception If there was any problems getting a component.
*/
protected Component doGet()
throws Exception
{
- if( !m_initialized )
- {
- throw new IllegalStateException( "You cannot get a component
from an uninitialized holder." );
- }
-
- if( m_disposed )
- {
- throw new IllegalStateException( "You cannot get a component
from a disposed holder" );
- }
+ Component component = super.doGet();
- Component component = (Component)m_factory.newInstance();
-
// Notify the instrument manager
m_getsInstrument.increment();
// Reference count will be incremented after this returns
@@ -126,63 +89,51 @@
}
/**
- * Return a reference of the desired Component
+ * Return a reference of the desired Component.
+ *
+ * @param component Component to put back into the handler.
*/
protected void doPut( final Component component )
{
- if( !m_initialized )
- {
- throw new IllegalStateException( "You cannot put a component in
an uninitialized holder." );
- }
-
// Notify the instrument manager
m_putsInstrument.increment();
// References decremented before this call.
m_referencesInstrument.setValue( getReferences() );
- try
- {
- m_factory.decommission( component );
- }
- catch( final Exception e )
- {
- if( getLogger().isWarnEnabled() )
- {
- getLogger().warn( "Error decommissioning component: " +
- m_factory.getCreatedClass().getName(), e );
- }
- }
+ super.doPut( component );
}
-
+
+ /*---------------------------------------------------------------
+ * Instrumentable Methods
+ *-------------------------------------------------------------*/
/**
- * Dispose of the ComponentHandler and any associated Pools and
Factories.
+ * Sets the name for the Instrumentable. The Instrumentable Name is used
+ * to uniquely identify the Instrumentable during the configuration of
+ * the InstrumentManager and to gain access to an
InstrumentableDescriptor
+ * through the InstrumentManager. The value should be a string which
does
+ * not contain spaces or periods.
+ * <p>
+ * This value may be set by a parent Instrumentable, or by the
+ * InstrumentManager using the value of the 'instrumentable' attribute
in
+ * the configuration of the component.
+ *
+ * @param name The name used to identify a Instrumentable.
*/
- public void dispose()
+ public void setInstrumentableName( String name )
{
- try
- {
- // do nothing here
-
- if( m_factory instanceof Disposable )
- {
- ( (Disposable)m_factory ).dispose();
- }
- }
- catch( final Exception e )
- {
- if( getLogger().isWarnEnabled() )
- {
- getLogger().warn( "Error decommissioning component: " +
- m_factory.getCreatedClass().getName(), e );
- }
- }
-
- m_disposed = true;
+ m_instrumentableName = name;
}
- /*---------------------------------------------------------------
- * Instrumentable Methods
- *-------------------------------------------------------------*/
+ /**
+ * Gets the name of the Instrumentable.
+ *
+ * @return The name used to identify a Instrumentable.
+ */
+ public String getInstrumentableName()
+ {
+ return m_instrumentableName;
+ }
+
/**
* Obtain a reference to all the Instruments that the Instrumentable
object
* wishes to expose. All sampling is done directly through the
@@ -202,5 +153,20 @@
m_getsInstrument,
m_putsInstrument
};
+ }
+
+ /**
+ * Any Object which implements Instrumentable can also make use of other
+ * Instrumentable child objects. This method is used to tell the
+ * InstrumentManager about them.
+ *
+ * @return An array of child Instrumentables. This method should never
+ * return null. If there are no child Instrumentables, then
+ * EMPTY_INSTRUMENTABLE_ARRAY can be returned.
+ */
+ public Instrumentable[] getChildInstrumentables()
+ {
+ // Child Instrumenatables are registered as they are found.
+ return Instrumentable.EMPTY_INSTRUMENTABLE_ARRAY;
}
}
1.5 +8 -12
jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/avalon/excalibur/instrument/component/InstrumentComponentHandler.java
Index: InstrumentComponentHandler.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/avalon/excalibur/instrument/component/InstrumentComponentHandler.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- InstrumentComponentHandler.java 3 Apr 2002 13:18:29 -0000 1.4
+++ InstrumentComponentHandler.java 10 Apr 2002 05:39:37 -0000 1.5
@@ -12,14 +12,10 @@
import org.apache.avalon.excalibur.instrument.InstrumentManager;
import org.apache.avalon.excalibur.component.ComponentHandler;
import org.apache.avalon.excalibur.component.DefaultComponentFactory;
-//import org.apache.avalon.excalibur.component.DefaultComponentHandler;
-//import org.apache.avalon.excalibur.component.PoolableComponentHandler;
import org.apache.avalon.excalibur.component.RoleManager;
-//import org.apache.avalon.excalibur.component.ThreadSafeComponentHandler;
import org.apache.avalon.excalibur.logger.LogKitManager;
import org.apache.avalon.excalibur.pool.Poolable;
-import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.context.Context;
@@ -29,7 +25,7 @@
/**
*
* @author <a href="mailto:[EMAIL PROTECTED]">Leif Mortenson</a>
- * @version CVS $Revision: 1.4 $ $Date: 2002/04/03 13:18:29 $
+ * @version CVS $Revision: 1.5 $ $Date: 2002/04/10 05:39:37 $
* @since 4.1
*/
public abstract class InstrumentComponentHandler
@@ -60,7 +56,7 @@
*/
public static ComponentHandler getComponentHandler(
final Class componentClass,
- final Configuration config,
+ final Configuration configuration,
final ComponentManager componentManager,
final Context context,
final RoleManager roleManager,
@@ -94,7 +90,7 @@
// Create the factory to use to create the instances of the
Component.
DefaultComponentFactory factory =
new InstrumentDefaultComponentFactory( componentClass,
- config,
+ configuration,
componentManager,
context,
roleManager,
@@ -102,22 +98,22 @@
instrumentManager,
instrumentableName );
- InstrumentComponentHandler handler;
+ ComponentHandler handler;
if( Poolable.class.isAssignableFrom( componentClass ) )
{
- handler = new PoolableComponentHandler( factory, config );
+ handler = new PoolableComponentHandler( factory, configuration );
}
else if( ThreadSafe.class.isAssignableFrom( componentClass ) )
{
- handler = new ThreadSafeComponentHandler( factory, config );
+ handler = new ThreadSafeComponentHandler( factory, configuration
);
}
else // This is a SingleThreaded component
{
- handler = new DefaultComponentHandler( factory, config );
+ handler = new DefaultComponentHandler( factory, configuration );
}
// Register the new handler with the instrumentManager if it exists.
- handler.setInstrumentableName( instrumentableName );
+ ((Instrumentable)handler).setInstrumentableName( instrumentableName
);
return handler;
}
1.3 +71 -102
jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/avalon/excalibur/instrument/component/PoolableComponentHandler.java
Index: PoolableComponentHandler.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/avalon/excalibur/instrument/component/PoolableComponentHandler.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PoolableComponentHandler.java 3 Apr 2002 13:18:29 -0000 1.2
+++ PoolableComponentHandler.java 10 Apr 2002 05:39:37 -0000 1.3
@@ -10,18 +10,11 @@
import org.apache.avalon.excalibur.component.DefaultComponentFactory;
import org.apache.avalon.excalibur.instrument.CounterInstrument;
import org.apache.avalon.excalibur.instrument.Instrument;
+import org.apache.avalon.excalibur.instrument.Instrumentable;
import org.apache.avalon.excalibur.instrument.ValueInstrument;
-import org.apache.avalon.excalibur.logger.LogKitManager;
-import org.apache.avalon.excalibur.pool.Poolable;
-import org.apache.avalon.excalibur.pool.ResourceLimitingPool;
-import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.component.Component;
-import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.context.Context;
-import org.apache.avalon.framework.logger.LogKitLogger;
-import org.apache.log.Logger;
/**
* The PoolableComponentHandler to make sure that poolable components are
initialized
@@ -84,28 +77,16 @@
*
* </ul>
*
- * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Leif Mortenson</a>
- * @author <a href="mailto:[EMAIL PROTECTED]">Ryan Shaw</a>
- * @version CVS $Revision: 1.2 $ $Date: 2002/04/03 13:18:29 $
+ * @version CVS $Revision: 1.3 $ $Date: 2002/04/10 05:39:37 $
* @since 4.0
*/
-public class PoolableComponentHandler extends InstrumentComponentHandler
+public class PoolableComponentHandler
+ extends org.apache.avalon.excalibur.component.PoolableComponentHandler
+ implements Instrumentable
{
- /** The default max size of the pool */
- public static final int DEFAULT_MAX_POOL_SIZE = 8;
-
- /** The instance of the ComponentFactory that creates and disposes of
the Component */
- private final DefaultComponentFactory m_factory;
-
- /** The pool of components for <code>Poolable</code> Components */
- private final ResourceLimitingPool m_pool;
-
- /** State management boolean stating whether the Handler is initialized
or not */
- private boolean m_initialized = false;
-
- /** State management boolean stating whether the Handler is disposed or
not */
- private boolean m_disposed = false;
+ /** Instrumentable Name assigned to this Instrumentable */
+ private String m_instrumentableName;
/** Instrument used to profile the number of outstanding references. */
private ValueInstrument m_referencesInstrument;
@@ -116,6 +97,9 @@
/** Instrument used to profile the number of puts. */
private CounterInstrument m_putsInstrument;
+ /*---------------------------------------------------------------
+ * Constructors
+ *-------------------------------------------------------------*/
/**
* Create a PoolableComponentHandler which manages a pool of Components
* created by the specified factory object.
@@ -123,21 +107,14 @@
* @param factory The factory object which is responsible for creating
the components
* managed by the ComponentHandler.
* @param config The configuration to use to configure the pool.
+ *
+ * @throws Exception if the handler could not be created.
*/
public PoolableComponentHandler( final DefaultComponentFactory factory,
final Configuration config )
throws Exception
{
- m_factory = factory;
-
- int poolMax = config.getAttributeAsInteger( "pool-max",
DEFAULT_MAX_POOL_SIZE );
- boolean poolMaxStrict = config.getAttributeAsBoolean(
"pool-max-strict", false );
- boolean poolBlocking = config.getAttributeAsBoolean(
"pool-blocking", true );
- long poolTimeout = config.getAttributeAsLong( "pool-timeout", 0 );
- long poolTrimInterval = config.getAttributeAsLong(
"pool-trim-interval", 0 );
-
- m_pool = new ResourceLimitingPool( m_factory, poolMax,
poolMaxStrict, poolBlocking,
- poolTimeout, poolTrimInterval );
+ super( factory, config );
// Initialize the Instrumentable elements.
m_referencesInstrument = new ValueInstrument( "references" );
@@ -145,56 +122,21 @@
m_putsInstrument = new CounterInstrument( "puts" );
}
+ /*---------------------------------------------------------------
+ * ComponentHandler Methods
+ *-------------------------------------------------------------*/
/**
- * Sets the logger that the ComponentHandler will use.
- */
- public void setLogger( final Logger logger )
- {
- m_factory.setLogger( logger );
- m_pool.enableLogging( new LogKitLogger( logger ) );
-
- super.setLogger( logger );
- }
-
- /**
- * Initialize the ComponentHandler.
- */
- public void initialize()
- {
- if( m_initialized )
- {
- return;
- }
-
- if( getLogger().isDebugEnabled() )
- {
- getLogger().debug( "ComponentHandler initialized for: " +
- m_factory.getCreatedClass().getName() );
- }
-
- m_initialized = true;
- }
-
- /**
- * Get a reference of the desired Component
+ * Get a reference of the desired Component.
+ *
+ * @return A component from the handler.
+ *
+ * @throws Exception If there was any problems getting a component.
*/
protected Component doGet()
throws Exception
{
- if( !m_initialized )
- {
- throw new IllegalStateException( "You cannot get a component
from an " +
- "uninitialized holder." );
- }
-
- if( m_disposed )
- {
- throw new IllegalStateException( "You cannot get a component
from " +
- "a disposed holder" );
- }
+ Component component = super.doGet();
- Component component = (Component)m_pool.get();
-
// Notify the instrument manager
m_getsInstrument.increment();
// Reference count will be incremented after this returns
@@ -204,42 +146,51 @@
}
/**
- * Return a reference of the desired Component
+ * Return a reference of the desired Component.
+ *
+ * @param component Component to put back into the handler.
*/
protected void doPut( final Component component )
{
- if( !m_initialized )
- {
- throw new IllegalStateException( "You cannot put a component in
" +
- "an uninitialized holder." );
- }
-
// Notify the instrument manager
m_putsInstrument.increment();
// References decremented before this call.
m_referencesInstrument.setValue( getReferences() );
- m_pool.put( (Poolable)component );
+ super.doPut( component );
}
-
+
+ /*---------------------------------------------------------------
+ * Instrumentable Methods
+ *-------------------------------------------------------------*/
/**
- * Dispose of the ComponentHandler and any associated Pools and
Factories.
+ * Sets the name for the Instrumentable. The Instrumentable Name is used
+ * to uniquely identify the Instrumentable during the configuration of
+ * the InstrumentManager and to gain access to an
InstrumentableDescriptor
+ * through the InstrumentManager. The value should be a string which
does
+ * not contain spaces or periods.
+ * <p>
+ * This value may be set by a parent Instrumentable, or by the
+ * InstrumentManager using the value of the 'instrumentable' attribute
in
+ * the configuration of the component.
+ *
+ * @param name The name used to identify a Instrumentable.
*/
- public void dispose()
+ public void setInstrumentableName( String name )
{
- m_pool.dispose();
-
- if( m_factory instanceof Disposable )
- {
- ( (Disposable)m_factory ).dispose();
- }
-
- m_disposed = true;
+ m_instrumentableName = name;
}
- /*---------------------------------------------------------------
- * Instrumentable Methods
- *-------------------------------------------------------------*/
+ /**
+ * Gets the name of the Instrumentable.
+ *
+ * @return The name used to identify a Instrumentable.
+ */
+ public String getInstrumentableName()
+ {
+ return m_instrumentableName;
+ }
+
/**
* Obtain a reference to all the Instruments that the Instrumentable
object
* wishes to expose. All sampling is done directly through the
@@ -258,6 +209,24 @@
m_referencesInstrument,
m_getsInstrument,
m_putsInstrument
+ };
+ }
+
+ /**
+ * Any Object which implements Instrumentable can also make use of other
+ * Instrumentable child objects. This method is used to tell the
+ * InstrumentManager about them.
+ *
+ * @return An array of child Instrumentables. This method should never
+ * return null. If there are no child Instrumentables, then
+ * EMPTY_INSTRUMENTABLE_ARRAY can be returned.
+ */
+ public Instrumentable[] getChildInstrumentables()
+ {
+ // Child Instrumenatables are registered as they are found.
+ return new Instrumentable[]
+ {
+ getPool()
};
}
}
1.3 +70 -125
jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/avalon/excalibur/instrument/component/ThreadSafeComponentHandler.java
Index: ThreadSafeComponentHandler.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/avalon/excalibur/instrument/component/ThreadSafeComponentHandler.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ThreadSafeComponentHandler.java 3 Apr 2002 13:18:29 -0000 1.2
+++ ThreadSafeComponentHandler.java 10 Apr 2002 05:39:37 -0000 1.3
@@ -10,35 +10,27 @@
import org.apache.avalon.excalibur.component.DefaultComponentFactory;
import org.apache.avalon.excalibur.instrument.CounterInstrument;
import org.apache.avalon.excalibur.instrument.Instrument;
+import org.apache.avalon.excalibur.instrument.Instrumentable;
import org.apache.avalon.excalibur.instrument.ValueInstrument;
-import org.apache.avalon.excalibur.logger.LogKitManager;
-import org.apache.avalon.framework.activity.Disposable;
-import org.apache.avalon.framework.activity.Startable;
import org.apache.avalon.framework.component.Component;
-import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.context.Context;
-import org.apache.log.Logger;
/**
* The ThreadSafeComponentHandler to make sure components are initialized
* and destroyed correctly.
*
- * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
- * @author <a href="mailto:[EMAIL PROTECTED]">Ryan Shaw</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Leif Mortenson</a>
- * @version CVS $Revision: 1.2 $ $Date: 2002/04/03 13:18:29 $
+ * @version CVS $Revision: 1.3 $ $Date: 2002/04/10 05:39:37 $
* @since 4.0
*/
public class ThreadSafeComponentHandler
- extends InstrumentComponentHandler
+ extends org.apache.avalon.excalibur.component.ThreadSafeComponentHandler
+ implements Instrumentable
{
- private Component m_instance;
- private final DefaultComponentFactory m_factory;
- private boolean m_initialized = false;
- private boolean m_disposed = false;
-
+ /** Instrumentable Name assigned to this Instrumentable */
+ private String m_instrumentableName;
+
/** Instrument used to profile the number of outstanding references. */
private ValueInstrument m_referencesInstrument;
@@ -48,6 +40,9 @@
/** Instrument used to profile the number of puts. */
private CounterInstrument m_putsInstrument;
+ /*---------------------------------------------------------------
+ * Constructors
+ *-------------------------------------------------------------*/
/**
* Create a ThreadSafeComponentHandler which manages a pool of Components
* created by the specified factory object.
@@ -55,12 +50,14 @@
* @param factory The factory object which is responsible for creating
the components
* managed by the ComponentHandler.
* @param config The configuration to use to configure the pool.
+ *
+ * @throws Exception if the handler could not be created.
*/
public ThreadSafeComponentHandler( final DefaultComponentFactory factory,
final Configuration config )
throws Exception
{
- m_factory = factory;
+ super( factory, config );
// Initialize the Instrumentable elements.
m_referencesInstrument = new ValueInstrument( "references" );
@@ -68,142 +65,75 @@
m_putsInstrument = new CounterInstrument( "puts" );
}
+ /*---------------------------------------------------------------
+ * ComponentHandler Methods
+ *-------------------------------------------------------------*/
/**
- * 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.
- */
- /* Don't need this?
- protected ThreadSafeComponentHandler( final Component component )
- throws Exception
- {
- m_instance = component;
- m_factory = null;
- }
- */
-
- public void setLogger( Logger log )
- {
- if( this.m_factory != null )
- {
- m_factory.setLogger( log );
- }
-
- super.setLogger( log );
- }
-
- /**
- * Initialize the ComponentHandler.
- */
- public void initialize()
- throws Exception
- {
- if( m_initialized )
- {
- return;
- }
-
- if( m_instance == null )
- {
- m_instance = (Component)this.m_factory.newInstance();
- }
-
- if( getLogger().isDebugEnabled() )
- {
- if( this.m_factory != null )
- {
- getLogger().debug( "ComponentHandler initialized for: " +
this.m_factory.getCreatedClass().getName() );
- }
- else
- {
- getLogger().debug( "ComponentHandler initialized for: " +
this.m_instance.getClass().getName() );
- }
- }
-
- m_initialized = true;
- }
-
- /**
- * Get a reference of the desired Component
+ * Get a reference of the desired Component.
+ *
+ * @return A component from the handler.
+ *
+ * @throws Exception If there was any problems getting a component.
*/
- protected final Component doGet()
+ protected Component doGet()
throws Exception
{
- if( !m_initialized )
- {
- throw new IllegalStateException( "You cannot get a component
from an uninitialized holder." );
- }
-
- if( m_disposed )
- {
- throw new IllegalStateException( "You cannot get a component
from a disposed holder" );
- }
+ Component component = super.doGet();
// Notify the instrument manager
m_getsInstrument.increment();
// Reference count will be incremented after this returns
m_referencesInstrument.setValue( getReferences() + 1 );
- return m_instance;
+ return component;
}
/**
- * Return a reference of the desired Component
+ * Return a reference of the desired Component.
+ *
+ * @param component Component to put back into the handler.
*/
protected void doPut( final Component component )
{
- if( !m_initialized )
- {
- throw new IllegalStateException( "You cannot put a component in
an uninitialized holder." );
- }
-
// Notify the instrument manager
m_putsInstrument.increment();
// References decremented before this call.
m_referencesInstrument.setValue( getReferences() );
+
+ super.doPut( component );
}
+ /*---------------------------------------------------------------
+ * Instrumentable Methods
+ *-------------------------------------------------------------*/
/**
- * Dispose of the ComponentHandler and any associated Pools and
Factories.
+ * Sets the name for the Instrumentable. The Instrumentable Name is used
+ * to uniquely identify the Instrumentable during the configuration of
+ * the InstrumentManager and to gain access to an
InstrumentableDescriptor
+ * through the InstrumentManager. The value should be a string which
does
+ * not contain spaces or periods.
+ * <p>
+ * This value may be set by a parent Instrumentable, or by the
+ * InstrumentManager using the value of the 'instrumentable' attribute
in
+ * the configuration of the component.
+ *
+ * @param name The name used to identify a Instrumentable.
*/
- public void dispose()
+ public void setInstrumentableName( String name )
{
- try
- {
- if( null != m_factory )
- {
- m_factory.decommission( m_instance );
- }
- else
- {
- if( m_instance instanceof Startable )
- {
- ( (Startable)m_instance ).stop();
- }
-
- if( m_instance instanceof Disposable )
- {
- ( (Disposable)m_instance ).dispose();
- }
- }
-
- m_instance = null;
- }
- catch( final Exception e )
- {
- if( getLogger().isWarnEnabled() )
- {
- getLogger().warn( "Error decommissioning component: " +
- m_factory.getCreatedClass().getName(), e );
- }
- }
-
- m_disposed = true;
+ m_instrumentableName = name;
}
- /*---------------------------------------------------------------
- * Instrumentable Methods
- *-------------------------------------------------------------*/
+ /**
+ * Gets the name of the Instrumentable.
+ *
+ * @return The name used to identify a Instrumentable.
+ */
+ public String getInstrumentableName()
+ {
+ return m_instrumentableName;
+ }
+
/**
* Obtain a reference to all the Instruments that the Instrumentable
object
* wishes to expose. All sampling is done directly through the
@@ -223,5 +153,20 @@
m_getsInstrument,
m_putsInstrument
};
+ }
+
+ /**
+ * Any Object which implements Instrumentable can also make use of other
+ * Instrumentable child objects. This method is used to tell the
+ * InstrumentManager about them.
+ *
+ * @return An array of child Instrumentables. This method should never
+ * return null. If there are no child Instrumentables, then
+ * EMPTY_INSTRUMENTABLE_ARRAY can be returned.
+ */
+ public Instrumentable[] getChildInstrumentables()
+ {
+ // Child Instrumenatables are registered as they are found.
+ return Instrumentable.EMPTY_INSTRUMENTABLE_ARRAY;
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>