Package org.jcsp.net2
Class Link
- java.lang.Object
-
- org.jcsp.net2.Link
-
- All Implemented Interfaces:
CSProcess
- Direct Known Subclasses:
TCPIPLink
public abstract class Link extends java.lang.Object implements CSProcess
Abstract class representing a Link. This class defines the two processes (Link TX, Link RX) where the network protocol is of key importance. Specific technology protocols (e.g. TCP/IP) must extend this class, providing the necessary streams for operation, and also overriding the methods connect, createResources and destroyResources, which will have specific implementations dependent on the underlying technology. Everything else should operate as defined in this class.- See Also:
NetworkProtocol
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
Link.RxLoop
The RxLoop for the Link.(package private) class
Link.TxLoop
The TxLoop for the Link.
-
Field Summary
Fields Modifier and Type Field Description protected boolean
connected
A flag used to indicate whether the Link is connected or not.private java.util.Hashtable
connectedBarriers
This Hashtable is used to keep track of the current barriers that are connected to this Link.private java.util.Hashtable
connectedOutputs
This Hashtable is used to keep track of the current output channels that are connected to this Link.static int
LINK_PRIORITY
Link priority in the system.protected int
priority
Link priority for this Link.protected NodeID
remoteID
The NodeID of the opposite end of the connection.protected java.io.DataInputStream
rxStream
The incoming stream for the connection.private Any2OneChannel
txChannel
The channel connected to the Link Tx process.protected java.io.DataOutputStream
txStream
The outgoing stream for the connection.
-
Constructor Summary
Constructors Constructor Description Link()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract boolean
connect()
Connects to the remote Node.protected abstract boolean
createResources()
Creates the resources (if any) required for the Node.(package private) void
deRegisterBarrier(BarrierData data)
Unregisters a barrier with the Link(package private) void
deRegisterChannel(ChannelData data)
Unregisters and removes the channel from the Link.protected abstract void
destroyResources()
Destroys any used resources.NodeID
getRemoteNodeID()
Returns the NodeID of the connected Link.protected ChannelOutput
getTxChannel()
Gets the channel that is connected to the Link Tx process.protected void
lostLink()
Marks the Link as lost within the LinkManager.(package private) void
registerBarrier(BarrierData data)
Registers a barrier with the Link(package private) void
registerChannel(ChannelData data)
Register a channel with the Link.boolean
registerLink()
Registers the Link with the LinkManagervoid
run()
The run method for the process.
-
-
-
Field Detail
-
connected
protected boolean connected
A flag used to indicate whether the Link is connected or not. This flag is set normally during the connect operation, but may be done within the constructor. If not set during the constructor, and if connect is not called to set the flag to true, then when the process is run connect will be called.
-
rxStream
protected java.io.DataInputStream rxStream
The incoming stream for the connection. This must be created by the specific protocol implementation.
-
txStream
protected java.io.DataOutputStream txStream
The outgoing stream for the connection. This must be created by the specific protocol implementation.
-
txChannel
private final Any2OneChannel txChannel
The channel connected to the Link Tx process. This is used by channels, barriers, and the Link Rx to send messages to the node this Link is connected to.
-
remoteID
protected NodeID remoteID
The NodeID of the opposite end of the connection. This should be set either during construction, or during the connect method of a child class.
-
LINK_PRIORITY
public static int LINK_PRIORITY
Link priority in the system. This is a publicly accessible value that can be set by a user.
-
priority
protected int priority
Link priority for this Link. This is exposed to child classes to allow specific Link priorities for different Link types.
-
connectedOutputs
private java.util.Hashtable connectedOutputs
This Hashtable is used to keep track of the current output channels that are connected to this Link. In the outcome of a connection failure to the remote Node, the Link uses this table to notify all registered output ends, allowing them to throw an exception instead of deadlocking.
-
connectedBarriers
private java.util.Hashtable connectedBarriers
This Hashtable is used to keep track of the current barriers that are connected to this Link. In the outcome of a connection failure to the remote Node, the Link uses this table to notify all registered barriers, allowing them to throw an exception instead of deadlocking.
-
-
Method Detail
-
getRemoteNodeID
public final NodeID getRemoteNodeID()
Returns the NodeID of the connected Link.- Returns:
- NodeID of the connected Link.
-
getTxChannel
protected final ChannelOutput getTxChannel()
Gets the channel that is connected to the Link Tx process.- Returns:
- The ChannelOutput used to communicate with the Link Tx.
-
connect
public abstract boolean connect() throws JCSPNetworkException
Connects to the remote Node. This must be overridden by a child class implementation.- Returns:
- True if the connection succeeds, false otherwise.
- Throws:
JCSPNetworkException
- Thrown if the connection fails.
-
createResources
protected abstract boolean createResources() throws JCSPNetworkException
Creates the resources (if any) required for the Node. These could be set up during construction, but if not, this method is called immediately after connect within the run method. Child implementations should override this method.- Returns:
- True if resources were created OK, false otherwise.
- Throws:
JCSPNetworkException
- Thrown if a problem occurs creating the resources.
-
destroyResources
protected abstract void destroyResources()
Destroys any used resources. This is called whenever a Node fails. Particular implementations must overwrite this method.
-
registerLink
public final boolean registerLink()
Registers the Link with the LinkManager- Returns:
- True if Link was registered, false otherwise.
-
lostLink
protected final void lostLink()
Marks the Link as lost within the LinkManager.
-
registerChannel
void registerChannel(ChannelData data)
Register a channel with the Link.- Parameters:
data
- The ChannelData object representing the channel
-
deRegisterChannel
void deRegisterChannel(ChannelData data)
Unregisters and removes the channel from the Link.- Parameters:
data
- The ChannelData object representing the channel.
-
registerBarrier
void registerBarrier(BarrierData data)
Registers a barrier with the Link- Parameters:
data
- The barrier to register with the Link
-
deRegisterBarrier
void deRegisterBarrier(BarrierData data)
Unregisters a barrier with the Link- Parameters:
data
- The BarrierData representing the Barrier to unregister
-
-