communication
Class CommunicationElement

java.lang.Object
  extended by communication.CommunicationElement
All Implemented Interfaces:
ICommunication
Direct Known Subclasses:
ReliableCommElt, UnreliableCommElt

public abstract class CommunicationElement
extends java.lang.Object
implements ICommunication

Communication element for a process to communicate with other processes. The underlying communication support is TCP. Fault and communication delays are simulated through a set of parameters.


Nested Class Summary
protected  class CommunicationElement.Receiver
          Thread that loops indefinitely for receiving messages through the TCP element associated with the communication element
 
Field Summary
protected  FaultLevel crashLevel
          Level of crash of the process
protected  boolean debugFault
          Precise if debug information, concerning message lost and transmission delays, must be printed on standard output
protected  SynchronizedBuffer msgBuffer
          Internal buffer for received messages
protected  IPProcessIdentifier myPid
          Identifier of the process
protected  FaultLevel packetLostLevel
          Level of lost of packet sent through the network
protected  java.util.Random randGen
          Generator of random numbers for managing the lost and delays for messages
protected  TCPElement tcp
          TCP element for physically sending and receiving messages
protected  FaultLevel transmissionDelayLowerBound
          Level of the minimum delay for a message to join the receiver element
protected  FaultLevel transmissionDelayUpperBound
          Level of the maximum delay for a message to join the receiver element
 
Constructor Summary
CommunicationElement()
          Create and fully initialize a communication element, using any available TCP port
CommunicationElement(int port)
          Create and fully initialize a communication element
 
Method Summary
 Message asynchReceiveMessage()
          Return a received message coming from any remote process.
 boolean availableMessage()
          Check if there is unread received messages
 void crashProcess()
          Depending of the crash level and a random value generated, crash the process or not
 FaultLevel getCrashLevel()
           
 IPProcessIdentifier getMyPid()
          Get the complete process identifier.
 FaultLevel getPacketLostLevel()
           
 FaultLevel getTransmissionDelayLowerBound()
           
 FaultLevel getTransmissionDelayUpperBound()
           
 boolean isDebugFault()
           
protected  boolean isPacketLost()
           
protected abstract  void physicalSendMessage(Message msg, ProcessIdentifier id)
          Method called to "physically" send a message through TCP sockets.
 void sendMessage(Message msg)
          Send a message to a remote process which address is embedded in the message.
 void sendMessage(ProcessIdentifier id, java.lang.Object data)
          Send a message to a remote process.
 void setCrashLevel(FaultLevel crashLevel)
           
 void setDebugFault(boolean debugFault)
           
 void setMyPid(int id)
          Modify the (supposed unique) identifier integer value inside the process identifier.
 void setPacketLostLevel(FaultLevel packetLostLevel)
           
 void setTransmissionDelayLowerBound(FaultLevel transmissionDelayLowerBound)
           
 void setTransmissionDelayUpperBound(FaultLevel transmissionDelayUpperBound)
           
 Message synchReceiveMessage()
          Return a received message coming from any remote process.
protected  int transmissionDelay()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

packetLostLevel

protected FaultLevel packetLostLevel
Level of lost of packet sent through the network


transmissionDelayLowerBound

protected FaultLevel transmissionDelayLowerBound
Level of the minimum delay for a message to join the receiver element


transmissionDelayUpperBound

protected FaultLevel transmissionDelayUpperBound
Level of the maximum delay for a message to join the receiver element


crashLevel

protected FaultLevel crashLevel
Level of crash of the process


debugFault

protected boolean debugFault
Precise if debug information, concerning message lost and transmission delays, must be printed on standard output


myPid

protected IPProcessIdentifier myPid
Identifier of the process


msgBuffer

protected SynchronizedBuffer msgBuffer
Internal buffer for received messages


tcp

protected TCPElement tcp
TCP element for physically sending and receiving messages


randGen

protected java.util.Random randGen
Generator of random numbers for managing the lost and delays for messages

Constructor Detail

CommunicationElement

public CommunicationElement()
                     throws CommunicationException
Create and fully initialize a communication element, using any available TCP port

Throws:
CommunicationException - in case of problem (the socket can not be bound to required port)

CommunicationElement

public CommunicationElement(int port)
                     throws CommunicationException
Create and fully initialize a communication element

