org.apache.excalibur.instrument.manager.impl
Class DefaultInstrumentManagerImpl

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.excalibur.instrument.manager.impl.DefaultInstrumentManagerImpl
All Implemented Interfaces:
java.lang.Runnable, org.apache.avalon.framework.activity.Disposable, org.apache.avalon.framework.activity.Initializable, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.logger.LogEnabled, org.apache.excalibur.instrument.Instrumentable, org.apache.excalibur.instrument.InstrumentManager, org.apache.excalibur.instrument.manager.DefaultInstrumentManager

public class DefaultInstrumentManagerImpl
extends org.apache.avalon.framework.logger.AbstractLogEnabled
implements org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.activity.Initializable, org.apache.avalon.framework.activity.Disposable, org.apache.excalibur.instrument.manager.DefaultInstrumentManager, org.apache.excalibur.instrument.Instrumentable, java.lang.Runnable

Since:
4.1
Version:
CVS $Revision: 1.4 $ $Date: 2004/02/28 11:47:25 $
Author:
Avalon Development Team

Field Summary
private  org.apache.excalibur.instrument.ValueInstrument m_activeThreadCountInstrument
          Instrument used to profile the active thread count of the JVM.
private  java.util.List m_connectors
          List of configured connectors.
private  java.lang.String m_description
          The description of this InstrumentManager.
private  org.apache.excalibur.instrument.ValueInstrument m_freeMemoryInstrument
          Instrument used to profile the free memory.
private  int m_instrumentableCount
          The Instrumentable count.
private  org.apache.excalibur.instrument.manager.InstrumentableDescriptor[] m_instrumentableDescriptorArray
          Optimized array of the InstrumentableDescriptors.
private  java.lang.String m_instrumentableName
          Instrumentable Name assigned to this Instrumentable
private  java.util.Map m_instrumentableProxies
          HashMap of all of the registered InstrumentableProxies by their keys.
private  InstrumentableProxy[] m_instrumentableProxyArray
          Optimized array of the InstrumentableProxies.
private  org.apache.excalibur.instrument.ValueInstrument m_instrumentablesInstrument
          Instrument used to track the number of Instrumentables in the system.
private  int m_instrumentCount
          The Instrument count.
private  org.apache.excalibur.instrument.ValueInstrument m_instrumentsInstrument
          Instrument used to track the number of Instruments in the system.
private  long m_lastStateSave
          Last time that the state was saved.
private  InstrumentSample[] m_leasedInstrumentSampleArray
          Optimized array of the leased InstrumentSamples.
private  java.util.List m_leasedInstrumentSamples
          List of leased InstrumentSamples.
private  int m_leasedSampleCount
          The Leased Instrument Sample count.
private  org.apache.excalibur.instrument.ValueInstrument m_leasedSamplesInstrument
          Instrument used to track the number of Leased Instrument samples in the system.
private  org.apache.excalibur.instrument.CounterInstrument m_leaseRequestsInstrument
          Instrument used to track the number of lease requests.
private  long m_maxLeasedSampleLease
          The maximum amount of time that a lease will be granted for.
private  int m_maxLeasedSamples
          The maximum number of leased samples which will be allowed.
private  int m_maxLeasedSampleSize
          The maximum size of a leased sample.
private  org.apache.excalibur.instrument.ValueInstrument m_memoryInstrument
          Instrument used to profile the in use memory.
private  java.lang.String m_name
          The name used to identify this InstrumentManager.
private  java.lang.String[][] m_nameTranslationArray
          Optimized array of the registered translations.
private  java.util.Map m_nameTranslations
          Map of all registered translations.
private  int m_permanentSampleCount
          The Permanent Instrument Sample count.
private  org.apache.excalibur.instrument.CounterInstrument m_registrationsInstrument
          Instrument to track the number of times registerInstrumentable is called.
private  java.lang.Thread m_runner
          Thread used to keep the instruments published by the InstrumentManager up to date.
private  org.apache.excalibur.instrument.ValueInstrument m_samplesInstrument
          Instrument used to track the number of Instrument samples in the system.
private  java.lang.Object m_semaphore
          Semaphore for actions which must be synchronized
private  java.io.File m_stateFile
          State file.
private  long m_stateInterval
          Save state interval.
private  org.apache.excalibur.instrument.CounterInstrument m_stateSavesInstrument
          Instrument used to track the number of state saves performed.
