nl.tudelft.ewi.alg.distsim
Class DProcess<M>

java.lang.Object
  extended by nl.tudelft.ewi.alg.distsim.DProcess<M>
Type Parameters:
M - The message payload to be sent around. Can be any type.
Direct Known Subclasses:
MyProc

public abstract class DProcess<M>
extends java.lang.Object

Subclasses of this class implement the distributed algorithm. All work should be done in the receiveMessage method.

To indicate that the algorithm has work of its own to do, without needing to be activated by a message, let isDone return false. Then, receiveMessage will be called with a null message if there is indeed no incoming message, allowing this work to be done.

Whenever the algorithm would do a non-blocking receive, return from receiveMessage with isDone returning false. To instead do a blocking receive, have isDone return true. In this latter case, receiveMessage will only be called if there is an actual message incoming.

Author:
Léon Planken, James Boerkoel Jr.

Field Summary
 int id
           
protected  MasterProcess<M> masterProc
           
 
Constructor Summary
protected DProcess(MasterProcess<M> master, int id)
           
 
Method Summary
 boolean equals(java.lang.Object obj)
           
 long getClock()
           
 long getIdle()
           
 MasterProcess<?> getMasterProcess()
           
 int hashCode()
           
abstract  boolean isDone()
          Whether or not this process is done.
protected  void log(java.lang.String str)
          Log something, including a timestamp.
protected abstract  void receiveMessage(int senderID, M message)
          Subclasses need to implement this.
protected  void sendMessage(int receiverID, M payload)
          Send a message.
protected  void setClock(long value)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

id

public final int id

masterProc

protected final MasterProcess<M> masterProc
Constructor Detail

DProcess

protected DProcess(MasterProcess<M> master,
                   int id)
Method Detail

setClock

protected void setClock(long value)

getClock

public long getClock()

getIdle

public long getIdle()

sendMessage

protected void sendMessage(int receiverID,
                           M payload)
Send a message. Must be invoked by this object itself.

Parameters:
receiverID - the ID of the receiver of the message
payload - the message

log

protected void log(java.lang.String str)
Log something, including a timestamp. Assumed to be invoked by this object itself.

Parameters:
str - the string to log.

receiveMessage

protected abstract void receiveMessage(int senderID,
                                       M message)
Subclasses need to implement this.

Parameters:
senderID - the sender of the message
message - the message received.

isDone

public abstract boolean isDone()
Whether or not this process is done.

Returns:
false if there is work to do yet even if no message is available; if so, receiveMessage(null,null) is called.

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

getMasterProcess

public MasterProcess<?> getMasterProcess()