| java.lang.Object java.lang.Thread com.quadcap.util.threads.PeriodicScheduler
PeriodicScheduler | public class PeriodicScheduler extends Thread implements DebugMonitor(Code) | | This class acts as a scheduler for periodic tasks, which are named and
execute repeatedly with a specified interval. Each task is a
Command
object, as used by e.g.,
StreamWorker.
Two flavors of this class are expressed here -- the first class
takes a Stream
parameter. When each task becomes ready, the Command object is
written to the Stream, and it is presumed that a StreamWorker task
will be sitting at the other end of the Stream, executing the
Commands that come down the pipe.
The other flavor of this class takes a context argument, which can
be any Java object (i.e., this class doesn't ever look at the context.)
When each task becomes ready, it is simply executed within the
PeriodicScheduler thread.
author: Stan Bailes |
Method Summary | |
public void | add(String name, Command c, long interval) Add a new task, with the specified name, action, and interval.
The task will NOT be executed 'now'; rather its first
execution will be scheduled at time 'now + interval'.
Parameters: name - the name of this task. | public void | add(String name, Runnable r, long interval) Add a new task, with the specified name, action, and interval.
The task will NOT be executed 'now'; rather its first
execution will be scheduled at time 'now + interval'.
Parameters: name - the name of this task. | public int | handleInteractiveCommand(String cmd, Vector args) Handle a debug monitor command directed at this instance. | long | msUntil(Date d) | void | remove(ScheduleItem item) | public void | run() Thread method, runs the main scheduler event loop: Get the next
task to execute (the active list is sorted by execution time) and
wait that long. | void | schedule(ScheduleItem item) Add the specified schedule item to the queue. | public void | terminate() Terminate this scheduler. | public String | toString() |
terminate | boolean terminate(Code) | | |
PeriodicScheduler | public PeriodicScheduler(ThreadGroup group, String name, Object obj)(Code) | | Construct a new PeriodicScheduler which will write Commands to the
specified Stream.
Parameters: stream - the Stream used to write Commands when they becomeready. |
add | public void add(String name, Command c, long interval)(Code) | | Add a new task, with the specified name, action, and interval.
The task will NOT be executed 'now'; rather its first
execution will be scheduled at time 'now + interval'.
Parameters: name - the name of this task. Any existing task with thesame name is replaced by this one. Parameters: c - the Command action associated with this task. Parameters: interval - the interval (in ms) between invocations of thistask. |
add | public void add(String name, Runnable r, long interval)(Code) | | Add a new task, with the specified name, action, and interval.
The task will NOT be executed 'now'; rather its first
execution will be scheduled at time 'now + interval'.
Parameters: name - the name of this task. Any existing task with thesame name is replaced by this one. Parameters: r - the Runnable action associated with this task. Parameters: interval - the interval (in ms) between invocations of thistask. |
handleInteractiveCommand | public int handleInteractiveCommand(String cmd, Vector args)(Code) | | Handle a debug monitor command directed at this instance.
|
msUntil | long msUntil(Date d)(Code) | | How many ms between now and then (d)?
Parameters: d - then then - now |
remove | void remove(ScheduleItem item)(Code) | | |
run | public void run()(Code) | | Thread method, runs the main scheduler event loop: Get the next
task to execute (the active list is sorted by execution time) and
wait that long. If another thread puts a new task in the queue,
we'll get interrupted, but than's ok. Then, look at the head of the
active list again and, if the task is ready, execute it.
|
schedule | void schedule(ScheduleItem item)(Code) | | Add the specified schedule item to the queue.
Parameters: item - the item to schedule |
terminate | public void terminate()(Code) | | Terminate this scheduler.
|
|
|