Package org.jcsp.net2

Class Any2NetChannel<T>

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

final class Any2NetChannel<T> extends Object implements NetSharedChannelOutput<T>
An outputting network channel (TX) that can be safely shared amongst multiple writers (Any2Net). This is the concrete implementation of the construct. For information on the user level interface, see NetSharedChannelOutput
See Also:
  • Field Details

    • chan

      private final One2NetChannel chan
      The underlying One2NetChannel used by this channel. This class acts like a wrapper, protecting the underlying unshared connection.
  • Constructor Details

    • Any2NetChannel

      private Any2NetChannel(One2NetChannel channel)
      Constructor wrapping an existing One2NetChannel in an Any2NetChannel
      Parameters:
      channel - The One2NetChannel to be wrapped.
  • Method Details

    • create

      static <T2> Any2NetChannel<T2> create(NetChannelLocation loc, int immunity, NetworkMessageFilter.FilterTx filter) throws JCSPNetworkException
      Static factory method used to create an Any2NetChannel
      Parameters:
      loc - The location of the input channel end
      immunity - The immunity level of the channel
      filter - The filter used to convert the object being sent into bytes
      Returns:
      A new Any2NetChannel connected to the input end.
      Throws:
      JCSPNetworkException - Thrown if a connection to the Node cannot be made.
    • poison

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

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

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

      public void asyncWrite(T object) throws JCSPNetworkException, PoisonException
      Writes asynchronously to the underlying channel.
      Specified by:
      asyncWrite in interface NetChannelOutput<T>
      Parameters:
      object - The object to write to the channel
      Throws:
      JCSPNetworkException - Thrown if something happens in the underlying architecture
      PoisonException - Thrown is the channel has been poisoned
    • destroy

      public void destroy()
      Removes the channel from the ChannelManager, and sets the state to DESTROYED
      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