Class LogicalProcess

java.lang.Object
  extended by LogicalProcess
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
Phold, Ping, Pong

public abstract class LogicalProcess
extends java.lang.Object
implements java.io.Serializable

This class represents a logical processe that communicates with other logical processes by exchanging timestamped messages. LPs cannot "spontaneously" begin new computations without first receiving a message.

If an LP receives a "straggler" message with timestamps smaller than that its LVT(local virtual time), it rolls back to its LVT and reprocessed (after the straggler) in timestamp order. Each message sent by a rolled back computation is cancelled by sending an anti-message that annihilates the original message. A received anti-message will also cause a rollback if the cancelled message has already been processed.

This is an abstract class. The simulation application programmer needs to implement the abstract methods specified in this class. All such methods are prefixed "app" for ease of recognition.

Version 1.5 changes monitoring/steering yet again. It also adapts the class to the new multi-threaded design (in which the PE scheduling loop is a separate thread from the PE communication loop). As a result, this class (which is handled entirely by the scheduling loop) handles much less of the communication work than earlier versions did.

Version 1.6 changes the format of monitoring/steering slightly (using Strings instead of Objects).

Version 1.7 added a few abstract methods for application programmers to implement. These methods are needed for state-saving and rollback by the kernel.

Version:
1.7 (07/2006)
Author:
Yin Xiong, Glenn Matthews
See Also:
Serialized Form

Field Summary
static java.lang.String ALL_LPS
          Reserved APPid indicating a message to be broadcast to every LP rather than sent to a single specific LP.
(package private)  java.lang.String APPid
          Unique application-assigned identifier of this LP
 java.lang.String configData
          Configuration data string.
protected  int currentTime
          Local virtual time(LVT) for this LP.
protected  int lastTime
          Value of currentTime the previous time runLP(Message) was called.
(package private)  int LPid
          Unique numeric identifier assigned to this LP by the system.
(package private)  java.lang.String myname
          Unique application-assigned full name of this LP
(package private)  int PEid
          Unique numeric identifier for the PE where this LP resides; for debugging purposes
(package private)  SchedulingLoop scheduler
          SchedulingLoop that this LP can access; it's declared transient so it won't be serialized and copied each time this LP's state is saved
 
Constructor Summary
LogicalProcess()
           
 
Method Summary
abstract  void appFinalizeLP()
          Terminates LP and displays simulation statistics.
abstract  java.util.List<java.lang.String> appGetMonitorable()
          Returns a List of Strings describing all application-specific monitorable parameters of this LP, each in the form "paramName, paramType".
abstract  java.lang.String appGetState(java.lang.String name)
          Method to get the value of a given application-level monitorable variable.
abstract  java.util.List<java.lang.String> appGetSteerable()
          Returns a List of Strings describing all application-specific steerable parameters of this LP, each in the form "paramName, paramType".
abstract  boolean appInitializeLP()
          Initializes the LP state and sends out initial message(s) if necessary.
abstract  void appRunLP(java.lang.Object content, java.lang.String sender)
          Handles events according to the specific requirements of the simulation application.
abstract  LogicalProcess appSavingLPState()
          Save LP state, for monitoring-steering purpose
abstract  void appSetConfigData(java.lang.String cdata)
          Application-specific configuration.
abstract  void appSetLPState(LogicalProcess lp)
          Application LP sets LP state
abstract  java.lang.String appSetState(java.lang.String name, java.lang.String val)
          Method to set the value of a given application-level monitorable variable.
abstract  java.lang.String appToString()
          Returns a string representation of the application lp; for debugging purpose
 void finalizeLP()
          Invokes application-specific termination then does any needed generic cleanup.
 java.lang.String getAPPid()
          Returns the application-assigned id of this LP.
 int getCurrentTime()
          Returns the current simulation time of this LogicalProcess.
 int getLID()
          Returns the LP id.
 java.util.List<java.lang.String> getMonitorable()
          Returns a List of Strings describing all monitorable parameters of this LP, each in the form "paramName, paramType".
 java.lang.String getName()
          Returns the name of this LP.
 int getPID()
          Returns PE id where this LP resides.
 java.lang.String getState(java.lang.String name)
          Method to get the value of a given monitorable variable.
 java.util.List<java.lang.String> getSteerable()
          Returns a List of Strings describing all steerable parameters of this LP, each in the form "paramName, paramType".
 boolean initializeLP()
          Performs generic initialization (if any) then invokes application-specific initialization.
(package private)  void rollback(LogicalProcess lpState, int rbtime)
          Rolls back to the the specified time point and restore the state of this LP
 void runLP(Message msg)
          Handles any events that need to occur before or after any given invocation of appRunLP(java.lang.Object, java.lang.String).
