moka.util
Class Timer

java.lang.Object
  |
  +--moka.lang.Object
        |
        +--moka.event.Interrupt
              |
              +--moka.util.Timer

public class Timer
extends Interrupt

A facility to schedule tasks for future execution in a background loop. This class proposes also a static method to pause the execution of the program.

Since:
MDK1.0a

Field Summary
 boolean active
          Is the timer activated ? Should be only read.
 int delay
          The delay of the timer (in 1/20th of second).
 moka.event.EventListener listen
          The listener binded to this timer.
 short no
          Deprecated.  
 int time
          The time stamp value when this timer will expire.
static int timeStamp
          The current time stamp (in 1/20th of second).
 
Fields inherited from class moka.event.Interrupt
busy
 
Constructor Summary
Timer()
          Creates a new Timer using the timer ID number 6 and a 20 1/20th of second delay (1 second).
Timer(int delay)
          Creates a new Timer specifying the the delay.
Timer(short no, int delay)
          Deprecated. As of MDK2.1, use Timer(int delay) instead
 
Method Summary
 boolean check()
          Used to verify if this timer should trigger an event.
 void run()
          Handles the code to execute when this object interrupts.
 void setActive(boolean b)
          Sets if this timer is activated.
 void wait()
          Pauses the execution of the program until this timer's delay expires according that this timer is activated.
static void wait(int delay)
          Pauses the execution of the program until the specified delay expires.
 
Methods inherited from class moka.event.Interrupt
finalize, register, unregister
 
Methods inherited from class moka.lang.Object
equals, getClassName, toString
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait
 

Field Detail

no

public short no
Deprecated.  

The id number of the timer (1 to 6: BATT_TIMER = 1, APD_TIMER = 2, LIO_TIMER = 3, CURSOR_TIMER = 4, MISC_TIMER = 5, USER_TIMER = 6). Should be modified only when the timer is inactive.


active

public boolean active
Is the timer activated ? Should be only read.


delay

public int delay
The delay of the timer (in 1/20th of second). Should be modified only when the timer is inactive.


time

public int time
The time stamp value when this timer will expire.


listen

public moka.event.EventListener listen
The listener binded to this timer.


timeStamp

public static volatile int timeStamp
The current time stamp (in 1/20th of second). Should be only read.

Constructor Detail

Timer

public Timer()
Creates a new Timer using the timer ID number 6 and a 20 1/20th of second delay (1 second).


Timer

public Timer(int delay)
Creates a new Timer specifying the the delay.

Parameters:
delay - The delay of the timer (in 1/20th of second).
Since:
MDK2.1

Timer

public Timer(short no,
             int delay)
Deprecated. As of MDK2.1, use Timer(int delay) instead

Creates a new Timer specifying the timer ID number and the delay.

Parameters:
no - The id number of the timer (1 to 6).
delay - The delay of the timer (in 1/20th of second).
Method Detail

check

public boolean check()
Used to verify if this timer should trigger an event. It is the case when the timer is actived and that its delay is expired. The timer is reseted if it is the case.

Specified by:
check in class Interrupt
Returns:
true if this timer should trigger an event

run

public void run()
Handles the code to execute when this object interrupts. In the case of a timer, the EventListener will be notified.

Specified by:
run in class Interrupt

setActive

public void setActive(boolean b)
Sets if this timer is activated.

Parameters:
b - a flag indicating whether this timer is activated. If this flag is set to true and this timer is already activated, the timer is reseted.

wait

public void wait()
Pauses the execution of the program until this timer's delay expires according that this timer is activated. When this timer's delay expires, an event is triggered.

Overrides:
wait in class java.lang.Object

wait

public static void wait(int delay)
Pauses the execution of the program until the specified delay expires.

Parameters:
delay - The the timer (in 1/20th of second).