SSJ
3.3.1
Stochastic Simulation in Java
|
This abstract class provides event scheduling tools. More...
Public Member Functions | |
final int | getRa () |
final void | setRa (int r) |
Event () | |
Constructs a new event instance, which can be placed afterwards into the event list of the default simulator by calling one of the schedule... variants. More... | |
Event (Simulator sim) | |
Construct a new event instance associated with the given simulator. More... | |
void | schedule (double delay) |
Schedules this event to happen in delay time units, i.e., at time sim.time() + delay , by inserting it in the event list. More... | |
void | scheduleNext () |
Schedules this event as the first event in the event list, to be executed at the current time (as the next event). | |
void | scheduleBefore (Event other) |
Schedules this event to happen just before, and at the same time, as the event other . More... | |
void | scheduleAfter (Event other) |
Schedules this event to happen just after, and at the same time, as the event other . More... | |
void | reschedule (double delay) |
Cancels this event and reschedules it to happen in delay time units. More... | |
boolean | cancel () |
Cancels this event before it occurs. More... | |
final boolean | cancel (String type) |
Finds the first occurence of an event of class "type" in the event list, and cancels it. More... | |
final Simulator | simulator () |
Returns the simulator linked to this event. More... | |
final void | setSimulator (Simulator sim) |
Sets the simulator associated with this event to sim . More... | |
final double | time () |
Returns the (planned) time of occurence of this event. More... | |
final void | setTime (double time) |
Sets the (planned) time of occurence of this event to time . More... | |
final double | priority () |
Returns the priority of this event. More... | |
final void | setPriority (double priority) |
Sets the priority of this event to inPriority . More... | |
int | compareTo (Event e) |
Compares this object with the specified object e for order. More... | |
abstract void | actions () |
This is the method that is executed when this event occurs. More... | |
Protected Attributes | |
Simulator | sim |
double | priority |
double | eventTime |
This abstract class provides event scheduling tools.
Each type of event should be defined as a subclass of the class Event
, and should provide an implementation of the method actions which is executed when an event of this type occurs. The instances of these subclasses are the actual events.
Each event is linked to a simulator represented by an instance of Simulator before it can be scheduled and processed. A default simulator, given by Simulator.getDefaultSimulator
, is used if no simulator is linked explicitly with an event. When an event is constructed, it is not scheduled. It must be scheduled separately by calling one of the scheduling methods schedule, scheduleNext, scheduleBefore, etc. An event can also be cancelled before it occurs.
A scheduled event has an associated time at which it will happen and a priority, which can be queried using the methods time and #priority, respectively. By default, events occur in ascending order of time, and have priority 1. Events with the same time occur in ascending order of priority. For example, if events e1
and e2
occur at the same time with priority 2 and 1 respectively, then e2
will occur before e1
. Events with the same time and priority occur in the order they were scheduled.
Event | ( | ) |
Constructs a new event instance, which can be placed afterwards into the event list of the default simulator by calling one of the schedule...
variants.
For example, if Bang
is an Event
subclass, the statement "<tt>new Bang().scheduleNext();</tt>" creates a new Bang
event and places it at the beginning of the event list.
Constructs a new event and inserts it in the event list of the default simulator. If delay >= 0.0
, the event is scheduled to happen in delay
units of simutated time. If two or more events are scheduled to happen at the same time, events with the highest priorities (lowest value of the priority
field) occur first. If two or more events are schedule to the same time, with the same priority, they are placed in the event list (and executed) in the same order as they have been scheduled.
We recall that such constructors with parameters are not inherited automatically by the subclasses in Java, but they can be invoked using super
. For example, one can have
and then invoke the constructor "<tt>new Bang (10.0)</tt>" to get a Bang
in 10 units of time. This is equivalent to "<tt>new
Bang().schedule(10.0)</tt>."
delay | simulation time that must pass before the event happens |
|
abstract |
This is the method that is executed when this event occurs.
Every subclass of Event
that is to be instantiated must provide an implementation of this method.
boolean cancel | ( | ) |
Cancels this event before it occurs.
Returns true
if cancellation succeeds (this event was found in the event list), false
otherwise.
true
if the event could be cancelled final boolean cancel | ( | String | type | ) |
Finds the first occurence of an event of class "type" in the event list, and cancels it.
Returns true
if cancellation succeeds, false
otherwise.
type | name of an event subclass |
true
if an event of this class was found and cancelled int compareTo | ( | Event | e | ) |
Compares this object with the specified object e
for order.
Returns \(-1\) or \(+1\) as this event occurs before or after the specified event e
, respectively. If the two events occur at the same time, then returns \(-1\), \(0\), or \(+1\) as this event has a smaller, equal, or larger priority than event e
.
final double priority | ( | ) |
Returns the priority of this event.
void reschedule | ( | double | delay | ) |
Cancels this event and reschedules it to happen in delay
time units.
delay | simulation time units that must elapse before the event happens |
void schedule | ( | double | delay | ) |
Schedules this event to happen in delay
time units, i.e., at time sim.time() + delay
, by inserting it in the event list.
When two or more events are scheduled to happen at the same time and with the same priority, they are placed in the event list (and executed) in the same order as they have been scheduled. Note that the priority of this event should be adjusted using setPriority before it is scheduled.
delay | simulation time that must pass before the event happens |
void scheduleAfter | ( | Event | other | ) |
Schedules this event to happen just after, and at the same time, as the event other
.
other | event after which this event will be scheduled |
void scheduleBefore | ( | Event | other | ) |
Schedules this event to happen just before, and at the same time, as the event other
.
For example, if Bing
and Bang
are Event
subclasses, after the statements
the event list contains two new events scheduled to happen in 12 units of time: a Bing
event, followed by a Bang
called bigOne
.
other | event before which this event will be scheduled |
final void setPriority | ( | double | priority | ) |
Sets the priority of this event to inPriority
.
This method should never be called after the event was scheduled, otherwise the events would not execute in ascending priority order anymore.
priority | new priority for the event |
final void setSimulator | ( | Simulator | sim | ) |
Sets the simulator associated with this event to sim
.
This method should not be called while this event is in an event list.
sim | the Simulator |
final void setTime | ( | double | time | ) |
Sets the (planned) time of occurence of this event to time
.
This method should never be called after the event was scheduled, otherwise the events would not execute in ascending time order anymore.
time | new time of occurence for the event |
final Simulator simulator | ( | ) |
Returns the simulator linked to this event.
final double time | ( | ) |
Returns the (planned) time of occurence of this event.