SSJ
V. 1.2.5.

umontreal.iro.lecuyer.simprocs
Class AbstractSimProcess

java.lang.Object
  extended by umontreal.iro.lecuyer.simprocs.AbstractSimProcess
Direct Known Subclasses:
SimProcess, SimProcess

public abstract class AbstractSimProcess
extends Object

This abstract class provides process scheduling tools. Each type of process should be defined as a subclass of the class AbstractSimProcess, and must provide an implementation of the method actions which describes the life of a process of this class. Whenever a process instance starts, its actions method begins executing.

Just like an event, a process must first be constructed, then scheduled. Scheduling a process is equivalent to placing an event in the event list that will start this process when the simulation clock reaches the specified time. The toString method can be overridden to return information about the process. This information will be returned when formating the event list as a string, if the process is delayed.

A process can be in one of the following states: INITIAL, EXECUTING, DELAYED, SUSPENDED, and DEAD . At most one process can be in the EXECUTING state at any given time, and when there is one, this executing process (called the current process) is said to have control and is executing one of the instructions of its actions method. A process that has been constructed but not yet scheduled is in the INITIAL state. A process is in the DELAYED state if there is a planned event in the event list to activate it (give it control). When a process is scheduled, it is placed in the DELAYED state. It is in the SUSPENDED state if it is waiting to be reactivated (i.e., obtain control) without having an event to do so in the event list. A process can suspends itself by calling suspend directly or indirectly (e.g., by requesting a busy Resource). Usually, a SUSPENDED process must be reactivated by another process or event via the resume method. A process in the DEAD state no longer exists.

It is important to note that when processes are used in a simulation, the simulation clock and event list must be initialized via SimProcess.init instead of Sim.init.

To construct new processes, the user needs to extend one of the two subclasses of AbstractSimProcess. A simulation program should always use the same process base class. The SimProcess subclass implements processes by using Java threads. This is the fastest implementation. The SimProcess from package simprocs.dsol uses the DSOL interpreter to simulate processes in a single-threaded program, but it is much slower than the multi-threaded implementation.


Field Summary
static int DEAD
          The process has terminated its execution.
static int DELAYED
          The process is not executing but has an event in the event list to reactivate it later on.
static int EXECUTING
          The process is the one currently executing its actions method.
static int INITIAL
          The process has been created but not yet scheduled.
static int SUSPENDED
          The process is not executing and will have to be reactivated by another process or event later on.
 
Constructor Summary
AbstractSimProcess()
          Constructs a new process without scheduling it.
 
Method Summary
abstract  void actions()
          This is the method that is called when this process is executing.
 boolean cancel()
          Cancel the activating event that was supposed to resume this process, and place the process in the SUSPENDED state.
static AbstractSimProcess currentProcess()
          Returns the process that is currently executing, if any.
abstract  void delay(double delay)
          Suspends the execution of the currently executing process and schedules it to resume its execution in delay units of simulation time.
 double getDelay()
          If the process is in the DELAYED state, returns the remaining time until the planned occurrence of its activating event.
 int getState()
          Returns the state of the process.
 boolean isAlive()
          Returns true if the process is alive, otherwise false.
abstract  void kill()
          Terminates the life of this process and sets its state to DEAD, after canceling its activating event if there is one.
 void reschedule(double delay)
          If the process is in the DELAYED state, removes it from the event list and reschedules it in delay units of time.
 void resume()
          Places this process at the beginning of the event list to resume its execution.
 void schedule(double delay)
          Schedules the process to start in delay time units.
 void scheduleNext()
          Schedules this process to start at the current time, by placing it at the beginning of the event list.
abstract  void suspend()
          This method can only be invoked for the EXECUTING or a DELAYED process.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INITIAL

public static final int INITIAL
The process has been created but not yet scheduled.

See Also:
Constant Field Values

EXECUTING

public static final int EXECUTING
The process is the one currently executing its actions method.

See Also:
Constant Field Values

DELAYED

public static final int DELAYED
The process is not executing but has an event in the event list to reactivate it later on.

See Also:
Constant Field Values

SUSPENDED

public static final int SUSPENDED
The process is not executing and will have to be reactivated by another process or event later on.

See Also:
Constant Field Values

DEAD

public static final int DEAD
The process has terminated its execution.

See Also:
Constant Field Values
Constructor Detail

AbstractSimProcess

public AbstractSimProcess()
Constructs a new process without scheduling it. It will have to be scheduled later on. The process is in the INITIAL state.

Method Detail

schedule

public void schedule(double delay)
Schedules the process to start in delay time units. This puts the process in the DELAYED state.

Parameters:
delay - delay, in simulation time, before the process starts

scheduleNext

public void scheduleNext()
Schedules this process to start at the current time, by placing it at the beginning of the event list. This puts the process in the DELAYED state.


currentProcess

public static AbstractSimProcess currentProcess()
Returns the process that is currently executing, if any. Otherwise, returns null.

Returns:
the currently executing process

isAlive

public final boolean isAlive()
Returns true if the process is alive, otherwise false.

Returns:
true if the process is not in the DEAD state

getState

public int getState()
Returns the state of the process.

Returns:
one of the process states INITIAL, EXECUTING, DELAYED, SUSPENDED, or DEAD.

getDelay

public double getDelay()
If the process is in the DELAYED state, returns the remaining time until the planned occurrence of its activating event. Otherwise, an illegal state exception will be thrown printing an error message.

Returns:
remaining delay before the process starts
Throws:
IllegalStateException - if the process is not in DELAYED state

delay

public abstract void delay(double delay)
Suspends the execution of the currently executing process and schedules it to resume its execution in delay units of simulation time. It becomes in the DELAYED state. Only the process in the EXECUTING state can call this method.

Parameters:
delay - delay, in simulation time, before the process is resumed

reschedule

public void reschedule(double delay)
If the process is in the DELAYED state, removes it from the event list and reschedules it in delay units of time. Example: If the process p has called delay (5.0) at time 10.0, and another process invokes reschedule (p, 6.2) at time 13.5, then the process p will resume at time 13.5 + 6.2 = 19.7.

Parameters:
delay - new delay, in simulation time units, before the process starts or is resumed

suspend

public abstract void suspend()
This method can only be invoked for the EXECUTING or a DELAYED process. If the process is EXECUTING, suspends execution. If the process is DELAYED, cancels its activating event. This places the process in the SUSPENDED state.


resume

public void resume()
Places this process at the beginning of the event list to resume its execution. If the process was DELAYED, cancels its earlier activating event.


cancel

public boolean cancel()
Cancel the activating event that was supposed to resume this process, and place the process in the SUSPENDED state. This method can be invoked only for a process in the DELAYED state.

Returns:
true if the process was canceled successfully

kill

public abstract void kill()
Terminates the life of this process and sets its state to DEAD, after canceling its activating event if there is one.


actions

public abstract void actions()
This is the method that is called when this process is executing. Every subclass of SimProcess 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.