private  org.apache.excalibur.instrument.ValueInstrument m_stateSaveTimeInstrument
          Instrument used to track the time it takes to save the state.
private  int m_stateVersion
          State Version.
private  org.apache.excalibur.instrument.ValueInstrument m_totalMemoryInstrument
          Instrument used to profile the total memory.
private  org.apache.avalon.framework.logger.Logger m_translationLogger
          Logger dedicated to logging translations.
 
Fields inherited from interface org.apache.excalibur.instrument.manager.DefaultInstrumentManager
INSTRUMENT_SAMPLE_TYPE_COUNTER, INSTRUMENT_SAMPLE_TYPE_MAXIMUM, INSTRUMENT_SAMPLE_TYPE_MEAN, INSTRUMENT_SAMPLE_TYPE_MINIMUM, INSTRUMENT_TYPE_COUNTER, INSTRUMENT_TYPE_NONE, INSTRUMENT_TYPE_VALUE
 
Fields inherited from interface org.apache.excalibur.instrument.InstrumentManager
ROLE
 
Fields inherited from interface org.apache.excalibur.instrument.Instrumentable
EMPTY_INSTRUMENT_ARRAY, EMPTY_INSTRUMENTABLE_ARRAY
 
Constructor Summary
DefaultInstrumentManagerImpl()
          Creates a new DefaultInstrumentManagerImpl.
DefaultInstrumentManagerImpl(java.lang.String name)
          Deprecated. Name should be set in the instrument configuration file.
 
Method Summary
 void configure(org.apache.avalon.framework.configuration.Configuration configuration)
          Initializes the configured instrumentables.
(package private)  void decrementLeasedSampleCount()
          Called to decrement the number of Leased Instrument Samples registered.
 void dispose()
          Disposes the InstrumentManager.
 org.apache.excalibur.instrument.Instrumentable[] getChildInstrumentables()
          Any Object which implements Instrumentable can also make use of other Instrumentable child objects.
 java.lang.String getDescription()
          Returns the description of this DefaultInstrumentManager.
 org.apache.excalibur.instrument.manager.InstrumentableDescriptor getInstrumentableDescriptor(java.lang.String instrumentableName)
          Returns a InstrumentableDescriptor based on its name or the name of any of its children.
 org.apache.excalibur.instrument.manager.InstrumentableDescriptor[] getInstrumentableDescriptors()
          Returns an array of Descriptors for the Instrumentables managed by this DefaultInstrumentManager.
 java.lang.String getInstrumentableName()
          Gets the name of the Instrumentable.
private  InstrumentableProxy getInstrumentableProxy(java.lang.String instrumentableName)
          Returns a InstrumentableDescriptor based on its name or the name of any of its children.
private  InstrumentableProxy getInstrumentableProxy(java.lang.String instrumentableName, boolean create)
           
private  InstrumentProxy getInstrumentProxy(java.lang.String instrumentName, boolean create)
           
private  InstrumentProxy getInstrumentProxyForSample(java.lang.String sampleName, boolean create)
           
 org.apache.excalibur.instrument.Instrument[] getInstruments()
          Obtain a reference to all the Instruments that the Instrumentable object wishes to expose.
 int getLeaseSampleCount()
          Returns the current number of leased samples.
 long getMaxLeasedSampleLease()
          Returns the maximum number of milliseconds that a lease will be granted for.
 int getMaxLeasedSamples()
          Returns the maximum number of leased samples that will be approved.
 int getMaxLeasedSampleSize()
          Returns the maximum size of a leased sample.
 java.lang.String getName()
          Returns the name used to identify this DefaultInstrumentManager.
 int getStateVersion()
          Returns the stateVersion of the DefaultInstrumeManager.
(package private)  java.lang.String getTranslatedName(java.lang.String name)
          Translates a item name depending on a set of configured translations.
(package private)  void incrementInstrumentableCount()
          Called to increment the number of Instrumentables registered.
(package private)  void incrementInstrumentCount()
          Called to increment the number of Instruments registered.
(package private)  void incrementLeasedSampleCount()
          Called to increment the number of Leased Instrument Samples registered.
(package private)  void incrementLeaseRequests()
          Increment the lease requests.
