jutil
Class Simulator

java.lang.Object
  extended by jutil.Simulator
All Implemented Interfaces:
java.io.Serializable

public class Simulator
extends java.lang.Object
implements java.io.Serializable

The Sim framework consists of the Simulator, Events, and priority queue.

See Also:
Serialized Form

Field Summary
protected  int clock
          The simulated time.
protected  boolean debug
          Set to true to see the clock and event queue after each event is fired.
protected  PriorityQueue events
          Scheduled events are placed in this queue in order of their firing times.
 
Constructor Summary
Simulator()
          Initializes event queue as a binary heap.
Simulator(PriorityQueue q)
           
 
Method Summary
protected  void handle(java.lang.Exception e)
          Handles errors by terminating the simulation.
 void run()
          Repeatedly removes the next event from the event queue, updates the clock, and fires the event.
 void schedule(Event e)
          Adds events to the events queue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

events

protected PriorityQueue events
Scheduled events are placed in this queue in order of their firing times. Currently, the priority queue is implemented as a binary heap with capacity 512. Consider replacing this implementation with a sorted list or a larger binary heap.


clock

protected int clock
The simulated time.


debug

protected boolean debug
Set to true to see the clock and event queue after each event is fired.

Constructor Detail

Simulator

public Simulator(PriorityQueue q)

Simulator

public Simulator()
Initializes event queue as a binary heap.

Method Detail

schedule

public void schedule(Event e)
              throws OverflowException
Adds events to the events queue.

Throws:
OverflowException

run

public void run()
Repeatedly removes the next event from the event queue, updates the clock, and fires the event. If firing the event creates a new event, then this event is scheduled.


handle

protected void handle(java.lang.Exception e)
Handles errors by terminating the simulation. Errors are either queue overflow or empty queue errors.

Parameters:
e - The exception thrown.