org.planx.xmlstore.routing
Class Node

java.lang.Object
  extended by org.planx.xmlstore.routing.Node
All Implemented Interfaces:
Streamable

public class Node
extends Object
implements Streamable

Represents a node and contains information about the IP address, UDP port, and ID of the node.

Author:
Thomas Ambus

Nested Class Summary
static class Node.DistanceComparator
          A DistanceComparator is capable of comparing Node objects according to closeness to a predetermined identifier using the XOR metric.
static class Node.FirstSeenComparator
          A FirstSeenComparator is capable of comparing Node objects according to time first seen.
static class Node.LastSeenComparator
          A LastSeenComparator is capable of comparing Node objects according to time last seen.
 
Field Summary
static Comparator FIRSTSEEN_COMPARATOR
           
static Comparator LASTSEEN_COMPARATOR
           
 
Constructor Summary
Node(DataInput in)
          Constructs a node by reading the state from a DataInput.
Node(InetAddress ip, int port, Identifier id)
          Constructs a node with the specified IP address, UDP port, and identifier.
Node(InetAddress ip, int port, int contactPort, Identifier id)
           
 
Method Summary
 boolean equals(Object o)
          Returns true if o is a Node and has the same identifier as this.
 long firstSeen()
          Returns the time this node was first seen.
 void fromStream(DataInput in)
          Reads the internal state of the Streamable object from the input stream.
 int getContactPort()
          Returns the contact port associated with this node.
 Identifier getId()
          Returns the identifier of this node.
 InetAddress getInetAddress()
          Returns the IP address of this node.
 int getPort()
          Returns the UDP port of this node.
 int hashCode()
           
 int incFailCount()
          Increments the failure counter and returns the new value.
 long lastSeen()
          Returns the time this node was last seen.
 void seenNow()
          Update time last seen for this node and reset fail count.
 void setContactPort(int contactPort)
          Sets the contact port associated with this node.
static Node[] sort(Collection nodes, Identifier rel)
          Sorts the nodes in the specified list in order of increasing distance to the specified identifier.
 void toStream(DataOutput out)
          Writes the internal state of the Streamable object to the output stream in a format that can later be read by the same Streamble class using the Streamable.fromStream(java.io.DataInput) method.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

LASTSEEN_COMPARATOR

public static final Comparator LASTSEEN_COMPARATOR

FIRSTSEEN_COMPARATOR

public static final Comparator FIRSTSEEN_COMPARATOR
Constructor Detail

Node

public Node(InetAddress ip,
            int port,
            Identifier id)
Constructs a node with the specified IP address, UDP port, and identifier. This constructor should be used for foreign nodes.


Node

public Node(InetAddress ip,
            int port,
            int contactPort,
            Identifier id)

Node

public Node(DataInput in)
     throws IOException
Constructs a node by reading the state from a DataInput.

Throws:
IOException
Method Detail

fromStream

public void fromStream(DataInput in)
                throws IOException
Description copied from interface: Streamable
Reads the internal state of the Streamable object from the input stream. Immutable objects should throw an UnsupportedOperationException, and instead implement a constructor as described above.

Specified by:
fromStream in interface Streamable
Throws:
IOException

toStream

public void toStream(DataOutput out)
              throws IOException
Description copied from interface: Streamable
Writes the internal state of the Streamable object to the output stream in a format that can later be read by the same Streamble class using the Streamable.fromStream(java.io.DataInput) method.

Specified by:
toStream in interface Streamable
Throws:
IOException

seenNow

public void seenNow()
Update time last seen for this node and reset fail count.


firstSeen

public long firstSeen()
Returns the time this node was first seen.


lastSeen

public long lastSeen()
Returns the time this node was last seen.


getInetAddress

public InetAddress getInetAddress()
Returns the IP address of this node.


getPort

public int getPort()
Returns the UDP port of this node.


getId

public Identifier getId()
Returns the identifier of this node.


getContactPort

public int getContactPort()
Returns the contact port associated with this node.


setContactPort

public void setContactPort(int contactPort)
Sets the contact port associated with this node.


incFailCount

public int incFailCount()
Increments the failure counter and returns the new value.


equals

public boolean equals(Object o)
Returns true if o is a Node and has the same identifier as this. Note that IP address and port are ignored in this comparison.

Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object

sort

public static Node[] sort(Collection nodes,
                          Identifier rel)
Sorts the nodes in the specified list in order of increasing distance to the specified identifier.



Copyright © 2010. All Rights Reserved.