(package private)  void incrementPermanentSampleCount()
          Called to increment the number of Permanent Instrument Samples registered.
 void initialize()
          Initializes the InstrumentManager.
 void invokeGarbageCollection()
          Invokes garbage collection.
 void loadStateFromConfiguration(org.apache.avalon.framework.configuration.Configuration state)
          Loads the Instrument Manager state from the specified Configuration.
private  void loadStateFromConfiguration(org.apache.avalon.framework.configuration.Configuration state, java.lang.String parentName)
           
 void loadStateFromFile(java.io.File stateFile)
          Loads the Instrument Manager state from the specified file.
 void loadStateFromStream(java.io.InputStream is)
          Loads the Instrument Manager state from the specified stream.
private  void loadStateFromStream(java.io.InputStream is, java.lang.String location)
          Loads the Instrument Manager state from the specified stream.
private  InstrumentableProxy locateDeepestInstrumentableProxy(java.lang.String instrumentableName)
          Given the name of an instrumentable proxy, locate the deepest child instrumentable given the name.
 org.apache.excalibur.instrument.manager.InstrumentableDescriptor locateInstrumentableDescriptor(java.lang.String instrumentableName)
          Searches the entire instrument tree for an instrumentable with the given name.
 org.apache.excalibur.instrument.manager.InstrumentDescriptor locateInstrumentDescriptor(java.lang.String instrumentName)
          Searches the entire instrument tree for an instrument with the given name.
 org.apache.excalibur.instrument.manager.InstrumentSampleDescriptor locateInstrumentSampleDescriptor(java.lang.String sampleName)
          Searches the entire instrument tree for an instrument sample with the given name.
private  void memoryInstruments()
          Updates the Memory based Profile Points published by the InstrumentManager.
private  void registerDummyInstrumentableInner(org.apache.excalibur.instrument.Instrumentable instrumentable, InstrumentableProxy instrumentableProxy, java.lang.String instrumentableName, java.lang.String childName)
          Called as a place holder to handle the registration of instrumentables that do not really exist.
 void registerInstrumentable(org.apache.excalibur.instrument.Instrumentable instrumentable, java.lang.String instrumentableName)
          Instrumentable to be registered with the instrument manager.
private  void registerInstrumentableInner(org.apache.excalibur.instrument.Instrumentable instrumentable, InstrumentableProxy instrumentableProxy, java.lang.String instrumentableName)
          Examines a instrumentable and Registers all of its child Instrumentables and Instruments.
(package private)  void registerLeasedInstrumentSample(InstrumentSample instrumentSample)
          Registers an InstrumentSample which has been leased so that the Instrument Manager can efficiently purge it when it has expired.
 void registerNameTranslation(java.lang.String source, java.lang.String target)
          Registers a name translation that will be applied to all named based lookups of instrumentables, instruments, and samples.
private  void registerNameTranslationInner(java.lang.String source, java.lang.String target)
          Registers a name translation that will be applied to all named based lookups of instrumentables, instruments, and samples.
 void run()
           
private  void saveState()
          Saves the state to the current state file if configured.
 void saveStateToFile(java.io.File stateFile)
          Saves the Instrument Manager's state to the specified file.
 void saveStateToStream(java.io.OutputStream os)
          Saves the Instrument Manager's state to the specified output stream.
 void setInstrumentableName(java.lang.String name)
          Sets the name for the Instrumentable.
(package private)  void stateChanged()
          Called whenever the state of the instrument manager is changed.
private  void testInstrumentSampleLeases()
          Handles the maintenance of all Instrument Samples which have been leased by a client.
private  void threadInstruments()
          Updates the Thread based Profile Points published by the InstrumentManager.
private  org.apache.excalibur.instrument.manager.InstrumentableDescriptor[] updateInstrumentableDescriptorArray()
          Updates the cached array of InstrumentableDescriptors taking synchronization into account.
private  InstrumentableProxy[] updateInstrumentableProxyArray()
          Updates the cached array of InstrumentableProxies taking synchronization into account.
private  java.lang.String[][] updateNameTranslationArray()
          Updates the cached array of registered name translations taking synchronization into account.
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_name

private java.lang.String m_name
The name used to identify this InstrumentManager.


m_description

private java.lang.String m_description
The description of this InstrumentManager.


m_maxLeasedSamples

private int m_maxLeasedSamples
The maximum number of leased samples which will be allowed. This is important to prevent denial of service attacks using connectors.