(package private)  void savingLPState(LogicalProcess lp)
          Saves the state of this LP
 void sendSimMessage(java.lang.Object content, int timeInc, int targetLPid)
          Informs the SchedulingLoop of a new outgoing simulation message.
 void sendSimMessage(java.lang.Object content, int timeInc, java.lang.String targetAPPid)
          Informs the SchedulingLoop of a new outgoing simulation message.
 void setAppID(java.lang.String aid)
          Sets the application-specific short id for this LP.
 void setConfigData(java.lang.String cdata)
          Stores the application-specific data used for configuration and passes it on to the application to apply.
 void setEndOfSimFlag()
          Sets the end-of-sim flag so the simulation will stop.
 void setLID(int lid)
          Sets the LP id for this LP.
(package private)  void setLPState(LogicalProcess lp)
          Sets the state of this LP to the state of the LP passed in as parameter
 void setName(java.lang.String n)
          Sets the long name of this LP.
 void setPID(int pid)
          Sets the PE id where the LP resides.
 void setScheduler(SchedulingLoop sl)
          Assigns the SchedulingLoop for this LP.
 java.lang.String setState(java.lang.String name, java.lang.String val)
          Method to set the value of a given steerable variable.
 java.lang.String toString()
          Provides a String summarizing this LogicalProcess.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ALL_LPS

public static final java.lang.String ALL_LPS
Reserved APPid indicating a message to be broadcast to every LP rather than sent to a single specific LP.

Since:
1.3
See Also:
Constant Field Values

PEid

int PEid
Unique numeric identifier for the PE where this LP resides; for debugging purposes


LPid

int LPid
Unique numeric identifier assigned to this LP by the system.


APPid

java.lang.String APPid
Unique application-assigned identifier of this LP


myname

java.lang.String myname
Unique application-assigned full name of this LP


configData

public java.lang.String configData
Configuration data string. Cached in expectation that future versions may support "suspending" the simulation and writing the simulation status to disk to be resumed at a later time.


currentTime

protected int currentTime
Local virtual time(LVT) for this LP. Automatically updated every time runLP(Message) is called to match the timestamp of the incoming Message. Subclasses may make other changes to this, but generally should not need to!


lastTime

protected int lastTime
Value of currentTime the previous time runLP(Message) was called. Again, automatically updated by runLP; subclasses may make other changes to it, but only with very good reason.


scheduler

transient SchedulingLoop scheduler
SchedulingLoop that this LP can access; it's declared transient so it won't be serialized and copied each time this LP's state is saved

Constructor Detail

LogicalProcess

public LogicalProcess()
Method Detail

savingLPState

void savingLPState(LogicalProcess lp)
Saves the state of this LP

Since:
1.7

setLPState

void setLPState(LogicalProcess lp)
Sets the state of this LP to the state of the LP passed in as parameter

Since:
1.7

rollback

void rollback(LogicalProcess lpState,
              int rbtime)
Rolls back to the the specified time point and restore the state of this LP

Parameters:
lpState - LogicalProcess that contains the saved state of the LP
Since:
1.7

appSetLPState

public abstract void appSetLPState(LogicalProcess lp)
Application LP sets LP state

Parameters:
lp - LogicalProcess containing the state information; the application program decides what state information need to be stored
Since:
1.7

appSavingLPState

public abstract LogicalProcess appSavingLPState()
Save LP state, for monitoring-steering purpose


appToString

public abstract java.lang.String appToString()
Returns a string representation of the application lp; for debugging purpose


setEndOfSimFlag

public void setEndOfSimFlag()
Sets the end-of-sim flag so the simulation will stop.


sendSimMessage

public final void sendSimMessage(java.lang.Object content,
                                 int timeInc,
                                 java.lang.String targetAPPid)
Informs the SchedulingLoop of a new outgoing simulation message. This method is to be preferred by LogicalProcess implementations, because it requires no knowledge of the structure of Message.

Parameters:
content - The contents of the simulation message.
timeInc - the time increment assigned by the sender(@since 1.7)
targetAPPid - the APPid of the LP the message should go to.

sendSimMessage

public final void sendSimMessage(java.lang.Object content,
                                 int timeInc,
                                 int targetLPid)
Informs the SchedulingLoop of a new outgoing simulation message.

Parameters:
content - The contents of the simulation message.
timeInc - the time increment assigned by the sender(@since 1.7)
targetLPid - int the LPid of the receiver

setScheduler

public void setScheduler(SchedulingLoop sl)
Assigns the SchedulingLoop for this LP.

Parameters:
sl - SchedulingLoop to control this LP.

getPID

public int getPID()
Returns PE id where this LP resides.


setPID

public void setPID(int pid)
Sets the PE id where the LP resides. For debugging purposes.

Parameters:
pid - int representing the PE id.

getLID

public int getLID()
Returns the LP id.


setLID

public void setLID(int lid)
Sets the LP id for this LP. LP id is system-assigned.

Parameters:
lid - int representing the LP id.

getAPPid

public java.lang.String getAPPid()
Returns the application-assigned id of this LP.


setAppID

