planet.util.timer
Interface Timer

All Superinterfaces:
java.io.Serializable
All Known Subinterfaces:
SimulationTimer
All Known Implementing Classes:
SimulationTimerImpl, ThreadTimer

public interface Timer
extends java.io.Serializable

This interface permits to schedule differents tasks to specified delays, and to make periodic any task, begining to the specified delay and rerun after period time.

Both delay and period are longs. Differents implementations will use this value as steps (in simulation case) or millis (in real implementation case).

At last, also it permits to cancel all scheduled tasks.

The final implementations must to have a constructor with no arguments.

Author:
Jordi Pujol

Method Summary
 void cancel()
          Cancels all TimerTasks active actually.
 void setTimerTask(TimerTask task, long delay)
          Sets a TimerTask to execute only once, after delay time.
 void setTimerTask(TimerTask task, long delay, long period)
          Sets a TimerTask to execute only once, after delay time, and after each period time.
 

Method Detail

setTimerTask

public void setTimerTask(TimerTask task,
                         long delay)
Sets a TimerTask to execute only once, after delay time. The time will be steps in simulation world, or millis in real world.

Parameters:
task - TimerTask implementation with the job to do.
delay - Time after which will be invoked task.run()

setTimerTask

public void setTimerTask(TimerTask task,
                         long delay,
                         long period)
Sets a TimerTask to execute only once, after delay time, and after each period time. The time will be steps in simulation world, or millis in real world.

Parameters:
task - TimerTask implementation with the job to do.
delay - Timer after which will be invoked task.run()
period - The period of time for waiting after first invocation (and followings) to invoke another time task.run().

cancel

public void cancel()
Cancels all TimerTasks active actually.