planet.symphony
Class SymphonyNode

java.lang.Object
  extended byplanet.generic.commonapi.NodeImpl
      extended byplanet.symphony.SymphonyNode
All Implemented Interfaces:
Node, java.io.Serializable

public class SymphonyNode
extends NodeImpl

This node is an implementation of the Symphony overlay.

Author:
Helio Tejedor, Marc Sanchez, Ruben Mondejar, Carles Pairot, Jordi Pujol
See Also:
Serialized Form

Nested Class Summary
 class SymphonyNode.StabilizeTask
          Simple TimerTask that invoke stabilize() Node method.
 
Field Summary
static int ACCEPT_CONNECT
           
 boolean alive
           
static int CANCEL_CONNECT
           
static int CLOSE_LONG_CONNECT
           
static int CLOSE_NEIGHBOUR_CONNECT
           
static int DATA
          Type value: It identifies that this message contains an application level Message.
 boolean fixedNeighbours
           
static java.lang.String[] MODES
          This String contains a string representation of each mode value of the RouteMessage.
 SortedKList neighbourSet
           
static int NumberOfModes
           
static int NumberOfTypes
           
static int QUERY_CONNECT
           
static int QUERY_JOIN
          Type value: First message that is send by any node to get its inmediate successor.
static int REFRESH
          Mode value: Defines a message's mode that requires only communication on one way.
static int REPLY
          Mode value: Defines the response of a communication.
static int REQUEST
          Mode value: Defines the start of communication that requires response (REPLY).
 int retriesNewLongDistance
           
static int SET_INFO
           
 int statisticStabilizationSteps
           
 boolean statisticStabilized
           
static java.lang.String[] TYPES
          This String contains a string representation of each type value of the RouteMessage.
 
Fields inherited from class planet.generic.commonapi.NodeImpl
endpoints, id, listeners, nodeHandle, role
 
Constructor Summary
SymphonyNode()
          Initialize the internal data structure.
 
Method Summary
 boolean addToNeighbourSet(java.util.Collection c, boolean adviceForClosing)
          Add all NodeHandle in the c Collection to the neighbour set.
 void addToNeighbourSet(NodeHandle neighbour)
          Add the neighbour to hte neighbour set.
 void broadcast(java.lang.String appId, NodeHandle to, NodeHandle nextHop, Message msg)
          This method throws a NoSuchMethodError, because the broadcast algorithm is not implemented yet.
 void buildEdges(java.lang.String resultName, java.util.Collection edgeCollection, ResultsConstraint constraint)
          This method is a callback method used to collect all of the edges of a graph according to current resultName format.
 RouteMessage buildMessage(NodeHandle from, NodeHandle to, int type, int mode, Message m)
          Builds a RouteMessage with the specified data.
 RouteMessage buildMessage(NodeHandle from, NodeHandle to, int type, int mode, Message m, java.lang.String key)
          Builds a new RouteMessage with the specified data.
 RouteMessage buildMessage(NodeHandle from, NodeHandle to, NodeHandle nextHop, int type, int mode, Message m)
          Builds a nw RouteMessage with the specified data.
 RouteMessage buildMessage(NodeHandle from, NodeHandle to, NodeHandle nextHop, int type, int mode, Message m, java.lang.String key)
          Builds a RouteMessage with the specified data.
 RouteMessage buildMessage(RouteMessage toCopy, NodeHandle nextHop)
          Builds a new RouteMessage with all the values appeared in toCopy, and the specified nextHop.
 void dispatcher(RouteMessage msg)
          Dispatch any incomming RouteMessage and update the local state or is resent to other node.
 void fail()
          The leave protocol is the same as in leave case.
 java.util.Set getAllLinks()
          Gets all node connections to other nodes as its NodeHandles.
 NodeHandle getClosestNodeHandle(Id id)
          Returns the NodeHandle closest to id.
 java.util.Hashtable getEndPoints()
          Return the endpoints, based on (key,value) structure, where the key is the Application name, and the value the own EndPoint instance.
 java.util.Collection getFarthestNeighbours()
          Gets the farthest neighbours.
 java.util.List getIncommingSet()
          Get the incomming set of long distance connections.
 java.util.Hashtable getInfo()
          This method returns the internal data in a Hashtable, where the key is a String with the field name, and the value, the related object.
