org.javasimon
Class NullStopwatch

java.lang.Object
  extended by org.javasimon.NullSimon
      extended by org.javasimon.NullStopwatch
All Implemented Interfaces:
HasAttributes, Simon, Stopwatch

final class NullStopwatch
extends NullSimon
implements Stopwatch

Null Stopwatch implements Simon returned by the disabled Manager.getStopwatch(String). It extends NullSimon to satisfy Stopwatch interface.

Author:
Richard "Virgo" Richter

Field Summary
(package private) static NullStopwatch INSTANCE
          Internal singleton value of the null Stopwatch.
private static Split NULL_SPLIT
           
 
Constructor Summary
private NullStopwatch()
           
 
Method Summary
 Stopwatch addSplit(Split split)
          Adds Split to the stopwatch which is useful for aggregation of splits created for other stopwatch.
 Stopwatch addTime(long ns)
          Adds split time in nanoseconds to total time of the stopwatch.
 long getActive()
          Returns current number of measured splits (concurrently running).
 long getCounter()
          Returns usage count of the stopwatch.
 long getLast()
          Returns value of the last added split - wheter it was added directly or with stop method.
 long getMax()
          Returns maximal time split value in nanoseconds.
 long getMaxActive()
          Returns peek value of active concurrent splits.
 long getMaxActiveTimestamp()
          Retruns ms timestamp when the last peek of the active split count occured.
 long getMaxTimestamp()
          Returns ms timestamp when the max value was measured.
 double getMean()
          Returns zero.
 long getMin()
          Returns minimal time split value in nanoseconds.
 long getMinTimestamp()
          Returns ms timestamp when the min value was measured.
 double getStandardDeviation()
          Returns zero.
 long getTotal()
          Returns total sum of all split times in nanoseconds.
 double getVariance()
          Returns zero.
 double getVarianceN()
          Returns zero.
 NullStopwatch reset()
          Resets the Simon values related to the measuring, timestamps and so on - usage timestamps, state, attributes are not affected.
 StopwatchSample sample()
          Samples Simon values and returns them in a Java Bean derived from Sample interface.
 StopwatchSample sampleAndReset()
          Samples Simon values and returns them in a Java Bean derived from Sample interface and resets the Simon.
 Split start()
          Starts the new split for this stopwatch.
 
Methods inherited from class org.javasimon.NullSimon
getAttribute, getAttribute, getAttributeNames, getCopyAsSortedMap, getFirstUsage, getChildren, getLastReset, getLastUsage, getName, getNote, getParent, getState, isEnabled, removeAttribute, setAttribute, setNote, setState, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.javasimon.Simon
getFirstUsage, getChildren, getLastReset, getLastUsage, getName, getNote, getParent, getState, isEnabled, setNote, setState
 
Methods inherited from interface org.javasimon.HasAttributes
getAttribute, getAttribute, getAttributeNames, getCopyAsSortedMap, removeAttribute, setAttribute
 

Field Detail

INSTANCE

static final NullStopwatch INSTANCE
Internal singleton value of the null Stopwatch. Null Stopwatch is never directly used in the client code, it is always hidden behind the Stopwatch interface - only its behavior manifests to the client.


NULL_SPLIT

private static final Split NULL_SPLIT
Constructor Detail

NullStopwatch

private NullStopwatch()
Method Detail

reset

public NullStopwatch reset()
Description copied from interface: Simon
Resets the Simon values related to the measuring, timestamps and so on - usage timestamps, state, attributes are not affected. Timestamp of the last reset can be obtained by the method Simon.getLastReset(). Reset is perfomed even for disabled Simons.

Specified by:
reset in interface Simon
Specified by:
reset in interface Stopwatch
Overrides:
reset in class NullSimon
Returns:
returns this

getCounter

public long getCounter()
Description copied from interface: Stopwatch
Returns usage count of the stopwatch. Counter is increased by addTime and stop - that means that it's updated every time the next time split is added.

Specified by:
getCounter in interface Stopwatch
Returns:
count of time splits

getMin

public long getMin()
Description copied from interface: Stopwatch
Returns minimal time split value in nanoseconds.

Specified by:
getMin in interface Stopwatch
Returns:
minimal time split in nanoseconds

getMax

public long getMax()
Description copied from interface: Stopwatch
Returns maximal time split value in nanoseconds.

