LimeWire Consolidated API

org.limewire.statistic
Class AbstractStatistic

java.lang.Object
  extended by org.limewire.statistic.AbstractStatistic
All Implemented Interfaces:
Inspectable, Statistic
Direct Known Subclasses:
AbstractKilobytesStatistic, BasicStatistic, NetworkStatisticContainer.SizeStatistic, RoutingStatisticContainer.NodeCountStatistic

public abstract class AbstractStatistic
extends Object
implements Statistic

Provides a default implementation of the Statistic interface as an abstract class. AbstractStatistic tracks the history for the given statistic, provides access to the average value, the maximum value and optionally writes values to disk.

Additionally, AbstractStatistic implements Inspectable and includes a default implementation of inspect() to examine the stored statistics.

See the Lime Wire Wiki for sample code using the org.limewire.statistic package.


Field Summary
protected  Buffer<Double> _buffer
          IntBuffer for recording stats data -- initialized to an empty buffer until stats are actually recorded.
protected  int _current
          int for the statistic currently being added 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.
 
Fields inherited from interface org.limewire.statistic.Statistic
HISTORY_LENGTH
 
Constructor Summary
AbstractStatistic()
           
 
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.
 int getCurrent()
          Accessor for the current recorded stat value over the most recent time period.
 int getLastStored()
          Accessor for the most recently recorded stat value.
 double getMax()
          Accessor for the maximum recorded stat value over all recorded time periods.
 Buffer<Double> 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.
 Object inspect()
           
 void storeCurrentStat()
          Stores the current set of gathered statistics into the history set, setting the currently recorded data back to zero.
 void storeStats(Writer writer)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_buffer

protected final Buffer<Double> _buffer
IntBuffer for recording stats data -- initialized to an empty buffer until stats are actually recorded.


_current

protected volatile int _current
int 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.

Constructor Detail

AbstractStatistic

public AbstractStatistic()
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

getCurrent

public int getCurrent()
Description copied from interface: Statistic
Accessor for the current recorded stat value over the most recent time period.

Specified by:
getCurrent in interface Statistic
Returns:
the stat value current being added to

getLastStored

public int getLastStored()
Description copied from interface: Statistic
Accessor for the most recently recorded stat value.

Specified by:
getLastStored in interface Statistic
Returns:
the most recently recorded stat value

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 Buffer<Double> 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

storeStats

public void storeStats(Writer writer)
                throws IOException
Specified by:
storeStats in interface Statistic
Throws:
IOException

initializeBuffer

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


inspect

public Object inspect()
Specified by:
inspect in interface Inspectable
Returns:
a descriptive object for the target object.

LimeWire Consolidated API

Copyright © 2009. All Rights Reserved.