Package org.jcsp.net2

Class NodeID

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable

    public final class NodeID
    extends java.lang.Object
    implements java.lang.Comparable, java.io.Serializable
    This class is used to uniquely identify a Node within the entire JCSP network of Nodes in operation. This is to allow ease to identify individual Nodes when IDs come in, and to quickly find them within tables of other Links to allow usage of existing connections. This is different to a NodeAddress, which is a symbolic name representing a Node, and which therefore may be repeated. The hope here is that by using enough pieces of data the Node should have a unique identification. This is done by gathering the information on the current system time in milliseconds, the current free memory of the JVM, the hash code of a newly created object, the name of the Node, if there is one, and the address of the Node itself. Having this much information should provide us with a unique ID. Other implementations of the protocol can use other means of identifying a Node uniquely, but they must use the same amount of data, e.g. string(number 64 bits) - string(number 64 bits) - string (number 32 bits) - string - address string, when communicating with another JCSP Node for the sake of compatibility.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private NodeAddress address
      Address of the Node
      private int hashCode
      Hash code of a object
      private long mem
      Current amount of free memory to the JVM
      private java.lang.String name
      Name of the Node
      private static long serialVersionUID
      The SUID of this class
      private long time
      Current time in milliseconds
    • Constructor Summary

      Constructors 
      Constructor Description
      NodeID​(long long1, long long2, int int1, java.lang.String nodeName, NodeAddress nodeAddress)
      Constructor taking the full details for a remote Node connection
      NodeID​(java.lang.String nodeName, NodeAddress nodeAddress)
      Constructor taking the name and the address of the Node
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compareTo​(java.lang.Object arg0)
      Compares this NodeID with another NodeID.
      boolean equals​(java.lang.Object arg0)
      Checks if the given object is equal to this NodeID
      NodeAddress getNodeAddress()
      Gets the NodeAddress part of the NodeID
      int hashCode()
      Returns the hashCode for this object
      static NodeID parse​(java.lang.String str)
      Converts a string representation of a NodeID back to a NodeID object
      java.lang.String toString()
      Converts the NodeID into a string for communication with other implementations, or for display purposes.
      • Methods inherited from class java.lang.Object

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

      • serialVersionUID

        private static final long serialVersionUID
        The SUID of this class
        See Also:
        Constant Field Values
      • time

        private final long time
        Current time in milliseconds
      • mem

        private final long mem
        Current amount of free memory to the JVM
      • hashCode

        private final int hashCode
        Hash code of a object
      • name

        private final java.lang.String name
        Name of the Node
      • address

        private final NodeAddress address
        Address of the Node
    • Constructor Detail

      • NodeID

        NodeID​(java.lang.String nodeName,
               NodeAddress nodeAddress)
        Constructor taking the name and the address of the Node
        Parameters:
        nodeName - Symbolic name of the Node
        nodeAddress - Symbolic address of the Node
      • NodeID

        public NodeID​(long long1,
                      long long2,
                      int int1,
                      java.lang.String nodeName,
                      NodeAddress nodeAddress)
        Constructor taking the full details for a remote Node connection
        Parameters:
        long1 - The time component of the remote Node
        long2 - The memory component of the remote Node
        int1 - The hashCode component of the remote Node
        nodeName - The name component of the remote Node
        nodeAddress - The NodeAddress component of the remote Node
    • Method Detail

      • compareTo

        public int compareTo​(java.lang.Object arg0)
        Compares this NodeID with another NodeID.
        Specified by:
        compareTo in interface java.lang.Comparable
        Parameters:
        arg0 -
        Returns:
        -1, 0 or 1 if less than, equal, or greater than the other NodeID
      • equals

        public boolean equals​(java.lang.Object arg0)
        Checks if the given object is equal to this NodeID
        Overrides:
        equals in class java.lang.Object
        Parameters:
        arg0 -
        Returns:
        True if equal, false otherwise
      • hashCode

        public int hashCode()
        Returns the hashCode for this object
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        Hashcode for the NodeID
      • toString

        public java.lang.String toString()
        Converts the NodeID into a string for communication with other implementations, or for display purposes.
        Overrides:
        toString in class java.lang.Object
        Returns:
        String representation of the NodeID
      • getNodeAddress

        public NodeAddress getNodeAddress()
        Gets the NodeAddress part of the NodeID
        Returns:
        The NodeAddress part of the NodeID
      • parse

        public static NodeID parse​(java.lang.String str)
        Converts a string representation of a NodeID back to a NodeID object
        Parameters:
        str - The string version of a NodeID
        Returns:
        A new NodeID created from the String representation