Package jsl.simulation
Class JSLEvent<T>
- java.lang.Object
-
- jsl.simulation.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.
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_BATCH_PRIORITYA constant for the default batch prioritystatic intDEFAULT_END_REPLICATION_EVENT_PRIORITYDefault event priority for the end replication eventstatic intDEFAULT_PRIORITYRepresents the default priority for events within the Executive DEFAULT_PRIORITY = 10.static intDEFAULT_TYPEThe default type for an event is zero.static intDEFAULT_WARMUP_EVENT_PRIORITYA constant for the default warm up event priority
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(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 voidexecute()Called by the Executive class to cause the EventAction to have it's action method invokedbooleangetCanceledFlag()Gets a flag indicating whether the event is to be canceled or not.EntitygetEntity()Gets the entity attached to the event, if set May be nullEventActionIfcgetEventAction()Gets the EventListenerIfclonggetId()Gets the the id assigned to the event by the scheduler.TgetMessage()Returns the object representing the message sent with the eventModelElementgetModelElement()Returns the ModelElement that scheduled the eventjava.lang.StringgetName()Gets the name of the eventintgetPriority()Gets the priority of the eventdoublegetTime()Gets the time that the event is schedule for.intgetType()Gets the type of the event.booleanisScheduled()Gets a flag indicating whether the event is in the event calendar, i.e.voidsetCanceledFlag(boolean b)Indicates to the scheduler that the event should be canceled or not.voidsetEntity(Entity e)Allows the setting of an entity that is sent with the event.protected voidsetId(long id)Sets the id of the event, package scope because only the Scheduler should be setting the idprotected voidsetModelElement(ModelElement mElement)Sets the ModelElement that scheduled the event.voidsetName(java.lang.String name)Sets the name of the event.protected voidsetPriority(int p)Sets the scheduled priority of the event, package scope because only the Scheduler should indicate the priority of the eventprotected voidsetTime(double t)Sets the scheduled time of the event, protected scope because only the Scheduler should indicate when the event is scheduledvoidsetType(int type)Sets the type of the event.java.lang.StringtoString()Provides a string representation for the event.
-
-
-
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:
getNamein interfaceGetNameIfc- 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:
toStringin classjava.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:
compareToin interfacejava.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.
-
-