Class JSLEvent<T>

  • Type Parameters:
    T - the type associated with the (optional) message sent with the event
    All Implemented Interfaces:
    java.lang.Comparable<JSLEvent>, GetNameIfc

    public class JSLEvent<T>
    extends java.lang.Object
    implements java.lang.Comparable<JSLEvent>, GetNameIfc
    This class represents a simulated event. This file contains the JSLEvent class. It allows for the simulation of durations of simulated time. These events are placed on the Executive and ordered by time, priority, and order of creation. JSLEvents are the mechanism by which ModelElements notify each other of work to be done.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compareTo​(JSLEvent event)
      Returns a negative integer, zero, or a positive integer if this object is less than, equal to, or greater than the specified object.
      protected void execute()
      Called by the Executive class to cause the EventAction to have it's action method invoked
      boolean getCanceledFlag()
      Gets a flag indicating whether the event is to be canceled or not.
      Entity getEntity()
      Gets the entity attached to the event, if set May be null
      EventActionIfc getEventAction()
      Gets the EventListenerIfc
      long getId()
      Gets the the id assigned to the event by the scheduler.
      T getMessage()
      Returns the object representing the message sent with the event
      ModelElement getModelElement()
      Returns the ModelElement that scheduled the event
      java.lang.String getName()
      Gets the name of the event
      int getPriority()
      Gets the priority of the event
      double getTime()
      Gets the time that the event is schedule for.
      int getType()
      Gets the type of the event.
      boolean isScheduled()
      Gets a flag indicating whether the event is in the event calendar, i.e.
      void setCanceledFlag​(boolean b)
      Indicates to the scheduler that the event should be canceled or not.
      void setEntity​(Entity e)
      Allows the setting of an entity that is sent with the event.
      protected void setId​(long id)
      Sets the id of the event, package scope because only the Scheduler should be setting the id
      protected void setModelElement​(ModelElement mElement)
      Sets the ModelElement that scheduled the event.
      void setName​(java.lang.String name)
      Sets the name of the event.
      protected void setPriority​(int p)
      Sets the scheduled priority of the event, package scope because only the Scheduler should indicate the priority of the event
      protected void setTime​(double t)
      Sets the scheduled time of the event, protected scope because only the Scheduler should indicate when the event is scheduled
      void setType​(int type)
      Sets the type of the event.
      java.lang.String toString()
      Provides a string representation for the event.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • DEFAULT_PRIORITY

        public static final int DEFAULT_PRIORITY
        Represents the default priority for events within the Executive DEFAULT_PRIORITY = 10. Lower priority goes first. All integer priority numbers can be used to set the priority of an event.
        See Also:
        Constant Field Values
      • DEFAULT_END_REPLICATION_EVENT_PRIORITY

        public static final int DEFAULT_END_REPLICATION_EVENT_PRIORITY
        Default event priority for the end replication event
        See Also:
        Constant Field Values
      • DEFAULT_WARMUP_EVENT_PRIORITY

        public static final int DEFAULT_WARMUP_EVENT_PRIORITY
        A constant for the default warm up event priority
        See Also:
        Constant Field Values
      • DEFAULT_BATCH_PRIORITY

        public static final int DEFAULT_BATCH_PRIORITY
        A constant for the default batch priority
        See Also:
        Constant Field Values
      • DEFAULT_TYPE

        public static final int DEFAULT_TYPE
        The default type for an event is zero. It is just a number that can be use to map over to event type
        See Also:
        Constant Field Values
    • Method Detail

      • setEntity

        public final void setEntity​(Entity e)
        Allows the setting of an entity that is sent with the event.
        Parameters:
        e - Represents the Entity
      • getEntity

        public final Entity getEntity()
        Gets the entity attached to the event, if set May be null
        Returns:
        the entity attached to the event
      • getModelElement

        public final ModelElement getModelElement()
        Returns the ModelElement that scheduled the event
        Returns:
        the ModelElement that scheduled the event
      • setName

        public final void setName​(java.lang.String name)
        Sets the name of the event. Useful for tracing events.
        Parameters:
        name - A String representing the name of the event
      • setType

        public final void setType​(int type)
        Sets the type of the event. Useful for tracing events. or distinguishing between events.
        Parameters:
        type - An integer representing the type of the event
      • setCanceledFlag

        public final void setCanceledFlag​(boolean b)
        Indicates to the scheduler that the event should be canceled or not. True implies that the event is to be canceled. It is up to the scheduler to handle the cancellation. If the event is canceled, it's execute method will not be called when it becomes the current event. Thus, an event can be canceled or uncanceled at any simulated time prior to when the event is scheduled to occur. It is an error to attempt to cancel and event that is not scheduled.
        Parameters:
        b - A boolean (true is canceled, false is not canceled)
      • getMessage

        public final T getMessage()
        Returns the object representing the message sent with the event
        Returns:
        Object representing the message sent with the event
      • getEventAction

        public final EventActionIfc getEventAction()
        Gets the EventListenerIfc
        Returns:
        The object representing the EventListenerIfc
      • getName

        public final java.lang.String getName()
        Gets the name of the event
        Specified by:
        getName in interface GetNameIfc
        Returns:
        The name of the event
      • getTime

        public final double getTime()
        Gets the time that the event is schedule for.
        Returns:
        A double representing simulated time
      • getPriority

        public final int getPriority()
        Gets the priority of the event
        Returns:
        An int representing the priority. Lower is better.
      • getId

        public final long getId()
        Gets the the id assigned to the event by the scheduler. No two events have the same id.
        Returns:
        A long representing the id
      • getType

        public final int getType()
        Gets the type of the event. Useful for tracing events. or distinguishing between events.
        Returns:
        an int representing the type of the event.
      • getCanceledFlag

        public final boolean getCanceledFlag()
        Gets a flag indicating whether the event is to be canceled or not. True implies that the event is to be canceled. It is up to the scheduler to handle the cancellation. If the event is canceled, it's execute method will not be called when it becomes the current event. Thus, an event can be canceled or uncanceled at any simulated time prior to when the event is scheduled to occur.
        Returns:
        b A boolean (true is canceled, false is not canceled)
      • isScheduled

        public final boolean isScheduled()
        Gets a flag indicating whether the event is in the event calendar, i.e. it has been scheduled.

        True implies that the event has been scheduled. It is an error to attempt to schedule an event that has already been scheduled.

        Returns:
        A boolean (true is scheduled, false is not scheduled)
      • toString

        public java.lang.String toString()
        Provides a string representation for the event. Useful for tracing
        Overrides:
        toString in class java.lang.Object
        Returns:
        A String representing the event
      • setModelElement

        protected final void setModelElement​(ModelElement mElement)
        Sets the ModelElement that scheduled the event.
        Parameters:
        mElement - the model element that scheduled the event, cannot be null
      • setId

        protected final void setId​(long id)
        Sets the id of the event, package scope because only the Scheduler should be setting the id
        Parameters:
        id - Provided by the Scheduler class
      • setTime

        protected final void setTime​(double t)
        Sets the scheduled time of the event, protected scope because only the Scheduler should indicate when the event is scheduled
        Parameters:
        t - Provided by the Scheduler class. The time of the event.
      • setPriority

        protected final void setPriority​(int p)
        Sets the scheduled priority of the event, package scope because only the Scheduler should indicate the priority of the event
        Parameters:
        p - Provided by the Scheduler class
      • execute

        protected final void execute()
        Called by the Executive class to cause the EventAction to have it's action method invoked
      • compareTo

        public final int compareTo​(JSLEvent event)
        Returns a negative integer, zero, or a positive integer if this object is less than, equal to, or greater than the specified object.

        Natural ordering: time, then priority, then order of creation

        Lower time, lower priority, lower order of creation goes first

        Throws ClassCastException if the specified object's type prevents it from begin compared to this object.

        Throws RuntimeException if the id's of the objects are the same, but the references are not when compared with equals.

        Note: This class may have a natural ordering that is inconsistent with equals.

        Specified by:
        compareTo in interface java.lang.Comparable<T>
        Parameters:
        event - The event to compare this event to
        Returns:
        Returns a negative integer, zero, or a positive integer if this object is less than, equal to, or greater than the specified object.