m_maxLeasedSampleSize

private int m_maxLeasedSampleSize
The maximum size of a leased sample. This is important to prevent denial of service attacks using connectors.


m_maxLeasedSampleLease

private long m_maxLeasedSampleLease
The maximum amount of time that a lease will be granted for. This is important to prevent denial of service attacks using connectors.


m_connectors

private java.util.List m_connectors
List of configured connectors.


m_stateFile

private java.io.File m_stateFile
State file.


m_stateInterval

private long m_stateInterval
Save state interval.


m_lastStateSave

private long m_lastStateSave
Last time that the state was saved.


m_semaphore

private java.lang.Object m_semaphore
Semaphore for actions which must be synchronized


m_instrumentableProxies

private java.util.Map m_instrumentableProxies
HashMap of all of the registered InstrumentableProxies by their keys.


m_instrumentableProxyArray

private InstrumentableProxy[] m_instrumentableProxyArray
Optimized array of the InstrumentableProxies.


m_instrumentableDescriptorArray

private org.apache.excalibur.instrument.manager.InstrumentableDescriptor[] m_instrumentableDescriptorArray
Optimized array of the InstrumentableDescriptors.


m_leasedInstrumentSamples

private java.util.List m_leasedInstrumentSamples
List of leased InstrumentSamples.


m_leasedInstrumentSampleArray

private InstrumentSample[] m_leasedInstrumentSampleArray
Optimized array of the leased InstrumentSamples.


m_translationLogger

private org.apache.avalon.framework.logger.Logger m_translationLogger
Logger dedicated to logging translations.


m_nameTranslations

private java.util.Map m_nameTranslations
Map of all registered translations.


m_nameTranslationArray

private java.lang.String[][] m_nameTranslationArray
Optimized array of the registered translations.


m_runner

private java.lang.Thread m_runner
Thread used to keep the instruments published by the InstrumentManager up to date.


m_instrumentableName

private java.lang.String m_instrumentableName
Instrumentable Name assigned to this Instrumentable


m_totalMemoryInstrument

private org.apache.excalibur.instrument.ValueInstrument m_totalMemoryInstrument
Instrument used to profile the total memory.


m_freeMemoryInstrument

private org.apache.excalibur.instrument.ValueInstrument m_freeMemoryInstrument
Instrument used to profile the free memory.


m_memoryInstrument

private org.apache.excalibur.instrument.ValueInstrument m_memoryInstrument
Instrument used to profile the in use memory.


m_activeThreadCountInstrument

private org.apache.excalibur.instrument.ValueInstrument m_activeThreadCountInstrument
Instrument used to profile the active thread count of the JVM.


m_registrationsInstrument

private org.apache.excalibur.instrument.CounterInstrument m_registrationsInstrument
Instrument to track the number of times registerInstrumentable is called.


m_instrumentableCount

private int m_instrumentableCount
The Instrumentable count.


m_instrumentablesInstrument

private org.apache.excalibur.instrument.ValueInstrument m_instrumentablesInstrument
Instrument used to track the number of Instrumentables in the system.


m_instrumentCount

private int m_instrumentCount
The Instrument count.


m_instrumentsInstrument

private org.apache.excalibur.instrument.ValueInstrument m_instrumentsInstrument
Instrument used to track the number of Instruments in the system.


m_permanentSampleCount

private int m_permanentSampleCount
The Permanent Instrument Sample count.


m_leasedSampleCount

private int m_leasedSampleCount
The Leased Instrument Sample count.


m_samplesInstrument

private org.apache.excalibur.instrument.ValueInstrument m_samplesInstrument
Instrument used to track the number of Instrument samples in the system.


m_leasedSamplesInstrument

private org.apache.excalibur.instrument.ValueInstrument m_leasedSamplesInstrument
Instrument used to track the number of Leased Instrument samples in the system.


m_leaseRequestsInstrument

private org.apache.excalibur.instrument.CounterInstrument m_leaseRequestsInstrument
Instrument used to track the number of lease requests.


m_stateSavesInstrument

private org.apache.excalibur.instrument.CounterInstrument m_stateSavesInstrument
Instrument used to track the number of state saves performed.


m_stateSaveTimeInstrument

private org.apache.excalibur.instrument.ValueInstrument m_stateSaveTimeInstrument
Instrument used to track the time it takes to save the state.


m_stateVersion

