Package org.jcsp.net2

Class NodeAddress

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable
    Direct Known Subclasses:
    TCPIPNodeAddress

    public abstract class NodeAddress
    extends java.lang.Object
    implements java.io.Serializable, java.lang.Comparable
    This abstract class defines encapsulates the address of a Node within a JCSP networked system. Specific protocols must provide concrete implementations of this class to allow Node initialisation and connection. One concrete example is provided in the org.jcsp.net2.tcpip package.
    See Also:
    Node, Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.lang.String address
      String representation of the address
      private static java.util.Hashtable installedProtocols
      The table of installed protocols on this Node
      protected java.lang.String protocol
      String representing the protocol in used
    • Constructor Summary

      Constructors 
      Constructor Description
      NodeAddress()  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      int compareTo​(java.lang.Object arg0)
      Compares this NodeAddress to another
      protected abstract Link createLink()
      Creates a Link connected to this address
      protected abstract LinkServer createLinkServer()
      Creates a LinkServer listening on this address
      boolean equals​(java.lang.Object obj)
      Checks if this NodeAddress is equal to another
      java.lang.String getAddress()
      Gets a string representing the address
      java.lang.String getProtocol()
      Gets the string representing the protocol
      protected abstract ProtocolID getProtocolID()
      Retrieves the correct protocol handler for the implemented address type.
      int hashCode()
      Gets the hash code of this object
      static void installProtocol​(java.lang.String name, ProtocolID protocol)
      Installs a new Protocol on the Node
      static NodeAddress parse​(java.lang.String str)
      Parses a string representation of a NodeAddress back to its object form
      java.lang.String toString()
      Converts the NodeAddress into a String.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • protocol

        protected java.lang.String protocol
        String representing the protocol in used
      • address

        protected java.lang.String address
        String representation of the address
      • installedProtocols

        private static java.util.Hashtable installedProtocols
        The table of installed protocols on this Node
    • Constructor Detail

      • NodeAddress

        public NodeAddress()
    • Method Detail

      • getProtocol

        public java.lang.String getProtocol()
        Gets the string representing the protocol
        Returns:
        The String representation of the protocol part of the NodeAddress
      • getAddress

        public java.lang.String getAddress()
        Gets a string representing the address
        Returns:
        The String representation of the address part of the NodeAddress
      • toString

        public java.lang.String toString()
        Converts the NodeAddress into a String. The form is [protocol]\\[address]
        Overrides:
        toString in class java.lang.Object
        Returns:
        A String representation of this NodeAddress
      • hashCode

        public int hashCode()
        Gets the hash code of this object
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        Hashcode for this NodeAddress
      • equals

        public boolean equals​(java.lang.Object obj)
        Checks if this NodeAddress is equal to another
        Overrides:
        equals in class java.lang.Object
        Parameters:
        obj - The NodeAddress to compare to
        Returns:
        True if object is equal to this NodeAddress, false otherwise
      • compareTo

        public int compareTo​(java.lang.Object arg0)
        Compares this NodeAddress to another
        Specified by:
        compareTo in interface java.lang.Comparable
        Parameters:
        arg0 - The NodeAddress to compare to
        Returns:
        1 if object is greater than this one, 0 if they are equal, -1 otherwise
      • createLink

        protected abstract Link createLink()
                                    throws JCSPNetworkException
        Creates a Link connected to this address
        Returns:
        A new Link connected to this address
        Throws:
        JCSPNetworkException - If something goes wrong during the creation of the Link
      • createLinkServer

        protected abstract LinkServer createLinkServer()
                                                throws JCSPNetworkException
        Creates a LinkServer listening on this address
        Returns:
        A new LinkServer listening on this address
        Throws:
        JCSPNetworkException - If something goes wrong during the creation of the LinkServer
      • getProtocolID

        protected abstract ProtocolID getProtocolID()
        Retrieves the correct protocol handler for the implemented address type. This is used during Node initialisation
        Returns:
        the ProtocolID for this address type
      • parse

        public static NodeAddress parse​(java.lang.String str)
                                 throws java.lang.IllegalArgumentException
        Parses a string representation of a NodeAddress back to its object form
        Parameters:
        str - The string to parse
        Returns:
        A new NodeAddress created from a String form
        Throws:
        java.lang.IllegalArgumentException - Thrown if the string is not for a recognised protocol.
      • installProtocol

        public static void installProtocol​(java.lang.String name,
                                           ProtocolID protocol)
        Installs a new Protocol on the Node
        Parameters:
        name - Name of the protocol to install
        protocol - ProtocolID installed