com.cogent
Class SimDispatchElement

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--com.cogent.SimElement
              |
              +--com.cogent.SimDispatchElement
All Implemented Interfaces:
java.lang.Runnable

public class SimDispatchElement
extends SimElement

The dispatcher.


Field Summary
private  java.util.Vector myActiveElements
           
private  long myCurrentTime
           
private  SimEventQueue myEventQueue
           
private static SimDispatchElement myInstance
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
private SimDispatchElement()
          Create a SimDispatchElement and start its thread.
 
Method Summary
private  void dispatchMessage(SimPacketEvent argEvent)
          Find the destination of a SimPacketEvent and send the event to the appropriate processing element.
static SimDispatchElement getInstance()
           
 void postEvent(SimEvent argEvent, long argTime)
          Callback from Processing elements to add events to the event queue.
 void run()
          While there are no events to process, wait.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

myCurrentTime

private long myCurrentTime

myInstance

private static SimDispatchElement myInstance

myEventQueue

private SimEventQueue myEventQueue

myActiveElements

private java.util.Vector myActiveElements
Constructor Detail

SimDispatchElement

private SimDispatchElement()
Create a SimDispatchElement and start its thread. Private as part of Singleton pattern.

Method Detail

postEvent

public void postEvent(SimEvent argEvent,
                      long argTime)
Callback from Processing elements to add events to the event queue.

Parameters:
argEvent - A SimEvent to add to the queue
argTime - A priority for the event (time)

getInstance

public static SimDispatchElement getInstance()
Returns:
the one and only instance of the dispatcher

dispatchMessage

private void dispatchMessage(SimPacketEvent argEvent)
Find the destination of a SimPacketEvent and send the event to the appropriate processing element.

Parameters:
argEvent - A SimPacketEvent to dispatch

run

public void run()
While there are no events to process, wait. When there are events, process all at the next priority level, and then go back to sleep. This method is synchronized to avoid deadlock with postEvent (@see postEvent) This may change if the granularity is too coarse and limits parallelism.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread