edu.harvard.syrah.pyxida.nc.lib
Class NCClient<T>

java.lang.Object
  extended by edu.harvard.syrah.pyxida.nc.lib.NCClient<T>
Type Parameters:
T - the type of the unique identifier of a host A note about time: Try to not use System.currentTimeMillis or similar references to the system's time in this code. This code should be able to run in simulation, where arbitrary times are passed in as parameters.
All Implemented Interfaces:
NCClientIF<T>
Direct Known Subclasses:
AppCoordClient

public class NCClient<T>
extends java.lang.Object
implements NCClientIF<T>

A class that is responsible for updating the local Vivaldi coordinates, both at the system and application level, and also maintaining the state of remote hosts that support Vivaldi.


Field Summary
static double COORD_CONTROL
           
static double COORD_ERROR
           
static byte CURRENT_VERSION
           
static boolean DEBUG
           
protected  double error
           
static double GRAVITY_DIAMETER
           
protected  java.util.Set<T> hosts
           
static boolean KEEP_STATS
           
protected  T local_addr
           
protected static edu.harvard.syrah.prp.Log logger
           
static long MAINTENANCE_PERIOD
           
static double MAX_DIST_FROM_ORIGIN
           
static double MAX_ERROR
           
static int MAX_NEIGHBORS
           
static long MAX_PING_RESPONSE_TIME
           
static int MAX_RS_MAP_SIZE
           
static long MIN_UPDATE_TIME_TO_PING
           
protected  java.util.List<RemoteState<T>> neighbors
           
protected static java.text.NumberFormat nf
           
protected static int NFDigits
           
protected  int num_dims
           
protected  ObserverList obs_list
           
static double OUTRAGEOUSLY_LARGE_RTT
           
static java.util.Random random
           
static long RS_EXPIRATION
           
protected  java.util.HashMap<T,RemoteState<T>> rs_map
           
static int RUNNING_STAT_HISTORY
           
protected  EWMAStatistic running_sys_dd
           
protected  WindowStatistic running_sys_error
           
protected  EWMAStatistic running_sys_update_frequency
           
static boolean SIM
           
protected  Coordinate sys_coord
           
protected  long time_of_last_sys_update
           
static boolean USE_HEIGHT
           
static boolean VERBOSE
           
static byte VERSION_04
           
 
Constructor Summary
NCClient(int _num_dims)
          Creates a new instance.
 
Method Summary
 boolean addHost(T addr)
          Notifies this VivaldiClient object that a host that supports Vivaldi has joined the system.
 boolean addHost(T addr, Coordinate _r_coord, double r_error, long curr_time, boolean can_update)
          Notifies this VivaldiClient object that a host that supports Vivaldi and has the provided coordinates and error has joined the system.
protected  boolean addNeighbor(RemoteState<T> guy)
           
 boolean containsHost(T addr)
          Returns whether the given host has been registered with this VivaldiClient object.
 long getAge(long curr_time)
          Returns the age of our coordinate Note that this does not require clock-synchronization because it is relative to our coordinate
 double getDistanceDelta()
           
 java.util.Set<T> getHosts()
          Returns all hosts that support Vivaldi and have been registered with this VivaldiClient object.
protected  int getIdFromAddr(T addr)
           
 T getNeighborToPing(long curr_time)
           
 int getNumDimensions()
          Returns the dimension of the Euclidian space coordinates are embedded in.
 ObserverList getObserverList()
          Returns the list of observers, to which observers for the application-level coordinate can be added, removed, and so forth.
 java.util.Hashtable<java.lang.String,java.lang.Double> getStatistics()
           
 Coordinate getSystemCoords()
          Returns the system-level Vivaldi coordinates.
 double getSystemError()
          Returns the system-level error, which denotes the accuracy of the system-level coordinates.
 boolean hasAllNeighbors()
           
protected  void performMaintenance(long curr_time)
           
 java.lang.String printNeighbors()
           
 boolean processSample(T addr, Coordinate _r_coord, double r_error, double sample_rtt, long sample_age, long curr_time, boolean can_add)
          This method is invoked when a new RTT sample is made to a host that supports Vivaldi.
 boolean removeHost(T addr)
          Notifies this VivaldiClient object that a host that supports Vivaldi has left the system.
protected  boolean removeNeighbor(RemoteState<T> guy)
           
 void reset()
           
 void setLocalID(T _local_addr)
           
static void setRandomSeed(long seed)
           
static void setRealLargeNetworkParameters()
           
 void shutDown(java.io.DataOutputStream os)
           
protected  void simpleCoordinateUpdate(T addr, Coordinate r_coord, double r_error, double rtt, double sample_rtt, long sample_age, int sample_size, long curr_time)
           
 boolean stabilized()
           
 void startUp(java.io.DataInputStream is)
           
 java.lang.String toString()
           