private int m_stateVersion
State Version.

Constructor Detail

DefaultInstrumentManagerImpl

public DefaultInstrumentManagerImpl(java.lang.String name)
Deprecated. Name should be set in the instrument configuration file.

Creates a new DefaultInstrumentManagerImpl.

Parameters:
name - The name used to identify this InstrumentManager. Should not contain any spaces or periods.

DefaultInstrumentManagerImpl

public DefaultInstrumentManagerImpl()
Creates a new DefaultInstrumentManagerImpl.

Method Detail

configure

public void configure(org.apache.avalon.framework.configuration.Configuration configuration)
               throws org.apache.avalon.framework.configuration.ConfigurationException
Initializes the configured instrumentables.

Specified by:
configure in interface org.apache.avalon.framework.configuration.Configurable
Parameters:
configuration - InstrumentManager configuration.
Throws:
org.apache.avalon.framework.configuration.ConfigurationException - If there are any configuration problems.

initialize

public void initialize()
                throws java.lang.Exception
Initializes the InstrumentManager.

Specified by:
initialize in interface org.apache.avalon.framework.activity.Initializable
Throws:
java.lang.Exception - If there were any problems initializing the object.

dispose

public void dispose()
Disposes the InstrumentManager.

Specified by:
dispose in interface org.apache.avalon.framework.activity.Disposable

registerInstrumentable

public void registerInstrumentable(org.apache.excalibur.instrument.Instrumentable instrumentable,
                                   java.lang.String instrumentableName)
                            throws java.lang.Exception
Instrumentable to be registered with the instrument manager. Should be called whenever an Instrumentable is created. The '.' character is used to denote a child Instrumentable and can be used to register the instrumentable at a specific point in an instrumentable hierarchy.

Specified by:
registerInstrumentable in interface org.apache.excalibur.instrument.InstrumentManager
Parameters:
instrumentable - Instrumentable to register with the InstrumentManager.
instrumentableName - The name to use when registering the Instrumentable.
Throws:
java.lang.Exception - If there were any problems registering the Instrumentable.

getName

public java.lang.String getName()
Returns the name used to identify this DefaultInstrumentManager.

Specified by:
getName in interface org.apache.excalibur.instrument.manager.DefaultInstrumentManager
Returns:
The name used to identify this DefaultInstrumentManager.

getDescription

public java.lang.String getDescription()
Returns the description of this DefaultInstrumentManager.

Specified by:
getDescription in interface org.apache.excalibur.instrument.manager.DefaultInstrumentManager
Returns:
The description of this DefaultInstrumentManager.

registerNameTranslation

public void registerNameTranslation(java.lang.String source,
                                    java.lang.String target)
                             throws java.lang.IllegalArgumentException
Registers a name translation that will be applied to all named based lookups of instrumentables, instruments, and samples. The more translations that are registered, the greater the impact on name based lookups will be.

General operation of the instrument manager will not be affected as collection on sample data is always done using direct object references.

Translations can be registered for exact name matches, or for the bases of names. Any translation which ends in a '.' will imply a translation to any name beginning with that name base. If the source ends with a '.' then the target must as well.

Parameters:
source - The source name or name base of the translation.
target - The target name or name base of the translation.
Throws:
java.lang.IllegalArgumentException - If the one but not both of the source and target parameters end in '.'.

getInstrumentableDescriptor

public org.apache.excalibur.instrument.manager.InstrumentableDescriptor getInstrumentableDescriptor(java.lang.String instrumentableName)
                                                                                             throws org.apache.excalibur.instrument.manager.NoSuchInstrumentableException
Returns a InstrumentableDescriptor based on its name or the name of any of its children.

Specified by:
getInstrumentableDescriptor in interface org.apache.excalibur.instrument.manager.DefaultInstrumentManager
Parameters:
instrumentableName - Name of the Instrumentable being requested.
Returns:
A Descriptor of the requested Instrumentable.
Throws:
org.apache.excalibur.instrument.manager.NoSuchInstrumentableException - If the specified Instrumentable does not exist.

getInstrumentableDescriptors

public org.apache.excalibur.instrument.manager.InstrumentableDescriptor[] getInstrumentableDescriptors()
Returns an array of Descriptors for the Instrumentables managed by this DefaultInstrumentManager.

