edu.cuny.cat.task
Class PrioritySynchronousDispatcher

java.lang.Object
  extended by edu.cuny.cat.task.PrioritySynchronousDispatcher
All Implemented Interfaces:
Dispatcher

public class PrioritySynchronousDispatcher
extends java.lang.Object
implements Dispatcher

A synchronous task dispatcher without any internal thread. It allows to use a task comparator and the task IDs to support a stable priority queue of tasks.

Version:
$Revision: 1.3 $
Author:
Jinzhong Niu
See Also:
PriorityAsynchronousDispatcher

Field Summary
protected  int counter
           
protected  boolean running
           
protected  java.util.PriorityQueue<DispatchingTask> tasks
           
 
Constructor Summary
PrioritySynchronousDispatcher(java.util.Comparator<DispatchingTask> comparator)
           
 
Method Summary
 void addTask(DispatchingTask task)
          adds a dispatching task to process.
 DispatchingTask[] getTasks()
           
 void process()
          to process the pending tasks.
 void processTask(DispatchingTask task)
          to add the task and process all pending tasks.
 void terminate()
          terminates the dispatcher.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tasks

protected final java.util.PriorityQueue<DispatchingTask> tasks

running

protected boolean running

counter

protected int counter
Constructor Detail

PrioritySynchronousDispatcher

public PrioritySynchronousDispatcher(java.util.Comparator<DispatchingTask> comparator)
Method Detail

addTask

public void addTask(DispatchingTask task)
Description copied from interface: Dispatcher
adds a dispatching task to process.

Specified by:
addTask in interface Dispatcher
Parameters:
task - task to process

process

public void process()
Description copied from interface: Dispatcher
to process the pending tasks.

Specified by:
process in interface Dispatcher

processTask

public void processTask(DispatchingTask task)
Description copied from interface: Dispatcher
to add the task and process all pending tasks. This does exactly what Dispatcher.addTask(DispatchingTask) and Dispatcher.process() do together.

Specified by:
processTask in interface Dispatcher

terminate

public void terminate()
Description copied from interface: Dispatcher
terminates the dispatcher.

Specified by:
terminate in interface Dispatcher

getTasks

public DispatchingTask[] getTasks()
Specified by:
getTasks in interface Dispatcher
Returns:
the array of tasks yet to process.