static int getLongDistanceNumber()
          Gets the maximum number of long distance links per node.
 java.util.Collection getNeighbourSet()
          Gets the neightbour set.
 RouteMessage getNewLongDistance()
          Returns a RouteMessage to be sent to acquire a new long distance.
 java.util.List getOutcommingSet()
          Get the outcomming set of long distance connections.
 NodeHandle getPred()
          Returns the NodeHandle of node predecessor.
 NodeHandle getSucc()
          Returns the NodeHandle of node successor.
static int getSuccessorsNumber()
          Gets the maximum number of successors per node.
 java.util.Vector getSuccList(int max)
          Returns up to max successors of the actual node.
 boolean isAlive()
          Shows if the node is already alive.
 boolean isLocalMessage(RouteMessage msg)
          The isLocalMessage's method is an extension method for commonapi specs.
 boolean isStabilized()
          Informs if this node is stabilized.
 void join(NodeHandle bootstrap)
          This node joins to the overlay network by the bootstrap node with NodeHandle bootstrap.
 void leave()
          Leaves the node from the overlay network.
 java.util.Vector localLookup(Id key, int max, boolean safe)
          Returns a list of nodes that can be used as next hops on a route towards key.
 java.util.Vector neighborSet(int max)
          Obtains an unordered list of up to max nodes that are neighbors of the local node.
 boolean neighbourSetContains(NodeHandle o)
          Test if the NodeHandle o is in the neighbour set.
 void prettyPrintNode()
          Shows a brief description of the internal routing state.
 void printNode()
          Shows in the standard out all internal routing information.
 boolean process(int actualStep)
          This method is invoked to each simulation step to process the internal data, and all incomming RouteMessage.
 boolean range(NodeHandle node, Id rank, Id leftKey, Id rightKey)
          This methods ALWAYS return false.
 boolean removeNeighbour(NodeHandle o)
          Removes the o from the neighbourSet
 java.util.Vector replicaSet(Id key, int maxRank)
          Returns an ordered set of nodes on which replicas of the object with this key can be stored.
 NodeHandle route(NodeHandle to)
          Returns the NodeHandle with the shortest path to the destination node, using all internal routing information.
 void routeData(java.lang.String appId, NodeHandle to, NodeHandle nextHop, Message msg)
          Receive's data of the application level and sends it through de network.
 Node setValues(Id newId)
          Sets the new Id.
 java.lang.String toString()
          Shows a String representation of this node, showing only its Id.
 
Methods inherited from class planet.generic.commonapi.NodeImpl
addEdges, addMessageListener, buildMessage, buildMessage, buildNewEdge, dispatchDataMessage, getId, getLocalHandle, getRegisteredApplication, getRegisteredApplications, hasMoreMessages, inMessages, invokeByStepToAllApplications, nextMessage, outMessages, playsGoodRole, receive, registerApplication, removeMessageListener, send, sendMessage, sendMessage, sendMessage, sendMessage, setGoodRole, setTimer, setTimer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

REQUEST

public static final int REQUEST
Mode value: Defines the start of communication that requires response (REPLY).

See Also:
Constant Field Values

REPLY

public static final int REPLY
Mode value: Defines the response of a communication.

See Also:
Constant Field Values

REFRESH

public static final int REFRESH
Mode value: Defines a message's mode that requires only communication on one way.

See Also:
Constant Field Values

QUERY_JOIN

public static final int QUERY_JOIN
Type value: First message that is send by any node to get its inmediate successor.

See Also:
Constant Field Values

SET_INFO

public static final int SET_INFO
See Also:
Constant Field Values

QUERY_CONNECT

public static final int QUERY_CONNECT
See Also:
Constant Field Values

ACCEPT_CONNECT

public static final int ACCEPT_CONNECT
See Also:
Constant Field Values

CANCEL_CONNECT

public static final int CANCEL_CONNECT
See Also:
Constant Field Values

CLOSE_LONG_CONNECT

public static final int CLOSE_LONG_CONNECT
See Also:
Constant Field Values

CLOSE_NEIGHBOUR_CONNECT

public static final int CLOSE_NEIGHBOUR_CONNECT
See Also:
Constant Field Values

DATA

public static final int DATA
Type value: It identifies that this message contains an application level Message.

See Also:
Constant Field Values

NumberOfTypes

public static final int NumberOfTypes
See Also:
Constant Field Values

NumberOfModes

public static final int NumberOfModes
See Also:
Constant Field Values

TYPES

