com.limegroup.gnutella
Class ExtendedEndpoint

java.lang.Object
  extended bycom.limegroup.gnutella.Endpoint
      extended bycom.limegroup.gnutella.ExtendedEndpoint
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable, java.io.Serializable

public class ExtendedEndpoint
extends Endpoint

An endpoint with additional history information used to prioritize HostCatcher's permanent list:

ExtendedEndpoint has methods to read and write information to a single line of text, e.g.:
    "18.239.0.144:6347,3043,1039939393,529333939;3343434;23433,3934223"
 
This "poor man's serialization" is used to help HostCatcher implement the reading and writing of gnutella.net files.

ExtendedEndpoint does not override the compareTo method for two reasons:

For comparing by priority, users should use the return value of priorityComparator()

See Also:
Serialized Form

Field Summary
 
Fields inherited from class com.limegroup.gnutella.Endpoint
processed
 
Constructor Summary
ExtendedEndpoint(java.lang.String host, int port)
          Creates a new ExtendedEndpoint without extended uptime information.
ExtendedEndpoint(java.lang.String host, int port, int dailyUptime)
          Creates a new ExtendedEndpoint with uptime data read from a ping reply.
 
Method Summary
 boolean equals(java.lang.Object other)
          Endpoints are equal if their hostnames and ports are.
 java.util.Iterator getConnectionFailures()
          Returns the last few times we successfully connected to this.
 java.util.Iterator getConnectionSuccesses()
          Returns the last few times we successfully connected to this.
 int getDailyUptime()
          Returns the average daily uptime (in seconds per day) reported in this' pong.
 long getTimeRecorded()
          Returns the system time (in milliseconds) when this' was created.
protected  long now()
          Returns the current system time in milliseconds.
static java.util.Comparator priorityComparator()
          Returns a Comparator that compares ExtendedEndpoint's by priority, where ExtendedEndpoint's with higher priority are more likely to be available.
static ExtendedEndpoint read(java.lang.String line)
          Parses a new ExtendedEndpoint.
 void recordConnectionFailure()
          Records that we just failed to connect to this.
 void recordConnectionSuccess()
          Records that we just successfully connected to this.
 void write(java.io.Writer out)
          Writes this' state to a single line of out.
 
Methods inherited from class com.limegroup.gnutella.Endpoint
clone, compareTo, getConnectivity, getFiles, getHostBytes, getHostname, getKbytes, getPort, getWeight, hashCode, isPrivateAddress, isSameSubnet, normalizeFilesAndSize, setConnectivity, setFiles, setHostname, setKbytes, setWeight, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ExtendedEndpoint

public ExtendedEndpoint(java.lang.String host,
                        int port,
                        int dailyUptime)
Creates a new ExtendedEndpoint with uptime data read from a ping reply. The creation time is set to the current system time. It is assumed that that we have not yet attempted a connection to this.


ExtendedEndpoint

public ExtendedEndpoint(java.lang.String host,
                        int port)
Creates a new ExtendedEndpoint without extended uptime information. (The default will be used.) The creation time is set to the current system time. It is assumed that we have not yet attempted a connection to this.

Method Detail

getTimeRecorded

public long getTimeRecorded()
Returns the system time (in milliseconds) when this' was created.


getDailyUptime

public int getDailyUptime()
Returns the average daily uptime (in seconds per day) reported in this' pong.


recordConnectionSuccess

public void recordConnectionSuccess()
Records that we just successfully connected to this.


recordConnectionFailure

public void recordConnectionFailure()
Records that we just failed to connect to this.


getConnectionSuccesses

public java.util.Iterator getConnectionSuccesses()
Returns the last few times we successfully connected to this.

Returns:
an Iterator of system times in milliseconds, each as a Long, in descending order.

getConnectionFailures

public java.util.Iterator getConnectionFailures()
Returns the last few times we successfully connected to this.

Returns:
an Iterator of system times in milliseconds, each as a Long, in descending order.

now

protected long now()
Returns the current system time in milliseconds. Exists solely as a hook for testing.


write

public void write(java.io.Writer out)
           throws java.io.IOException
Writes this' state to a single line of out. Does not flush out.

Throws:
java.io.IOException - some problem writing to out
See Also:
read

read

public static ExtendedEndpoint read(java.lang.String line)
                             throws java.text.ParseException
Parses a new ExtendedEndpoint. Strictly validates all data. For example, addresses MUST be in dotted quad format.

Parameters:
line - a single line read from the stream
Returns:
the endpoint constructed from the line
Throws:
java.io.IOException - problem reading from in, e.g., EOF reached prematurely
java.text.ParseException - data not in proper format. Does NOT necessarily set the offset of the exception properly.
See Also:
write

priorityComparator

public static java.util.Comparator priorityComparator()
Returns a Comparator that compares ExtendedEndpoint's by priority, where ExtendedEndpoint's with higher priority are more likely to be available. Currently this is implemented as follows, though the heuristic may change in the future:


equals

public boolean equals(java.lang.Object other)
Description copied from class: Endpoint
Endpoints are equal if their hostnames and ports are. The number and size of files does not matter.

Overrides:
equals in class Endpoint