Specified by:
getInstrumentableDescriptors in interface org.apache.excalibur.instrument.manager.DefaultInstrumentManager
Returns:
An array of InstrumentableDescriptors.

locateInstrumentableDescriptor

public org.apache.excalibur.instrument.manager.InstrumentableDescriptor locateInstrumentableDescriptor(java.lang.String instrumentableName)
                                                                                                throws org.apache.excalibur.instrument.manager.NoSuchInstrumentableException
Searches the entire instrument tree for an instrumentable with the given name.

Specified by:
locateInstrumentableDescriptor in interface org.apache.excalibur.instrument.manager.DefaultInstrumentManager
Parameters:
instrumentableName - Name of the Instrumentable being requested.
Returns:
A Descriptor of the requested Instrumentable.
Throws:
org.apache.excalibur.instrument.manager.NoSuchInstrumentableException - If the specified Instrumentable does not exist.

locateInstrumentDescriptor

public org.apache.excalibur.instrument.manager.InstrumentDescriptor locateInstrumentDescriptor(java.lang.String instrumentName)
                                                                                        throws org.apache.excalibur.instrument.manager.NoSuchInstrumentException
Searches the entire instrument tree for an instrument with the given name.

Specified by:
locateInstrumentDescriptor in interface org.apache.excalibur.instrument.manager.DefaultInstrumentManager
Parameters:
instrumentName - Name of the Instrument being requested.
Returns:
A Descriptor of the requested Instrument.
Throws:
org.apache.excalibur.instrument.manager.NoSuchInstrumentException - If the specified Instrument does not exist.

locateInstrumentSampleDescriptor

public org.apache.excalibur.instrument.manager.InstrumentSampleDescriptor locateInstrumentSampleDescriptor(java.lang.String sampleName)
                                                                                                    throws org.apache.excalibur.instrument.manager.NoSuchInstrumentSampleException
Searches the entire instrument tree for an instrument sample with the given name.

Specified by:
locateInstrumentSampleDescriptor in interface org.apache.excalibur.instrument.manager.DefaultInstrumentManager
Parameters:
sampleName - Name of the Instrument Sample being requested.
Returns:
A Descriptor of the requested Instrument Sample.
Throws:
org.apache.excalibur.instrument.manager.NoSuchInstrumentSampleException - If the specified Instrument Sample does not exist.

getStateVersion

public int getStateVersion()
Returns the stateVersion of the DefaultInstrumeManager. 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.

Specified by:
getStateVersion in interface org.apache.excalibur.instrument.manager.DefaultInstrumentManager
Returns:
The state version of the instrument manager.

invokeGarbageCollection

public void invokeGarbageCollection()
Invokes garbage collection.

Specified by:
invokeGarbageCollection in interface org.apache.excalibur.instrument.manager.DefaultInstrumentManager

getLeaseSampleCount

public int getLeaseSampleCount()
Returns the current number of leased samples.

Specified by:
getLeaseSampleCount in interface org.apache.excalibur.instrument.manager.DefaultInstrumentManager
Returns:
The current number of leased samples.

getMaxLeasedSamples

public int getMaxLeasedSamples()
Returns the maximum number of leased samples that will be approved.

Specified by:
getMaxLeasedSamples in interface org.apache.excalibur.instrument.manager.DefaultInstrumentManager
Returns:
The maximum number of leased samples.

getMaxLeasedSampleSize

public int getMaxLeasedSampleSize()
Returns the maximum size of a leased sample.

Specified by:
getMaxLeasedSampleSize in interface org.apache.excalibur.instrument.manager.DefaultInstrumentManager
Returns:
The maximum size of a leased sample.

getMaxLeasedSampleLease

public long getMaxLeasedSampleLease()
Returns the maximum number of milliseconds that a lease will be granted for.

Specified by:
getMaxLeasedSampleLease in interface org.apache.excalibur.instrument.manager.DefaultInstrumentManager
Returns:
The maximum lease length.

setInstrumentableName

public void setInstrumentableName(java.lang.String name)
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.

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.

Specified by:
setInstrumentableName in interface org.apache.excalibur.instrument.Instrumentable
Parameters:
name - The name used to identify a Instrumentable.

getInstrumentableName

public java.lang.String getInstrumentableName()
Gets the name of the Instrumentable.

Specified by:
getInstrumentableName in interface org.apache.excalibur.instrument.Instrumentable
Returns:
The name used to identify a Instrumentable.

