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 boolean
acknowledged
Indicates whether this channel requires acknowledgements to be returned from the receiver.private boolean
broken
True iff the link's been dropped.private ChannelID
channelID
The channel ID of the remote computer.private long
channelIndex
Our channel index.private NetChannelLocation
channelLocation
The channel name.private boolean
connected
True iff we're connected to the remote computer.(package private) static Any2OneChannel
failedLinks
private AltingChannelInput
fromNetIn
The channel we use for recieving from the demuxes.private SharedChannelOutput
fromNetOut
private Profile
linkProfile
The Profile that the link used by this channel should match.private int
maxUnacknowledged
The maximum number of data items "in flight" when a call to write() returns.private ChannelMessage.Data
messageA
private ChannelMessage.Data
messageB
private int
numUnacknowledged
The number of data items currently unacknowledged ("in flight").private boolean
sendMessageA
private ChannelOutput
toNet
The channel we use for sending to the network TX.
-
Constructor Summary
Constructors Constructor Description One2NetChannel(NetChannelLocation channelLocation)
Constructor which takes the location of aNetworked
ChannelInput
to which to send data.One2NetChannel(NetChannelLocation channelLocation, boolean acknowledged)
Constructor which takes the location of aNetworked
ChannelInput
to which to send data and aboolean
indicating whether or not to obtain acknowledgements.One2NetChannel(NetChannelLocation channelLocation, boolean acknowledged, Profile linkProfile)
Constructor which takes the location of aNetworked
ChannelInput
to which to send data and aboolean
indicating whether or not to obtain acknowledgements.One2NetChannel(NetChannelLocation channelLocation, Profile linkProfile)
Constructor which takes the location of aNetworked
ChannelInput
to which to send data and aProfile
that any Link used should match.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
destroyWriter()
This destroys this write end of the channel and frees any resources in the JCSP.NET infrastructure.NetChannelLocation
getChannelLocation()
Returns a clone of theNetChannelLocation
object held by the instance of this class which contains information about the location of the networkedChannelInput
object to which thisChannelOutput
is connected.java.lang.Class
getFactoryClass()
Returns the factory class used for constructing this channel end object.(package private) void
linkFailed(NodeID remoteID)
void
poison(int strength)
Currently, network channels are unpoisonable so this method has no effect.private void
readObject(java.io.ObjectInputStream stream)
Handles deserialization.void
recreate()
Requests that the channel recreates itself and reconnects to the other end of the channel.void
recreate(NetChannelLocation newLoc)
Requests that the channel recreates itself and reconnects to the other end of the channel.void
write(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 aNetworked
ChannelInput
to which to send data. The channel constructed will block after any data is sent until an acknowledgement is returned. A Link to theChannelInput
object'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 the
boolean
set totrue
and theProfile
set tonull
.
-
One2NetChannel
public One2NetChannel(NetChannelLocation channelLocation, Profile linkProfile)
Constructor which takes the location of aNetworked
ChannelInput
to which to send data and aProfile
that any Link used should match. The channel constructed will block after any data is sent until an acknowledgement is returned. A Link to theChannelInput
object's Node will be established if necessary. This Link will match the specified Profile. A
RuntimeException
will be thrown if a a matching Link cannot be established. This constructor is equivalent to using the (NetChannelLocation, boolean, Profile) constructor with theboolean
set totrue
.
-
One2NetChannel
public One2NetChannel(NetChannelLocation channelLocation, boolean acknowledged)
Constructor which takes the location of aNetworked
ChannelInput
to which to send data and aboolean
indicating 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 theChannelInput
object'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 the
Profile
set tonull
.
-
One2NetChannel
public One2NetChannel(NetChannelLocation channelLocation, boolean acknowledged, Profile linkProfile)
Constructor which takes the location of aNetworked
ChannelInput
to which to send data and aboolean
indicating 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 theChannelInput
object's Node will be established if necessary. This Link will match the specified Profile. A
RuntimeException
will 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:
write
in interfaceChannelOutput
- Parameters:
data
- an object to send over the channel. This should beSerializable
.
-
getChannelLocation
public NetChannelLocation getChannelLocation()
Returns a clone of theNetChannelLocation
object held by the instance of this class which contains information about the location of the networkedChannelInput
object to which thisChannelOutput
is connected.- Specified by:
getChannelLocation
in interfaceNetworked
- Returns:
- the
NetChannelLocation
of 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:
destroyWriter
in 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 theNetChannelLocation
it holds for its destination. If the instance held is an instance of a sub-class ofNetChannelLocation
then this provides an oportunity for the instance to refresh its information. This could, for example, be from a naming service.- Specified by:
recreate
in 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:
recreate
in interfaceNetChannelOutput
- Parameters:
newLoc
- the new location of the read end of the channel.
-
getFactoryClass
public java.lang.Class getFactoryClass()
Description copied from interface:NetChannelOutput
Returns the factory class used for constructing this channel end object.
- Specified by:
getFactoryClass
in interfaceNetChannelOutput
- Returns:
- the
Class
of the
-
poison
public void poison(int strength)
Currently, network channels are unpoisonable so this method has no effect.- Specified by:
poison
in 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.ClassNotFoundException
Handles deserialization. This is responsible for starting up the process which handles output, and for creating the internal channel.- Throws:
java.io.IOException
java.lang.ClassNotFoundException
-
-