public void setAppID(java.lang.String aid)
Sets the application-specific short id for this LP.

Parameters:
aid - String representing the application-specific id for this LP.

getName

public java.lang.String getName()
Returns the name of this LP.


setName

public void setName(java.lang.String n)
Sets the long name of this LP.

Parameters:
n - String, the long name of this LP.

getCurrentTime

public int getCurrentTime()
Returns the current simulation time of this LogicalProcess.

Since:
1.5

setConfigData

public final void setConfigData(java.lang.String cdata)
Stores the application-specific data used for configuration and passes it on to the application to apply.

Parameters:
cdata - String representing the data that are used for configuration.

appSetConfigData

public abstract void appSetConfigData(java.lang.String cdata)
Application-specific configuration.

Parameters:
cdata - String representing configuration data.

getMonitorable

public final java.util.List<java.lang.String> getMonitorable()
Returns a List of Strings describing all monitorable parameters of this LP, each in the form "paramName, paramType". Handles all LogicalProcess parameters; calls appGetMonitorable() to get application-specific parameters. Monitorable parameters are:

Returns:
List containing all monitorable parameters of this LP.
Since:
1.5

appGetMonitorable

public abstract java.util.List<java.lang.String> appGetMonitorable()
Returns a List of Strings describing all application-specific monitorable parameters of this LP, each in the form "paramName, paramType".

Returns:
List listing all application-specific montiorable parameters.
Since:
1.5

getSteerable

public final java.util.List<java.lang.String> getSteerable()
Returns a List of Strings describing all steerable parameters of this LP, each in the form "paramName, paramType". Handles all LogicalProcess parameters; calls appGetSteerable() to get application-specific parameters. Steerable parameters include:

Returns:
List containing all steerable parameters of this LP.
Since:
1.5

appGetSteerable

public abstract java.util.List<java.lang.String> appGetSteerable()
Returns a List of Strings describing all application-specific steerable parameters of this LP, each in the form "paramName, paramType".

Returns:
List listing all application-specific steerable parameters.
Since:
1.5

getState

public final java.lang.String getState(java.lang.String name)
Method to get the value of a given monitorable variable. The PE that owns this LP will call this automatically when appropriate. Handles requests about any LogicalProcess variable; application variable requests fall through into appGetState(java.lang.String).

Parameters:
name - The name of the variable to monitor
Returns:
The value of the variable in question
Since:
1.5

appGetState

public abstract java.lang.String appGetState(java.lang.String name)
Method to get the value of a given application-level monitorable variable.

Parameters:
name - The name of the variable to monitor
Returns:
The value of the variable in question
Since:
1.5

setState

public final java.lang.String setState(java.lang.String name,
                                       java.lang.String val)
Method to set the value of a given steerable variable. The PE that owns this LP will call this automatically when appropriate. Handles requests about LogicalProcess variables; application-level requests fall through into appSetState(java.lang.String, java.lang.String).

Parameters:
name - The name of the variable to steer
val - The value to assign to the variable
Returns:
Null if the steering was successful, else a String describing the error that occurred.
Since:
1.5

appSetState

public abstract java.lang.String appSetState(java.lang.String name,
                                             java.lang.String val)
Method to set the value of a given application-level monitorable variable.

Parameters:
name - The name of the variable to steer
val - The value to assign to the variable
Returns:
Null if the steering was successful, else a String describing the error that occurred.
Since:
1.5

initializeLP

public final boolean initializeLP()
Performs generic initialization (if any) then invokes application-specific initialization. Equivalent of GTW's IProc method.

Returns:
false if initialization failed for some reason, true if successful.

appInitializeLP

public abstract boolean appInitializeLP()
Initializes the LP state and sends out initial message(s) if necessary. This is the counterpart of IProc in GTW. Sim application programmer has to implement this method.

Returns:
false if initialization failed for some reason, true if successful.

runLP

public final void runLP(Message msg)
Handles any events that need to occur before or after any given invocation of appRunLP(java.lang.Object, java.lang.String). This includes updating the local simulation time before invoking appRunLP.

Parameters:
msg - Message object received from another LP.

appRunLP

public abstract void appRunLP(java.lang.Object content,
                              java.lang.String sender)
Handles events according to the specific requirements of the simulation application. It is the counterpart of "Proc" in GTW. Sim application programmer has to implement this method.

Parameters:
content - The object associated with the new event.
sender - The APPid of the LP the event came from.

finalizeLP

public final void finalizeLP()
Invokes application-specific termination then does any needed generic cleanup. Equivalent to GTW's FProc method.


appFinalizeLP

public abstract void appFinalizeLP()
Terminates LP and displays simulation statistics. It is optionally called at the end of the simulation. It is the counterpart of "FProc" in GTW.


toString

public java.lang.String toString()
Provides a String summarizing this LogicalProcess. Subclasses should extend this as needed.

Overrides:
toString in class java.lang.Object