visidia.simulation.process.algorithm
Class Algorithm

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

public abstract class Algorithm
extends java.lang.Object
implements java.lang.Cloneable, java.lang.Runnable, java.io.Serializable

This is the abstract base class representing an algorithm in visidia. It is the API to be used to implement new algorithms (extending Algorithm class).

See Also:
Serialized Form

Field Summary
protected  MessageProcess proc
          The process.
 
Constructor Summary
Algorithm()
           
 
Method Summary
abstract  java.lang.Object clone()
           
protected  int getArity()
          Returns the node arity (its degree, or number of neighbors).
 java.lang.String getDescription()
          Gets the description.
protected  java.lang.Object getEdgeProperty(int door, java.lang.Object key)
          Gets the edge property value.
protected  int getId()
          Returns the node identity.
 java.util.Collection<MessageType> getMessageTypeList()
          Gets the message type list.
protected  int getNetSize()
          Gets the net size.
protected  java.util.Enumeration<java.lang.Integer> getOrientedDoors()
          Gets the oriented doors of the current node.
protected  java.lang.Object getProperty(java.lang.String key)
          Gets the node property value associated to the key.
abstract  void init()
          This method is executed by the node.
protected  boolean isIncomingDoor(int door)
          Returns true if the door corresponds to an edge pointing to the current node.
protected  boolean isOutgoingDoor(int door)
          Returns true if the door corresponds to an edge leaving the current node.
protected  void putProperty(java.lang.String key, java.lang.Object value)
          Put property.
protected  void putProperty(java.lang.String key, java.lang.Object value, int status)
          Adds a property to this node.
protected  Message receive(Door door)
          Gets the first message arriving on the node.
protected  Message receiveFrom(int door)
          Gets the first message arriving on target door.
protected  Message receiveFrom(int door, MessageCriterion mc)
          Gets the first message arriving on target door that matches the criterion.
 void run()
          This method is used at the thread instantiation.
protected  void sendAll(Message msg)
          Sends the message message to all neighbors.
protected  boolean sendTo(int door, Message msg)
          Sends the message message on target door.
protected  void setDoorState(EdgeState st, int door)
          Sets the door state.
protected  void setEdgeProperty(int door, java.lang.Object key, java.lang.Object value)
          Sets the edge property.
 void setMessageProcess(MessageProcess proc)
          Sets the message process.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

proc

protected transient MessageProcess proc
The process.

Constructor Detail

Algorithm

public Algorithm()
Method Detail

clone

public abstract java.lang.Object clone()
Overrides:
clone in class java.lang.Object

init

public abstract void init()
This method is executed by the node. The user has to overwrite it to implement its own algorithm using message passing.


getDescription

public java.lang.String getDescription()
Gets the description.

Returns:
the description

getMessageTypeList

public java.util.Collection<MessageType> getMessageTypeList()
Gets the message type list.

Returns:
the message type list

getArity

protected final int getArity()
Returns the node arity (its degree, or number of neighbors).

Returns:
the arity

getId

protected final int getId()
Returns the node identity.

Returns:
the id

getNetSize

protected final int getNetSize()
Gets the net size. Provided for convenience, since an algorithm is not supposed to know graph global information.

Returns:
the net size

getOrientedDoors

protected final java.util.Enumeration<java.lang.Integer> getOrientedDoors()
Gets the oriented doors of the current node. Both incoming and outgoing doors are considered.

Returns:
the oriented doors

isIncomingDoor

protected final boolean isIncomingDoor(int door)
Returns true if the door corresponds to an edge pointing to the current node. Also returns true if the edge is not oriented.

Parameters:
door - the door
Returns:
true, if is incoming door

isOutgoingDoor

protected final boolean isOutgoingDoor(int door)
Returns true if the door corresponds to an edge leaving the current node. Also returns true if the edge is not oriented.

Parameters:
door - the door
Returns:
true, if is outgoing door

putProperty

protected final void putProperty(java.lang.String key,
                                 java.lang.Object value,
                                 int status)
Adds a property to this node. If value is null the property is removed.

Parameters:
key - the key
value - the value
status - the status

putProperty

protected final void putProperty(java.lang.String key,
                                 java.lang.Object value)
Put property.

Parameters:
key - the key
value - the value

getProperty

protected final java.lang.Object getProperty(java.lang.String key)
Gets the node property value associated to the key.

Parameters:
key - the key
Returns:
the property value, or null if the key does not exist.

getEdgeProperty

protected final java.lang.Object getEdgeProperty(int door,
                                                 java.lang.Object key)
Gets the edge property value.

Parameters:
door - the door
key - the key
Returns:
the property value, or null if the key does not exist.

setEdgeProperty

protected final void setEdgeProperty(int door,
                                     java.lang.Object key,
                                     java.lang.Object value)
Sets the edge property.

Parameters:
door - the door
key - the key
value - the value

setDoorState

protected final void setDoorState(EdgeState st,
                                  int door)
Sets the door state.

Parameters:
st - the new state
door - the door

sendTo

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

Parameters:
door - the door
msg - the message
Returns:
true, if the message has been sent

sendAll

protected final void sendAll(Message msg)
Sends the message message to all neighbors.

Parameters:
msg - the message

receiveFrom

protected final Message receiveFrom(int door)
Gets the first message arriving on target door. The algorithm is blocked until reception.

Parameters:
door - the door
Returns:
the message

receiveFrom

protected final Message receiveFrom(int door,
                                    MessageCriterion mc)
Gets the first message arriving on target door that matches the criterion. The algorithm is blocked until reception.

Parameters:
door - the door
mc - the message criterion
Returns:
the message

receive

protected Message receive(Door door)
Gets the first message arriving on the node. The algorithm is blocked until reception. The door on which the message is arrived is stored.

Parameters:
door - the door
Returns:
the message

setMessageProcess

public void setMessageProcess(MessageProcess proc)
Sets the message process.

Parameters:
proc - the new message process

run

public final void run()
This method is used at the thread instantiation. This method launches the init method.

Specified by:
run in interface java.lang.Runnable