All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class util.Timer

java.lang.Object
   |
   +----java.lang.Thread
           |
           +----util.Timer

public class Timer
extends Thread
The Timer class allows various timers to be created with multiple events inside each timer allowed. Most of the time the user will just need to use the createEvent routine and wait for the timer event to be activated. All times are in milliseconds.


Constructor Index

 o Timer(String, int)
Create a new timer set with the given name and resolution.

Method Index

 o createEvent(String, TimerListener, int, Object, int)
This routine allows you to create a new event inside the named timer and is the main access point to the timer routines.
 o createEvent(TimerListener, int, Object, int)
If you already have a reference to a timer you can use this routine to directly create the event.
 o getResolution(int)
Get the current resolution of a timer.
 o getTimer(String)
This method allows the user to access a given Timer.
 o removeEvent(TimerEvent)
Remove an event by search ALL timers for the event.
 o removeEventFromTimer(TimerEvent)
Remove an event from this timer.
 o rescheduleEvent(TimerEvent, int)
Resechedule a timer event to occur later.
 o run()
 o setResolution(int)
Change the resolution of a timer.
 o shutdown()
This methods calls stopTimer on all the currently running timers.
 o stopTimer()
Stop a timer from running.
 o toString()
 o toStringDetail()
Get a detailed string of the timer, including all the events that are waiting to be fired.

Constructors

 o Timer
 public Timer(String name,
              int resolution)
Create a new timer set with the given name and resolution.

Parameters:
name - The name of the timer
resolution - The resolution of this time. How often we should check to see if a timer event is ready to be fired.

Methods

 o createEvent
 public static synchronized TimerEvent createEvent(String timerName,
                                                   TimerListener listener,
                                                   int eventID,
                                                   Object callback,
                                                   int relTime)
This routine allows you to create a new event inside the named timer and is the main access point to the timer routines. If the timer specified doesn't exist yet, it will automatically be created.

Parameters:
timerName - The name of the timer the event should be placed on
listener - Who should be informed when the timer event is fired.
eventID - The id of the event we are created. This id is NOT used internally and is for external (listener) use only. There CAN be multiple timer events with the same eventID set to go off at different times.
callback - A extra data item that will be passed to the listener when the timer goes off. Can be null if you don't have an extra data.
relTime - How far in the future should this timer event be fired?
Returns:
The timer event that has been created.
 o shutdown
 public static synchronized void shutdown()
This methods calls stopTimer on all the currently running timers.

 o getTimer
 public static synchronized Timer getTimer(String timerName)
This method allows the user to access a given Timer.

Parameters:
timerName - The timer the user wants to get
Returns:
The requested timer.
 o setResolution
 public void setResolution(int res)
Change the resolution of a timer.

 o getResolution
 public long getResolution(int res)
Get the current resolution of a timer.

 o createEvent
 public synchronized TimerEvent createEvent(TimerListener listener,
                                            int eventID,
                                            Object callback,
                                            int relTime)
If you already have a reference to a timer you can use this routine to directly create the event. The static createEvent calls this method after first looking up the timer.

Parameters:
listener - Who should be informed when the timer event is fired.
eventID - The id of the event we are created. This id is NOT used internally and is for external (listener) use only. There CAN be multiple timer events with the same eventID set to go off at different times.
callback - A extra data item that will be passed to the listener when the timer goes off. Can be null if you don't have an extra data.
relTime - How far in the future should this timer event be fired?
Returns:
The timer event that has been created.
 o toStringDetail
 public synchronized String toStringDetail()
Get a detailed string of the timer, including all the events that are waiting to be fired.

 o toString
 public String toString()
Overrides:
toString in class Thread
 o rescheduleEvent
 public synchronized boolean rescheduleEvent(TimerEvent event,
                                             int relTime)
Resechedule a timer event to occur later.

Parameters:
event - The event we want to reschedule
relTime - How many more milliseconds before the event should be fired.
Returns:
True if the event was rescheduled, false otherwise
 o removeEventFromTimer
 public synchronized boolean removeEventFromTimer(TimerEvent event)
Remove an event from this timer.

Parameters:
event - The event we want to remove
Returns:
True if the event was removed, false otherwise
 o removeEvent
 public static synchronized boolean removeEvent(TimerEvent d)
Remove an event by search ALL timers for the event.

Parameters:
event - The event we want to remove
Returns:
True if the event was removed, false otherwise
 o stopTimer
 public synchronized void stopTimer()
Stop a timer from running.

 o run
 public void run()
Overrides:
run in class Thread

All Packages  Class Hierarchy  This Package  Previous  Next  Index