Class EventQueue


  • public class EventQueue
    extends java.lang.Object
    The eventQueue 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 from other processes. When activated it runs the simulation.

    Title: JAS-mine

    Description: Java Agent-based Simulation library. Modelling In a Networked Environment.

    Copyright (C) 2002 Michele Sonnessa and Ross Richardson

    This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
    Author:
    Michele Sonnessa and Ross Richardson

    • Field Detail

      • EVENT_LIST_STEP

        public static final int EVENT_LIST_STEP
        The action type passed to step listeners. The int value is 10000.
        See Also:
        Constant Field Values
    • Constructor Detail

      • EventQueue

        public EventQueue()
        Build new event queue with TIME_TICKS time unit.
      • EventQueue

        public EventQueue​(EventQueue previousEventQueue)
        Build new event queue inheriting parameters from another EventQueue.
    • Method Detail

      • clear

        public void clear()
        Empty the eventQueue and set up time for a new simulation.
      • setSimulationTimeout

        public static void setSimulationTimeout​(double steps)
        Set the simulation timeout. When simulation is started without activating Control Panel, user cannot stop it. By setting this timeout simulation is automatically stopped after given steps.
      • getSimulationTimeout

        public static double getSimulationTimeout()
        Return current simulation timeout. If not previously set it returns the default value.
      • getTime

        public double getTime()
        Return current simulation timer.
      • simulate

        public void simulate()
                      throws SimulationException
        Run an entire simulation. If model does not stop itself simulation, it will be stop automatically at timeout time.
        Throws:
        SimulationException
      • scheduleOnce

        public EventQueue scheduleOnce​(Event event,
                                       double atTime,
                                       int withOrdering)
        Schedule 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.
      • scheduleRepeat

        public EventQueue scheduleRepeat​(Event event,
                                         double atTime,
                                         int withOrdering,
                                         double timeBetweenEvents)
        Schedule 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.
      • schedule

        @Deprecated
        public EventQueue schedule​(Event event,
                                   double atTime,
                                   double timeBetweenEvents)
        Deprecated.
        Schedule a generic (possibly looped) event at a given time. Warning - This method is deprecated as it doesn't specify the ordering of events scheduled for the same time - all events scheduled using this method are set with a default ordering of 0. In this instance, if events e1 and e2 are scheduled for the same time (i.e. e1.time == e2.time) using this method, there is no way of ensuring that, for example, e2 is fired before e1 - the actual order these same-time events is determined by the order in which they are added to the EventQueue. This method is still included in the JAS-mine libraries for backwards compatibility with JAS2 models, however it is preferable to use scheduleOnce(Event, double, int) or scheduleRepeating(Event, double, int, double), where the order of same-time events can be fully specified using the int withOrdering parameter.
        Parameters:
        atTime - The time when event will be fired for the first time.
        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.
      • schedule

        @Deprecated
        public EventQueue schedule​(Event event,
                                   double atTime)
        Deprecated.
        Schedule a single generic event at a given time. Warning - This method is deprecated as it doesn't specify the ordering of events scheduled for the same time - all events scheduled using this method are set with a default ordering of 0. In this instance, if events e1 and e2 are scheduled for the same time (i.e. e1.time == e2.time) using this method, there is no way of ensuring that, for example, e2 is fired before e1 - the actual order these same-time events is determined by the order in which they are added to the EventQueue. This method is still included in the JAS-mine libraries for backwards compatibility with JAS2 models, however it is preferable to use scheduleOnce(Event, double, int) or scheduleRepeating(Event, double, int, double), where the order of same-time events can be fully specified using the int withOrdering parameter.
        Parameters:
        atTime - The time when event will be fired for the first time.
      • unschedule

        public void unschedule​(Event event)
        Remove from event queue the given event.
      • scheduleSystem

        public SystemEvent scheduleSystem​(double atTime,
                                          int withOrdering,
                                          double withLoop,
                                          SimulationEngine engine,
                                          SystemEventType type)
        Schedule 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 -
        type -
        Returns:
      • getEventArray

        public Event[] getEventArray()
        Return event queue as Event array.