Class SchedulingLoop

java.lang.Object
  extended by SchedulingLoop
All Implemented Interfaces:
java.lang.Runnable

public class SchedulingLoop
extends java.lang.Object
implements java.lang.Runnable

This class provides the simulation engine logical process scheduling loop. This loop runs in its own thread in parallel with the communication thread of the PE. After instantiation, this class should have one or more LogicalProcesses added (by createLP) before the thread is started.

Requires Java 5.0 due to use of the PriorityBlockingQueue class and others.

Version:
1.7 (07/2006)
Author:
Yin Xiong, Glenn Matthews

Field Summary
(package private)  java.util.Vector<Message> antiMsgsIn
           
(package private)  java.util.Vector<Message> antiMsgsOut
           
 boolean done
          Very primitive way of stopping the run loop: set this to true.
(package private)  java.util.Vector<Message> eventQueue
           
(package private)  Flag flag
          The flag indicating whether the simulation is finished.
(package private)  int id
          The id of the parent PE of this scheduler.
 java.util.concurrent.PriorityBlockingQueue<Message> incoming
          Shared priority queue containing incoming Messages from the communication thread.
(package private)  java.util.List<LogicalProcess> LPs
          Local list storing all LogicalProcesses managed by this SchedulingLoop.
(package private)  java.util.Vector<LogicalProcess> lpStates
          The queue that store the saved LP state
private  java.util.List<java.util.SortedSet<MonitorNode>> monitoring
          Local list storing sorted sets (one per LP) of current and future monitoring commands.
 java.util.concurrent.PriorityBlockingQueue<Message> outgoing
          Shared priority queue containing outgoing Messages to the communication thread.
 java.util.PriorityQueue<Message> simMessages
          Local priority queue storing simulation messages yet to be handled.
private  java.util.List<java.util.SortedSet<SteerNode>> steering
          Local list storing sorted sets (one per LP) of current and future steering commands.
 
Constructor Summary
SchedulingLoop(Flag f, int pid)
          Constructs a new PE instance.
 
Method Summary
(package private)  void annihilateMsg(Message m)
          Annihilates the positive message who has received a matching anti-message.
 void applyMonitoring(int index)
          Applies any scheduled monitoring of a single LP.
 void applySteering(int index)
          Applies any scheduled steering to the specified LP.
 void createLP(int pid, int LPid, java.lang.String APPid, java.lang.String name, java.lang.String className, java.lang.String data)
          Creates a new LogicalProcess of the specified type and adds it to the list of LPs managed by this run loop.
 LogicalProcess getLPByAPPid(java.lang.String appid)
          Locates one of the LPs managed by this scheduling loop, based on its APPid.
 int getLPIndexByAPPid(java.lang.String appid)
          Finds the list index of a given LP (position associated with it in LPs, monitoring, and steering) based on its APPid.
(package private)  boolean isMsgCanceled(Message m)
           
 void processIncoming()
          Reads incoming messages from the communication thread and, based on their Message.MsgType places them in the appropriate data structures for later processing.
(package private)  Message rollBack(LogicalProcess theLP, int rbtime)
          Rolls back to the time specified by rbtime and returns the first message immediately after the rollback.
 void run()
          Method required by Runnable interface; called when the thread is first created.
 int runOneLP()
          Calls LogicalProcess.runLP(Message) for the first Message in the simMessages queue.
 Message sendAntiMsgs(int lp, int rbtime)
          Sends out anti-messages.
 void sendMessage(Message msg)
          Places the specified (partly-formatted) Message into the outgoing message queue for the communication thread to send out.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

id

int id
The id of the parent PE of this scheduler.


flag

Flag flag
The flag indicating whether the simulation is finished.


lpStates

java.util.Vector<LogicalProcess> lpStates
The queue that store the saved LP state


done

public boolean done
Very primitive way of stopping the run loop: set this to true. Run loop will terminate after current iteration and clean up after itself.


incoming

public java.util.concurrent.PriorityBlockingQueue<Message> incoming
Shared priority queue containing incoming Messages from the communication thread.


outgoing

public java.util.concurrent.PriorityBlockingQueue<Message> outgoing
Shared priority queue containing outgoing Messages to the communication thread. Note that the addressing of these Messages are not likely to be fully specified, since this class does not have access to a GlobalNameServer. In general, the communication thread should expect to have to use Message.senderAPPid and Message.receiverAPPid to look up the LPid and PE of the sender and receiver. The communication thread is also expected to recognize and handle the case where receiverAPPid == LogicalProcess.ALL_LPS.


LPs

java.util.List<LogicalProcess> LPs
Local list storing all LogicalProcesses managed by this SchedulingLoop.


simMessages

public java.util.PriorityQueue<Message> simMessages
Local priority queue storing simulation messages yet to be handled.


antiMsgsOut

