com.sas.util
Interface TimerInterface

All Superinterfaces:
com.sas.beans.PropertyChangeSource, com.sas.util.TimeIntervals
All Known Subinterfaces:
AlarmInterface
All Known Implementing Classes:
Alarm, Timer

public interface TimerInterface
extends com.sas.util.TimeIntervals, com.sas.beans.PropertyChangeSource

An interface for timers. All time units are measured in milliseconds. This simple timer interface is used for measuring a duration of time; i.e. measure how much time an action takes to execute.

Several references are made to the Epoch, which is the name given to the special date/time value of 00:00:00 January 1, 1970 UTC. Millisecond date/time values are measured relative to the Epoch.

Properties

Name startTime
Type long
Default value 0
Short description start time
Description Time when the timer was started, measured in milliseconds after the Epoch
Name stopTime
Type long
Default value 0
Short description stop time
Description Time when the timer was stopped, in milliseconds after the Epoch
Name duration
Type long
Short description timer duration in milliseconds
Description Amount of time in milliseconds the timer has run.
Name running
Type boolean
Default value false
Short description true if the timer is running
Description true if and only if the timer is currently running.

See Also:
AlarmInterface, Timer, Alarm

Field Summary
 
Fields inherited from interface com.sas.util.TimeIntervals
ONE_DAY, ONE_HOUR, ONE_MINUTE, ONE_SECOND, ONE_WEEK
 
Method Summary
 long getDuration()
          Return how long this timer has been running, in milliseconds.
 long getStartTime()
          Return this timer's start time.
 long getStopTime()
          Return this timer's stop time.
 boolean isRunning()
          Test if this timer is running.
 void setRunning(boolean newState)
          Change the running state of this timer.
 void start()
          Start the timer.
 void stop()
          Stop the timer.
 

Method Detail

start

void start()
Start the timer. This sets its state to running and resets the start time to the current time. If this timer is already running, it is restarted.


stop

void stop()
Stop the timer. After stopping, this timer is no longer running; the stop time does not advance. If called when the timer has not been started, it is ignored.


setRunning

void setRunning(boolean newState)
Change the running state of this timer. In most implementations, this method will call either start() or stop(), but only if newState differs from the current running state of this timer.

Parameters:
newState - The new running state of this timer. If newState == isRunning(), do nothing. Otherwise, this timer should behave as: if (newState) start(); else stop();

isRunning

boolean isRunning()
Test if this timer is running.

Returns:
true if this timer is running, false if not. start() sets a timer running, stop() stops a timer.

getStartTime

long getStartTime()
Return this timer's start time.

Returns:
the time the timer was last started, in number of milliseconds since the Epoch returns 0 if not yet started.

getStopTime

long getStopTime()
Return this timer's stop time.

Returns:
the time this timer was stopped, in number of milliseconds since the Epoch returns 0 if this timer has not stopped since it was last started.

getDuration

long getDuration()
Return how long this timer has been running, in milliseconds.

Returns:
the number of milliseconds this timer has been running. If this timer has been stopped, this is the difference between the stop time and the start time. If this timer has not been stopped, this is the difference between the current time and the start time. If this timer has never been started, return 0.



Copyright © 2009 SAS Institute Inc. All Rights Reserved.