Package org.jcsp.net2

Class One2NetChannel<T>

java.lang.Object
org.jcsp.net2.One2NetChannel<T>
All Implemented Interfaces:
ChannelOutput<T>, Poisonable, NetChannelOutput<T>, Networked

final class One2NetChannel<T> extends Object implements NetChannelOutput<T>
An outputting end of a networked channel (TX). This is a concrete implementation created internally by JCSP. For information on how to use networked channels, and how to create them, see the relevant documentation.
See Also:
  • Field Details

    • toLinkTx

      private final ChannelOutput toLinkTx
      The channel connecting to the Link that connects to the networked input end of this channel.
    • linkConnectedTo

      private final Link linkConnectedTo
      The actual Link this output channel sends on. We keep this as it allows us to register and unregister with the Link as we are created and destroyed, allowing the Link to inform the channel when a Link goes down.
    • localChannel

      private final ChannelData localChannel
      This is used if we are ever connected locally. We use this to check the state of a locally connected channel prior to sending a message.
    • theAckChannel

      private final AltingChannelInput theAckChannel
      The channel used to receive acknowledgements from the input end via the Link.
    • data

      private final ChannelData data
      A structure containing the information on the state of the channel.
    • remoteLocation

      private final NetChannelLocation remoteLocation
      The location that this channel is connected to (the input channel ends location)
    • localLocation

      private final NetChannelLocation localLocation
      The local channel end location
    • isLocal

      private final boolean isLocal
      Flag to determine if this is a locally connected channel or not
    • messageFilter

      private NetworkMessageFilter.FilterTx messageFilter
      The filter used to encode outgoing messages
  • Constructor Details

    • One2NetChannel

      private One2NetChannel(AltingChannelInput ackChannel, ChannelOutput toLink, Link link, ChannelData chanData, NetChannelLocation loc, int immunity, NetworkMessageFilter.FilterTx filter)
      Private constructor for creating a One2NetChannel. This is called by the create method.
      Parameters:
      ackChannel - The channel used to receive acknowledgements from Links
      toLink - The channel used to send messages to the input end
      link - The Link that this channel is connected to
      chanData - The structure used to store the state of the channel
      loc - The location of the input end that this channel is connected to
      immunity - The poison immunity level of the channel
      filter - Filter used to encode outgoing messages
  • Method Details

    • create

      static <T2> One2NetChannel<T2> create(NetChannelLocation loc, int immunity, NetworkMessageFilter.FilterTx filter) throws JCSPNetworkException
      Creates a new One2NetChannel by connecting to an already created NetChannelInput
      Parameters:
      loc - The location of the NetChannelInput
      immunity - The immunity level of the channel
      filter - The filter used to encode outgoing messages
      Returns:
      A new One2NetChannel
      Throws:
      JCSPNetworkException - Thrown if the connection to the remote Node fails
    • poison

      public void poison(int strength)
      Poisons the underlying channel.
      Specified by:
      poison in interface Poisonable
      Parameters:
      strength - The strength of the poison being placed on the channel
    • getLocation

      public NetLocation getLocation()
      Gets the NetChannelLocation that this channel is connected to (i.e. the input end location)
      Specified by:
      getLocation in interface Networked
      Returns:
      The NetChannelLocation that this channel is connected to
    • localLocation

      NetChannelLocation localLocation()
      Gets the local NetChannelLocation that represents this channel.
      Returns:
      The local location of the output end
    • write

      public void write(T object) throws JCSPNetworkException, PoisonException
      Writes an object to the input end
      Specified by:
      write in interface ChannelOutput<T>
      Parameters:
      object - The object to send to the input end.
      Throws:
      JCSPNetworkException - Thrown if something goes wrong in the network architecture
      PoisonException - Thrown if the channel has been poisoned
    • asyncWrite

      public void asyncWrite(T object) throws JCSPNetworkException, PoisonException
      Asynchronously writes an object to the channel
      Specified by:
      asyncWrite in interface NetChannelOutput<T>
      Parameters:
      object - The object being written to the channel
      Throws:
      JCSPNetworkException - Thrown when something goes wrong in the network architecture
      PoisonException - Thrown if the channel is poisoned
    • getChannelData

      final ChannelData getChannelData()
      Gets the channel data state for this channel.
      Returns:
      ChannelData for this channel
    • destroy

      public void destroy()
      Destroys the channel and removes it from the ChannelManager.
      Specified by:
      destroy in interface Networked
    • setEncoder

      public void setEncoder(NetworkMessageFilter.FilterTx encoder)
      Sets the underlying message filter
      Specified by:
      setEncoder in interface NetChannelOutput<T>
      Parameters:
      encoder - The new message filter to use