getInstruments

public org.apache.excalibur.instrument.Instrument[] getInstruments()
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.

Specified by:
getInstruments in interface org.apache.excalibur.instrument.Instrumentable
Returns:
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.

getChildInstrumentables

public org.apache.excalibur.instrument.Instrumentable[] getChildInstrumentables()
Any Object which implements Instrumentable can also make use of other Instrumentable child objects. This method is used to tell the InstrumentManager about them.

Specified by:
getChildInstrumentables in interface org.apache.excalibur.instrument.Instrumentable
Returns:
An array of child Instrumentables. This method should never return null. If there are no child Instrumentables, then EMPTY_INSTRUMENTABLE_ARRAY can be returned.

run

public void run()
Specified by:
run in interface java.lang.Runnable

loadStateFromFile

public void loadStateFromFile(java.io.File stateFile)
                       throws java.lang.Exception
Loads the Instrument Manager state from the specified file.

Parameters:
stateFile - File to read the instrument manager's state from.
Throws:
java.lang.Exception - if there are any problems loading the state.

loadStateFromStream

public void loadStateFromStream(java.io.InputStream is)
                         throws java.lang.Exception
Loads the Instrument Manager state from the specified stream.

Parameters:
is - Stream to read the instrument manager's state from.
Throws:
java.lang.Exception - if there are any problems loading the state.

loadStateFromStream

private void loadStateFromStream(java.io.InputStream is,
                                 java.lang.String location)
                          throws java.lang.Exception
Loads the Instrument Manager state from the specified stream.

Parameters:
is - Stream to read the instrument manager's state from.
location - The location of the stream. Used to improve the usefulness of any exceptions thrown.
Throws:
java.lang.Exception - if there are any problems loading the state.

loadStateFromConfiguration

public void loadStateFromConfiguration(org.apache.avalon.framework.configuration.Configuration state)
                                throws org.apache.avalon.framework.configuration.ConfigurationException
Loads the Instrument Manager state from the specified Configuration.

Parameters:
state - Configuration object to load the state from.
Throws:
org.apache.avalon.framework.configuration.ConfigurationException - If there were any problems loading the state.

loadStateFromConfiguration

private void loadStateFromConfiguration(org.apache.avalon.framework.configuration.Configuration state,
                                        java.lang.String parentName)
                                 throws org.apache.avalon.framework.configuration.ConfigurationException
Throws:
org.apache.avalon.framework.configuration.ConfigurationException

saveStateToFile

public void saveStateToFile(java.io.File stateFile)
                     throws java.lang.Exception
Saves the Instrument Manager's state to the specified file. Any existing file is backed up before the save takes place and replaced in the event of an error.

Parameters:
stateFile - File to write the Instrument Manager's state to.
Throws:
java.lang.Exception - if there are any problems saving the state.

saveStateToStream

public void saveStateToStream(java.io.OutputStream os)
                       throws java.lang.Exception
Saves the Instrument Manager's state to the specified output stream.

Parameters:
os - Stream to write the Instrument Manager's state to.
Throws:
java.lang.Exception - if there are any problems saving the state.

registerLeasedInstrumentSample

void registerLeasedInstrumentSample(InstrumentSample instrumentSample)
Registers an InstrumentSample which has been leased so that the Instrument Manager can efficiently purge it when it has expired.

Parameters:
instrumentSample - Leased InstrumentSample to register.

stateChanged

void stateChanged()
Called whenever the state of the instrument manager is changed.


incrementInstrumentableCount

void incrementInstrumentableCount()
Called to increment the number of Instrumentables registered.


incrementInstrumentCount

void incrementInstrumentCount()
Called to increment the number of Instruments registered.


incrementPermanentSampleCount

void incrementPermanentSampleCount()
Called to increment the number of Permanent Instrument Samples registered.


incrementLeasedSampleCount

void incrementLeasedSampleCount()
Called to increment the number of Leased Instrument Samples registered.


decrementLeasedSampleCount

void decrementLeasedSampleCount()
Called to decrement the number of Leased Instrument Samples registered.


incrementLeaseRequests

void incrementLeaseRequests()
Increment the lease requests.


saveState

private void saveState()
Saves the state to the current state file if configured.


updateNameTranslationArray

private java.lang.String[][] updateNameTranslationArray()
Updates the cached array of registered name translations taking synchronization into account.

