Prism.core
Class RRobinDispatcher

java.lang.Object
  extended by Prism.core.RRobinDispatcher
All Implemented Interfaces:
AbstractDispatch

public class RRobinDispatcher
extends java.lang.Object
implements AbstractDispatch

The dispatcher is the container of a set of worker threads and an associated queue. This class initiates, controls and terminates worker threads.

Version:
2.0
Author:
USC Soft. Arch. Group. Contact: Sam Malek malek@usc.edu

Constructor Summary
RRobinDispatcher(AbstractScheduler sched)
          Create a dispatcher that dispatches messages on a round robin basis with a default of DEFAULT_COUNT threads
RRobinDispatcher(AbstractScheduler sched, int n)
          Create a dispatcher that dispatches messages on a round robin basis with the given number of threads.
RRobinDispatcher(int n)
          Create a scheduler that dispatches messages on a round robin basis with a default of DEFAULT_COUNT threads
 
Method Summary
 int getThreadCount()
          This method returns the current count of the threads servicing the message queue.
 void setThreadCount(int n)
          This method sets the number of threads this architecture uses to service the message queue to n.
 void setTimeStep(int step)
          Set the time the thread stops before dispatching another message
 void shutdown()
          This method exits the JVM ASAP without gently killing the threads.
 void start()
          This method starts all the threads in the scheduler and allows the messages to be dispatched to the destination components.
 void stop()
          This method stops all the threads in the architecture and finally exits the JVM.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RRobinDispatcher

public RRobinDispatcher(AbstractScheduler sched)
Create a dispatcher that dispatches messages on a round robin basis with a default of DEFAULT_COUNT threads

Parameters:
sched - AbstractScheduler a reference to the event store.

RRobinDispatcher

public RRobinDispatcher(int n)
Create a scheduler that dispatches messages on a round robin basis with a default of DEFAULT_COUNT threads

Parameters:
n - int number of threads in the scheduler.

RRobinDispatcher

public RRobinDispatcher(AbstractScheduler sched,
                        int n)
Create a dispatcher that dispatches messages on a round robin basis with the given number of threads. The threads required should be in the range of allowable threads, otherwise a default of DEFAULT_COUNT threads are used.

Parameters:
sched - AbstractScheduler a reference to the message store.
Method Detail

setThreadCount

public void setThreadCount(int n)
This method sets the number of threads this architecture uses to service the message queue to n. If n is less than or greater than LOWER_BOUND or UPPER_BOUND respectively then it the function does nothing and returns.

Parameters:
n - int the new number of threads to use from now.

getThreadCount

public int getThreadCount()
This method returns the current count of the threads servicing the message queue.

Returns:
int the number of threads servicing the message queue.

start

public void start()
This method starts all the threads in the scheduler and allows the messages to be dispatched to the destination components.

Specified by:
start in interface AbstractDispatch

stop

public void stop()
This method stops all the threads in the architecture and finally exits the JVM. The threads will stop only after completeling the current threadFunction() call that they are executing. To shutdown the scheduler and system.

Specified by:
stop in interface AbstractDispatch
See Also:
Prism.framework.Architecture#shutdown

shutdown

public void shutdown()
This method exits the JVM ASAP without gently killing the threads. To halt or pause the threads use stop(). Restart the scheduler by calling start.

Specified by:
shutdown in interface AbstractDispatch
See Also:
Prism.framework.Architecture#stop

setTimeStep

public void setTimeStep(int step)
Set the time the thread stops before dispatching another message

Parameters:
step - the number of milliseconds to wait