net.sf.sensor.timer
Class Timer

java.lang.Object
  extended bynet.sf.sensor.timer.Timer

public final class Timer
extends Object

Short-lived, non thread-safe input frontend class for working with timers.

This class is not thread-safe and for good reasons. The TimerData instance that is nested inside each Timer instance is thread-safe and is shared between many seperate instances of Timer. When the stop() method is called, a synchronized call to TimerData.updateStatistics(long)} will be made to update the "real" timer. After that call, the instance of Timer can be safely reused or garbage collected.

Author:
Age Mooy

Method Summary
 void addLabel(String label)
          Adds the specified label to the set of labels associated with this instance.
 String getId()
          Returns the id straight from the nested TimerData.
 boolean isRunning()
          Is this Timer instance currently running (ie start() was called but stop() was not called yet.
 Timer start()
          Starts the timer.
 void stop()
          Stops the timer and reports the time that passed since the first call to start() to the nested TimerData instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

addLabel

public void addLabel(String label)
Adds the specified label to the set of labels associated with this instance.

Parameters:
label -

getId

public String getId()
Returns the id straight from the nested TimerData. Unsynchronized since the label is immutable.

Returns:
Returns the label.

start

public Timer start()
Starts the timer. Will not do anything if the timer has already been started (meaning the start() method has been called but the stop() method has not yet been called. For convernience, this method returns the 'this' reference.

Returns:
the current instance (the 'this' reference).

isRunning

public boolean isRunning()
Is this Timer instance currently running (ie start() was called but stop() was not called yet.

Returns:
true if this Timer instance is in a runing state, false otherwise.

stop

public void stop()
Stops the timer and reports the time that passed since the first call to start() to the nested TimerData instance.



Copyright © 2005-2006 SourceForge. All Rights Reserved.