Returns:
An array of the String[2]s representing the registered name translations.

getTranslatedName

java.lang.String getTranslatedName(java.lang.String name)
Translates a item name depending on a set of configured translations. If the name does not exist as a translation then the requested name will be returned unmodified.

Parameters:
name - Requested name.
Returns:
target name.

getInstrumentableProxy

private InstrumentableProxy getInstrumentableProxy(java.lang.String instrumentableName,
                                                   boolean create)

getInstrumentProxy

private InstrumentProxy getInstrumentProxy(java.lang.String instrumentName,
                                           boolean create)
                                    throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException - If the specified instrumentName is invalid.

getInstrumentProxyForSample

private InstrumentProxy getInstrumentProxyForSample(java.lang.String sampleName,
                                                    boolean create)
                                             throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException - If the specified sampleName is invalid.

getInstrumentableProxy

private InstrumentableProxy getInstrumentableProxy(java.lang.String instrumentableName)
Returns a InstrumentableDescriptor based on its name or the name of any of its children.

Parameters:
instrumentableName - Name of the Instrumentable being requested.
Returns:
A Proxy of the requested Instrumentable or null if not found.

locateDeepestInstrumentableProxy

private InstrumentableProxy locateDeepestInstrumentableProxy(java.lang.String instrumentableName)
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.

Parameters:
instrumentableName - Fully qualified name of the instrumentable being requested, or of any of its children.
Returns:
The requested instrumentable, or null if not found.

memoryInstruments

private void memoryInstruments()
Updates the Memory based Profile Points published by the InstrumentManager.


threadInstruments

private void threadInstruments()
Updates the Thread based Profile Points published by the InstrumentManager.


testInstrumentSampleLeases

private void testInstrumentSampleLeases()
Handles the maintenance of all Instrument Samples which have been leased by a client. Any Samples whose leases which have expired are cleaned up.


updateInstrumentableProxyArray

private InstrumentableProxy[] updateInstrumentableProxyArray()
Updates the cached array of InstrumentableProxies taking synchronization into account.

Returns:
An array of the InstrumentableProxies.

updateInstrumentableDescriptorArray

private org.apache.excalibur.instrument.manager.InstrumentableDescriptor[] updateInstrumentableDescriptorArray()
Updates the cached array of InstrumentableDescriptors taking synchronization into account.

Returns:
An array of the InstrumentableDescriptors.

registerNameTranslationInner

private void registerNameTranslationInner(java.lang.String source,
                                          java.lang.String target)
                                   throws java.lang.IllegalArgumentException
Registers a name translation that will be applied to all named based lookups of instrumentables, instruments, and samples. The more translations that are registered, the greater the impact on name based lookups will be.

General operation of the instrument manager will not be affected as collection on sample data is always done using direct object references.

Translations can be registered for translations of sample names up to and including the name of the instrument. This means that all source and target names must end in a '.'.

This method should only be called when m_semaphore is synchronized.

Parameters:
source - The source name or name base of the translation.
target - The target name or name base of the translation.
Throws:
java.lang.IllegalArgumentException - If either the source or target does not end in a '.' or is invalid.

registerDummyInstrumentableInner

private void registerDummyInstrumentableInner(org.apache.excalibur.instrument.Instrumentable instrumentable,
                                              InstrumentableProxy instrumentableProxy,
                                              java.lang.String instrumentableName,
                                              java.lang.String childName)
                                       throws java.lang.Exception
Called as a place holder to handle the registration of instrumentables that do not really exist. This makes it possible to register instrumentables at arbitrary locations in the instrumentable hierarchy.

Parameters:
instrumentable - The instrumentable that was registered below a dummy parent.
instrumentableProxy - The proxy assigned to the current placeholder instrumentable.
instrumentableName - The name of the current placeholder instrumentable.
childName - The name of the child instrumentable to register. May contain further '.' characters.
Throws:
java.lang.Exception

registerInstrumentableInner

private void registerInstrumentableInner(org.apache.excalibur.instrument.Instrumentable instrumentable,
                                         InstrumentableProxy instrumentableProxy,
                                         java.lang.String instrumentableName)
                                  throws java.lang.Exception
Examines a instrumentable and Registers all of its child Instrumentables and Instruments.

Only called when m_semaphore is locked.

Throws:
java.lang.Exception