FIM.Util.Threads
Class TimerQueue
java.lang.Object
|
+--FIM.Util.Threads.TimerQueue
- Direct Known Subclasses:
- AgentTimerQueue
- public class TimerQueue
- extends Object
Creates a queue, where an arbitrary number of alarms can be set for a given time or after
a specified interval. Only one thread will be running at every time, waiting for the time to elapse.
The time when the alarms are called is not guaranteed, but they will not be called BEFORE their time and
they will be called in ASCENDING order. Alarms with exactly the same point in time will be called in
the order they are added.
Each event is assigned an ID, which is returned on creation. It can be used for cancelling it and
is sent as a paremeter upon notification.
- Version:
- 1.0, 1.7.2000
- Author:
- Michael Sonntag
- See Also:
Timer
Constructor Summary |
TimerQueue()
Creates a new and empty timer queue. |
Methods inherited from class java.lang.Object |
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
TimerQueue
public TimerQueue()
- Creates a new and empty timer queue.
addAtTimeAction
public long addAtTimeAction(Date atTime,
TimerAction recipient)
- Adds a new alarm at an absolute point in time.
- Parameters:
atTime
- the point in time when the alarm will be calledrecipient
- the interface, where the method doTimerAction will be called- Returns:
- ID of the event
addAfterIntervalAction
public long addAfterIntervalAction(int afterSecondsInterval,
TimerAction recipient)
- Adds a new alarm at a relative point in time. The alarm will be called the
specified number of seconds after this method is called.
- Parameters:
atTime
- the duration in seconds before the alarm will be calledrecipient
- the interface, where the method doTimerAction will be called- Returns:
- ID of the event
cancelAction
public void cancelAction(long id)
- Removes a alarm from the queue.
If it is called before the activation of the event: There is NO guarantee, that the action
will not be called if the time before is too short. After this method returns, the action
will guaranteed NOT be called any more.
- Parameters:
id
- The id of the alarm
killAll
public void killAll()
- Removes all alarms from the queue.
toString
public String toString()
- Returns a string representation of this object. The number or alarms and details for all of them
will be returned.
- Overrides:
toString
in class Object
- Returns:
- A String containing information about the state of this object
Submit a bug
Copyright 2001,2002 Michael Sonntag & Institute for Information Processing and Microprocessor Technology (FIM), Johannes-Kepler-University Linz, Altenbergerstr. 69, A-4040 Linz, Austria.