com.limegroup.gnutella.statistics
Class AbstractStatistic

java.lang.Object
  extended bycom.limegroup.gnutella.statistics.AbstractStatistic
All Implemented Interfaces:
Statistic
Direct Known Subclasses:
AbstractKilobytesStatistic, com.limegroup.gnutella.statistics.AdvancedStatistic, NumericalStatistic

public abstract class AbstractStatistic
extends java.lang.Object
implements Statistic

This class provides a default implementation of the Statistic interface, providing such functionality as keeping track of the history for the given statistic, providing access to the average value, the maximum value, etc.


Field Summary
protected  IntBuffer _buffer
          IntBuffer for recording stats data -- initialized to an empty buffer until stats are actually recorded.
protected  int _current
          Long for the statistic currently being added to.
protected  java.lang.String _fileName
          The file name to write stat data to.
protected  double _max
          The maximum value ever recorded for any time period.
protected  double _total
          Variable for the total number of messages received for this statistic.
protected  int _totalStatsRecorded
          The total number of stats recorded.
protected static StatisticsManager STATS_MANAGER
          Constant for the StatisticsManager for use in subclasses.
 
Fields inherited from interface com.limegroup.gnutella.statistics.Statistic
HISTORY_LENGTH
 
Constructor Summary
protected AbstractStatistic()
          Constructs a new Statistic instance.
 
Method Summary
 void addData(int data)
          Add the specified number to the current recording for this statistic.
 void clearData()
          Clears the current data stored in this statistic.
 double getAverage()
          Accessor for the average number of this statistic type received per recording time period.
 double getMax()
          Accessor for the maximum recorded stat value over all recorded time periods.
 IntBuffer getStatHistory()
          Accessor for the Integer array of all statistics recorded over a discrete interval.
 double getTotal()
          Accessor for the total number of this statistic recorded.
 void incrementStat()
          Increments this statistic by one.
protected  void initializeBuffer()
          Constructs the IntBuffer with 0 for all values if it is not already constructed.
 void setWriteStatToFile(boolean write)
          Sets whether or not to write this Statistic out to a file.
 void storeCurrentStat()
          Stores the current set of gathered statistics into the history set, setting the currently recorded data back to zero.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STATS_MANAGER

protected static final StatisticsManager STATS_MANAGER
Constant for the StatisticsManager for use in subclasses.


_buffer

protected IntBuffer _buffer
IntBuffer for recording stats data -- initialized to an empty buffer until stats are actually recorded.


_current

protected volatile int _current
Long for the statistic currently being added to.


_total

protected volatile double _total
Variable for the total number of messages received for this statistic.


_totalStatsRecorded

protected volatile int _totalStatsRecorded
The total number of stats recorded.


_max

protected volatile double _max
The maximum value ever recorded for any time period.


_fileName

protected java.lang.String _fileName
The file name to write stat data to. If this is null or the empty string, we attempt to derive the appropriate file name via reflection.

Constructor Detail

AbstractStatistic

protected AbstractStatistic()
Constructs a new Statistic instance.

Method Detail

getTotal

public double getTotal()
Description copied from interface: Statistic
Accessor for the total number of this statistic recorded.

Specified by:
getTotal in interface Statistic
Returns:
the total of this statistic recorded, regardless of any time increments

getAverage

public double getAverage()
Description copied from interface: Statistic
Accessor for the average number of this statistic type received per recording time period.

Specified by:
getAverage in interface Statistic
Returns:
the average number of this statistic type received per recording time period

getMax

public double getMax()
Description copied from interface: Statistic
Accessor for the maximum recorded stat value over all recorded time periods.

Specified by:
getMax in interface Statistic
Returns:
the maximum recorded stat value over all recorded time periods

incrementStat

public void incrementStat()
Description copied from interface: Statistic
Increments this statistic by one.

Specified by:
incrementStat in interface Statistic

addData

public void addData(int data)
Description copied from interface: Statistic
Add the specified number to the current recording for this statistic. This is the equivalent of calling incrementStat data times.

Specified by:
addData in interface Statistic
Parameters:
data - the number to increment the current statistic

getStatHistory

public IntBuffer getStatHistory()
Description copied from interface: Statistic
Accessor for the Integer array of all statistics recorded over a discrete interval. Note that this has a finite size, so only a fixed size array will be returned.

Specified by:
getStatHistory in interface Statistic
Returns:
the Integer array for all statistics recorded for this statistic

clearData

public void clearData()
Description copied from interface: Statistic
Clears the current data stored in this statistic. Useful for statistics that want to be analyzed repeatedly in a single session, starting from scratch each time.

Specified by:
clearData in interface Statistic

storeCurrentStat

public void storeCurrentStat()
Description copied from interface: Statistic
Stores the current set of gathered statistics into the history set, setting the currently recorded data back to zero.

Specified by:
storeCurrentStat in interface Statistic

setWriteStatToFile

public void setWriteStatToFile(boolean write)
Description copied from interface: Statistic
Sets whether or not to write this Statistic out to a file. If it does write to a file, the file name is automatically generated from the name of the class, which should easily label the data. All data is written in comma-delimited format.

Specified by:
setWriteStatToFile in interface Statistic
Parameters:
write - whether or not to write the data to a file

initializeBuffer

protected final void initializeBuffer()
Constructs the IntBuffer with 0 for all values if it is not already constructed.