You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by le...@apache.org on 2002/04/10 07:34:20 UTC
cvs commit: jakarta-avalon-excalibur/pool/src/java/org/apache/avalon/excalibur/pool ResourceLimitingPool.java
leif 02/04/09 22:34:20
Modified: pool ant.properties.sample build.xml
pool/src/java/org/apache/avalon/excalibur/pool
ResourceLimitingPool.java
Log:
Modify ResourceLimitingPool to implement Instrumentable.
Revision Changes Path
1.4 +4 -1 jakarta-avalon-excalibur/pool/ant.properties.sample
Index: ant.properties.sample
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/pool/ant.properties.sample,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ant.properties.sample 8 Apr 2002 10:32:12 -0000 1.3
+++ ant.properties.sample 10 Apr 2002 05:34:19 -0000 1.4
@@ -10,7 +10,7 @@
# It is overridden by ../ant.properties and ~/build.properties
# It overrides all default.properties files and ~/.ant.properties
#
-# $Id: ant.properties.sample,v 1.3 2002/04/08 10:32:12 jefft Exp $
+# $Id: ant.properties.sample,v 1.4 2002/04/10 05:34:19 leif Exp $
# -----------------------------------------------------------------------------
# ----- Compile Control Flags -----
@@ -42,6 +42,9 @@
excalibur-concurrent.home=../concurrent/build/lib
excalibur-concurrent.jar=${excalibur-concurrent.home}/excalibur-concurrent-1.0.jar
+# ----- Excalibur Instrument -----
+excalibur-instrument.home=../instrument/build/lib
+excalibur-instrument.jar=${excalibur-instrument.home}/excalibur-instrument-0.1.jar
# --------------------------------------------------
# OPTIONAL LIBRARIES
1.8 +2 -0 jakarta-avalon-excalibur/pool/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/pool/build.xml,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- build.xml 8 Apr 2002 12:15:41 -0000 1.7
+++ build.xml 10 Apr 2002 05:34:19 -0000 1.8
@@ -16,6 +16,8 @@
<pathelement location="${avalon-logkit.jar}"/>
<pathelement location="${avalon-framework.jar}"/>
<pathelement location="${excalibur-collections.jar}"/>
+ <pathelement location="${excalibur-concurrent.jar}"/>
+ <pathelement location="${excalibur-instrument.jar}"/>
<pathelement location="${junit.jar}"/>
<pathelement location="${checkstyle.jar}"/>
</path>
1.2 +170 -10 jakarta-avalon-excalibur/pool/src/java/org/apache/avalon/excalibur/pool/ResourceLimitingPool.java
Index: ResourceLimitingPool.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/pool/src/java/org/apache/avalon/excalibur/pool/ResourceLimitingPool.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ResourceLimitingPool.java 4 Apr 2002 05:09:04 -0000 1.1
+++ ResourceLimitingPool.java 10 Apr 2002 05:34:20 -0000 1.2
@@ -9,6 +9,12 @@
import java.util.Iterator;
import java.util.LinkedList;
+
+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.framework.activity.Disposable;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.logger.LogEnabled;
@@ -26,13 +32,22 @@
* trimmed. See the {@link #trim()} method for details of how trimming works.
*
* @author <a href="mailto:leif@tanukisoftware.com">Leif Mortenson</a>
- * @version CVS $Revision: 1.1 $ $Date: 2002/04/04 05:09:04 $
+ * @version CVS $Revision: 1.2 $ $Date: 2002/04/10 05:34:20 $
* @since 4.1
*/
public class ResourceLimitingPool
extends AbstractLogEnabled
- implements Pool, LogEnabled, Disposable, ThreadSafe
+ implements Pool, LogEnabled, Disposable, ThreadSafe, Instrumentable
{
+ public static final String DEFAULT_INSTRUMENTABLE_NAME = "pool";
+ public static final String INSTRUMENT_SIZE_NAME = "size";
+ public static final String INSTRUMENT_READY_SIZE_NAME = "ready-size";
+ public static final String INSTRUMENT_GETS_NAME = "gets";
+ public static final String INSTRUMENT_PUTS_NAME = "puts";
+ public static final String INSTRUMENT_BLOCKS_NAME = "blocks";
+ public static final String INSTRUMENT_CREATES_NAME = "creates";
+ public static final String INSTRUMENT_DECOMMISSIONS_NAME = "decommissions";
+
/*---------------------------------------------------------------
* Protected Fields
*-------------------------------------------------------------*/
@@ -111,6 +126,30 @@
*/
private int m_size;
+ /** Instrumentable Name assigned to this Instrumentable */
+ private String m_instrumentableName = DEFAULT_INSTRUMENTABLE_NAME;
+
+ /** Instrument used to profile the size of the pool. */
+ private ValueInstrument m_sizeInstrument;
+
+ /** Instrument used to profile the number of available poolables. */
+ private ValueInstrument m_readySizeInstrument;
+
+ /** Instrument used to profile the number of gets. */
+ private CounterInstrument m_getsInstrument;
+
+ /** Instrument used to profile the number of puts. */
+ private CounterInstrument m_putsInstrument;
+
+ /** Instrument used to profile the number of blocks. */
+ private CounterInstrument m_blocksInstrument;
+
+ /** Instrument used to profile the number of created poolables. */
+ private CounterInstrument m_createsInstrument;
+
+ /** Instrument used to profile the number of decommissioned poolables. */
+ private CounterInstrument m_decommissionsInstrument;
+
/*---------------------------------------------------------------
* Constructors
*-------------------------------------------------------------*/
@@ -150,6 +189,15 @@
{
m_oldReady = new LinkedList();
}
+
+ // Initialize the Instrumentable elements.
+ m_sizeInstrument = new ValueInstrument( INSTRUMENT_SIZE_NAME );
+ m_readySizeInstrument = new ValueInstrument( INSTRUMENT_READY_SIZE_NAME );
+ m_getsInstrument = new CounterInstrument( INSTRUMENT_GETS_NAME );
+ m_putsInstrument = new CounterInstrument( INSTRUMENT_PUTS_NAME );
+ m_blocksInstrument = new CounterInstrument( INSTRUMENT_BLOCKS_NAME );
+ m_createsInstrument = new CounterInstrument( INSTRUMENT_CREATES_NAME );
+ m_decommissionsInstrument = new CounterInstrument( INSTRUMENT_DECOMMISSIONS_NAME );
}
/*---------------------------------------------------------------
@@ -169,6 +217,7 @@
{
if( m_disposed ) throw new IllegalStateException( "Already Disposed" );
+ Poolable poolable;
synchronized( m_semaphore )
{
// If trimming is enabled then trim if it is time
@@ -178,7 +227,6 @@
trimInner();
}
- Poolable poolable;
// Look for a Poolable at the end of the m_ready list
if( m_readySize > 0 )
{
@@ -211,6 +259,9 @@
+ "Thread: " + Thread.currentThread().getName() );
}
+ // Notify the InstrumentManager
+ m_blocksInstrument.increment();
+
if( m_blockTimeout > 0 )
{
// Wait for a limited amount of time for a poolable is made
@@ -306,8 +357,8 @@
else
{
// Create a new poolable
- poolable = newPoolable();
m_size++;
+ poolable = newPoolable();
if( getLogger().isDebugEnabled() )
{
@@ -316,14 +367,21 @@
}
}
}
+ }
- if( getLogger().isDebugEnabled() )
- {
- getLogger().debug( "Got a " + poolable.getClass().getName() + " from the pool." );
- }
-
- return poolable;
+ if( getLogger().isDebugEnabled() )
+ {
+ getLogger().debug( "Got a " + poolable.getClass().getName() + " from the pool." );
+ }
+
+ // Notify the InstrumentManager
+ m_getsInstrument.increment();
+ if ( m_readySizeInstrument.isActive() )
+ {
+ m_readySizeInstrument.setValue( getReadySize() );
}
+
+ return poolable;
}
/**
@@ -385,6 +443,13 @@
permanentlyRemovePoolable( poolable );
}
}
+
+ // Notify the InstrumentManager
+ m_putsInstrument.increment();
+ if ( m_readySizeInstrument.isActive() )
+ {
+ m_readySizeInstrument.setValue( getReadySize() );
+ }
}
/*---------------------------------------------------------------
@@ -435,10 +500,90 @@
getLogger().debug( "There were " + m_size
+ " outstanding objects when the pool was disposed." );
}
+
+ // Notify the InstrumentManager
+ if ( m_sizeInstrument.isActive() )
+ {
+ m_sizeInstrument.setValue( getSize() );
+ }
+ if ( m_readySizeInstrument.isActive() )
+ {
+ m_readySizeInstrument.setValue( getReadySize() );
+ }
}
}
/*---------------------------------------------------------------
+ * Instrumentable Methods
+ *-------------------------------------------------------------*/
+ /**
+ * 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 setInstrumentableName( String name )
+ {
+ m_instrumentableName = name;
+ }
+
+ /**
+ * 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
+ * Instruments as opposed to the Instrumentable interface.
+ *
+ * @return An array of the Instruments available for profiling. Should
+ * never be null. If there are no Instruments, then
+ * EMPTY_INSTRUMENT_ARRAY can be returned. This should never be
+ * the case though unless there are child Instrumentables with
+ * Instruments.
+ */
+ public Instrument[] getInstruments()
+ {
+ return new Instrument[]
+ {
+ m_sizeInstrument,
+ m_readySizeInstrument,
+ m_getsInstrument,
+ m_putsInstrument,
+ m_blocksInstrument,
+ m_createsInstrument,
+ m_decommissionsInstrument
+ };
+ }
+
+ /**
+ * 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()
+ {
+ return Instrumentable.EMPTY_INSTRUMENTABLE_ARRAY;
+ }
+
+ /*---------------------------------------------------------------
* Methods
*-------------------------------------------------------------*/
/**
@@ -484,6 +629,14 @@
protected Poolable newPoolable() throws Exception
{
Object obj = m_factory.newInstance();
+
+ // Notify the InstrumentManager
+ m_createsInstrument.increment();
+ if ( m_sizeInstrument.isActive() )
+ {
+ m_sizeInstrument.setValue( getSize() );
+ }
+
return (Poolable)obj;
}
@@ -501,6 +654,13 @@
try
{
m_factory.decommission( poolable );
+
+ // Notify the InstrumentManager
+ m_decommissionsInstrument.increment();
+ if ( m_sizeInstrument.isActive() )
+ {
+ m_sizeInstrument.setValue( getSize() );
+ }
}
catch( Exception e )
{
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>