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

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.excalibur.instrument.manager.impl.AbstractInstrumentSample
          extended by org.apache.excalibur.instrument.manager.impl.AbstractValueInstrumentSample
All Implemented Interfaces:
org.apache.avalon.framework.logger.LogEnabled, InstrumentSample, org.apache.excalibur.instrument.manager.InstrumentListener, org.apache.excalibur.instrument.manager.ValueInstrumentListener
Direct Known Subclasses:
MaximumValueInstrumentSample, MeanValueInstrumentSample, MinimumValueInstrumentSample

abstract class AbstractValueInstrumentSample
extends AbstractInstrumentSample
implements org.apache.excalibur.instrument.manager.ValueInstrumentListener

An AbstractValueInstrumentSample contains all of the functionality common to all InstrumentSamples which represent a fixed value.

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

Field Summary
protected  int m_lastValue
          Last value set to the sample for use for sample periods where no value is set.
protected  int m_value
          The sample value.
protected  int m_valueCount
          The number of times that the value has been changed in this sample period.
 
Fields inherited from class org.apache.excalibur.instrument.manager.impl.AbstractInstrumentSample
m_time
 
Constructor Summary
protected AbstractValueInstrumentSample(InstrumentProxy instrumentProxy, java.lang.String name, long interval, int size, java.lang.String description, long lease)
          Creates a new AbstractValueInstrumentSample
 
Method Summary
protected  void advanceToNextSample(boolean reset)
          The current sample has already been stored.
protected  int getFillValue()
          Returns the value to use for filling in the buffer when time is skipped.
 int getInstrumentType()
          Returns the Type of the Instrument which can use the sample.
 int getValueInner()
          Obtain the value of the sample.
protected  void loadState(int value, org.apache.avalon.framework.configuration.Configuration state)
          Used to load the state, called from AbstractInstrumentSample.loadState();
 void setValue(java.lang.String instrumentName, int value, long time)
          Called by a ValueInstrument whenever its value is set.
protected abstract  void setValueInner(int value, long time)
          Sets the current value of the sample.
protected  void writeStateAttributes(java.io.PrintWriter out)
          Allow subclasses to add information into the saved state.
 
Methods inherited from class org.apache.excalibur.instrument.manager.impl.AbstractInstrumentSample
addInstrumentSampleListener, expire, extendLease, getDescription, getDescriptor, getInstrumentProxy, getInterval, getLeaseExpirationTime, getName, getSize, getSnapshot, getStateVersion, getTime, getValue, isConfigured, loadState, makePermanent, removeInstrumentSampleListener, setConfigured, stateChanged, toString, update, updateListeners, writeState
 
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, wait, wait, wait
 
Methods inherited from interface org.apache.excalibur.instrument.manager.impl.InstrumentSample
getType
 
Methods inherited from interface org.apache.avalon.framework.logger.LogEnabled
enableLogging
 

Field Detail

m_value

protected int m_value
The sample value.


m_valueCount

protected int m_valueCount
The number of times that the value has been changed in this sample period.


m_lastValue

protected int m_lastValue
Last value set to the sample for use for sample periods where no value is set.

Constructor Detail

AbstractValueInstrumentSample

protected AbstractValueInstrumentSample(InstrumentProxy instrumentProxy,
                                        java.lang.String name,
                                        long interval,
                                        int size,
                                        java.lang.String description,
                                        long lease)
Creates a new AbstractValueInstrumentSample

Parameters:
instrumentProxy - The InstrumentProxy which owns the InstrumentSample.
name - The name of the new InstrumentSample.
interval - The sample interval of the new InstrumentSample.
size - The number of samples to store as history. Assumes that size is at least 1.
description - The description of the new InstrumentSample.
lease - The length of the lease in milliseconds.
Method Detail

getInstrumentType

public final int getInstrumentType()
Returns the Type of the Instrument which can use the sample. This should be the same for all instances of a class.

This InstrumentSample returns DefaultInstrumentManager.INSTRUMENT_TYPE_VALUE

Specified by:
getInstrumentType in interface InstrumentSample
Returns:
The Type of the Instrument which can use the sample.

getValueInner

public int getValueInner()
Obtain the value of the sample. All samples are integers, so the profiled objects must measure quantity (numbers of items), rate (items/period), time in milliseconds, etc.

Should only be called when synchronized.

Specified by:
getValueInner in class AbstractInstrumentSample
Returns:
The sample value.

advanceToNextSample

protected void advanceToNextSample(boolean reset)
The current sample has already been stored. Reset the current sample and move on to the next.

Should only be called when synchronized.

Specified by:
advanceToNextSample in class AbstractInstrumentSample
Parameters:
reset - True if the next sample should be reset.

getFillValue

protected int getFillValue()
Returns the value to use for filling in the buffer when time is skipped.

Should only be called when synchronized.

Specified by:
getFillValue in class AbstractInstrumentSample

writeStateAttributes

protected void writeStateAttributes(java.io.PrintWriter out)
Allow subclasses to add information into the saved state.

Overrides:
writeStateAttributes in class AbstractInstrumentSample
Parameters:
out - PrintWriter to write to.

loadState

protected void loadState(int value,
                         org.apache.avalon.framework.configuration.Configuration state)
                  throws org.apache.avalon.framework.configuration.ConfigurationException
Used to load the state, called from AbstractInstrumentSample.loadState();

Should only be called when synchronized.

Specified by:
loadState in class AbstractInstrumentSample
Parameters:
value - Current value loaded from the state.
state - Configuration object to load state from.
Throws:
org.apache.avalon.framework.configuration.ConfigurationException - If there were any problems loading the state.

setValue

public void setValue(java.lang.String instrumentName,
                     int value,
                     long time)
Called by a ValueInstrument whenever its value is set.

Specified by:
setValue in interface org.apache.excalibur.instrument.manager.ValueInstrumentListener
Parameters:
instrumentName - The key of Instrument whose value was set.
value - Value that was set.
time - The time that the Instrument was incremented. ValueInstrument

setValueInner

protected abstract void setValueInner(int value,
                                      long time)
Sets the current value of the sample.

Parameters:
value - New sample value.
time - Time that the new sample arrives.