Parameters:
port - the port on which to bind the TCP socket server of the communication element. 0 for taken any available port
Throws:
CommunicationException - in case of problem (the socket can not be bound to required port)
Method Detail

getTransmissionDelayLowerBound

public FaultLevel getTransmissionDelayLowerBound()
Returns:
the transmissionDelayLowerBound

setTransmissionDelayLowerBound

public void setTransmissionDelayLowerBound(FaultLevel transmissionDelayLowerBound)
Parameters:
transmissionDelayLowerBound - the transmissionDelayLowerBound to set

getTransmissionDelayUpperBound

public FaultLevel getTransmissionDelayUpperBound()
Returns:
the transmissionDelayUpperBound

setTransmissionDelayUpperBound

public void setTransmissionDelayUpperBound(FaultLevel transmissionDelayUpperBound)
Parameters:
transmissionDelayUpperBound - the transmissionDelayUpperBound to set

getPacketLostLevel

public FaultLevel getPacketLostLevel()
Returns:
the packetLostLevel

setPacketLostLevel

public void setPacketLostLevel(FaultLevel packetLostLevel)
Parameters:
packetLostLevel - the packetLostLevel to set

getCrashLevel

public FaultLevel getCrashLevel()
Returns:
the process crash level

setCrashLevel

public void setCrashLevel(FaultLevel crashLevel)
Parameters:
crashLevel - the crash level to set

isDebugFault

public boolean isDebugFault()
Returns:
the debugFault

setDebugFault

public void setDebugFault(boolean debugFault)
Parameters:
debugFault - the debugFault to set

getMyPid

public IPProcessIdentifier getMyPid()
Get the complete process identifier. Notice that the IP and port field are automatically set once the communication element has been created. The identifier integer field is not set and has the value of 0 by default.

Returns:
the process identifier

setMyPid

public void setMyPid(int id)
Modify the (supposed unique) identifier integer value inside the process identifier. The other fields (IP and port) of the complete process identifier have not to be changed because they are initialized when the communication element is created and must not change after that.

Parameters:
id - the identifier of the process

sendMessage

public void sendMessage(Message msg)
                 throws CommunicationException
Description copied from interface: ICommunication
Send a message to a remote process which address is embedded in the message.

Specified by:
sendMessage in interface ICommunication
Parameters:
msg - the message to send
Throws:
CommunicationException - in case of communication error

sendMessage

public void sendMessage(ProcessIdentifier id,
                        java.lang.Object data)
                 throws CommunicationException
Description copied from interface: ICommunication
Send a message to a remote process.

Specified by:
sendMessage in interface ICommunication
Parameters:
id - the identifier, including its physical address, of the remote process
data - the data to send to the remote process
Throws:
CommunicationException - in case of communication error

synchReceiveMessage

public Message synchReceiveMessage()
Description copied from interface: ICommunication
Return a received message coming from any remote process. If no unread message is available wait for the reception of a message.

Specified by:
synchReceiveMessage in interface ICommunication
Returns:
the next unread received message

asynchReceiveMessage

public Message asynchReceiveMessage()
Description copied from interface: ICommunication
Return a received message coming from any remote process. If no unread message is available return directly the null value.

Specified by:
asynchReceiveMessage in interface ICommunication
Returns:
the next unread received message or null if none

availableMessage

public boolean availableMessage()
Description copied from interface: ICommunication
Check if there is unread received messages

Specified by:
availableMessage in interface ICommunication
Returns:
true if there is at least one unread received message, false otherwise

physicalSendMessage

protected abstract void physicalSendMessage(Message msg,
                                            ProcessIdentifier id)
                                     throws CommunicationException
Method called to "physically" send a message through TCP sockets. Will be specialized in ReliableCommElt and UnreliableCommElt depending on the reliability policy.

Parameters:
msg - the message to be sent (including the receiver id)
id - the id of the sender
Throws:
CommunicationException - in case of communication problem

isPacketLost

protected boolean isPacketLost()
Returns:
true if the packet must be lost according to the lost fault level

transmissionDelay

protected int transmissionDelay()
Returns:
the transmission delay to wait before sending the message according to the transmission delay bounds

crashProcess

public void crashProcess()
Description copied from interface: ICommunication
Depending of the crash level and a random value generated, crash the process or not

Specified by:
crashProcess in interface ICommunication