at.gv.egovernment.moa.util
Class MOATimer

java.lang.Object
  |
  +--at.gv.egovernment.moa.util.MOATimer

public class MOATimer
extends Object

A timer utility for named timers.

Author:
Sven Aigner

Constructor Summary
protected MOATimer()
          Create a new MOATimer.
 
Method Summary
 void clearTiming(String id)
          Remove a timing.
 long duration(Object id)
          Get the duration of an action.
 String durationAsString(Object id)
          Get the duration of an action, as a nicely formatted String.
static MOATimer getInstance()
          Return the single instance of this class.
 void startTiming(Object id)
          Start timing a certain action.
 void stopTiming(Object id)
          Stop timing an action.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MOATimer

protected MOATimer()
Create a new MOATimer. Protected to disallow multiple instances.
Method Detail

getInstance

public static MOATimer getInstance()
Return the single instance of this class.
Returns:
The single instance of this class.

startTiming

public void startTiming(Object id)
Start timing a certain action. The timing belonging to the action ID is garbage collected as soon as there exists no other reference to the action ID.
Parameters:
id - The action ID.

stopTiming

public void stopTiming(Object id)
Stop timing an action.
Parameters:
id - The action ID.

duration

public long duration(Object id)
Get the duration of an action.
Parameters:
id - The action ID for which to compute the duration.
Returns:
long The duration in milliseconds between calls to startTiming() and stopTiming(). If only startTiming() has been called for the action, then current difference to the system time is returned. If no timing exists for the action, - 1 is returned.

durationAsString

public String durationAsString(Object id)
Get the duration of an action, as a nicely formatted String.
Parameters:
id - The action ID.
Returns:
String The duration() as a String.

clearTiming

public void clearTiming(String id)
Remove a timing.
Parameters:
id - The action ID.