public static final java.lang.String[] TYPES
This String contains a string representation of each type value of the RouteMessage.


MODES

public static final java.lang.String[] MODES
This String contains a string representation of each mode value of the RouteMessage.


neighbourSet

public SortedKList neighbourSet

retriesNewLongDistance

public int retriesNewLongDistance

alive

public boolean alive

fixedNeighbours

public boolean fixedNeighbours

statisticStabilized

public boolean statisticStabilized

statisticStabilizationSteps

public int statisticStabilizationSteps
Constructor Detail

SymphonyNode

public SymphonyNode()
             throws InitializationException
Initialize the internal data structure.

Throws:
InitializationException
Method Detail

getSuccessorsNumber

public static int getSuccessorsNumber()
Gets the maximum number of successors per node.

Returns:
the maximum number of successors per node.

getLongDistanceNumber

public static int getLongDistanceNumber()
Gets the maximum number of long distance links per node.

Returns:
the maximum number of long distance links per node.

getEndPoints

public java.util.Hashtable getEndPoints()
Return the endpoints, based on (key,value) structure, where the key is the Application name, and the value the own EndPoint instance.

Returns:
The Hashtable with all the endpoint instances.

buildMessage

public RouteMessage buildMessage(NodeHandle from,
                                 NodeHandle to,
                                 int type,
                                 int mode,
                                 Message m)
Builds a RouteMessage with the specified data.

Parameters:
from - Communication source.
to - Communitacion destination.
type - Communication type.
mode - Communication mode, from the specified type.
m - Data to be sent in this communication.
Returns:
The built RouteMessage or null if any error has ocurred.

buildMessage

public RouteMessage buildMessage(NodeHandle from,
                                 NodeHandle to,
                                 int type,
                                 int mode,
                                 Message m,
                                 java.lang.String key)
Builds a new RouteMessage with the specified data.

Parameters:
from - Communication source.
to - Communication destination.
type - Communication type.
mode - Communication mode, from the specified type.
m - Data to be sent in this communication.
key - Unique communication key.
Returns:
The built RouteMessage or null if any error has ocurred.

buildMessage

public RouteMessage buildMessage(NodeHandle from,
                                 NodeHandle to,
                                 NodeHandle nextHop,
                                 int type,
                                 int mode,
                                 Message m)
Builds a nw RouteMessage with the specified data.

Parameters:
from - Communication source.
to - Communication destination.
nextHop - Communication next hop.
type - Communication type.
mode - Communication mode, from the specified type.
m - Data to be sent in this communication.
Returns:
The built RouteMessage or null if any error has ocurred.

buildMessage

public RouteMessage buildMessage(NodeHandle from,
                                 NodeHandle to,
                                 NodeHandle nextHop,
                                 int type,
                                 int mode,
                                 Message m,
                                 java.lang.String key)
Builds a RouteMessage with the specified data.

Parameters:
from - Communication source.
to - Communication destination.
nextHop - Communication next hop.
type - Communication type.
mode - Communication mode, from the specified type.
m - Data to be sent in this communication.
key - Unique communication key.
Returns:
The built RouteMessage or null if any error has ocurred.

buildMessage

public RouteMessage buildMessage(RouteMessage toCopy,
                                 NodeHandle nextHop)
Builds a new RouteMessage with all the values appeared in toCopy, and the specified nextHop.

Parameters:
toCopy - Message to be cloned.
nextHop - Next hop in the route.
Returns:
A valid RouteMessage or null if there are any error.

addToNeighbourSet

public boolean addToNeighbourSet(java.util.Collection c,
                                 boolean adviceForClosing)
Add all NodeHandle in the c Collection to the neighbour set.

Parameters:
c - Collection with neighbours.
adviceForClosing - Send a CLOSE_NEIGHBOUR message to the removed neighbours
Returns:
true if any neighbour has been added. false in other case.

addToNeighbourSet

public void addToNeighbourSet(NodeHandle neighbour)
Add the neighbour to hte neighbour set.

Parameters:
neighbour - Neighbour NodeHandle to be added.

getNeighbourSet

public java.util.Collection getNeighbourSet()
Gets the neightbour set.

Returns:
The neighbour set.

getFarthestNeighbours

public java.util.Collection getFarthestNeighbours()
Gets the farthest neighbours.

Returns:
The farthest neighbours.
See Also:
SortedKList.getFarthestNeighbours()

neighbourSetContains

