Quadcap Embeddable Server

com.quadcap.util.threads.PeriodicScheduler Class Reference

Inheritance diagram for com.quadcap.util.threads.PeriodicScheduler:

Thread com.quadcap.util.threads.DebugMonitor List of all members.

Detailed Description

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

Definition at line 76 of file PeriodicScheduler.java.

Public Member Functions

 PeriodicScheduler (ThreadGroup group, String name, Object obj)
 Construct a new PeriodicScheduler which will write Commands to the specified Stream.

void add (String name, Command c, long interval)
 Add a new task, with the specified name, action, and interval.

void add (String name, Runnable r, long interval)
 Add a new task, with the specified name, action, and interval.

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.

int handleInteractiveCommand (String cmd, Vector args)
 Handle a debug monitor command directed at this instance.

String toString ()
void terminate ()
 Terminate this scheduler.


Package Functions

void remove (ScheduleItem item)
void schedule (ScheduleItem item)
 Add the specified schedule item to the queue.

long msUntil (Date d)
 How many ms between now and then (d)?


Package Attributes

DList active = new DList()
Stream stream = null
Object context = null
boolean terminate = false
Hashtable schedule = new Hashtable()


Constructor & Destructor Documentation

com.quadcap.util.threads.PeriodicScheduler.PeriodicScheduler ThreadGroup  group,
String  name,
Object  obj
 

Construct a new PeriodicScheduler which will write Commands to the specified Stream.

Parameters:
stream the Stream used to write Commands when they become ready.

Definition at line 90 of file PeriodicScheduler.java.


Member Function Documentation

void com.quadcap.util.threads.PeriodicScheduler.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. Any existing task with the same name is replaced by this one.
r the Runnable action associated with this task.
interval the interval (in ms) between invocations of this task.

Definition at line 138 of file PeriodicScheduler.java.

References com.quadcap.util.threads.PeriodicScheduler.active, com.quadcap.util.threads.ScheduleItem.interval, com.quadcap.util.threads.PeriodicScheduler.remove(), com.quadcap.util.threads.ScheduleItem.runnable, and com.quadcap.util.threads.PeriodicScheduler.schedule.

void com.quadcap.util.threads.PeriodicScheduler.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. Any existing task with the same name is replaced by this one.
c the Command action associated with this task.
interval the interval (in ms) between invocations of this task.

Definition at line 111 of file PeriodicScheduler.java.

References com.quadcap.util.threads.PeriodicScheduler.active, com.quadcap.util.threads.PeriodicScheduler.add(), com.quadcap.util.threads.ScheduleItem.command, com.quadcap.util.threads.ScheduleItem.interval, com.quadcap.util.threads.PeriodicScheduler.remove(), and com.quadcap.util.threads.PeriodicScheduler.schedule.

Referenced by com.quadcap.util.threads.PeriodicScheduler.add().

int com.quadcap.util.threads.PeriodicScheduler.handleInteractiveCommand String  cmd,
Vector  args
 

Handle a debug monitor command directed at this instance.

Implements com.quadcap.util.threads.DebugMonitor.

Definition at line 279 of file PeriodicScheduler.java.

References com.quadcap.util.threads.PeriodicScheduler.active, com.quadcap.util.threads.ScheduleItem.date, com.quadcap.util.threads.PeriodicScheduler.handleInteractiveCommand(), com.quadcap.util.DList.head, com.quadcap.util.threads.ScheduleItem.interval, com.quadcap.util.threads.ScheduleItem.name, com.quadcap.util.DListItem.next, and com.quadcap.util.DListItem.obj.

Referenced by com.quadcap.util.threads.PeriodicScheduler.handleInteractiveCommand().

long com.quadcap.util.threads.PeriodicScheduler.msUntil Date  d  )  [package]
 

How many ms between now and then (d)?

Parameters:
d then
Returns:
then - now

Definition at line 347 of file PeriodicScheduler.java.

References com.quadcap.util.threads.PeriodicScheduler.msUntil().

Referenced by com.quadcap.util.threads.PeriodicScheduler.msUntil(), and com.quadcap.util.threads.PeriodicScheduler.run().

void com.quadcap.util.threads.PeriodicScheduler.remove ScheduleItem  item  )  [package]
 

Definition at line 154 of file PeriodicScheduler.java.

