Class One2NetChannel
- java.lang.Object
-
- org.jcsp.net.One2NetChannel
-
- All Implemented Interfaces:
java.io.Serializable,ChannelOutput,Poisonable,NetChannelOutput,Networked
class One2NetChannel extends java.lang.Object implements NetChannelOutput, java.io.Serializable
A channel for network output (TX). This is a "One2Net" channel, which can only be safely used by one writer.
-
-
Field Summary
Fields Modifier and Type Field Description private booleanacknowledgedIndicates whether this channel requires acknowledgements to be returned from the receiver.private booleanbrokenTrue iff the link's been dropped.private ChannelIDchannelIDThe channel ID of the remote computer.private longchannelIndexOur channel index.private NetChannelLocationchannelLocationThe channel name.private booleanconnectedTrue iff we're connected to the remote computer.(package private) static Any2OneChannelfailedLinksprivate AltingChannelInputfromNetInThe channel we use for recieving from the demuxes.private SharedChannelOutputfromNetOutprivate ProfilelinkProfileThe Profile that the link used by this channel should match.private intmaxUnacknowledgedThe maximum number of data items "in flight" when a call to write() returns.private ChannelMessage.DatamessageAprivate ChannelMessage.DatamessageBprivate intnumUnacknowledgedThe number of data items currently unacknowledged ("in flight").private booleansendMessageAprivate ChannelOutputtoNetThe channel we use for sending to the network TX.
-
Constructor Summary
Constructors Constructor Description One2NetChannel(NetChannelLocation channelLocation)Constructor which takes the location of aNetworkedChannelInputto which to send data.One2NetChannel(NetChannelLocation channelLocation, boolean acknowledged)Constructor which takes the location of aNetworkedChannelInputto which to send data and abooleanindicating whether or not to obtain acknowledgements.One2NetChannel(NetChannelLocation channelLocation, boolean acknowledged, Profile linkProfile)Constructor which takes the location of aNetworkedChannelInputto which to send data and abooleanindicating whether or not to obtain acknowledgements.One2NetChannel(NetChannelLocation channelLocation, Profile linkProfile)Constructor which takes the location of aNetworkedChannelInputto which to send data and aProfilethat any Link used should match.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddestroyWriter()This destroys this write end of the channel and frees any resources in the JCSP.NET infrastructure.NetChannelLocationgetChannelLocation()Returns a clone of theNetChannelLocationobject held by the instance of this class which contains information about the location of the networkedChannelInputobject to which thisChannelOutputis connected.java.lang.ClassgetFactoryClass()Returns the factory class used for constructing this channel end object.(package private) voidlinkFailed(NodeID remoteID)voidpoison(int strength)Currently, network channels are unpoisonable so this method has no effect.private voidreadObject(java.io.ObjectInputStream stream)Handles deserialization.voidrecreate()Requests that the channel recreates itself and reconnects to the other end of the channel.voidrecreate(NetChannelLocation newLoc)Requests that the channel recreates itself and reconnects to the other end of the channel.voidwrite(java.lang.Object data)Output data to this channel.
-
-
-
Field Detail
-
channelID
private transient ChannelID channelID
The channel ID of the remote computer. Not valid unless we are connected.
-
channelIndex
private transient long channelIndex
Our channel index. (On the local computer, for acknowlegements).
-
fromNetIn
private transient AltingChannelInput fromNetIn
The channel we use for recieving from the demuxes.
-
fromNetOut
private transient SharedChannelOutput fromNetOut
-
toNet
private transient ChannelOutput toNet
The channel we use for sending to the network TX. Not valid unless we are connected.
-
broken
private transient boolean broken
True iff the link's been dropped.
-
connected
private transient boolean connected
True iff we're connected to the remote computer.
-
messageA
private transient ChannelMessage.Data messageA
-
messageB
private transient ChannelMessage.Data messageB
-
sendMessageA
private transient boolean sendMessageA
-
channelLocation
private NetChannelLocation channelLocation
The channel name.
-
linkProfile
private final Profile linkProfile
The Profile that the link used by this channel should match.
-
maxUnacknowledged
private final int maxUnacknowledged
The maximum number of data items "in flight" when a call to write() returns. The default setting of zero gives standard unbuffered channel semantics. 5/Jun/2002 This is not currently used nor exposed to the user. Streaming has been changed so that acknowledgements are either on or off. Flow control really needs to be controlled from the receiving end but this functionality has not yet been implemented.
-
numUnacknowledged
private transient int numUnacknowledged
The number of data items currently unacknowledged ("in flight"). Always <= maxUnacknowledged + 1. If it is > maxUnacknowledged, then we must be blocked in write().
-
acknowledged
private boolean acknowledged
Indicates whether this channel requires acknowledgements to be returned from the receiver.
-
failedLinks
static Any2OneChannel failedLinks
-
-
Constructor Detail
-
One2NetChannel
public One2NetChannel(NetChannelLocation channelLocation)
Constructor which takes the location of aNetworkedChannelInputto which to send data. The channel constructed will block after any data is sent until an acknowledgement is returned. A Link to theChannelInputobject's Node will be established if necessary. This Link may be established over any available protocol implementation. This constructor is equivalent to using the (NetChannelLocation, boolean, Profile) constructor with thebooleanset totrueand theProfileset tonull.
-
One2NetChannel
public One2NetChannel(NetChannelLocation channelLocation, Profile linkProfile)
Constructor which takes the location of aNetworkedChannelInputto which to send data and aProfilethat any Link used should match. The channel constructed will block after any data is sent until an acknowledgement is returned. A Link to theChannelInputobject's Node will be established if necessary. This Link will match the specified Profile. ARuntimeExceptionwill be thrown if a a matching Link cannot be established. This constructor is equivalent to using the (NetChannelLocation, boolean, Profile) constructor with thebooleanset totrue.
-
One2NetChannel
public One2NetChannel(NetChannelLocation channelLocation, boolean acknowledged)
Constructor which takes the location of aNetworkedChannelInputto which to send data and abooleanindicating whether or not to obtain acknowledgements. If the acknowledged parameter istrue, then the channel constructed will block after any data is sent until an acknowledgement is returned. Otherwise, the channel should not block, however, some flow control may be implemented which may result in blocking. A Link to theChannelInputobject's Node will be established if necessary. This Link may be established over any available protocol implementation. This constructor is equivalent to using the (NetChannelLocation, boolean, Profile) constructor with theProfileset tonull.
-
One2NetChannel
public One2NetChannel(NetChannelLocation channelLocation, boolean acknowledged, Profile linkProfile)
Constructor which takes the location of aNetworkedChannelInputto which to send data and abooleanindicating whether or not to obtain acknowledgements. If the acknowledged parameter istrue, then the channel constructed will block after any data is sent until an acknowledgement is returned. Otherwise, the channel should not block, however, some flow control may be implemented which may result in blocking. A Link to theChannelInputobject's Node will be established if necessary. This Link will match the specified Profile. ARuntimeExceptionwill be thrown if a a matching Link cannot be established.
-
-
Method Detail
-
write
public void write(java.lang.Object data)
Output data to this channel. The data must be Serializable.For a normal channel (numUnacknowledged == 0), the contract of this method is as follows: When the method returns, the data has been sent to the remote computer, and the process (or user-supplied buffer) at the other end has accepted it. It is safe to modify data after the call. Transmission is guaranteed unless a LinkLostException is thrown, in which case it is impossible to determine whether or not the remote computer recieved the data before the link dropped.
For a streaming channel (numUnacknowledged > 0), the contract of this method is slightly different. When the method returns, the data has started it's trip to the remote computer, but the link may go down so there is no guarantee that it will get there. Also, since it may not have left this computer yet (the actual transmission is done in parallel with the return from this method), it is *NOT* safe to modify the passed data object. After the next call to this method, then you may assume that the data object has been transmitted, and re-use it or let the Java garbage collector deal with it as appropriate. You must wait a total of numUnacknowledged calls to this method before you can assume that the data was recieved - and if any of those calls throw a LinkLostException, then you cannot find out how much of the stream of data was recieved by the remote computer before the link broke.
A LinkLostException is thrown if the TCP/IP link is dropped. This could be due to a network problem, but more often it is caused when the remote Java VM crashes or is shut down. It can also be caused if there is a serialization problem with the TCP/IP link - e.g. an attempt to send a non-serializable object, or an attempt to send a class which doesn't exist or isn't the same version at the recieving end. Note that LinkLostException is a permanent error - if it is thrown, then any further call to this method will cause it to be thrown again.
- Specified by:
writein interfaceChannelOutput- Parameters:
data- an object to send over the channel. This should beSerializable.
-
getChannelLocation
public NetChannelLocation getChannelLocation()
Returns a clone of theNetChannelLocationobject held by the instance of this class which contains information about the location of the networkedChannelInputobject to which thisChannelOutputis connected.- Specified by:
getChannelLocationin interfaceNetworked- Returns:
- the
NetChannelLocationof the destinationChannelInput.
-
linkFailed
void linkFailed(NodeID remoteID)
-
destroyWriter
public void destroyWriter()
This destroys this write end of the channel and frees any resources in the JCSP.NET infrastructure.- Specified by:
destroyWriterin interfaceNetChannelOutput
-
recreate
public void recreate()
Requests that the channel recreates itself and reconnects to the other end of the channel. This method will callrefresh()on theNetChannelLocationit holds for its destination. If the instance held is an instance of a sub-class ofNetChannelLocationthen this provides an oportunity for the instance to refresh its information. This could, for example, be from a naming service.- Specified by:
recreatein interfaceNetChannelOutput
-
recreate
public void recreate(NetChannelLocation newLoc)
Requests that the channel recreates itself and reconnects to the other end of the channel. A new location of the read end can be supplied.- Specified by:
recreatein interfaceNetChannelOutput- Parameters:
newLoc- the new location of the read end of the channel.
-
getFactoryClass
public java.lang.Class getFactoryClass()
Description copied from interface:NetChannelOutputReturns the factory class used for constructing this channel end object.
- Specified by:
getFactoryClassin interfaceNetChannelOutput- Returns:
- the
Classof the
-
poison
public void poison(int strength)
Currently, network channels are unpoisonable so this method has no effect.- Specified by:
poisonin interfacePoisonable- Parameters:
strength- the strength of the poison (must be >= 0).
-
readObject
private void readObject(java.io.ObjectInputStream stream) throws java.io.IOException, java.lang.ClassNotFoundExceptionHandles deserialization. This is responsible for starting up the process which handles output, and for creating the internal channel.- Throws:
java.io.IOExceptionjava.lang.ClassNotFoundException
-
-