SSJ
V. 1.2.5.

umontreal.iro.lecuyer.simevents
Class Event

java.lang.Object
  extended by umontreal.iro.lecuyer.simevents.Event

public abstract class Event
extends Object

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.

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.


Constructor Summary
Event()
          Constructs a new event instance, which can be placed afterwards into the event list.
 
Method Summary
abstract  void actions()
          This is the method that is executed when this event occurs.
 boolean cancel()
          Cancels this event before it occurs.
static boolean cancel(String type)
          Finds the first occurence of an event of class ``type'' in the event list, and cancels it.
 void reschedule(double delay)
          Cancels this event and reschedules it to happen in delay time units.
 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.
 void scheduleAfter(Event other)
          Schedules this event to happen just after, and at the same time, as the event other.
 void scheduleBefore(Event other)
          Schedules this event to happen just before, and at the same time, as the event other.
 void scheduleNext()
          Schedules this event as the first event in the event list, to be executed at the current time (as the next event).
 double setTime(double time)
          Sets the (planned) time of occurence of this event to time.
 double time()
          Returns the (planned) time of occurence of this event.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Event

public Event()
Constructs a new event instance, which can be placed afterwards into the event list. For example, if Bang is an Event subclass, the statement ``new Bang().scheduleNext();'' creates a new Bang event and places it at the beginning of the event list.

Method Detail

schedule

public 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, they are placed in the event list (and executed) in the same order as they have been scheduled.

Parameters:
delay - simulation time that must pass before the event happens

scheduleNext

public void scheduleNext()
Schedules this event as the first event in the event list, to be executed at the current time (as the next event).


scheduleBefore

public 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


         Bang bigOne = new Bang().schedule (12.0);
         new Bing().scheduleBefore (bigOne);
   
the event list contains two new events scheduled to happen in 12 units of time: a Bing event, followed by a Bang called bigOne.

Parameters:
other - event before which this event will be scheduled

scheduleAfter

public void scheduleAfter(Event other)
Schedules this event to happen just after, and at the same time, as the event other.

Parameters:
other - event after which this event will be scheduled

reschedule

public void reschedule(double delay)
Cancels this event and reschedules it to happen in delay time units.

Parameters:
delay - simulation time units that must elapse before the event happens

cancel

public boolean cancel()
Cancels this event before it occurs. Returns true if cancellation succeeds (this event was found in the event list), false otherwise.

Returns:
true if the event could be cancelled

cancel

public static 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.

Parameters:
type - name of an event subclass
Returns:
true if an event of this class was found and cancelled

time

public final double time()
Returns the (planned) time of occurence of this event.

Returns:
the time of occurence of the event

setTime

public final double 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.

Parameters:
time - new time of occurence for the event
Returns:
the new event time

actions

public abstract void actions()
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.


SSJ
V. 1.2.5.

To submit a bug or ask questions, send an e-mail to Pierre L'Ecuyer.