protected  void updateError(T addr, Coordinate r_coord, double r_error, double smoothed_rtt, double sample_rtt, long sample_age, int sample_size, long curr_time)
           
protected  void updateSystemCoordinate(long curr_time)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

protected static edu.harvard.syrah.prp.Log logger

KEEP_STATS

public static boolean KEEP_STATS

DEBUG

public static boolean DEBUG

VERBOSE

public static boolean VERBOSE

SIM

public static boolean SIM

VERSION_04

public static final byte VERSION_04
See Also:
Constant Field Values

CURRENT_VERSION

public static final byte CURRENT_VERSION
See Also:
Constant Field Values

COORD_ERROR

public static double COORD_ERROR

COORD_CONTROL

public static double COORD_CONTROL

USE_HEIGHT

public static boolean USE_HEIGHT

MAX_NEIGHBORS

public static int MAX_NEIGHBORS

RS_EXPIRATION

public static long RS_EXPIRATION

MAINTENANCE_PERIOD

public static final long MAINTENANCE_PERIOD
See Also:
Constant Field Values

MAX_PING_RESPONSE_TIME

public static final long MAX_PING_RESPONSE_TIME
See Also:
Constant Field Values

MAX_RS_MAP_SIZE

public static final int MAX_RS_MAP_SIZE
See Also:
Constant Field Values

random

public static java.util.Random random

OUTRAGEOUSLY_LARGE_RTT

public static double OUTRAGEOUSLY_LARGE_RTT

GRAVITY_DIAMETER

public static double GRAVITY_DIAMETER

MAX_DIST_FROM_ORIGIN

public static double MAX_DIST_FROM_ORIGIN

MIN_UPDATE_TIME_TO_PING

public static long MIN_UPDATE_TIME_TO_PING

nf

protected static final java.text.NumberFormat nf

NFDigits

protected static final int NFDigits
See Also:
Constant Field Values

num_dims

protected final int num_dims

sys_coord

protected Coordinate sys_coord

error

protected double error

MAX_ERROR

public static final double MAX_ERROR
See Also:
Constant Field Values

RUNNING_STAT_HISTORY

public static int RUNNING_STAT_HISTORY

running_sys_error

protected WindowStatistic running_sys_error

running_sys_dd

protected EWMAStatistic running_sys_dd

running_sys_update_frequency

protected EWMAStatistic running_sys_update_frequency

neighbors

protected final java.util.List<RemoteState<T>> neighbors

time_of_last_sys_update

protected long time_of_last_sys_update

obs_list

protected final ObserverList obs_list

rs_map

protected final java.util.HashMap<T,RemoteState<T>> rs_map

hosts

protected final java.util.Set<T> hosts

local_addr

protected T local_addr
Constructor Detail

NCClient

public NCClient(int _num_dims)
Creates a new instance. Typically an application should only have one instance of this class, as it only needs one set of Vivaldi coordinates.

Parameters:
_num_dims - the number of Euclidian dimensions coordinates should have
Method Detail

setRealLargeNetworkParameters

public static void setRealLargeNetworkParameters()

setLocalID

public void setLocalID(T _local_addr)
Specified by:
setLocalID in interface NCClientIF<T>

toString

public java.lang.String toString()
Specified by:
toString in interface NCClientIF<T>
Overrides:
toString in class java.lang.Object

getStatistics

public java.util.Hashtable<java.lang.String,java.lang.Double> getStatistics()
Specified by:
getStatistics in interface NCClientIF<T>

getDistanceDelta

public double getDistanceDelta()

reset

public void reset()
Specified by:
reset in interface NCClientIF<T>

getNumDimensions

public int getNumDimensions()
Description copied from interface: NCClientIF
Returns the dimension of the Euclidian space coordinates are embedded in.

Specified by:
getNumDimensions in interface NCClientIF<T>
Returns:
the coordinate space dimension

getSystemCoords

public Coordinate getSystemCoords()
Description copied from interface: NCClientIF
Returns the system-level Vivaldi coordinates. These coordinates change more frequently than the application-level coordinates.

Specified by:
getSystemCoords in interface NCClientIF<T>
Returns:
the system-level coordinates

getSystemError

public double getSystemError()
Description copied from interface: NCClientIF
Returns the system-level error, which denotes the accuracy of the system-level coordinates.

Specified by:
getSystemError in interface NCClientIF<T>
Returns:
the system-level error

getAge

public long getAge(long curr_time)
Description copied from interface: NCClientIF
Returns the age of our coordinate Note that this does not require clock-synchronization because it is relative to our coordinate

Specified by:
getAge in interface NCClientIF<T>
Returns:
relative age of our coordinate since we last updated it

getObserverList

public ObserverList getObserverList()
Description copied from interface: NCClientIF
Returns the list of observers, to which observers for the application-level coordinate can be added, removed, and so forth.

