leif 2002/11/07 23:59:13
Modified: instrument-manager/src/java/org/apache/excalibur/instrument/manager
DefaultInstrumentManager.java
InstrumentManagerClientLocal.java
InstrumentManagerClientLocalImpl.java
instrument-manager/src/java/org/apache/excalibur/instrument/manager/interfaces
InstrumentManagerClient.java
InstrumentSampleUtils.java
Added: instrument-manager/src/test/org/apache/excalibur/instrument/manager/test
DefaultInstrumentManagerTestCase.java
Log:
Add lookup methods to the DefaultInstrumentManager which make it possible to
quickly gain access to any object in the instrument tree.
Revision Changes Path
1.3 +150 -15
jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/DefaultInstrumentManager.java
Index: DefaultInstrumentManager.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/DefaultInstrumentManager.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DefaultInstrumentManager.java 6 Sep 2002 02:10:12 -0000 1.2
+++ DefaultInstrumentManager.java 8 Nov 2002 07:59:13 -0000 1.3
@@ -27,6 +27,8 @@
import org.apache.excalibur.instrument.ValueInstrument;
import org.apache.excalibur.instrument.manager.interfaces.InstrumentManagerClient;
import
org.apache.excalibur.instrument.manager.interfaces.NoSuchInstrumentableException;
+import org.apache.excalibur.instrument.manager.interfaces.NoSuchInstrumentException;
+import
org.apache.excalibur.instrument.manager.interfaces.NoSuchInstrumentSampleException;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.activity.Initializable;
@@ -447,20 +449,6 @@
return proxy.getDescriptor();
}
-
- /**
- * Returns the stateVersion of the instrument manager. The state version
- * will be incremented each time any of the configuration of the
- * instrument manager or any of its children is modified.
- * Clients can use this value to tell whether or not anything has
- * changed without having to do an exhaustive comparison.
- *
- * @return The state version of the instrument manager.
- */
- int getStateVersion()
- {
- return m_stateVersion;
- }
/**
* Returns an array of Descriptors for the Instrumentables managed by this
@@ -480,6 +468,126 @@
}
/**
+ * Searches the entire instrument tree an instrumentable with the given
+ * name.
+ *
+ * @param instrumentableName Name of the Instrumentable being requested.
+ *
+ * @return A Descriptor of the requested Instrumentable.
+ *
+ * @throws NoSuchInstrumentableException If the specified Instrumentable does
+ * not exist.
+ */
+ public InstrumentableDescriptorLocal locateInstrumentableDescriptor( String
instrumentableName )
+ throws NoSuchInstrumentableException
+ {
+ InstrumentableProxy instrumentableProxy =
+ locateDeepestInstrumentableProxy( instrumentableName );
+ if ( instrumentableProxy != null )
+ {
+ if ( instrumentableProxy.getName().equals( instrumentableName ) )
+ {
+ // Found what we were looking for
+ return instrumentableProxy.getDescriptor();
+ }
+ }
+
+ // Unable to locate the requested Instrumentable
+ throw new NoSuchInstrumentableException(
+ "No instrumentable can be found with the name: " + instrumentableName );
+ }
+
+ /**
+ * Searches the entire instrument tree an instrument with the given name.
+ *
+ * @param instrumentName Name of the Instrument being requested.
+ *
+ * @return A Descriptor of the requested Instrument.
+ *
+ * @throws NoSuchInstrumentException If the specified Instrument does
+ * not exist.
+ */
+ public InstrumentDescriptorLocal locateInstrumentDescriptor( String
instrumentName )
+ throws NoSuchInstrumentException
+ {
+ InstrumentableProxy instrumentableProxy =
+ locateDeepestInstrumentableProxy( instrumentName );
+ if ( instrumentableProxy != null )
+ {
+ // Now look for the specified instrument
+ InstrumentProxy instrumentProxy =
+ instrumentableProxy.getInstrumentProxy( instrumentName );
+ if ( instrumentProxy != null )
+ {
+ if ( instrumentProxy.getName().equals( instrumentName ) )
+ {
+ // Found what we were looking for
+ return instrumentProxy.getDescriptor();
+ }
+ }
+ }
+
+ // Unable to locate the requested Instrument
+ throw new NoSuchInstrumentException(
+ "No instrument can be found with the name: " + instrumentName );
+ }
+
+ /**
+ * Searches the entire instrument tree an instrument sample with the given
+ * name.
+ *
+ * @param sampleName Name of the Instrument Sample being requested.
+ *
+ * @return A Descriptor of the requested Instrument Sample.
+ *
+ * @throws NoSuchInstrumentSampleException If the specified Instrument
+ * Sample does not exist.
+ */
+ public InstrumentSampleDescriptorLocal locateInstrumentSampleDescriptor( String
sampleName )
+ throws NoSuchInstrumentSampleException
+ {
+ InstrumentableProxy instrumentableProxy =
+ locateDeepestInstrumentableProxy( sampleName );
+ if ( instrumentableProxy != null )
+ {
+ // Now look for the specified instrument
+ InstrumentProxy instrumentProxy =
+ instrumentableProxy.getInstrumentProxy( sampleName );
+ if ( instrumentProxy != null )
+ {
+ // Now look for the specified sample
+ InstrumentSample sample = instrumentProxy.getInstrumentSample(
sampleName );
+ if ( sample != null )
+ {
+ if ( sample.getName().equals( sampleName ) )
+ {
+ // Found what we were looking for
+ return sample.getDescriptor();
+ }
+ }
+ }
+ }
+
+ // Unable to locate the requested Instrument Sample
+ throw new NoSuchInstrumentException(
+ "No instrument sample can be found with the name: " + sampleName );
+ }
+
+ /**
+ * Returns the stateVersion of the instrument manager. The state version
+ * will be incremented each time any of the configuration of the
+ * instrument manager or any of its children is modified.
+ * Clients can use this value to tell whether or not anything has
+ * changed without having to do an exhaustive comparison.
+ *
+ * @return The state version of the instrument manager.
+ */
+ int getStateVersion()
+ {
+ return m_stateVersion;
+ }
+
+ /**
* Invokes garbage collection.
*/
public void invokeGarbageCollection()
@@ -849,6 +957,33 @@
return null;
}
}
+ }
+
+ /**
+ * Given the name of an instrumentable proxy, locate the deepest child
+ * instrumentable given the name. The name can be the name of an
+ * instrumentable or of any of its children.
+ *
+ * @param instrumentableName Fully qualified name of the instrumentable
+ * being requested, or of any of its children.
+ *
+ * @return The requested instrumentable, or null if not found.
+ */
+ private InstrumentableProxy locateDeepestInstrumentableProxy( String
instrumentableName )
+ {
+ InstrumentableProxy deepestProxy = null;
+ // Start by obtaining a top level instrumentable
+ InstrumentableProxy proxy = getInstrumentableProxy( instrumentableName );
+
+ // Now attempt to locate a child instrumentable
+ while ( proxy != null )
+ {
+ deepestProxy = proxy;
+
+ proxy = deepestProxy.getChildInstrumentableProxy( instrumentableName );
+ }
+
+ return deepestProxy;
}
/**
1.2 +44 -1
jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/InstrumentManagerClientLocal.java
Index: InstrumentManagerClientLocal.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/InstrumentManagerClientLocal.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- InstrumentManagerClientLocal.java 14 Aug 2002 14:58:21 -0000 1.1
+++ InstrumentManagerClientLocal.java 8 Nov 2002 07:59:13 -0000 1.2
@@ -10,6 +10,8 @@
import org.apache.excalibur.instrument.Instrumentable;
import org.apache.excalibur.instrument.manager.interfaces.InstrumentManagerClient;
import
org.apache.excalibur.instrument.manager.interfaces.NoSuchInstrumentableException;
+import org.apache.excalibur.instrument.manager.interfaces.NoSuchInstrumentException;
+import
org.apache.excalibur.instrument.manager.interfaces.NoSuchInstrumentSampleException;
import org.apache.avalon.framework.configuration.Configuration;
@@ -46,5 +48,46 @@
* InstrumentManager.
*/
InstrumentableDescriptorLocal[] getInstrumentableDescriptorLocals();
+
+ /**
+ * Searches the entire instrument tree an instrumentable with the given
+ * name.
+ *
+ * @param instrumentableName Name of the Instrumentable being requested.
+ *
+ * @return A Descriptor of the requested Instrumentable.
+ *
+ * @throws NoSuchInstrumentableException If the specified Instrumentable does
+ * not exist.
+ */
+ InstrumentableDescriptorLocal locateInstrumentableDescriptorLocal( String
instrumentableName )
+ throws NoSuchInstrumentableException;
+
+ /**
+ * Searches the entire instrument tree an instrument with the given name.
+ *
+ * @param instrumentName Name of the Instrument being requested.
+ *
+ * @return A Descriptor of the requested Instrument.
+ *
+ * @throws NoSuchInstrumentException If the specified Instrument does
+ * not exist.
+ */
+ InstrumentDescriptorLocal locateInstrumentDescriptorLocal( String
instrumentName )
+ throws NoSuchInstrumentException;
+
+ /**
+ * Searches the entire instrument tree an instrument sample with the given
+ * name.
+ *
+ * @param sampleName Name of the Instrument Sample being requested.
+ *
+ * @return A Descriptor of the requested Instrument Sample.
+ *
+ * @throws NoSuchInstrumentSampleException If the specified Instrument
+ * Sample does not exist.
+ */
+ InstrumentSampleDescriptorLocal locateInstrumentSampleDescriptorLocal( String
sampleName )
+ throws NoSuchInstrumentSampleException;
}
1.3 +115 -9
jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/InstrumentManagerClientLocalImpl.java
Index: InstrumentManagerClientLocalImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/InstrumentManagerClientLocalImpl.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- InstrumentManagerClientLocalImpl.java 6 Sep 2002 02:10:12 -0000 1.2
+++ InstrumentManagerClientLocalImpl.java 8 Nov 2002 07:59:13 -0000 1.3
@@ -8,7 +8,11 @@
package org.apache.excalibur.instrument.manager;
import org.apache.excalibur.instrument.manager.interfaces.InstrumentableDescriptor;
+import org.apache.excalibur.instrument.manager.interfaces.InstrumentDescriptor;
+import
org.apache.excalibur.instrument.manager.interfaces.InstrumentSampleDescriptor;
import
org.apache.excalibur.instrument.manager.interfaces.NoSuchInstrumentableException;
+import org.apache.excalibur.instrument.manager.interfaces.NoSuchInstrumentException;
+import
org.apache.excalibur.instrument.manager.interfaces.NoSuchInstrumentSampleException;
import org.apache.avalon.framework.configuration.Configuration;
@@ -84,6 +88,70 @@
}
/**
+ * Searches the entire instrument tree an instrumentable with the given
+ * name.
+ *
+ * @param instrumentableName Name of the Instrumentable being requested.
+ *
+ * @return A Descriptor of the requested Instrumentable.
+ *
+ * @throws NoSuchInstrumentableException If the specified Instrumentable does
+ * not exist.
+ */
+ public InstrumentableDescriptor locateInstrumentableDescriptor( String
instrumentableName )
+ throws NoSuchInstrumentableException
+ {
+ return locateInstrumentableDescriptorLocal( instrumentableName );
+ }
+
+ /**
+ * Searches the entire instrument tree an instrument with the given name.
+ *
+ * @param instrumentName Name of the Instrument being requested.
+ *
+ * @return A Descriptor of the requested Instrument.
+ *
+ * @throws NoSuchInstrumentException If the specified Instrument does
+ * not exist.
+ */
+ public InstrumentDescriptor locateInstrumentDescriptor( String instrumentName )
+ throws NoSuchInstrumentException
+ {
+ return locateInstrumentDescriptorLocal( instrumentName );
+ }
+
+ /**
+ * Searches the entire instrument tree an instrument sample with the given
+ * name.
+ *
+ * @param sampleName Name of the Instrument Sample being requested.
+ *
+ * @return A Descriptor of the requested Instrument Sample.
+ *
+ * @throws NoSuchInstrumentSampleException If the specified Instrument
+ * Sample does not exist.
+ */
+ public InstrumentSampleDescriptor locateInstrumentSampleDescriptor( String
sampleName )
+ throws NoSuchInstrumentSampleException
+ {
+ return locateInstrumentSampleDescriptorLocal( sampleName );
+ }
+
+ /**
+ * Returns the stateVersion of the instrument manager. The state version
+ * will be incremented each time any of the configuration of the
+ * instrument manager or any of its children is modified.
+ * Clients can use this value to tell whether or not anything has
+ * changed without having to do an exhaustive comparison.
+ *
+ * @return The state version of the instrument manager.
+ */
+ public int getStateVersion()
+ {
+ return m_manager.getStateVersion();
+ }
+
+ /**
* Invokes garbage collection.
*/
public void invokeGarbageCollection()
@@ -125,17 +193,55 @@
}
/**
- * Returns the stateVersion of the instrument manager. The state version
- * will be incremented each time any of the configuration of the
- * instrument manager or any of its children is modified.
- * Clients can use this value to tell whether or not anything has
- * changed without having to do an exhaustive comparison.
+ * Searches the entire instrument tree an instrumentable with the given
+ * name.
*
- * @return The state version of the instrument manager.
+ * @param instrumentableName Name of the Instrumentable being requested.
+ *
+ * @return A Descriptor of the requested Instrumentable.
+ *
+ * @throws NoSuchInstrumentableException If the specified Instrumentable does
+ * not exist.
*/
- public int getStateVersion()
+ public InstrumentableDescriptorLocal locateInstrumentableDescriptorLocal(
+ String instrumentableName )
+ throws NoSuchInstrumentableException
{
- return m_manager.getStateVersion();
+ return m_manager.locateInstrumentableDescriptor( instrumentableName );
+ }
+
+ /**
+ * Searches the entire instrument tree an instrument with the given name.
+ *
+ * @param instrumentName Name of the Instrument being requested.
+ *
+ * @return A Descriptor of the requested Instrument.
+ *
+ * @throws NoSuchInstrumentException If the specified Instrument does
+ * not exist.
+ */
+ public InstrumentDescriptorLocal locateInstrumentDescriptorLocal( String
instrumentName )
+ throws NoSuchInstrumentException
+ {
+ return m_manager.locateInstrumentDescriptor( instrumentName );
+ }
+
+ /**
+ * Searches the entire instrument tree an instrument sample with the given
+ * name.
+ *
+ * @param sampleName Name of the Instrument Sample being requested.
+ *
+ * @return A Descriptor of the requested Instrument Sample.
+ *
+ * @throws NoSuchInstrumentSampleException If the specified Instrument
+ * Sample does not exist.
+ */
+ public InstrumentSampleDescriptorLocal locateInstrumentSampleDescriptorLocal(
+ String sampleName )
+ throws NoSuchInstrumentSampleException
+ {
+ return m_manager.locateInstrumentSampleDescriptor( sampleName );
}
}
1.1
jakarta-avalon-excalibur/instrument-manager/src/test/org/apache/excalibur/instrument/manager/test/DefaultInstrumentManagerTestCase.java
Index: DefaultInstrumentManagerTestCase.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.excalibur.instrument.manager.test;
import junit.framework.TestCase;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
import org.apache.avalon.framework.logger.ConsoleLogger;
import org.apache.excalibur.instrument.manager.DefaultInstrumentManager;
import org.apache.excalibur.instrument.manager.interfaces.InstrumentableDescriptor;
import org.apache.excalibur.instrument.manager.interfaces.InstrumentDescriptor;
import org.apache.excalibur.instrument.manager.interfaces.InstrumentSampleDescriptor;
import
org.apache.excalibur.instrument.manager.interfaces.NoSuchInstrumentableException;
import org.apache.excalibur.instrument.manager.interfaces.NoSuchInstrumentException;
import
org.apache.excalibur.instrument.manager.interfaces.NoSuchInstrumentSampleException;
/**
* Test of the DefaultInstrumentManager.
*
* @author <a href="mailto:leif@;tanukisoftware.com">Leif Mortenson</a>
* @version CVS $Revision: 1.1 $ $Date: 2002/11/08 07:59:13 $
*/
public class DefaultInstrumentManagerTestCase
extends TestCase
{
private DefaultInstrumentManager m_instrumentManager;
/*---------------------------------------------------------------
* Constructors
*-------------------------------------------------------------*/
public DefaultInstrumentManagerTestCase( String name )
{
super( name );
}
/*---------------------------------------------------------------
* TestCase Methods
*-------------------------------------------------------------*/
public void setUp()
throws Exception
{
System.out.println( "setUp()" );
super.setUp();
DefaultConfiguration instrumentConfig = new DefaultConfiguration(
"instrument" );
m_instrumentManager = new DefaultInstrumentManager();
m_instrumentManager.enableLogging( new ConsoleLogger(
ConsoleLogger.LEVEL_DEBUG ) );
m_instrumentManager.configure( instrumentConfig );
m_instrumentManager.initialize();
}
public void tearDown()
throws Exception
{
System.out.println( "tearDown()" );
m_instrumentManager.dispose();
m_instrumentManager = null;
super.tearDown();
}
/*---------------------------------------------------------------
* Methods
*-------------------------------------------------------------*/
private void assertInstrumentableExists( String name )
{
InstrumentableDescriptor descriptor =
m_instrumentManager.locateInstrumentableDescriptor( name );
assertEquals( "Looked up instrumentable name incorrect.",
descriptor.getName(), name );
}
private void assertInstrumentableNotExists( String name )
{
try
{
InstrumentableDescriptor descriptor =
m_instrumentManager.locateInstrumentableDescriptor( name );
fail( "Found an instrumentable named " + name + " when it should not
have existed." );
}
catch( NoSuchInstrumentableException e )
{
// Ok
}
}
private void assertInstrumentExists( String name )
{
InstrumentDescriptor descriptor =
m_instrumentManager.locateInstrumentDescriptor( name );
assertEquals( "Looked up instrument name incorrect.", descriptor.getName(),
name );
}
private void assertInstrumentNotExists( String name )
{
try
{
InstrumentDescriptor descriptor =
m_instrumentManager.locateInstrumentDescriptor( name );
fail( "Found an instrument named " + name + " when it should not have
existed." );
}
catch( NoSuchInstrumentException e )
{
// Ok
}
}
private void assertInstrumentSampleExists( String name )
{
InstrumentSampleDescriptor descriptor =
m_instrumentManager.locateInstrumentSampleDescriptor( name );
assertEquals( "Looked up instrument sample name incorrect.",
descriptor.getName(), name );
}
private void assertInstrumentSampleNotExists( String name )
{
try
{
InstrumentSampleDescriptor descriptor =
m_instrumentManager.locateInstrumentSampleDescriptor( name );
fail( "Found an instrument sample named " + name + " when it should not
have existed." );
}
catch( NoSuchInstrumentSampleException e )
{
// Ok
}
}
/*---------------------------------------------------------------
* Test Cases
*-------------------------------------------------------------*/
public void testCreateDestroy() throws Exception
{
}
public void testLookupDefaultInstruments() throws Exception
{
// Look for elements which should always exist.
assertInstrumentableExists( "instrument-manager" );
assertInstrumentExists( "instrument-manager.total-memory" );
assertInstrumentExists( "instrument-manager.free-memory" );
assertInstrumentExists( "instrument-manager.memory" );
assertInstrumentExists( "instrument-manager.active-thread-count" );
// Look for elements which should not exist.
assertInstrumentableNotExists( "instrument-manager.total-memory" );
assertInstrumentableNotExists( "instrument-manager.foobar" );
assertInstrumentableNotExists( "foobar" );
assertInstrumentNotExists( "instrument-manager.foobar" );
}
public void testLookupSamples() throws Exception
{
}
}
1.3 +42 -1
jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/interfaces/InstrumentManagerClient.java
Index: InstrumentManagerClient.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/interfaces/InstrumentManagerClient.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- InstrumentManagerClient.java 6 Sep 2002 02:10:13 -0000 1.2
+++ InstrumentManagerClient.java 8 Nov 2002 07:59:13 -0000 1.3
@@ -78,6 +78,47 @@
InstrumentableDescriptor[] getInstrumentableDescriptors();
/**
+ * Searches the entire instrument tree an instrumentable with the given
+ * name.
+ *
+ * @param instrumentableName Name of the Instrumentable being requested.
+ *
+ * @return A Descriptor of the requested Instrumentable.
+ *
+ * @throws NoSuchInstrumentableException If the specified Instrumentable does
+ * not exist.
+ */
+ InstrumentableDescriptor locateInstrumentableDescriptor( String
instrumentableName )
+ throws NoSuchInstrumentableException;
+
+ /**
+ * Searches the entire instrument tree an instrument with the given name.
+ *
+ * @param instrumentName Name of the Instrument being requested.
+ *
+ * @return A Descriptor of the requested Instrument.
+ *
+ * @throws NoSuchInstrumentException If the specified Instrument does
+ * not exist.
+ */
+ InstrumentDescriptor locateInstrumentDescriptor( String instrumentName )
+ throws NoSuchInstrumentException;
+
+ /**
+ * Searches the entire instrument tree an instrument sample with the given
+ * name.
+ *
+ * @param sampleName Name of the Instrument Sample being requested.
+ *
+ * @return A Descriptor of the requested Instrument Sample.
+ *
+ * @throws NoSuchInstrumentSampleException If the specified Instrument
+ * Sample does not exist.
+ */
+ InstrumentSampleDescriptor locateInstrumentSampleDescriptor( String sampleName )
+ throws NoSuchInstrumentSampleException;
+
+ /**
* Returns the stateVersion of the instrument manager. The state version
* will be incremented each time any of the configuration of the
* instrument manager or any of its children is modified.
1.2 +3 -3
jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/interfaces/InstrumentSampleUtils.java
Index: InstrumentSampleUtils.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/instrument-manager/src/java/org/apache/excalibur/instrument/manager/interfaces/InstrumentSampleUtils.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- InstrumentSampleUtils.java 14 Aug 2002 14:58:24 -0000 1.1
+++ InstrumentSampleUtils.java 8 Nov 2002 07:59:13 -0000 1.2
@@ -87,8 +87,8 @@
long sampleInterval,
int sampleSize )
{
- return getInstrumentSampleTypeName( sampleType ) + "." +
- sampleInterval + "." + sampleSize;
+ return getInstrumentSampleTypeName( sampleType ) + "_" +
+ sampleInterval + "_" + sampleSize;
}
/**
--
To unsubscribe, e-mail: <mailto:avalon-cvs-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@;jakarta.apache.org>