|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object communication.CommunicationElement
public abstract class CommunicationElement
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 |
---|
protected FaultLevel packetLostLevel
protected FaultLevel transmissionDelayLowerBound
protected FaultLevel transmissionDelayUpperBound
protected FaultLevel crashLevel
protected boolean debugFault
protected IPProcessIdentifier myPid
protected SynchronizedBuffer msgBuffer
protected TCPElement tcp
protected java.util.Random randGen
Constructor Detail |
---|
public CommunicationElement() throws CommunicationException
CommunicationException
- in case of problem (the socket can not be bound to
required port)public CommunicationElement(int port) throws CommunicationException
port
- the port on which to bind the TCP socket server of the communication element.
0 for taken any available port
CommunicationException
- in case of problem (the socket can not be bound to
required port)Method Detail |
---|
public FaultLevel getTransmissionDelayLowerBound()
public void setTransmissionDelayLowerBound(FaultLevel transmissionDelayLowerBound)
transmissionDelayLowerBound
- the transmissionDelayLowerBound to setpublic FaultLevel getTransmissionDelayUpperBound()
public void setTransmissionDelayUpperBound(FaultLevel transmissionDelayUpperBound)
transmissionDelayUpperBound
- the transmissionDelayUpperBound to setpublic FaultLevel getPacketLostLevel()
public void setPacketLostLevel(FaultLevel packetLostLevel)
packetLostLevel
- the packetLostLevel to setpublic FaultLevel getCrashLevel()
public void setCrashLevel(FaultLevel crashLevel)
crashLevel
- the crash level to setpublic boolean isDebugFault()
public void setDebugFault(boolean debugFault)
debugFault
- the debugFault to setpublic IPProcessIdentifier getMyPid()
public void setMyPid(int id)
id
- the identifier of the processpublic void sendMessage(Message msg) throws CommunicationException
ICommunication
sendMessage
in interface ICommunication
msg
- the message to send
CommunicationException
- in case of communication errorpublic void sendMessage(ProcessIdentifier id, java.lang.Object data) throws CommunicationException
ICommunication
sendMessage
in interface ICommunication
id
- the identifier, including its physical address, of the remote processdata
- the data to send to the remote process
CommunicationException
- in case of communication errorpublic Message synchReceiveMessage()
ICommunication
synchReceiveMessage
in interface ICommunication
public Message asynchReceiveMessage()
ICommunication
null
value.
asynchReceiveMessage
in interface ICommunication
null
if nonepublic boolean availableMessage()
ICommunication
availableMessage
in interface ICommunication
true
if there is at least one unread received message,
false
otherwiseprotected abstract void physicalSendMessage(Message msg, ProcessIdentifier id) throws CommunicationException
msg
- the message to be sent (including the receiver id)id
- the id of the sender
CommunicationException
- in case of communication problemprotected boolean isPacketLost()
protected int transmissionDelay()
public void crashProcess()
ICommunication
crashProcess
in interface ICommunication
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |