Class EventQueue

java.lang.Object
microsim.event.EventQueue

public class EventQueue extends Object
The EventQueue class manages a time ordered queue of events. It is based on a priority queue. At every simulation step the head of the queue is taken and fired. This class extends a thread, because it runs independently of other processes. When activated it runs the simulation.
  • Field Details

    • EVENT_LIST_STEP

      public static final int EVENT_LIST_STEP
      The action type passed to step listeners. The int value is 10000.
      See Also:
    • eventQueue

      protected Queue<Event> eventQueue
  • Constructor Details

    • EventQueue

      public EventQueue()
      Builds a new event queue of size 10.
    • EventQueue

      public EventQueue(@NonNull @NonNull EventQueue previousEventQueue)
      Builds a new event queue inheriting parameters from another EventQueue.
      Parameters:
      previousEventQueue - An EventQueue to copy.
      Throws:
      NullPointerException - when previousEventQueue is null.
  • Method Details

    • clear

      public void clear()
      Empties this object and sets time to 0 for a new simulation.
    • step

      public void step() throws SimulationException
      Makes one simulation step forward. Does nothing when the queue is empty.
      Throws:
      SimulationException - when fails to invoke an event.
    • simulate

      public void simulate() throws SimulationException
      Runs an entire simulation. If model does not stop itself during the process of simulation, it will be stopped automatically at timeout time.
      Throws:
      SimulationException - when step() fails to progress.
    • scheduleEvent

      protected void scheduleEvent(@NonNull @NonNull Event event)
      Adds an event to the queue.
      Parameters:
      event - An Event object.
      Throws:
      NullPointerException - when event is null.
    • scheduleOnce

      public EventQueue scheduleOnce(@NonNull @NonNull Event event, double atTime, int withOrdering)
      Schedules a generic event to occur at a given time.
      Parameters:
      atTime - The time when event will be fired.
      withOrdering - The order that the event will be fired: for two events e1 and e2 scheduled to occur at the same time e1.time == e2.time, if e1.ordering < e2.ordering, then e1 will be fired first. If e1.time == e2.time AND e1.ordering == e2.ordering, the first event that was scheduled (added to the EventQueue) will be fired first.
      Throws:
      NullPointerException - when event is null.
    • scheduleRepeat

      public EventQueue scheduleRepeat(@NonNull @NonNull Event event, double atTime, int withOrdering, double timeBetweenEvents)
      Schedules a generic looped event at a given time and ordering.
      Parameters:
      atTime - The time when event will be fired for the first time.
      withOrdering - The order that the event will be fired: for two events e1 and e2 scheduled to occur at the same time e1.time == e2.time, if e1.ordering < e2.ordering, then e1 will be fired first. If e1.time == e2.time AND e1.ordering == e2.ordering, the first event that was scheduled (added to the EventQueue) will be fired first.
      timeBetweenEvents - The time period between repeated firing of the event. If this parameter is set to 0, this event will not be fired more than once.
      Throws:
      NullPointerException - when event is null.
    • unschedule

      public void unschedule(@NonNull @NonNull Event event)
      Removes a certain event from the queue.
      Parameters:
      event - An event to remove.
      Throws:
      NullPointerException - when event is null.
    • scheduleSystem

      public SystemEvent scheduleSystem(double atTime, int withOrdering, double withLoop, @NonNull @NonNull SimulationEngine engine, @NonNull @NonNull SystemEventType type)
      Schedules a looped system event.
      Parameters:
      atTime - The time when event will be fired for the first time.
      withOrdering - The order that the event will be fired: for two events e1 and e2 scheduled to occur at the same time e1.time == e2.time, if e1.ordering < e2.ordering, then e1 will be fired first. If e1.time == e2.time AND e1.ordering == e2.ordering, the first event that was scheduled (added to the EventQueue) will be fired first.
      withLoop - The time period between repeated firing of the event. If this parameter is set to 0, this event will not be fired more than once.
      engine - A SimulationEngine object to use.
      type - A SystemEventType to use.
      Returns:
      a new scheduled SystemEvent.
      Throws:
      NullPointerException - when any of the input parameters is null.
    • getEventArray

      @NonNull public @NonNull Event[] getEventArray()
      Converts the event queue to an array.
      Returns:
      an Event array.