Class TCPIPAddressID

java.lang.Object
org.jcsp.net.NodeAddressID
org.jcsp.net.tcpip.TCPIPAddressID
All Implemented Interfaces:
Serializable, Cloneable

public class TCPIPAddressID extends NodeAddressID

Provides a concrete implementation of the abstract NodeAddressID for use with the TCP/IP link protocol. A TCP/IP node address consists of an internet host address (IP address) and 16bit IP port number.

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private InetAddress
     
    private boolean
     
    private final int
     
    private ProtocolID
     
    private String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    TCPIPAddressID(String host, int port, boolean isUnique)
    Creates a TCPIPAddressID for a computer, given it's host name and port number.
    TCPIPAddressID(InetAddress host, int port, boolean isUnique)
    Creates a TCPIPAddressID for a computer, given it's IP address and port number.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Compares two TCPIPAddressID for equality.
    Constructs and returns a TCPIPv4 NodeAddressID from a String.
    Returns the computer's IP address
    final int
    Returns the computer's port number for incoming link requests.
    Returns the ProtocolID for this address
    protected String
    Returns a string representation of the address suitable for use in the createAddressID method of TCPIPProtocolID.
    final int
    Returns a hashCode for this TCPIPAddressID
    boolean
    Returns true if this NodeAddressID is known to be unique within the global org.jcsp.net domain.
    final String
    Returns a string representation of this TCPIPAddressID, in the form "123.45.67.234:5678".

    Methods inherited from class org.jcsp.net.NodeAddressID

    clone

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • host

      private InetAddress host
    • port

      private final int port
    • protocolID

      private ProtocolID protocolID
    • stringForm

      private String stringForm
    • isUnique

      private boolean isUnique
  • Constructor Details

    • TCPIPAddressID

      public TCPIPAddressID(InetAddress host, int port, boolean isUnique) throws IllegalArgumentException
      Creates a TCPIPAddressID for a computer, given it's IP address and port number.
      Parameters:
      host - The computer's IP address.
      port - The computer's port number, in the range 0-65535 inclusive.
      isUnique - True if the address ID is globally unique, false otherwise.
      Throws:
      IllegalArgumentException - If the port is invalid.
    • TCPIPAddressID

      public TCPIPAddressID(String host, int port, boolean isUnique) throws IllegalArgumentException, UnknownHostException
      Creates a TCPIPAddressID for a computer, given it's host name and port number.
      Parameters:
      host - The computer's IP address, as a string
      port - The computer's port number.
      Throws:
      IllegalArgumentException - If the port is invalid.
      UnknownHostException - If the host name cannot be resolved.
  • Method Details

    • getAddressIDFromString

      public static NodeAddressID getAddressIDFromString(String stringForm) throws IllegalArgumentException
      Constructs and returns a TCPIPv4 NodeAddressID from a String. The String MUST be in the form of that returned from the getStringForm method.
      Parameters:
      stringForm - The String form representing a NodeAddressID.
      Throws:
      IllegalArgumentException - if the string is incorrectly formatted.
    • getStringForm

      protected String getStringForm()
      Returns a string representation of the address suitable for use in the createAddressID method of TCPIPProtocolID.
      Specified by:
      getStringForm in class NodeAddressID
      Returns:
      a String that can be passed to the static getAddressIDFromString(String) method in order to reconstuct the object.
    • getProtocolID

      public ProtocolID getProtocolID()
      Returns the ProtocolID for this address
      Specified by:
      getProtocolID in class NodeAddressID
      Returns:
      this NodeAddressID object's ProtocolID.
    • getHost

      public final InetAddress getHost()
      Returns the computer's IP address
      Returns:
      IP address of server.
    • getPort

      public final int getPort()
      Returns the computer's port number for incoming link requests.
      Returns:
      Port number of server.
    • equals

      public final boolean equals(Object obj)
      Compares two TCPIPAddressID for equality.
      Specified by:
      equals in class NodeAddressID
      Parameters:
      obj - another object that should be another NodeAddressID.
      Returns:
      true iff obj is a non-null TCPIPAddressID for the same port invalid input: '&' host, false otherwise.
    • hashCode

      public final int hashCode()
      Returns a hashCode for this TCPIPAddressID
      Specified by:
      hashCode in class NodeAddressID
      Returns:
      an int hash code.
    • isGloballyUnique

      public boolean isGloballyUnique()
      Description copied from class: NodeAddressID

      Returns true if this NodeAddressID is known to be unique within the global org.jcsp.net domain.

      A Node may have several addresses. If a Node is on an internal network that is connected to the Internet, it may have one local address and one address that is accessible from the Internet. The Internet address may be globally unique whereas the local address may be duplicated in other internal networks. The NodeAddressID object representing the Internet address should return true when this method is called whereas the NodeAddressID representing the local address should return false.

      Specified by:
      isGloballyUnique in class NodeAddressID
      Returns:
      true iff this NodeAddressID is globally unique.
    • toString

      public final String toString()
      Returns a string representation of this TCPIPAddressID, in the form "123.45.67.234:5678".
      Overrides:
      toString in class Object
      Returns:
      A string representation of this ComputerID.