public boolean neighbourSetContains(NodeHandle o)
Test if the NodeHandle o is in the neighbour set.

Parameters:
o - The NodeHandle to be test.
Returns:
true if o is in the set.

removeNeighbour

public boolean removeNeighbour(NodeHandle o)
Removes the o from the neighbourSet

Parameters:
o - The NodeHandle to be removed.
Returns:
true if it is removed or false in other case.

getSucc

public NodeHandle getSucc()
Returns the NodeHandle of node successor.

Returns:
The NodeHandle of node successor.
See Also:
Node.getSucc()

getPred

public NodeHandle getPred()
Returns the NodeHandle of node predecessor.

Returns:
The NodeHandle of node predecessor.
See Also:
Node.getPred()

getOutcommingSet

public java.util.List getOutcommingSet()
Get the outcomming set of long distance connections.

Returns:
the outcomming set of long distance connections.

getIncommingSet

public java.util.List getIncommingSet()
Get the incomming set of long distance connections.

Returns:
the incomming set of long distance connections.

join

public void join(NodeHandle bootstrap)
This node joins to the overlay network by the bootstrap node with NodeHandle bootstrap.

Specified by:
join in interface Node
Specified by:
join in class NodeImpl
Parameters:
bootstrap - NodeHandle of the bootstrap node.
See Also:
Node.join(planet.commonapi.NodeHandle)

leave

public void leave()
Leaves the node from the overlay network.

Specified by:
leave in interface Node
Specified by:
leave in class NodeImpl
See Also:
Node.leave()

getNewLongDistance

public RouteMessage getNewLongDistance()
Returns a RouteMessage to be sent to acquire a new long distance.

Returns:
a RouteMessage to be sent to acquire a new long distance.

dispatcher

public void dispatcher(RouteMessage msg)
Dispatch any incomming RouteMessage and update the local state or is resent to other node.

Parameters:
msg - Incomming RouteMessage to be treat.

process

public boolean process(int actualStep)
This method is invoked to each simulation step to process the internal data, and all incomming RouteMessage.

Specified by:
process in interface Node
Overrides:
process in class NodeImpl
Parameters:
actualStep - The current simulation step.
Returns:
true if the node is stabilized or false in other case.
See Also:
Node.process(int)

isLocalMessage

public boolean isLocalMessage(RouteMessage msg)
The isLocalMessage's method is an extension method for commonapi specs. This method is used to allow BehavioursPool decide wether the incoming RouteMessage is for the local node or for a remote node. Remenber, this decision may only be addressed by the underlying overlay protocol. For example, for Symphony's Lookup protocol a node is responsible for all RouteMessages whose keys have as an immediate succesor the node's id or have as destination the own node.

Specified by:
isLocalMessage in interface Node
Overrides:
isLocalMessage in class NodeImpl
Returns:
True if the incoming RouteMessage taken as input its for the local node.
See Also:
BehavioursPool

getInfo

public java.util.Hashtable getInfo()
This method returns the internal data in a Hashtable, where the key is a String with the field name, and the value, the related object.

Specified by:
getInfo in class NodeImpl
Returns:
A Hashtable with all internal information.
See Also:
NodeImpl.getInfo()

routeData

public void routeData(java.lang.String appId,
                      NodeHandle to,
                      NodeHandle nextHop,
                      Message msg)
Description copied from interface: Node
Receive's data of the application level and sends it through de network.

Parameters:
appId - String that includes the application identification.
to - Node that must receive this message. If cannot represents a real node.
nextHop - Node that must receive this message as first hop.
msg - Message to be sent. If it is null, the message must be routed.

printNode

public void printNode()
Shows in the standard out all internal routing information.

See Also:
Node.printNode()

prettyPrintNode

public void prettyPrintNode()
Shows a brief description of the internal routing state.

See Also:
Node.prettyPrintNode()

isAlive

public boolean isAlive()
Shows if the node is already alive.

Returns:
true if the node is alive. false in other case.
See Also:
Node.isAlive()

route

public NodeHandle route(NodeHandle to)
Returns the NodeHandle with the shortest path to the destination node, using all internal routing information.

Parameters:
to - Destination node.
Returns:
The best node to route any RouteMessage to the node to.

toString

public java.lang.String toString()
Shows a String representation of this node, showing only its Id.

Returns:
A String representation of this node.
See Also:
Object.toString()

isStabilized

public boolean isStabilized()
Informs if this node is stabilized.

