Package microsim.event
Class EventQueue
java.lang.Object
microsim.event.EventQueue
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe action type passed to step listeners. -
Constructor Summary
ConstructorsConstructorDescriptionBuilds a new event queue of size 10.EventQueue(@NonNull EventQueue previousEventQueue) Builds a new event queue inheriting parameters from another EventQueue. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Empties this object and sets time to0for a new simulation.@NonNull Event[]Converts the event queue to an array.protected voidscheduleEvent(@NonNull Event event) Adds an event to the queue.scheduleOnce(@NonNull Event event, double atTime, int withOrdering) Schedules a generic event to occur at a given time.scheduleRepeat(@NonNull Event event, double atTime, int withOrdering, double timeBetweenEvents) Schedules a generic looped event at a given time and ordering.scheduleSystem(double atTime, int withOrdering, double withLoop, @NonNull SimulationEngine engine, @NonNull SystemEventType type) Schedules a looped system event.voidsimulate()Runs an entire simulation.voidstep()Makes one simulation step forward.voidunschedule(@NonNull Event event) Removes a certain event from the queue.
-
Field Details
-
EVENT_LIST_STEP
public static final int EVENT_LIST_STEPThe action type passed to step listeners. Theintvalue is 10000.- See Also:
-
eventQueue
-
-
Constructor Details
-
EventQueue
public EventQueue()Builds a new event queue of size 10. -
EventQueue
Builds a new event queue inheriting parameters from another EventQueue.- Parameters:
previousEventQueue- AnEventQueueto copy.- Throws:
NullPointerException- whenpreviousEventQueueisnull.
-
-
Method Details
-
clear
public void clear()Empties this object and sets time to0for a new simulation. -
step
Makes one simulation step forward. Does nothing when the queue is empty.- Throws:
SimulationException- when fails to invoke an event.
-
simulate
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- whenstep()fails to progress.
-
scheduleEvent
Adds an event to the queue.- Parameters:
event- AnEventobject.- Throws:
NullPointerException- wheneventisnull.
-
scheduleOnce
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 eventse1ande2scheduled to occur at the same timee1.time == e2.time, ife1.ordering < e2.ordering, thene1will be fired first. Ife1.time == e2.time AND e1.ordering == e2.ordering, the first event that was scheduled (added to theEventQueue) will be fired first.- Throws:
NullPointerException- wheneventisnull.
-
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 eventse1ande2scheduled to occur at the same timee1.time == e2.time, ife1.ordering < e2.ordering, thene1will be fired first. Ife1.time == e2.time AND e1.ordering == e2.ordering, the first event that was scheduled (added to theEventQueue) 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- wheneventisnull.
-
unschedule
Removes a certain event from the queue.- Parameters:
event- An event to remove.- Throws:
NullPointerException- wheneventisnull.
-
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 eventse1ande2scheduled to occur at the same timee1.time == e2.time, ife1.ordering < e2.ordering, thene1will be fired first. Ife1.time == e2.time AND e1.ordering == e2.ordering, the first event that was scheduled (added to theEventQueue) 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- ASimulationEngineobject to use.type- ASystemEventTypeto use.- Returns:
- a new scheduled
SystemEvent. - Throws:
NullPointerException- when any of the input parameters isnull.
-
getEventArray
Converts the event queue to an array.- Returns:
- an
Eventarray.
-