Specified by:
getObserverList in interface NCClientIF<T>
Returns:
the list of observers for the application-level coordinate

addHost

public boolean addHost(T addr)
Description copied from interface: NCClientIF
Notifies this VivaldiClient object that a host that supports Vivaldi has joined the system. State associated with the new host is created. This method succeeds and returns true only if the host is not already registered with this VivaldiClient object.

Specified by:
addHost in interface NCClientIF<T>
Parameters:
addr - the address of the joining host
Returns:
true if addr is registered and its associated state created, false otherwise

addHost

public boolean addHost(T addr,
                       Coordinate _r_coord,
                       double r_error,
                       long curr_time,
                       boolean can_update)
Description copied from interface: NCClientIF
Notifies this VivaldiClient object that a host that supports Vivaldi and has the provided coordinates and error has joined the system. State associated with the new host is created. This method succeeds and returns true only if the host is not already registered with this VivaldiClient object.

Specified by:
addHost in interface NCClientIF<T>
Parameters:
addr - the address of the joining host
_r_coord - the app-level coordinates of the remote host
r_error - the system-level error of the remote host
curr_time - the current time, in milliseconds
can_update - true if this method can update a host already present
Returns:
true if addr is registered and its associated state created, false otherwise

removeHost

public boolean removeHost(T addr)
Description copied from interface: NCClientIF
Notifies this VivaldiClient object that a host that supports Vivaldi has left the system. However, the state (i.e. short list of RTT values) is kept because it will be useful if and when the node returns into the system

Specified by:
removeHost in interface NCClientIF<T>
Parameters:
addr - the address of the departing host
Returns:
true if addr was a known node

containsHost

public boolean containsHost(T addr)
Description copied from interface: NCClientIF
Returns whether the given host has been registered with this VivaldiClient object.

Specified by:
containsHost in interface NCClientIF<T>
Parameters:
addr - the address to query as registered
Returns:
true if registered, false otherwise

getHosts

public java.util.Set<T> getHosts()
Description copied from interface: NCClientIF
Returns all hosts that support Vivaldi and have been registered with this VivaldiClient object. The returned set is backed by the true set of registered hosts, but cannot be modified.

Specified by:
getHosts in interface NCClientIF<T>
Returns:
the set of registered Vivaldi-supporting hosts

processSample

public boolean processSample(T addr,
                             Coordinate _r_coord,
                             double r_error,
                             double sample_rtt,
                             long sample_age,
                             long curr_time,
                             boolean can_add)
Description copied from interface: NCClientIF
This method is invoked when a new RTT sample is made to a host that supports Vivaldi. This method succeeds and returns true only if the host is already registered with this VivaldiClient object, and the RTT sample is valid.

Specified by:
processSample in interface NCClientIF<T>
Parameters:
addr - the address of the host
_r_coord - the system-level coordinates of the remote host
r_error - the system-level error of the remote host
sample_rtt - the RTT sample to the remote host
curr_time - the current time, in milliseconds
can_add - true if this method can add a host not already present
Returns:
true if addr is registered and the sample is processed, false otherwise

getIdFromAddr

protected int getIdFromAddr(T addr)

simpleCoordinateUpdate

protected void simpleCoordinateUpdate(T addr,
                                      Coordinate r_coord,
                                      double r_error,
                                      double rtt,
                                      double sample_rtt,
                                      long sample_age,
                                      int sample_size,
                                      long curr_time)

updateError

protected void updateError(T addr,
                           Coordinate r_coord,
                           double r_error,
                           double smoothed_rtt,
                           double sample_rtt,
                           long sample_age,
                           int sample_size,
                           long curr_time)

addNeighbor

protected boolean addNeighbor(RemoteState<T> guy)

hasAllNeighbors

public boolean hasAllNeighbors()
Specified by:
hasAllNeighbors in interface NCClientIF<T>

stabilized

public boolean stabilized()
Specified by:
stabilized in interface NCClientIF<T>

printNeighbors

public java.lang.String printNeighbors()
Specified by:
printNeighbors in interface NCClientIF<T>

removeNeighbor

protected boolean removeNeighbor(RemoteState<T> guy)

getNeighborToPing

public T getNeighborToPing(long curr_time)
Specified by:
getNeighborToPing in interface NCClientIF<T>

updateSystemCoordinate

protected void updateSystemCoordinate(long curr_time)

performMaintenance

protected void performMaintenance(long curr_time)

setRandomSeed

public static void setRandomSeed(long seed)

startUp

public void startUp(java.io.DataInputStream is)
             throws java.io.IOException
Specified by:
startUp in interface NCClientIF<T>
Throws:
java.io.IOException

shutDown

public void shutDown(java.io.DataOutputStream os)
              throws java.io.IOException
Specified by:
shutDown in interface NCClientIF<T>
Throws:
java.io.IOException