Returns:
true if the node is stabilized. false in other case.

broadcast

public void broadcast(java.lang.String appId,
                      NodeHandle to,
                      NodeHandle nextHop,
                      Message msg)
This method throws a NoSuchMethodError, because the broadcast algorithm is not implemented yet.

Parameters:
appId - Application identification.
to - Source of the message.
nextHop - NextHop of the message.
msg - Message to be send as broadcast.
See Also:
Node.broadcast(java.lang.String, planet.commonapi.NodeHandle, planet.commonapi.NodeHandle, planet.commonapi.Message)

fail

public void fail()
The leave protocol is the same as in leave case.

See Also:
Node.fail()

getSuccList

public java.util.Vector getSuccList(int max)
Returns up to max successors of the actual node.

Parameters:
max - Maximum number of successors to return.
Returns:
Up to max successors.
See Also:
Node.getSuccList(int)

localLookup

public java.util.Vector localLookup(Id key,
                                    int max,
                                    boolean safe)
Returns a list of nodes that can be used as next hops on a route towards key. If is safe, the expected fraction of faulty nodes in the list is guaranteed to be no higher than the fraction of faulty nodes in the overlay.

Parameters:
key - Target key
max - Number of next hops.
safe - If true, the expected fraction of faulty nodes are the same of the nodes in the overlay.
Returns:
Until a maximum of max nodes to use as next hop.
See Also:
Node.localLookup(planet.commonapi.Id, int, boolean)

neighborSet

public java.util.Vector neighborSet(int max)
Obtains an unordered list of up to max nodes that are neighbors of the local node.

Parameters:
max - Maximum of nodes to return.
Returns:
Neighbor nodes.
See Also:
Node.neighborSet(int)

range

public boolean range(NodeHandle node,
                     Id rank,
                     Id leftKey,
                     Id rightKey)
This methods ALWAYS return false. It is not implemented yet.

This operation provides information about ranges of keys for which the node is currently a root. Returns false if the range could not be determined, true otherwise.

It is an error to query the range of a node not present in the neighbor set.

The [leftKey,rightKey] denotes the inclusive range of key values.

Parameters:
node - Node that is currently a root of some range of keys.
rank - Number of keys that is root the node (rank=rightKey-leftKey).
leftKey - The value that appears in the invokation is the candidate left key of the range. It may be modified to reflect the correct left margin once invokation has finished.
rightKey - Shows once the invokation has finished the left margin of the range.
Returns:
true if the range chold be determined; false otherwise, including the case of node is not present in the neighbor set returned by neighborSet().
See Also:
Node.range(planet.commonapi.NodeHandle, planet.commonapi.Id, planet.commonapi.Id, planet.commonapi.Id)

replicaSet

public java.util.Vector replicaSet(Id key,
                                   int maxRank)
Returns an ordered set of nodes on which replicas of the object with this key can be stored. The maximum number of nodes is maxRank. If the implementation's maximum replica set size is lower, then its maximum replica set is returned.

Parameters:
key - Id for which we find the replica set.
maxRank - Maximum number of members in replica set.
Returns:
An array of nodes with the replica set.
See Also:
Node.replicaSet(planet.commonapi.Id, int)

getClosestNodeHandle

public NodeHandle getClosestNodeHandle(Id id)
Returns the NodeHandle closest to id.

Specified by:
getClosestNodeHandle in interface Node
Specified by:
getClosestNodeHandle in class NodeImpl
Parameters:
id - Id to find.
Returns:
The NodeHandle closest to id.

getAllLinks

public java.util.Set getAllLinks()
Gets all node connections to other nodes as its NodeHandles. The order of NodeHandles is unexpected.

Returns:
A set with all connections as NodeHandles.

buildEdges

public void buildEdges(java.lang.String resultName,
                       java.util.Collection edgeCollection,
                       ResultsConstraint constraint)
This method is a callback method used to collect all of the edges of a graph according to current resultName format.

Parameters:
resultName - Result type name to use.
edgeCollection - Edge collection where to add new edges.
constraint - ResultsConstraint for edge selection

setValues

public Node setValues(Id newId)
               throws InitializationException
Sets the new Id.

Specified by:
setValues in interface Node
Overrides:
setValues in class NodeImpl
Parameters:
newId - New Id.
Returns:
This instance after it has been updated.
Throws:
InitializationException - if any error has occurred.
See Also:
Node.setValues(planet.commonapi.Id)