Specified by:
getMax in interface Stopwatch
Returns:
maximal time split in nanoseconds

getMaxTimestamp

public long getMaxTimestamp()
Description copied from interface: Stopwatch
Returns ms timestamp when the max value was measured.

Specified by:
getMaxTimestamp in interface Stopwatch
Returns:
ms timestamp of the max value measurement

getMinTimestamp

public long getMinTimestamp()
Description copied from interface: Stopwatch
Returns ms timestamp when the min value was measured.

Specified by:
getMinTimestamp in interface Stopwatch
Returns:
ms timestamp of the min value measurement

addTime

public Stopwatch addTime(long ns)
Description copied from interface: Stopwatch
Adds split time in nanoseconds to total time of the stopwatch.

Specified by:
addTime in interface Stopwatch
Parameters:
ns - split time
Returns:
this stopwatch

addSplit

public Stopwatch addSplit(Split split)
Description copied from interface: Stopwatch
Adds Split to the stopwatch which is useful for aggregation of splits created for other stopwatch. Split object should be stopped. Main difference is the callback method called as Callback.onStopwatchAdd(Stopwatch, Split, StopwatchSample) provides split object to the callback.

Usage examples:

Split split = Split.start(); // no stopwatch needed
...
someStopwatch.addSplit(split.stop()); // you may omit stop(), if you does not use the split after this point

Specified by:
addSplit in interface Stopwatch
Parameters:
split - split object (should be stopped)
Returns:
this stopwatch

start

public Split start()
Description copied from interface: Stopwatch
Starts the new split for this stopwatch. This action does not hold any resources and if Split object is collected, no leak occurs. However, active count is increased and without stopping the split active count stays increased which may render that information useless.

Specified by:
start in interface Stopwatch
Returns:
split object
See Also:
Split.stop()

getTotal

public long getTotal()
Description copied from interface: Stopwatch
Returns total sum of all split times in nanoseconds.

Specified by:
getTotal in interface Stopwatch
Returns:
total time of the stopwatch in nanoseconds

getLast

public long getLast()
Description copied from interface: Stopwatch
Returns value of the last added split - wheter it was added directly or with stop method.

Specified by:
getLast in interface Stopwatch
Returns:
value of the last added split

getActive

public long getActive()
Description copied from interface: Stopwatch
Returns current number of measured splits (concurrently running). This counter can show more splits than is measured at any moment if some splits were "forgotten" (not stopped and garbage collected). This does not imply any resource leak, just bad practice of not stopping Splits somewhere in the client code.

Specified by:
getActive in interface Stopwatch
Returns:
current number of active splits

getMaxActive

public long getMaxActive()
Description copied from interface: Stopwatch
Returns peek value of active concurrent splits.

Specified by:
getMaxActive in interface Stopwatch
Returns:
maximum reached value of active splits

getMaxActiveTimestamp

public long getMaxActiveTimestamp()
Description copied from interface: Stopwatch
Retruns ms timestamp when the last peek of the active split count occured.

Specified by:
getMaxActiveTimestamp in interface Stopwatch
Returns:
ms timestamp of the last peek of the active split count

getMean

public double getMean()
Returns zero.

Specified by:
getMean in interface Stopwatch
Returns:
zero

getStandardDeviation

public double getStandardDeviation()
Returns zero.

Specified by:
getStandardDeviation in interface Stopwatch
Returns:
zero

getVariance

public double getVariance()
Returns zero.

Specified by:
getVariance in interface Stopwatch
Returns:
zero

getVarianceN

public double getVarianceN()
Returns zero.

Specified by:
getVarianceN in interface Stopwatch
Returns:
zero

sample

public StopwatchSample sample()
Description copied from interface: Simon
Samples Simon values and returns them in a Java Bean derived from Sample interface.

Specified by:
sample in interface Simon
Specified by:
sample in interface Stopwatch
Overrides:
sample in class NullSimon
Returns:
sample containing all Simon values

sampleAndReset

public StopwatchSample sampleAndReset()
Description copied from interface: Simon
Samples Simon values and returns them in a Java Bean derived from Sample interface and resets the Simon. Operation is synchronized to assure atomicity.

Specified by:
sampleAndReset in interface Simon
Specified by:
sampleAndReset in interface Stopwatch
Overrides:
sampleAndReset in class NullSimon
Returns:
sample containing all Simon values


Copyright © 2013. All Rights Reserved.