class One2NetChannel extends java.lang.Object implements NetChannelOutput, java.io.Serializable
Modifier and Type | Field and 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 and Description |
---|
One2NetChannel(NetChannelLocation channelLocation)
Constructor which takes the location of a
Networked
ChannelInput to which to send data. |
One2NetChannel(NetChannelLocation channelLocation,
boolean acknowledged)
Constructor which takes the location of a
Networked
ChannelInput to which to send data and a
boolean indicating whether or not to obtain
acknowledgements. |
One2NetChannel(NetChannelLocation channelLocation,
boolean acknowledged,
Profile linkProfile)
Constructor which takes the location of a
Networked
ChannelInput to which to send data and a
boolean indicating whether or not to obtain
acknowledgements. |
One2NetChannel(NetChannelLocation channelLocation,
Profile linkProfile)
Constructor which takes the location of a
Networked
ChannelInput to which to send data and a
Profile that any Link used should match. |
Modifier and Type | Method and 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 the
NetChannelLocation object
held by the instance of this class which contains information
about the location of the networked ChannelInput
object to which this ChannelOutput 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.
|
private transient ChannelID channelID
private transient long channelIndex
private transient AltingChannelInput fromNetIn
private transient SharedChannelOutput fromNetOut
private transient ChannelOutput toNet
private transient boolean broken
private transient boolean connected
private transient ChannelMessage.Data messageA
private transient ChannelMessage.Data messageB
private transient boolean sendMessageA
private NetChannelLocation channelLocation
private final Profile linkProfile
private final int maxUnacknowledged
private transient int numUnacknowledged
private boolean acknowledged
static Any2OneChannel failedLinks
public One2NetChannel(NetChannelLocation channelLocation)
Networked
ChannelInput
to which to send data.
The channel constructed will block after any data is sent
until an acknowledgement is returned.
A Link to the ChannelInput 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 to true
and
the Profile
set to null
.
public One2NetChannel(NetChannelLocation channelLocation, Profile linkProfile)
Networked
ChannelInput
to which to send data and a
Profile
that any Link used should match.
The channel constructed will block after any data is sent
until an acknowledgement is returned.
A Link to the ChannelInput 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
the boolean
set to true
.
public One2NetChannel(NetChannelLocation channelLocation, boolean acknowledged)
Networked
ChannelInput
to which to send data and a
boolean
indicating whether or not to obtain
acknowledgements.
If the acknowledged parameter is true
, 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 the ChannelInput 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 to null
.
public One2NetChannel(NetChannelLocation channelLocation, boolean acknowledged, Profile linkProfile)
Networked
ChannelInput
to which to send data and a
boolean
indicating whether or not to obtain
acknowledgements.
If the acknowledged parameter is true
, 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 the ChannelInput 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.
public void write(java.lang.Object data)
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.
write
in interface ChannelOutput
data
- an object to send over the channel. This should be Serializable
.public NetChannelLocation getChannelLocation()
NetChannelLocation
object
held by the instance of this class which contains information
about the location of the networked ChannelInput
object to which this ChannelOutput
is connected.getChannelLocation
in interface Networked
NetChannelLocation
of the destination
ChannelInput
.void linkFailed(NodeID remoteID)
public void destroyWriter()
destroyWriter
in interface NetChannelOutput
public void recreate()
refresh()
on the
NetChannelLocation
it holds for its destination.
If the instance held is an instance of a sub-class of
NetChannelLocation
then this provides an oportunity
for the instance to refresh its information. This could, for example,
be from a naming service.recreate
in interface NetChannelOutput
public void recreate(NetChannelLocation newLoc)
recreate
in interface NetChannelOutput
newLoc
- the new location of the read end of the channel.public java.lang.Class getFactoryClass()
NetChannelOutput
Returns the factory class used for constructing this channel end object.
getFactoryClass
in interface NetChannelOutput
Class
of thepublic void poison(int strength)
poison
in interface Poisonable
strength
- the strength of the poison (must be >= 0).private void readObject(java.io.ObjectInputStream stream) throws java.io.IOException, java.lang.ClassNotFoundException
java.io.IOException
java.lang.ClassNotFoundException