java.util.Vector<Message> antiMsgsOut
Since:
1.7. The queue that contains anti-messages. A anti-message is a copy of the regular message with a negative sign. When processing an event on LP i that schedules an event on LP j, a message and a copy of the same message are created. The copy is the 'anti-message' sometimes called negative, or copy of the positive message. The original (positive) message is transmitted to the destination LP j and the anti-message stays at the source LP i as a record that the LP i transmitted a positive message to LP j

antiMsgsIn

java.util.Vector<Message> antiMsgsIn
Since:
1.7 The queue that contains unmatched anti-messages. Their positive counter- parts haven't been received yet.

eventQueue

java.util.Vector<Message> eventQueue
Since:
1.7 The queue that stores the processed messages; used for rollback; When an anti-message comes in, the scheduler first check if the positive message has already been processed; if yes, rollback; if not, cancel it; if the positive message is yet to receive, then store the anti message in antiMsgsIn.

monitoring

private java.util.List<java.util.SortedSet<MonitorNode>> monitoring
Local list storing sorted sets (one per LP) of current and future monitoring commands.


steering

private java.util.List<java.util.SortedSet<SteerNode>> steering
Local list storing sorted sets (one per LP) of current and future steering commands.

Constructor Detail

SchedulingLoop

public SchedulingLoop(Flag f,
                      int pid)
Constructs a new PE instance. Sets the id of the PE to peid.

Parameters:
pid - int the id of the PE, i.e. the id of this process.
f - Flag indicating whether the simulation applicatin program is finished.
Method Detail

sendMessage

public void sendMessage(Message msg)
Places the specified (partly-formatted) Message into the outgoing message queue for the communication thread to send out.

Parameters:
msg - Message to send, assumed to have correctly filled senderAPPid, senderLP, and receiverAPPid, but not necessarily senderPE, receiverLP, or receiverPE (which are not likely to be known by this class or by any LogicalProcess, but should be known by the messaging thread).

sendAntiMsgs

public Message sendAntiMsgs(int lp,
                            int rbtime)
Sends out anti-messages.


run

public void run()
Method required by Runnable interface; called when the thread is first created. Starts the scheduling loop and continues looping until done is set to true.

Specified by:
run in interface java.lang.Runnable

runOneLP

public int runOneLP()
Calls LogicalProcess.runLP(Message) for the first Message in the simMessages queue. Messages directed to a LogicalProcess not owned by this SchedulingLoop are assumed to have been misdelivered, and are placed in outgoing.

Returns:
The index of the given LogicalProcess in the local lists.

rollBack

Message rollBack(LogicalProcess theLP,
                 int rbtime)
Rolls back to the time specified by rbtime and returns the first message immediately after the rollback. e.g. if roll back from 4 to 2, then the returned message should be 3.

Parameters:
theLP - a LogicalProcess that needs to rollback
rbtime - int the time the LP will rollback to

annihilateMsg

void annihilateMsg(Message m)
Annihilates the positive message who has received a matching anti-message.


isMsgCanceled

boolean isMsgCanceled(Message m)
Parameters:
m - Message to be checked
Since:
1.7 Returns true if the message has been canceled with an anti-message.

processIncoming

public void processIncoming()
Reads incoming messages from the communication thread and, based on their Message.MsgType places them in the appropriate data structures for later processing. Messages of unrecognized MsgType are discarded. Messages directed to LogicalProcesses not owned by this SchedulingLoop are also discarded.


applyMonitoring

public void applyMonitoring(int index)
Applies any scheduled monitoring of a single LP.

Parameters:
index - The storage index of the LP to monitor.

applySteering

public void applySteering(int index)
Applies any scheduled steering to the specified LP.

Parameters:
index - The storage index of the LP to steer.

getLPIndexByAPPid

public int getLPIndexByAPPid(java.lang.String appid)
Finds the list index of a given LP (position associated with it in LPs, monitoring, and steering) based on its APPid.

Parameters:
appid - The APPid to look for (case insensitive)
Returns:
The index of the first occurrence of this LP, or -1 if none found.

createLP

public void createLP(int pid,
                     int LPid,
                     java.lang.String APPid,
                     java.lang.String name,
                     java.lang.String className,
                     java.lang.String data)
Creates a new LogicalProcess of the specified type and adds it to the list of LPs managed by this run loop.

Parameters:
pid - The numerical ID of the PE where this LP resides
LPid - The numerical ID of the LP
APPid - The application-assigned ID of the LP
name - The application-assigned full name of the LP
className - Name of LogicalProcess subclass to create
data - Configuration data to pass into the LP
See Also:
LogicalProcess

getLPByAPPid

public LogicalProcess getLPByAPPid(java.lang.String appid)
Locates one of the LPs managed by this scheduling loop, based on its APPid.

Parameters:
appid - The APPid to look for (case insensitive)
Returns:
The first LP found with the given APPid, or null if none found.