Class EventGenerator

  • All Implemented Interfaces:
    EventGeneratorIfc, ObservableIfc, GetNameIfc, IdentityIfc
    Direct Known Subclasses:
    EntityGenerator, JobGenerator

    public class EventGenerator
    extends SchedulingElement
    implements EventGeneratorIfc
    This class allows for the periodic generation of events similar to that achieved by "Create" modules in simulation languages. This class works in conjunction with the EventGeneratorActionIfc which is used to listen and react to the events that are generated by this class.

    Classes can supply an instance of an EventGeneratorActionIfc to provide the actions that take place when the event occurs. Alternatively, if no EventGeneratorActionIfc is supplied, by default the generator(JSLEvent event) method of this class will be called when the event occurs. Thus, sub-classes can simply override this method to provide behavior for when the event occurs. If no EventGeneratorActionIfc is supplied and the generate() method is not overridden, then the events will still occur; however, no meaningful actions will take place.

    Of particular note is the use of initial parameters:

    initial time of first event (default = Constant.ZERO)

    initial time between events (default = Constant.POSITIVE_INFINITY)

    initial maximum number of events (default = Long.MAX_VALUE)

    initial ending time (default = Double.POSITIVE_INFINITY)

    These parameters control the initial state of the generator at the start of each replication. The generator is re-initialized to these values at the start of each replication. There are also parameters for each of these that can be changed during a replication. The effect of that change is only within the current replication.

    • Field Detail

      • EVENT_PRIORITY

        public static final int EVENT_PRIORITY
        Determines the priority of the event generator's events The default is DEFAULT_PRIORITY - 1 A lower number implies higher priority.
        See Also:
        Constant Field Values
    • Constructor Detail

      • EventGenerator

        public EventGenerator​(ModelElement parent)
        Creates an EventGenerator that uses the supplied EventGeneratorActionIfc to react to the events. The default maximum number of events to generate is infinite (Long.MAX_VALUE) Default time between next is infinity. The default time of the first event is 0.0
        Parameters:
        parent - the parent model element
      • EventGenerator

        public EventGenerator​(ModelElement parent,
                              EventGeneratorActionIfc listener)
        Creates an EventGenerator that uses the supplied EventGeneratorActionIfc to react to the events. The default maximum number of events to generate is infinite (Long.MAX_VALUE) Default time between next is infinity. The default time of the first event is 0.0
        Parameters:
        parent - the parent model element
        listener - This listener supplies the "event" logic for reacting to the generated event.
      • EventGenerator

        public EventGenerator​(ModelElement parent,
                              EventGeneratorActionIfc listener,
                              java.lang.String name)
        Creates an EventGenerator that uses the supplied EventGeneratorActionIfc to react to the events. The default maximum number of events to generate is infinite (Long.MAX_VALUE) Default time between next is infinity. The default time of the first event is 0.0
        Parameters:
        parent - the parent model element
        listener - This listener supplies the "event" logic for reacting to the generated event.
        name - The name of the generator.
      • EventGenerator

        public EventGenerator​(ModelElement parent,
                              EventGeneratorActionIfc listener,
                              RandomIfc timeUntilFirst)
        Creates an EventGenerator that uses the supplied EventGeneratorActionIfc to react to the events. The default maximum number of events to generate is infinite (Long.MAX_VALUE) Default time between next is infinity.
        Parameters:
        parent - the parent model element
        listener - This listener supplies the "event" logic for reacting to the generated event.
        timeUntilFirst - A DistributionIfc object that supplies the time until the first event
      • EventGenerator

        public EventGenerator​(ModelElement parent,
                              EventGeneratorActionIfc listener,
                              RandomIfc timeUntilFirst,
                              RandomIfc timeUntilNext)
        Creates an EventGenerator that uses the supplied EventGeneratorActionIfc to react to the events. The default maximum number of events to generate is infinite (Long.MAX_VALUE)
        Parameters:
        parent - the parent model element
        listener - This listener supplies the "event" logic for reacting to the generated event.
        timeUntilFirst - A RandomIfc object that supplies the time until the first event.
        timeUntilNext - A RandomIfc object that supplies the time between events. Must not be a RandomIfc that always returns 0.0, if the maximum number of generations is infinite (Long.MAX_VALUE)
      • EventGenerator

        public EventGenerator​(ModelElement parent,
                              RandomIfc timeUntilFirst)
        Creates an EventGenerator that uses the supplied EventGeneratorActionIfc to react to the events. The default maximum number of events to generate is infinite (Long.MAX_VALUE) Default time between next is infinity.
        Parameters:
        parent - the parent model element
        timeUntilFirst - A RandomIfc object that supplies the time until the first event.
      • EventGenerator

        public EventGenerator​(ModelElement parent,
                              RandomIfc timeUntilFirst,
                              RandomIfc timeUntilNext)
        Creates an EventGenerator that uses the supplied EventGeneratorActionIfc to react to the events. The default maximum number of events to generate is infinite (Long.MAX_VALUE)
        Parameters:
        parent - the parent model element
        timeUntilFirst - A RandomIfc object that supplies the time until the first event.
        timeUntilNext - A RandomIfc object that supplies the time between events. Must not be a RandomIfc that always returns 0.0, if the maximum number of generations is infinite (Long.MAX_VALUE)
      • EventGenerator

        public EventGenerator​(ModelElement parent,
                              RandomIfc timeUntilFirst,
                              RandomIfc timeUntilNext,
                              java.lang.String name)
        Creates an EventGenerator that uses the supplied EventGeneratorActionIfc to react to the events. The default maximum number of events to generate is infinite (Long.MAX_VALUE)
        Parameters:
        parent - the parent model element
        timeUntilFirst - A RandomIfc object that supplies the time until the first event.
        timeUntilNext - A RandomIfc object that supplies the time between events. Must not be a RandomIfc that always returns 0.0, if the maximum number of generations is infinite (Long.MAX_VALUE)
        name - the name of the generator
      • EventGenerator

        public EventGenerator​(ModelElement parent,
                              EventGeneratorActionIfc listener,
                              RandomIfc timeUntilFirst,
                              RandomIfc timeUntilNext,
                              java.lang.String name)
        Creates an EventGenerator that uses the supplied EventGeneratorActionIfc to react to the events. The default maximum number of events to generate is infinite (Long.MAX_VALUE)
        Parameters:
        parent - the parent model element
        listener - This listener supplies the "event" logic for reacting to the generated event.
        timeUntilFirst - A RandomIfc object that supplies the time until the first event.
        timeUntilNext - A RandomIfc object that supplies the time between events. Must not be a RandomIfc that always returns 0.0, if the maximum number of generations is infinite (Long.MAX_VALUE)
        name - the name of the generator
      • EventGenerator

        public EventGenerator​(ModelElement parent,
                              EventGeneratorActionIfc listener,
                              RandomIfc timeUntilFirst,
                              RandomIfc timeUntilNext,
                              long maxNum)
        Creates an EventGenerator that uses the supplied EventGeneratorActionIfc to react to the events.
        Parameters:
        parent - the parent model element
        listener - This listener supplies the "event" logic for reacting to the generated event.
        timeUntilFirst - A RandomIfc object that supplies the time until the first event.
        timeUntilNext - A RandomIfc object that supplies the time between events. Must not be a RandomIfc that always returns 0.0, if the maximum number of generations is infinite (Long.MAX_VALUE)
        maxNum - A long that supplies the maximum number of events to generate. Each time an event is to be scheduled the maximum number of events is checked. If the maximum has been reached, then the generator is turned off. The default is Long.MAX_VALUE. This parameter cannot be Long.MAX_VALUE when the time until next always returns a value of 0.0
      • EventGenerator

        public EventGenerator​(ModelElement parent,
                              EventGeneratorActionIfc listener,
                              RandomIfc timeUntilFirst,
                              RandomIfc timeUntilNext,
                              long maxNum,
                              double timeUntilLast)
        Creates an EventGenerator that uses the supplied EventGeneratorActionIfc to react to the events.
        Parameters:
        parent - the parent model element
        listener - This listener supplies the "event" logic for reacting to the generated event.
        timeUntilFirst - A RandomIfc object that supplies the time until the first event.
        timeUntilNext - A RandomIfc object that supplies the time between events. Must not be a RandomIfc that always returns 0.0, if the maximum number of generations is infinite (Long.MAX_VALUE)
        maxNum - A long that supplies the maximum number of events to generate. Each time an event is to be scheduled the maximum number of events is checked. If the maximum has been reached, then the generator is turned off. The default is Long.MAX_VALUE. This parameter cannot be Long.MAX_VALUE when the time until next always returns a value of 0.0
        timeUntilLast - A double that supplies a time to stop generating events. When the generator is created, this variable is used to set the ending time of the generator. Each time an event is to be scheduled the ending time is checked. If the time of the next event is past this time, then the generator is turned off and the event won't be scheduled. The default is Double.POSITIVE_INFINITY.
      • EventGenerator

        public EventGenerator​(ModelElement parent,
                              EventGeneratorActionIfc listener,
                              RandomIfc timeUntilFirst,
                              RandomIfc timeUntilNext,
                              long maxNum,
                              double timeUntilLast,
                              java.lang.String name)
        Creates an EventGenerator that uses the supplied EventGeneratorActionIfc to react to the events.
        Parameters:
        parent - the parent model element
        listener - This listener supplies the "event" logic for reacting to the generated event.
        timeUntilFirst - A RandomIfc object that supplies the time until the first event.
        timeUntilNext - A RandomIfc object that supplies the time between events. Must not be a RandomIfc that always returns 0.0, if the maximum number of generations is infinite (Long.MAX_VALUE)
        maxNum - A long that supplies the maximum number of events to generate. Each time an event is to be scheduled the maximum number of events is checked. If the maximum has been reached, then the generator is turned off. The default is Long.MAX_VALUE. This parameter cannot be Long.MAX_VALUE when the time until next always returns a value of 0.0
        timeUntilLast - A double that supplies a time to stop generating events. When the generator is created, this variable is used to set the ending time of the generator. Each time an event is to be scheduled the ending time is checked. If the time of the next event is past this time, then the generator is turned off and the event won't be scheduled. The default is Double.POSITIVE_INFINITY.
        name - The name of the generator.
    • Method Detail

      • getEventPriority

        public final int getEventPriority()
        The priority of the events for the generator
        Returns:
        the event priority
      • setEventPriority

        public final void setEventPriority​(int priority)
        Lower means earlier (higher priority). Changing the priority effects only future scheduled events The changed priority is retained for all future replications
        Parameters:
        priority - the priority to set
      • setEventGeneratorListener

        public final void setEventGeneratorListener​(EventGeneratorActionIfc listener)
        Sets the listener for the events to the supplied EventGeneratorActionIfc
        Parameters:
        listener - This listener supplies the "event" logic for reacting to the generated event.
      • getEventGeneratorListener

        public final EventGeneratorActionIfc getEventGeneratorListener()
        Gets the listener for the events to the supplied EventGeneratorActionIfc. This can be null. If null, the generate(JSLEvent event) method is called.
        Returns:
        the event generator's action
      • getStartOnInitializeFlag

        public final boolean getStartOnInitializeFlag()
        Description copied from interface: EventGeneratorIfc
        This flag indicates whether or not the generator will automatically start at the beginning of a replication when initialized. By default this option is true.
        Specified by:
        getStartOnInitializeFlag in interface EventGeneratorIfc
        Returns:
        true if on
      • setStartOnInitializeFlag

        public final void setStartOnInitializeFlag​(boolean flag)
        Description copied from interface: EventGeneratorIfc
        Sets the flag that indicates whether or not the generator will automatically start at the beginning of a replication when initialized
        Specified by:
        setStartOnInitializeFlag in interface EventGeneratorIfc
        Parameters:
        flag - true indicates automatic start
      • turnOnGenerator

        public final void turnOnGenerator​(double t)
        Description copied from interface: EventGeneratorIfc
        If the generator was not started upon initialization at the beginning of a replication, then this method can be used to start the generator The generator will be started t time units after the call If this method is used when the generator is already started it does nothing. If this method is used after the generator is done it does nothing. If this method is used after the generator has been suspended it does nothing. Use suspend() and resume() to suspend and resume a generator that has already been started.
        Specified by:
        turnOnGenerator in interface EventGeneratorIfc
        Parameters:
        t - The time until the generator should be turned on
      • turnOnGenerator

        public void turnOnGenerator​(RandomIfc r)
        Description copied from interface: EventGeneratorIfc
        If the generator was not started upon initialization at the beginning of a replication, then this method can be used to start the generator The generator will be started r.getValue() time units after the call If this method is used when the generator is already started it does nothing. If this method is used after the generator is done it does nothing. If this method is used after the generator has been suspended it does nothing. Use suspend() and resume() to suspend and resume a generator that has already been started.
        Specified by:
        turnOnGenerator in interface EventGeneratorIfc
        Parameters:
        r - The time until the generator should be turned on
      • turnOnGenerator

        public final void turnOnGenerator()
        Description copied from interface: EventGeneratorIfc
        If the generator was not started upon initialization at the beginning of a replication, then this method can be used to start the generator The generator will be started 0.0 time units after the call If this method is used when the generator is already started it does nothing. If this method is used after the generator is done it does nothing. If this method is used after the generator has been suspended it does nothing. Use suspend() and resume() to suspend and resume a generator that has already been started.
        Specified by:
        turnOnGenerator in interface EventGeneratorIfc
      • turnOffGenerator

        public final void turnOffGenerator()
        Description copied from interface: EventGeneratorIfc
        This method turns the generator off, the next scheduled generation event will NOT occur, i.e. this method will also cancel a previously scheduled generation event if one exists. No future events will be scheduled after turning off the generator
        Specified by:
        turnOffGenerator in interface EventGeneratorIfc
      • isEventPending

        public final boolean isEventPending()
        Specified by:
        isEventPending in interface EventGeneratorIfc
        Returns:
        true if an event is scheduled to occur for the generator
      • suspend

        public final void suspend()
        Description copied from interface: EventGeneratorIfc
        Suspends the generation of events and cancels the next scheduled event from the generator
        Specified by:
        suspend in interface EventGeneratorIfc
      • isSuspended

        public final boolean isSuspended()
        Description copied from interface: EventGeneratorIfc
        Indicates whether or not the generator has been suspended
        Specified by:
        isSuspended in interface EventGeneratorIfc
        Returns:
        true if generator is suspended
      • resume

        public final void resume()
        Description copied from interface: EventGeneratorIfc
        Resume the generation of events according to the time between event distribution.
        Specified by:
        resume in interface EventGeneratorIfc
      • isGeneratorDone

        public final boolean isGeneratorDone()
        Description copied from interface: EventGeneratorIfc
        This method checks to see if the generator is done. In other words, if it has been turned off.
        Specified by:
        isGeneratorDone in interface EventGeneratorIfc
        Returns:
        True means that it is done.
      • getMaximumNumberOfEvents

        public final long getMaximumNumberOfEvents()
        Description copied from interface: EventGeneratorIfc
        Gets the maximum number of actions for the generator. This is set by the supplied maxNum upon creation of the generator. This implies that it will be the same for every simulation replication.
        Specified by:
        getMaximumNumberOfEvents in interface EventGeneratorIfc
        Returns:
        A long representing the maximum number of actions for the generator.
      • setTimeBetweenEvents

        public final void setTimeBetweenEvents​(RandomIfc timeUntilNext)
        Description copied from interface: EventGeneratorIfc
        Sets the time between event random source. Must not always evaluate to 0.0, if the current setting of the maximum number of events is infinite (Long.MAX_VALUE)
        Specified by:
        setTimeBetweenEvents in interface EventGeneratorIfc
        Parameters:
        timeUntilNext - time until the next event
      • setMaximumNumberOfEvents

        public final void setMaximumNumberOfEvents​(long maxNum)
        Description copied from interface: EventGeneratorIfc
        Sets the maximum number of events for the generator. Must not be infinite (Long.MAX_VALUE) if the current time between events is 0.0
        Specified by:
        setMaximumNumberOfEvents in interface EventGeneratorIfc
        Parameters:
        maxNum - maximum number of events
      • setTimeBetweenEvents

        public final void setTimeBetweenEvents​(RandomIfc timeBtwEvents,
                                               long maxNumEvents)
        Description copied from interface: EventGeneratorIfc
        Sets the time between events and the maximum number of events for the generator. These two parameters are dependent. The time between events cannot always evaluate to 0.0 if the maximum number of events is infinite (Long.MAX_VALUE). This method only changes these parameters for the current replication. The changes take effect when the next event is generated. If current number of events that have been generated is greater than or equal to the supplied maximum number of events, the generator will be turned off.
        Specified by:
        setTimeBetweenEvents in interface EventGeneratorIfc
        Parameters:
        timeBtwEvents - the time between events
        maxNumEvents - the maximum number of events
      • setInitialTimeBetweenEvents

        public final void setInitialTimeBetweenEvents​(RandomIfc timeBtwEvents)
        Description copied from interface: EventGeneratorIfc
        Sets the time between events and the maximum number of events to be used to initialize each replication. The time between events cannot evaluate to a constant value of 0.0. The maximum number of events is kept at its current value, which by default is Long.Max_Value
        Specified by:
        setInitialTimeBetweenEvents in interface EventGeneratorIfc
        Parameters:
        timeBtwEvents - the time between events
      • setInitialMaximumNumberOfEvents

        public final void setInitialMaximumNumberOfEvents​(long maxNumEvents)
        Description copied from interface: EventGeneratorIfc
        Sets the the maximum number of events to be used to initialize each replication. The time between events cannot evaluate to a constant value of 0.0 if the maximum number of events is infinite (Long.MAX_VALUE). Uses the current value for initial time between events
        Specified by:
        setInitialMaximumNumberOfEvents in interface EventGeneratorIfc
        Parameters:
        maxNumEvents - the the maximum number of events
      • setInitialTimeBetweenEventsAndMaxNumEvents

        public final void setInitialTimeBetweenEventsAndMaxNumEvents​(RandomIfc timeBtwEvents,
                                                                     long maxNumEvents)
        Description copied from interface: EventGeneratorIfc
        Sets the time between events and the maximum number of events to be used to initialize each replication. These parameters are dependent. The time between events cannot evaluate to a constant value of 0.0 if the maximum number of events is infinite (Long.MAX_VALUE)
        Specified by:
        setInitialTimeBetweenEventsAndMaxNumEvents in interface EventGeneratorIfc
        Parameters:
        timeBtwEvents - the initial time between events
        maxNumEvents - the initial maximum number of events
      • getInitialMaximumNumberOfEvents

        public final long getInitialMaximumNumberOfEvents()
        Description copied from interface: EventGeneratorIfc
        Returns the maximum number of events that is used for initializing each replication
        Specified by:
        getInitialMaximumNumberOfEvents in interface EventGeneratorIfc
        Returns:
        the initial maximum number of events
      • setInitialTimeUntilFirstEvent

        public final void setInitialTimeUntilFirstEvent​(RandomIfc timeUntilFirst)
        Description copied from interface: EventGeneratorIfc
        Sets the RandomIfc representing the time until the first event that is used at the beginning of each replication to generate the time until the first event. This change becomes effective at the beginning of the next replication to execute
        Specified by:
        setInitialTimeUntilFirstEvent in interface EventGeneratorIfc
        Parameters:
        timeUntilFirst - , The supplied RandomIfc, cannot be null
      • getInitialTimeUntilFirstEvent

        public final RandomIfc getInitialTimeUntilFirstEvent()
        Description copied from interface: EventGeneratorIfc
        Gets the RandomIfc that will be used at the beginning of each replication to generate the time until the first event
        Specified by:
        getInitialTimeUntilFirstEvent in interface EventGeneratorIfc
        Returns:
        RandomIfc that will be used at the beginning of each replication to generate the time until the first event
      • setEndingTime

        public final void setEndingTime​(double endingTime)
        Description copied from interface: EventGeneratorIfc
        Sets the ending time for generating events for the current replication. A new ending time will be applied to the generator. If this change results in an ending time that is less than the current time, the generator will be turned off
        Specified by:
        setEndingTime in interface EventGeneratorIfc
        Parameters:
        endingTime - the ending time for generating events
      • getEndingTime

        public final double getEndingTime()
        Description copied from interface: EventGeneratorIfc
        Gets the currently planned ending time of the generator.
        Specified by:
        getEndingTime in interface EventGeneratorIfc
        Returns:
        A double representing the ending time.
      • setInitialEndingTime

        public final void setInitialEndingTime​(double endingTime)
        Description copied from interface: EventGeneratorIfc
        This value is used to set the ending time for generating actions for each replication. Changing this variable during a replication cause the next replication to use this value for its ending time.
        Specified by:
        setInitialEndingTime in interface EventGeneratorIfc
        Parameters:
        endingTime - value is used to set the initial ending time for generating actions
      • getInitialEndingTime

        public final double getInitialEndingTime()
        Description copied from interface: EventGeneratorIfc
        Returns the ending time that is to be used when the generator is initialized for each replication.
        Specified by:
        getInitialEndingTime in interface EventGeneratorIfc
        Returns:
        Returns the initial ending time that is to be used when the generator
      • getNumberOfEventsGenerated

        public final long getNumberOfEventsGenerated()
        Description copied from interface: EventGeneratorIfc
        Gets the number of events that have been generated by the generator
        Specified by:
        getNumberOfEventsGenerated in interface EventGeneratorIfc
        Returns:
        the number of events that have been generated
      • initialize

        protected void initialize()
        Description copied from class: ModelElement
        This method should be overridden by subclasses that need actions performed to initialize prior to a replication. It is called once before each replication occurs if the model element wants initialization. It is called after beforeReplication() is called
        Overrides:
        initialize in class ModelElement
      • isGeneratorStarted

        public final boolean isGeneratorStarted()
        Specified by:
        isGeneratorStarted in interface EventGeneratorIfc
        Returns:
        true if the generator has been started (turned on) either automatically or manually
      • generate

        protected void generate​(JSLEvent event)
        This method should be overridden by sub-classes that do not supply an EventGeneratorActionIfc to model the action that occur when the event happens.
        Parameters:
        event - the event associated with the generations
      • scheduleFirstEvent

        protected final void scheduleFirstEvent​(GetValueIfc r)
        Schedules the first event at current time + r.getValue()
        Parameters:
        r - the time to the first event
      • scheduleFirstEvent

        protected final void scheduleFirstEvent​(double t)
        Schedules the first event at current time + t
        Parameters:
        t - the time to the first event
      • incrementNumberOfEvents

        protected final void incrementNumberOfEvents()
        Increments the number of actions and checks if the number of actions is greater than the maximum number of actions. If so, the generator is told to shut down.
      • removedFromModel

        protected void removedFromModel()
        Description copied from class: ModelElement
        This method should be overridden by subclasses that need actions performed when a model element is removed from a model
        Overrides:
        removedFromModel in class ModelElement