Package org.jcsp.net

Class One2NetChannel

java.lang.Object
org.jcsp.net.One2NetChannel
All Implemented Interfaces:
Serializable, ChannelOutput, Poisonable, NetChannelOutput, Networked

class One2NetChannel extends Object implements NetChannelOutput, Serializable
A channel for network output (TX). This is a "One2Net" channel, which can only be safely used by one writer.
  • Field Details

    • 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 invalid input: '<'= 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.
  • Constructor Details

    • One2NetChannel

      public One2NetChannel(NetChannelLocation channelLocation)
      Constructor which takes the location of a 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.
    • One2NetChannel

      public 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. 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.
    • One2NetChannel

      public 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. 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.
    • One2NetChannel

      public 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. 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.
  • Method Details

    • write

      public void write(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 interface ChannelOutput
      Parameters:
      data - an object to send over the channel. This should be Serializable.
    • getChannelLocation

      public 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.
      Specified by:
      getChannelLocation in interface Networked
      Returns:
      the NetChannelLocation of the destination ChannelInput.
    • 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 interface NetChannelOutput
    • recreate

      public void recreate()
      Requests that the channel recreates itself and reconnects to the other end of the channel. This method will call 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.
      Specified by:
      recreate in interface NetChannelOutput
    • 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 interface NetChannelOutput
      Parameters:
      newLoc - the new location of the read end of the channel.
    • getFactoryClass

      public Class getFactoryClass()
      Description copied from interface: NetChannelOutput

      Returns the factory class used for constructing this channel end object.

      Specified by:
      getFactoryClass in interface NetChannelOutput
      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 interface Poisonable
      Parameters:
      strength - the strength of the poison (must be >= 0).
    • readObject

      private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException
      Handles deserialization. This is responsible for starting up the process which handles output, and for creating the internal channel.
      Throws:
      IOException
      ClassNotFoundException