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

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.CounterInstrumentSample
All Implemented Interfaces:
org.apache.avalon.framework.logger.LogEnabled, org.apache.excalibur.instrument.manager.CounterInstrumentListener, InstrumentSample, org.apache.excalibur.instrument.manager.InstrumentListener

 class CounterInstrumentSample
extends AbstractInstrumentSample
implements org.apache.excalibur.instrument.manager.CounterInstrumentListener

A InstrumentSample which stores the number of times that increment has been called during the sample period.

Author:
Avalon Development Team

Field Summary
protected  int m_count
          The count.
 
Fields inherited from class org.apache.excalibur.instrument.manager.impl.AbstractInstrumentSample
m_time
 
Constructor Summary
CounterInstrumentSample(InstrumentProxy instrumentProxy, java.lang.String name, long interval, int size, java.lang.String description, long lease)
          Creates a new CounterInstrumentSample
 
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 getType()
          Returns the type of the Instrument Sample.
 int getValueInner()
          Obtain the value of the sample.
private  void increment(int count, long time)
          Increments the count.
 void increment(java.lang.String instrumentName, int count, long time)
          Called by a CounterInstrument whenever its value is incremented.
protected  void loadState(int value, org.apache.avalon.framework.configuration.Configuration state)
          Used to load the state, called from AbstractInstrumentSample.loadState();
 
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, writeStateAttributes
 
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.avalon.framework.logger.LogEnabled
enableLogging
 

Field Detail

m_count

protected int m_count
The count.

Constructor Detail

CounterInstrumentSample

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

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

getType

public int getType()
Returns the type of the Instrument Sample.

Specified by:
getType in interface InstrumentSample
Returns:
The type of the Instrument Sample.

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_COUNTER

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.

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

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.

increment

public void increment(java.lang.String instrumentName,
                      int count,
                      long time)
Called by a CounterInstrument whenever its value is incremented.

Specified by:
increment in interface org.apache.excalibur.instrument.manager.CounterInstrumentListener
Parameters:
instrumentName - The name of Instrument which was incremented.
count - A positive integer to increment the counter by.
time - The time that the Instrument was incremented.

increment

private void increment(int count,
                       long time)
Increments the count.

Parameters:
time - Time that the count is incremented.
count - A positive integer to increment the counter by.