ostore.tapestry.impl
Class RouteEntry

java.lang.Object
  |
  +--ostore.tapestry.impl.RouteEntry
All Implemented Interfaces:
QuickSerializable

public class RouteEntry
extends Object
implements QuickSerializable

Implements the routing table entry with multiple outgoing routes. This class supports sorted insertion of routes into the entry, and returns the best entry for general usage.

Version:
$Id: RouteEntry.java,v 1.31 2003/05/08 02:03:59 strib Exp $
Author:
Ben Y. Zhao

Inner Class Summary
static class RouteEntry.NodeEntry
           
 
Field Summary
static int LATENCY
           
static int LEAVING
           
static int LOCKED
           
static int LOSS
           
static int REDUNDANT_LVL
           
static short STATUS_ALIVE
           
static short STATUS_DEAD
           
static short STATUS_REPAIR_ONE
           
static short STATUS_REPAIR_TWO
           
 
Constructor Summary
RouteEntry()
           
RouteEntry(InputBuffer buffer)
           
RouteEntry(NodeId route, Double latency)
           
RouteEntry(NodeId route, Double latency, int flag)
           
 
Method Summary
 boolean add(NodeId newnode, Double latency, NodeId[] removed_node, Pair[] frlschanged)
          Function used to add a new entry to the RouteEntry.
 int get_frls()
           
 NodeId getAtIndex(int i)
          Method to return a NodeId at a position in the RouteEntry.
 RouteEntry.NodeEntry getEntryAt(int i)
           
 NodeId getFirst()
          Method to return the first (primary) NodeId address of this RouteEntry.
 NodeId getFRLS()
          Method to return the frls NodeId address of this RouteEntry.
 RouteEntry.NodeEntry[] getRoutes()
           
 boolean isLeavingAtIndex(int i)
          Method to ask whether a NodeEntry at a particular position is in the process of leaving or not.
 boolean isLockedAtIndex(int i)
          Method to ask whether a NodeEntry at a particular position is marked as locked (in the process of insertion) or not.
 boolean markLeaving(NodeId leavingnode)
          Function to mark a node as leaving
 boolean need_multicast(int mcast_threshold)
           
 Pair recalcFRLS()
          Method to recalculate who the FRLS entry should point to.
 Pair removeEntry(NodeId node)
          Search for an existing nodeid if it's in this entry, and remove it
 void serialize(OutputBuffer buffer)
          Add the object to the buffer.
 void setEntryAt(int i, RouteEntry.NodeEntry ne)
           
 int size()
           
 void sortRoutes(int criteria)
          Sort the entry according the given criteria.
 void switchRoutes(int from, int to)
           
 String toString()
           
 void updateLatency(NodeId route, Double latency)
          Search to see if route is actually part of this routeEntry.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

REDUNDANT_LVL

public static final int REDUNDANT_LVL

LOCKED

public static final int LOCKED

LEAVING

public static final int LEAVING

LOSS

public static final int LOSS

LATENCY

public static final int LATENCY

STATUS_ALIVE

public static final short STATUS_ALIVE

STATUS_DEAD

public static final short STATUS_DEAD

STATUS_REPAIR_ONE

public static final short STATUS_REPAIR_ONE

STATUS_REPAIR_TWO

public static final short STATUS_REPAIR_TWO
Constructor Detail

RouteEntry

public RouteEntry()

RouteEntry

public RouteEntry(NodeId route,
                  Double latency)

RouteEntry

public RouteEntry(NodeId route,
                  Double latency,
                  int flag)

RouteEntry

public RouteEntry(InputBuffer buffer)
           throws QSException
Method Detail

recalcFRLS

public Pair recalcFRLS()
Method to recalculate who the FRLS entry should point to. By default, the criteria we're judging FRLS on is failure rate, and the threshold value we use is Router.THRESHOLD_FRLS.
Returns:
Pair of Ints (oldfrls, newfrls), or null if no change made.

need_multicast

public boolean need_multicast(int mcast_threshold)

getRoutes

public RouteEntry.NodeEntry[] getRoutes()

get_frls

public int get_frls()

getFRLS

public NodeId getFRLS()
Method to return the frls NodeId address of this RouteEntry. This is the method we should use for ALL routing lookups. Returns null if no such NodeId exists.

getEntryAt

public RouteEntry.NodeEntry getEntryAt(int i)

setEntryAt

public void setEntryAt(int i,
                       RouteEntry.NodeEntry ne)

getFirst

public NodeId getFirst()
Method to return the first (primary) NodeId address of this RouteEntry. This method should be used RARELY and SPARINGLY to examine the routes, and at all other times, getFRLS should be used. Returns null if no such NodeId exists.

getAtIndex

public NodeId getAtIndex(int i)
Method to return a NodeId at a position in the RouteEntry. Result could be null if no NodeEntry exists at that position.

isLeavingAtIndex

public boolean isLeavingAtIndex(int i)
Method to ask whether a NodeEntry at a particular position is in the process of leaving or not.

isLockedAtIndex

public boolean isLockedAtIndex(int i)
Method to ask whether a NodeEntry at a particular position is marked as locked (in the process of insertion) or not.

removeEntry

public Pair removeEntry(NodeId node)
Search for an existing nodeid if it's in this entry, and remove it
Parameters:
node - The node to be replaced
Returns:
pair of oldfrls, newfrls if FRLS has changed, and a republish is necessary

markLeaving

public boolean markLeaving(NodeId leavingnode)
Function to mark a node as leaving
Parameters:
leavingnode - The node in process of leaving the network
Returns:
whether the node was found in this routeEntry

add

public boolean add(NodeId newnode,
                   Double latency,
                   NodeId[] removed_node,
                   Pair[] frlschanged)
Function used to add a new entry to the RouteEntry. We need to sort this guy compared to our current entries.
Parameters:
removed_node - Parameter hack for returning the node (if any) that was kicked out of the table during this writing. Like a pointer in C.
Returns:
True or false, whether this entry was added to the route entry.

switchRoutes

public void switchRoutes(int from,
                         int to)

sortRoutes

public void sortRoutes(int criteria)
Sort the entry according the given criteria.

updateLatency

public void updateLatency(NodeId route,
                          Double latency)
Search to see if route is actually part of this routeEntry. If so, then update its latency, and then do a sort to reorder the routes by latency

toString

public String toString()
Overrides:
toString in class Object

size

public int size()

serialize

public void serialize(OutputBuffer buffer)
Description copied from interface: QuickSerializable
Add the object to the buffer.
Specified by:
serialize in interface QuickSerializable
Following copied from interface: ostore.util.QuickSerializable
Parameters:
buffer - the output buffer to add the object to