jist.runtime
Class Node

java.lang.Object
  extended by jist.runtime.Node
All Implemented Interfaces:
java.io.Serializable

public final class Node
extends java.lang.Object
implements java.io.Serializable

Stores and manipulates host:port information.

Since:
JIST1.0
See Also:
Serialized Form

Constructor Summary
Node(byte[] node, int offset)
          Instantiate node object from serialized information in byte array at given offset.
Node(byte[] addr, short port)
          Instantiate node object with given host and port.
Node(java.net.InetAddress host, int port)
          Instantiate node object with given host and port.
Node(java.net.InetAddress host, short port)
          Instantiate node object with given host and port.
Node(int port)
          Instantiate node object with given port on local host.
Node(short port)
          Instantiate node object with given port on the local host.
Node(java.lang.String host, int port)
          Instantiate node object with host string and port.
Node(java.lang.String host, short port)
          Instantiate node object with given host and port.
 
Method Summary
 boolean equals(java.lang.Object o)
          Determine whether this node is the same as another.
 java.net.InetAddress getHost()
          Return host Internet address of current node.
 java.lang.String getHostString()
          Return host string of current node.
static java.net.InetAddress getLocalHostLinux(java.lang.String iface)
          Find local host Internet address using Unix mechanisms.
 short getPort()
          Return port of current node.
 int hashCode()
          Return node hash code.
static Node parse(java.lang.String s)
          Parse String (host:port) into a Node.
static Node parse(java.lang.String s, int defaultPort)
          Parse string (host:port) into a Node, using the default port if the string does not contain a port.
 byte[] toByteArray()
          Serialize node instance into byte array.
 void toByteArray(byte[] b, int offset)
          Serialize node instance into byte array.
 java.lang.String toString()
          Return string representation of node in format host:port.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Node

public Node(java.net.InetAddress host,
            short port)
Instantiate node object with given host and port.

Parameters:
host - Internet address of node instance
port - port of node instance

Node

public Node(java.lang.String host,
            short port)
     throws java.net.UnknownHostException
Instantiate node object with given host and port.

Parameters:
host - Internet address or name of node instance
port - port of node instance
Throws:
java.net.UnknownHostException - thrown if named host can not be resolved

Node

public Node(byte[] addr,
            short port)
     throws java.net.UnknownHostException
Instantiate node object with given host and port.

Parameters:
addr - Internet address of node instance as quad-byte array
port - port of node instance
Throws:
java.net.UnknownHostException - never

Node

public Node(short port)
Instantiate node object with given port on the local host.

Parameters:
port - port of node instance

Node

public Node(java.net.InetAddress host,
            int port)
Instantiate node object with given host and port. Convenience method to accept integer ports and convert to short.

Parameters:
host - Internet address of node instance
port - port of node instance

Node

public Node(java.lang.String host,
            int port)
     throws java.net.UnknownHostException
Instantiate node object with host string and port. Convenience method to accept integer ports and convert to short.

Parameters:
host - Internet address string of node instance
port - port of node instance
Throws:
java.net.UnknownHostException - invalid host name or IP address

Node

public Node(int port)
Instantiate node object with given port on local host. Convenience method to accept integer ports and convert to short.

Parameters:
port - port of node instance

Node

public Node(byte[] node,
            int offset)
Instantiate node object from serialized information in byte array at given offset. The byte array must contain 4-bytes for the Internet address and 2-bytes for the port.

Parameters:
node - byte array with node information
offset - location of information within byte array
Method Detail

toByteArray

public byte[] toByteArray()
Serialize node instance into byte array. The byte array will be of length 6.

Returns:
serialized node information

toByteArray

public void toByteArray(byte[] b,
                        int offset)
Serialize node instance into byte array. The serialized byte representation of a node occupies 6 bytes.

Parameters:
b - byte array to place node information into
offset - starting location within byte array.

parse

public static Node parse(java.lang.String s)
                  throws java.net.UnknownHostException
Parse String (host:port) into a Node.

Parameters:
s - serialized node string in format host:port
Returns:
node instance
Throws:
java.net.UnknownHostException - thrown if host name within string can not be resolved

parse

public static Node parse(java.lang.String s,
                         int defaultPort)
                  throws java.net.UnknownHostException
Parse string (host:port) into a Node, using the default port if the string does not contain a port.

Parameters:
s - serialized node string in format host[:port]
defaultPort - default port to use if port omitted
Returns:
parsed node object
Throws:
java.net.UnknownHostException - thrown if host name within string can not be resolved.

getHost

public java.net.InetAddress getHost()
Return host Internet address of current node.

Returns:
host Internet address

getHostString

public java.lang.String getHostString()
Return host string of current node.

Returns:
host string

getPort

public short getPort()
Return port of current node.

Returns:
node port

toString

public java.lang.String toString()
Return string representation of node in format host:port.

Overrides:
toString in class java.lang.Object
Returns:
string representation of node in format host:port

equals

public boolean equals(java.lang.Object o)
Determine whether this node is the same as another.

Overrides:
equals in class java.lang.Object
Parameters:
o - object to test equality
Returns:
whether this node is equal to given object

hashCode

public int hashCode()
Return node hash code.

Overrides:
hashCode in class java.lang.Object
Returns:
node hash code

getLocalHostLinux

public static java.net.InetAddress getLocalHostLinux(java.lang.String iface)
Find local host Internet address using Unix mechanisms. Specifically, this method invokes 'ifconfig', and parses its output, searching for the IP address of the given interface.

Parameters:
iface - network interface to query 'ifconfig'
Returns:
Internet address of localhost, or null if it can not be discovered.