messif.statistics
Class StatisticTimer

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

public final class StatisticTimer
extends Statistics<StatisticTimer>

Statistics for counting time. The time is incremented by the amount of time elapsed between calls to methods start() & stop(). Note that additional calls to start will have no affect until stop is called. Update & set methods will leave current statistics stopped/started state untouched, but they will add values including elapsed time if started. An example: get() => 0 milis start() 1000 milis elapsed get() => 1000 milis 100 milis elapsed get() => 1100 milis stop() 1000 milis elapsed get() => 1100 milis

See Also:
Serialized Form

Field Summary
protected  long lastStartTime
          Time of the last call to start() of started statistics
protected  long time
          Time elapsed between calls to start() and stop().
 
Fields inherited from class messif.statistics.Statistics
replaceWith
 
Constructor Summary
protected StatisticTimer(java.lang.String name)
          Creates a new instance of StatisticTimer
 
Method Summary
protected  void addBoundStat(StatisticTimer stat)
          Bind a statistic to this statistic.
protected  StatisticTimer cast()
          Returns this statistics as the type provided typed argument.
 long get()
          Time elapsed in msec.
static StatisticTimer getStatistics(java.lang.String name)
          Factory method for creating a new statistic timer with the specified name or get the one already existing.
 boolean changedSinceCheckpoint()
          Test whether this statistics has been changed since the last checkpoint.
protected  void removeBoundStat(StatisticTimer stat)
          Remove a bound statistic from this one.
 void reset()
          Reset the value of this statistic.
protected  void setFrom(StatisticTimer sourceStat)
          Set the value of this statistic to the actual value of the given sourceStat.
 void setCheckpoint()
          Sets checkpoint.
 void start()
          Starts incrementing the timer
 void stop()
          Stops incrementing timer
 java.lang.String toString()
           
protected  void updateFrom(StatisticTimer sourceStat)
          Updates the value of this statistic from the given sourceStat.
 
Methods inherited from class messif.statistics.Statistics
bindTo, canPerformOperation, disableGlobally, enableGlobally, getAllStatistics, getAllStatistics, getBoundStats, getBoundTo, getName, getStatistics, isBound, isEnabledGlobally, isRegisteredGlobally, printStatistics, printStatistics, printStatistics, readResolve, removeStatistic, resetStatistics, resetStatistics, unbind
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

time

protected long time
Time elapsed between calls to start() and stop().


lastStartTime

protected long lastStartTime
Time of the last call to start() of started statistics

Constructor Detail

StatisticTimer

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

Parameters:
name - requested name of the statitics
Method Detail

start

public void start()
Starts incrementing the timer


stop

public void stop()
Stops incrementing timer


get

public long get()
Time elapsed in msec. If the statistics has been stopped, the elapsed time is returned, otherwise current time minus start time is returned.

Returns:
time elapsed in msec.

addBoundStat

protected void addBoundStat(StatisticTimer stat)
Description copied from class: Statistics
Bind a statistic to this statistic. That is, register the stat to receive notifications when the value of this statistic is updated.

Overrides:
addBoundStat in class Statistics<StatisticTimer>
Parameters:
stat - the statistic to register

removeBoundStat

protected void removeBoundStat(StatisticTimer stat)
Description copied from class: Statistics
Remove a bound statistic from this one.

Overrides:
removeBoundStat in class Statistics<StatisticTimer>
Parameters:
stat - the statistic to unbind

updateFrom

protected void updateFrom(StatisticTimer sourceStat)
Description copied from class: Statistics
Updates the value of this statistic from the given sourceStat. Specifically, this method merges the value of the sourceStat with this statistic.

The actual implementation depends on the type of the statistic.

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

setFrom

protected void setFrom(StatisticTimer sourceStat)
Description copied from class: Statistics
Set the value of this statistic to the actual value of the given sourceStat.

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

reset

public void reset()
Description copied from class: Statistics
Reset the value of this statistic.

Specified by:
reset in class Statistics<StatisticTimer>

getStatistics

public static StatisticTimer getStatistics(java.lang.String name)
                                    throws java.lang.ClassCastException
Factory method for creating a new statistic timer with the specified name or get the one already existing.

Parameters:
name - requested name of the statistics
Returns:
instance of StatisticTimer having the passed name.
Throws:
java.lang.ClassCastException - if the statistics of the given name exists, but is of a different class than StatisticTimer

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

changedSinceCheckpoint

public boolean changedSinceCheckpoint()
Test whether this statistics has been changed since the last checkpoint.

Returns:
true if it has been changed, otherwise false.

setCheckpoint

public void setCheckpoint()
Sets checkpoint. Stores the current state of timer.


cast

protected StatisticTimer 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<StatisticTimer>
Returns:
this statistics