visidia.simulation.process.algorithm
Class SynchronousAlgorithm

java.lang.Object
  extended by visidia.simulation.process.algorithm.Algorithm
      extended by visidia.simulation.process.algorithm.SynchronousAlgorithm
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Runnable
Direct Known Subclasses:
SensorSyncAlgorithm

public abstract class SynchronousAlgorithm
extends Algorithm

This is the abstract base class representing a synchronous algorithm in visidia. It is the API to be used to implement new synchronous algorithms (extending SynchronousAlgorithm class). A synchronous algorithm (written by the user) must have the following skeleton
BEGIN
FOR EVERY PHASE i DO:
1 * actions to do in phase i :
action 0 : ...
action 1 : ...

...

action k : sendTo(...) receive(...) getMsg...(...), anyMsg...(), putProperty() ... ... ;

...
...

final action :

2 * nextPulse(); // the nodes declares that he has finished the actions to do in phase i
// it is blocked until all other nodes have finished their actions in phase i
// if the node v does not declare the end of its current phase then all other nodes
// will be blocked until the node v execute the nextPulse() method.
// the receive method automatically execute the nextPulse() method if no message
// have been found.
END DO
END

The main task of this class when sending a message is to set the
message clock with the value returned by the getPulse method of
class Algorithm.
the receive(...) and getMsg...(...) methods are more sophisticated and
the user should take a look. Note that he can always do without by using the
existMessage(...) and getMessage(...) methods of class SyncAlgorithm

See Also:
Serialized Form

Field Summary
 
Fields inherited from class visidia.simulation.process.algorithm.Algorithm
proc
 
Constructor Summary
SynchronousAlgorithm()
           
 
Method Summary
protected  boolean anyMsg()
          return true if the node has received any message which has been sent in the previous pulse
protected  boolean existMessage(DoorPulseCriterion dpc)
          return true if there exists a message that matches the dpc criterion in the message queue of the node.
protected  Message getNextMessage(DoorPulseCriterion dpc)
          The most general and powerful method to handle reception of messages.
 int getPulse()
          Gets the current pulse.
 int nextPulse()
          Make the node calling this function finish it's pulse.
protected  Message receive(Door door)
          return the first message arrived in the previous pulse and write the door number in the Door object.
protected  boolean sendTo(int door, Message msg)
          Send the message message on target door.
 
Methods inherited from class visidia.simulation.process.algorithm.Algorithm
clone, getArity, getDescription, getEdgeProperty, getId, getMessageTypeList, getNetSize, getOrientedDoors, getProperty, init, isIncomingDoor, isOutgoingDoor, putProperty, putProperty, receiveFrom, receiveFrom, run, sendAll, setDoorState, setEdgeProperty, setMessageProcess
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SynchronousAlgorithm

public SynchronousAlgorithm()
Method Detail

getPulse

public final int getPulse()
Gets the current pulse.

Returns:
the pulse

nextPulse

public final int nextPulse()
Make the node calling this function finish it's pulse. The node wait's until all the nodes have called this function. The last node calling the nextPulse function free the other and make the simulator to continue to a new pulse.

Returns:
the countNextPulse

sendTo

protected boolean sendTo(int door,
                         Message msg)
Send the message message on target door.

Overrides:
sendTo in class Algorithm
Parameters:
door - the door
msg - the message
Returns:
true, if the message has been sent

getNextMessage

protected final Message getNextMessage(DoorPulseCriterion dpc)
The most general and powerful method to handle reception of messages. It returns the message which matches the criterion dpc in the message queue of the node. If none then return null. The user should take a look at the DoorPulseCriterion class to learn more about how to initialize the dpc argument.
Note that if the Pulse field of dpc is set to be this.getPulse(), then the user can retrieve the messages that have been sent at the current phase and which arrives before its end. This is not allowed in the anyMsg... method (a verification is made). In fact, we consider that the only messages a node can retrieve are those sent in the previous pulses. We do not make any verification here, in order to let the user implement ad-hoc instructions if he want. Thus, use this method carefully.


receive

protected final Message receive(Door door)
return the first message arrived in the previous pulse and write the door number in the Door object. If there is no message then return null.

Overrides:
receive in class Algorithm
Parameters:
door - the door
Returns:
the message

existMessage

protected final boolean existMessage(DoorPulseCriterion dpc)
return true if there exists a message that matches the dpc criterion in the message queue of the node. The same remark than in the getNextMessage(...) method, holds when the pulse in dpc is set to be this.getPulse()


anyMsg

protected final boolean anyMsg()
return true if the node has received any message which has been sent in the previous pulse