References com.quadcap.util.threads.PeriodicScheduler.active, com.quadcap.util.DList.head, com.quadcap.util.DListItem.next, com.quadcap.util.DListItem.obj, com.quadcap.util.threads.PeriodicScheduler.remove(), and com.quadcap.util.DList.unlink().

Referenced by com.quadcap.util.threads.PeriodicScheduler.add(), and com.quadcap.util.threads.PeriodicScheduler.remove().

void com.quadcap.util.threads.PeriodicScheduler.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.

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.

Definition at line 211 of file PeriodicScheduler.java.

References com.quadcap.util.threads.PeriodicScheduler.active, com.quadcap.util.threads.ScheduleItem.command, com.quadcap.util.threads.PeriodicScheduler.context, com.quadcap.util.threads.Command.execute(), com.quadcap.util.DList.head, com.quadcap.util.threads.ScheduleItem.isRunning(), com.quadcap.util.threads.PeriodicScheduler.msUntil(), com.quadcap.util.DListItem.obj, com.quadcap.util.DList.popFront(), com.quadcap.util.threads.ScheduleItem.ready(), com.quadcap.util.threads.ScheduleItem.runnable, com.quadcap.util.threads.PeriodicScheduler.stream, com.quadcap.util.threads.PeriodicScheduler.terminate, and com.quadcap.util.threads.Stream.write().

void com.quadcap.util.threads.PeriodicScheduler.schedule ScheduleItem  item  )  [package]
 

Add the specified schedule item to the queue.

Parameters:
item the item to schedule

Definition at line 180 of file PeriodicScheduler.java.

References com.quadcap.util.threads.PeriodicScheduler.active, com.quadcap.util.DList.addBefore(), com.quadcap.util.DList.addFront(), com.quadcap.util.threads.ScheduleItem.checkDate(), com.quadcap.util.threads.ScheduleItem.date, com.quadcap.util.DList.head, com.quadcap.util.DListItem.next, com.quadcap.util.DListItem.obj, and com.quadcap.util.threads.PeriodicScheduler.schedule.

void com.quadcap.util.threads.PeriodicScheduler.terminate  ) 
 

Terminate this scheduler.

Definition at line 356 of file PeriodicScheduler.java.

References com.quadcap.util.threads.PeriodicScheduler.active.

String com.quadcap.util.threads.PeriodicScheduler.toString  ) 
 

Definition at line 316 of file PeriodicScheduler.java.

References com.quadcap.util.threads.PeriodicScheduler.active, com.quadcap.util.threads.ScheduleItem.date, com.quadcap.util.DList.head, com.quadcap.util.threads.ScheduleItem.interval, com.quadcap.util.threads.ScheduleItem.isRunning(), com.quadcap.util.threads.ScheduleItem.name, com.quadcap.util.DListItem.next, and com.quadcap.util.DListItem.obj.


Member Data Documentation

DList com.quadcap.util.threads.PeriodicScheduler.active = new DList() [package]
 

Definition at line 77 of file PeriodicScheduler.java.

Referenced by com.quadcap.util.threads.PeriodicScheduler.add(), com.quadcap.util.threads.PeriodicScheduler.handleInteractiveCommand(), com.quadcap.util.threads.PeriodicScheduler.remove(), com.quadcap.util.threads.PeriodicScheduler.run(), com.quadcap.util.threads.PeriodicScheduler.schedule(), com.quadcap.util.threads.PeriodicScheduler.terminate(), and com.quadcap.util.threads.PeriodicScheduler.toString().

Object com.quadcap.util.threads.PeriodicScheduler.context = null [package]
 

Definition at line 79 of file PeriodicScheduler.java.

Referenced by com.quadcap.util.threads.PeriodicScheduler.run().

Hashtable com.quadcap.util.threads.PeriodicScheduler.schedule = new Hashtable() [package]
 

Definition at line 81 of file PeriodicScheduler.java.

Referenced by com.quadcap.util.threads.PeriodicScheduler.add(), and com.quadcap.util.threads.PeriodicScheduler.schedule().

Stream com.quadcap.util.threads.PeriodicScheduler.stream = null [package]
 

Definition at line 78 of file PeriodicScheduler.java.

Referenced by com.quadcap.util.threads.PeriodicScheduler.run().

boolean com.quadcap.util.threads.PeriodicScheduler.terminate = false [package]
 

Definition at line 80 of file PeriodicScheduler.java.

Referenced by com.quadcap.util.threads.PeriodicScheduler.run().