Class Schedule

  • All Implemented Interfaces:
    ObservableIfc, GetNameIfc, IdentityIfc

    public class Schedule
    extends SchedulingElement
    A Schedule represents a known set of events that can occur according to a pattern. A schedule contains one or more instances of ScheduleItem. A ScheduleItem represents an item on a Schedule. It has a start time, relative to the start of the Schedule and a duration. If more than one schedule item needs to start at the same time, then a priority can be provided to determine the ordering (smallest priority goes first). ScheduleItems are not scheduled to occur until the Schedule actually starts. A Schedule has an auto start flag, which controls whether or not the schedule should start automatically upon initialization (at the start of the simulation). The default is to start automatically. A Schedule has an initial start time, which represents the amount of time after the beginning of the simulation that the schedule is to start. The default start time is zero (at the beginning of the simulation). A Schedule as a length (or duration) that represents the total time associated with the schedule. After this time has elapsed the entire schedule can repeat if the repeat option is on. The default length of a schedule is infinite. The total or maximum duration of scheduled items cannot exceed the schedule duration if it is finite. A Schedule has a repeat flag that controls whether or not it will repeat after its duration has elapsed. The default is to repeat the schedule and is only relevant if the schedule duration (length) is finite. A Schedule has a cycle start time that represents when the schedule started its current cycle. Again, this is only relevant if the repeat flag is true and the schedule duration is finite. If there is only one cycle, it is the time that the schedule started. A builder is used to configure the schedule and then items are added to the schedule. If no items are added to the schedule, then there will still be an event to start the schedule. To make a Schedule useful, instances of the ScheduleChangeListenerIfc interface should be added to listen for changes in the schedule. Instances of ScheduleChangeListenerIfc are notified in the order in which they are added to the schedule. Instances of ScheduleChangeListenerIfc are notified when the schedule starts, when it ends, and when any ScheduleItem starts and ends. It is up to the instance of ScheduleChangeListenerIfc to react to the schedule changes that it needs to react to and ignore those that it does not care about.
    • Method Detail

      • isAutoStartFlag

        public final boolean isAutoStartFlag()
        Returns:
        true if the schedule starts automatically
      • getStartEventPriority

        public final int getStartEventPriority()
        Returns:
        the priority associated with the schedule's start event
      • getItemStartEventPriority

        public final int getItemStartEventPriority()
        Returns:
        the priority associated with the item's start event
      • getInitialStartTime

        public final double getInitialStartTime()
        Returns:
        the time relative to the start of the simulation that indicates when the schedule should start
      • isScheduleRepeatable

        public final boolean isScheduleRepeatable()
        Returns:
        true if the schedule repeats after completing
      • getScheduleLength

        public final double getScheduleLength()
        Returns:
        the length or duration of the schedule
      • getCycleStartTime

        public final double getCycleStartTime()
        Returns:
        when the schedule actually starts, if repeated the time it last started
      • cancelScheduleStart

        public final void cancelScheduleStart()
        If scheduled to start, this cancels the start of the schedule.
      • addScheduleChangeListener

        public void addScheduleChangeListener​(ScheduleChangeListenerIfc listener)
        The same listener cannot be added more than once. Listeners are notified of schedule changes in the sequence by which they were added.
        Parameters:
        listener - the listener to add to the schedule
      • deleteScheduleChangeListener

        public void deleteScheduleChangeListener​(ScheduleChangeListenerIfc listener)
        Parameters:
        listener - the listener to delete from the schedule
      • deleteScheduleChangeListeners

        public void deleteScheduleChangeListeners()
        Deletes all listeners
      • contains

        public boolean contains​(ScheduleChangeListenerIfc listener)
        Parameters:
        listener - the listener to check
        Returns:
        true if the listener is already added
      • countScheduleChangeListeners

        public int countScheduleChangeListeners()
        Returns:
        the number of listeners
      • addItem

        public Schedule.ScheduleItem addItem​(double duration)
        Adds an item to the schedule with priority JSLEvent.DEFAULT_PRIORITY and default start time of 0.0 (i.e. when the schedule starts)
        Parameters:
        duration - the duration of the item
        Returns:
        the created ScheduleItem
      • addItem

        public Schedule.ScheduleItem addItem​(double startTime,
                                             double duration)
        Adds an item to the schedule with priority JSLEvent.DEFAULT_PRIORITY
        Parameters:
        startTime - the time past the start of the schedule to start the item
        duration - the duration of the item
        Returns:
        the created ScheduleItem
      • addItem

        public Schedule.ScheduleItem addItem​(double startTime,
                                             double duration,
                                             int priority)
        Adds an item to the schedule
        Parameters:
        startTime - the time past the start of the schedule to start the item
        duration - the duration of the item
        priority - the priority, among items, if items start at the same time
        Returns:
        the created ScheduleItem
      • addItem

        public <T> Schedule.ScheduleItem<T> addItem​(double startTime,
                                                    double duration,
                                                    T message)
        Adds an item to the schedule with priority JSLEvent.DEFAULT_PRIORITY
        Type Parameters:
        T - the type of the message
        Parameters:
        startTime - the time past the start of the schedule to start the item
        duration - the duration of the item
        message - a message or datum to attach to the item
        Returns:
        the created ScheduleItem
      • addItem

        public <T> Schedule.ScheduleItem<T> addItem​(double startTime,
                                                    double duration,
                                                    int priority,
                                                    T message)
        Adds an item to the schedule
        Type Parameters:
        T - the type of the message
        Parameters:
        startTime - the time past the start of the schedule to start the item
        duration - the duration of the item
        priority - the priority, (among items) if items start at the same time
        message - a message or datum to attach to the item
        Returns:
        the created ScheduleItem
      • removeItem

        public void removeItem​(Schedule.ScheduleItem item)
        Removes the item from the schedule. If the item is null or not on this schedule nothing happens.
        Parameters:
        item - the item to remove
      • clearSchedule

        public void clearSchedule()
        Removes all schedule items from the schedule
      • asString

        public java.lang.String asString()
        Description copied from class: ModelElement
        Allows sub-classes to provide more detail than toString() to represent the ModelElement as a String
        Overrides:
        asString in class ModelElement
        Returns:
        a detailed String representation
      • notifyScheduleChangeListenersScheduleStarted

        protected void notifyScheduleChangeListenersScheduleStarted()
      • notifyScheduleChangeListenersScheduleEnded

        protected void notifyScheduleChangeListenersScheduleEnded()
      • notifyScheduleChangeListenersScheduleItemEnded

        protected void notifyScheduleChangeListenersScheduleItemEnded​(Schedule.ScheduleItem<?> item)
      • notifyScheduleChangeListenersScheduleItemStarted

        protected void notifyScheduleChangeListenersScheduleItemStarted​(Schedule.ScheduleItem<?> item)
      • 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
      • afterReplication

        protected void afterReplication()
        Description copied from class: ModelElement
        This method should be overridden by subclasses that need actions performed after each replication. It is called after replicationEnded() has been called.
        Overrides:
        afterReplication in class ModelElement
      • scheduleStart

        public final void scheduleStart()
        Schedules the start of the schedule for the start time of the schedule if it has not already be started
      • startSchedule

        protected void startSchedule​(JSLEvent evt)
      • endSchedule

        protected void endSchedule​(JSLEvent evt)
      • startItem

        protected void startItem​(JSLEvent evt)
      • endItem

        protected void endItem​(JSLEvent evt)
      • scheduleEndOfSchedule

        protected final void scheduleEndOfSchedule()