messif.statistics
Class StatisticSlidingAvgCounter

java.lang.Object
  extended by messif.statistics.Statistics<StatisticSlidingAvgCounter>
      extended by messif.statistics.StatisticSlidingAvgCounter
All Implemented Interfaces:
java.io.Serializable

public class StatisticSlidingAvgCounter
extends Statistics<StatisticSlidingAvgCounter>
implements java.io.Serializable

This is a statistic that counts aggregated functions (especially avg) from 1) last n values - if n+1 value is added, the first is removed and not considered any more or 2) values stored in the time-sliding window 3) combination of 1) and 2) Moreover, there is a possibility of linking each value (and time) with a "key" and then all values added to this counter are sumed up according to the key

See Also:
Serialized Form

Nested Class Summary
protected static class StatisticSlidingAvgCounter.ValueTime
          This simple class encapsulates the pair: double value + time when it was added
 
Field Summary
protected  int count
           
protected  long resetTime
          Remember the time stamp of reseting (or creating) the statistics
protected  double sum
          aggregated values
 
Fields inherited from class messif.statistics.Statistics
replaceWith
 
Constructor Summary
protected StatisticSlidingAvgCounter(java.lang.String name)
          Creates a new instance of StatisticSlidingAvgCounter
 
Method Summary
 void addValue(double value)
          add value and expect that it has been measured now - get current time
 void addValue(double value, java.lang.Object obj)
          add value and expect that it has been measured now - get current time.
protected  StatisticSlidingAvgCounter cast()
          Returns this statistics as the type provided typed argument.
 double getAvg()
          return average of the values in queue
 double getAvg(boolean consolidate)
          return the average but do not consolidate the list of values if the parameter is false
 int getCnt()
          return number of values in the queue
 double getMax()
          return maximum value from the queue
 int getMaxNumberOfValues()
           
 double getMin()
          return minimum value from the queue
static StatisticSlidingAvgCounter getStatistics(java.lang.String name)
          Create new statistic counter with specified name or get the one already existing
 double getSum()
          return the sum of queue values
 long getWindowSizeMilis()
           
 boolean changedSinceCheckpoint()
          Reports if value of min/max has been changed since the last setCheckpoint() call.
 boolean checkUsedTime()
          Checks whether the sliding window was used for full time period
 void reset()
          Reset the current statistic
protected  void setFrom(StatisticSlidingAvgCounter sourceStat)
          Set this statistic to values from given statistic
 void setCheckpoint()
          Sets checkpoint.
 void setMaxNumberOfValues(int maxNumberOfValues)
          sets the size of window to consider
 void setWindowSizeMilis(long windowSizeMilis)
          and sets the size of the time-sliding window in milis
 void shiftValuesByTime(long time)
          add a given time difference to ALL values in the list
 java.lang.String toString()
          Text representation of the SlidingWindow
protected  void updateFrom(StatisticSlidingAvgCounter sourceStat)
          the final queue should be sorted according to time as required
 
Methods inherited from class messif.statistics.Statistics
addBoundStat, bindTo, canPerformOperation, disableGlobally, enableGlobally, getAllStatistics, getAllStatistics, getBoundStats, getBoundTo, getName, getStatistics, isBound, isEnabledGlobally, isRegisteredGlobally, printStatistics, printStatistics, printStatistics, readResolve, removeBoundStat, removeStatistic, resetStatistics, resetStatistics, unbind
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

resetTime

protected long resetTime
Remember the time stamp of reseting (or creating) the statistics


sum

protected double sum
aggregated values


count

protected int count
Constructor Detail

StatisticSlidingAvgCounter

protected StatisticSlidingAvgCounter(java.lang.String name)
Creates a new instance of StatisticSlidingAvgCounter

Method Detail

checkUsedTime

public boolean checkUsedTime()
Checks whether the sliding window was used for full time period


getMaxNumberOfValues

public int getMaxNumberOfValues()

setMaxNumberOfValues

public void setMaxNumberOfValues(int maxNumberOfValues)
sets the size of window to consider

Parameters:
maxNumberOfValues - if < 0 then - use all values

getWindowSizeMilis

public long getWindowSizeMilis()

setWindowSizeMilis

public void setWindowSizeMilis(long windowSizeMilis)
and sets the size of the time-sliding window in milis

Parameters:
windowSizeMilis - if <= 0 - do not use the time window

shiftValuesByTime

public void shiftValuesByTime(long time)
add a given time difference to ALL values in the list


addValue

public void addValue(double value)
add value and expect that it has been measured now - get current time


addValue

public void addValue(double value,
                     java.lang.Object obj)
add value and expect that it has been measured now - get current time. Before adding the value to the list, find out whether the "obj" is not stored in the list and if so, then increase the existing value by the given value


getSum

public double getSum()
return the sum of queue values


getCnt

public int getCnt()
return number of values in the queue


getAvg

public double getAvg()
return average of the values in queue


getAvg

public double getAvg(boolean consolidate)
return the average but do not consolidate the list of values if the parameter is false


getMin

public double getMin()
return minimum value from the queue


getMax

public double getMax()
return maximum value from the queue


getStatistics

public static StatisticSlidingAvgCounter getStatistics(java.lang.String name)
                                                throws java.lang.ClassCastException
Create new statistic counter with specified name or get the one already existing

Throws:
java.lang.ClassCastException

updateFrom

protected void updateFrom(StatisticSlidingAvgCounter sourceStat)
the final queue should be sorted according to time as required

Specified by:
updateFrom in class Statistics<StatisticSlidingAvgCounter>
Parameters:
sourceStat - the statistic from which to update this stat

setFrom

protected void setFrom(StatisticSlidingAvgCounter sourceStat)
Set this statistic to values from given statistic

Specified by:
setFrom in class Statistics<StatisticSlidingAvgCounter>
Parameters:
sourceStat - the statistic from which to set this stat

reset

public void reset()
Reset the current statistic

Specified by:
reset in class Statistics<StatisticSlidingAvgCounter>

changedSinceCheckpoint

public boolean changedSinceCheckpoint()
Reports if value of min/max has been changed since the last setCheckpoint() call.


setCheckpoint

public void setCheckpoint()
Sets checkpoint. Stores the current state of min/max.


toString

public java.lang.String toString()
Text representation of the SlidingWindow

Overrides:
toString in class java.lang.Object

cast

protected StatisticSlidingAvgCounter cast()
Description copied from class: Statistics
Returns this statistics as the type provided typed argument. This is a convenience method to avoid unchecked casts.

Specified by:
cast in class Statistics<StatisticSlidingAvgCounter>
Returns:
this statistics