com.twitter.common.stats
Class SampledStat<T extends Number>

java.lang.Object
  extended by com.twitter.common.stats.StatImpl<T>
      extended by com.twitter.common.stats.SampledStat<T>
All Implemented Interfaces:
Stat<T>
Direct Known Subclasses:
MovingAverage, MovingWindowDelta, Rate, Ratio

public abstract class SampledStat<T extends Number>
extends StatImpl<T>

A convenience class to perform the basic tasks needed for a RecordingStat except the actual value calculation.


Constructor Summary
SampledStat(String name, T defaultValue)
           
 
Method Summary
abstract  T doSample()
           
 T read()
          Retrieves the most recent value of the stat.
 T sample()
          Called by the variable sampler when a sample is being taken.
 
Methods inherited from class com.twitter.common.stats.StatImpl
getName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.twitter.common.stats.Stat
getName
 

Constructor Detail

SampledStat

public SampledStat(String name,
                   T defaultValue)
Method Detail

doSample

public abstract T doSample()

sample

public final T sample()
Called by the variable sampler when a sample is being taken. Only calls to this method should be used to store variable history. Note - if the sampling of this value depends on other variables, it is imperative that those variables values are updated first (and available via Stat.read().

Returns:
A new sample of the variable.

read

public T read()
Description copied from interface: Stat
Retrieves the most recent value of the stat.

Specified by:
read in interface Stat<T extends Number>
Returns:
The most recent value.