planet.generic.commonapi
Class EndPointImpl

java.lang.Object
  extended by planet.generic.commonapi.EndPointImpl
All Implemented Interfaces:
java.io.Serializable, EndPoint

public class EndPointImpl
extends java.lang.Object
implements EndPoint

Interface which represents a node in a peer-to-peer system, regardless of the underlying protocol. This represents the *local* node, upon which applications can call methods.

Author:
Jordi Pujol, Carles Pairot
See Also:
Serialized Form

Nested Class Summary
 class EndPointImpl.MessageScheduler
          Implements an scheduler for sent messages to this application with a specified delay.
 
Constructor Summary
EndPointImpl(Application app, Node node)
          Generates an EndPoint from id in String format and the actual Node.
 
Method Summary
 void broadcast(Id key, Message message)
          Sends a broadcast message to the network.
 void byStep()
          An upcall to inform to the top Application for a new step.
 boolean forward(RouteMessage message)
          Deliver only the content Message in RouteMessage to the application and returns if this message must be forward.
 java.util.Set getAllLinks()
          Returns all node links.
 Application getApplication()
          Gets the associated Application.
 java.lang.String getApplicationId()
          Returns the identification of the related Application
 Id getId()
          Returns the identification of the related Node
 NodeHandle getLocalNodeHandle()
          Returns a handle to the local node below this endpoint.
 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 range(NodeHandle node, Id rank, Id leftKey, Id rightKey)
          This operation provides information about ranges of keys for which the node is currently a root.
 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.
 void route(Id id, Message message, NodeHandle hint)
          This method makes an attempt to route the message to the root of the given id.
 void scheduleMessage(RouteMessage message, long delay)
          Schedules a message to be delivered to this application after the provided number of milliseconds.
 java.lang.String toString()
          Shows a String representatio of this EndPoint
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EndPointImpl

public EndPointImpl(Application app,
                    Node node)
Generates an EndPoint from id in String format and the actual Node.

Parameters:
app - Related Application
node - Actual Node.
Method Detail

byStep

public void byStep()
An upcall to inform to the top Application for a new step. This method is invoked at the end of each simulation step. Before this, may arrive any number of application Messages, depending on your own main application.

Specified by:
byStep in interface EndPoint

route

public void route(Id id,
                  Message message,
                  NodeHandle hint)
This method makes an attempt to route the message to the root of the given id. The hint handle will be the first hop in the route. If the id field is null, then the message is routed directly to the given node, and delivers the message there. If the hint field is null, then this method makes an attempt to route the message to the root of the given id. Note that one of the id and hint fields can be null, but not both.

Specified by:
route in interface EndPoint
Parameters:
id - The destination Id of the message.
message - The message to deliver
hint - The destination desired known node. If unknown node, it may be null.

broadcast

public void broadcast(Id key,
                      Message message)
Sends a broadcast message to the network.

Specified by:
broadcast in interface EndPoint
Parameters:
key - The destination Id of the message.
message - The message to deliver

getLocalNodeHandle

public NodeHandle getLocalNodeHandle()
Returns a handle to the local node below this endpoint. This node handle is serializable, and can therefore be sent to other nodes in the network and still be valid.

Specified by:
getLocalNodeHandle in interface EndPoint
Returns:
A NodeHandle referring to the local node.

scheduleMessage

public void scheduleMessage(RouteMessage message,
                            long delay)
Schedules a message to be delivered to this application after the provided number of milliseconds.

Specified by:
scheduleMessage in interface EndPoint
Parameters:
message - The message to be delivered
delay - The number of milliseconds to wait before delivering the message

forward

public boolean forward(RouteMessage message)
Deliver only the content Message in RouteMessage to the application and returns if this message must be forward.

Specified by:
forward in interface EndPoint
Parameters:
message - RouteMessage to be forwarding.
Returns:
true if the NodeImpl must forward the message.
See Also:
EndPoint.forward(planet.commonapi.RouteMessage)

getApplicationId

public java.lang.String getApplicationId()
Returns the identification of the related Application

Specified by:
getApplicationId in interface EndPoint
Returns:
Identification of the related Application
See Also:
EndPoint.getApplicationId()

getApplication

public Application getApplication()
Gets the associated Application.

Specified by:
getApplication in interface EndPoint
Returns:
The associated application.

getId

public Id getId()
Returns the identification of the related Node

Specified by:
getId in interface EndPoint
Returns:
Identification of the related Node
See Also:
EndPoint.getId()

replicaSet

public java.util.Vector replicaSet(Id key,
                                   int maxRank)
Description copied from interface: EndPoint
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.

Specified by:
replicaSet in interface EndPoint
Parameters:
key - Key from which obtain the replica set.
maxRank - Number of nodes in replica set.
Returns:
Up to maxRank nodes as replica set.
See Also:
Returns the replica node set. The number of successor list is defined in the context.

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.

Specified by:
localLookup in interface EndPoint
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.

neighborSet

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

Specified by:
neighborSet in interface EndPoint
Parameters:
max - Maximum of nodes to return.
Returns:
Neighbor nodes.

range

public boolean range(NodeHandle node,
                     Id rank,
                     Id leftKey,
                     Id rightKey)
Description copied from interface: EndPoint
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.

Specified by:
range in interface EndPoint
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 replicaSet.
See Also:
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.

toString

public java.lang.String toString()
Shows a String representatio of this EndPoint

Overrides:
toString in class java.lang.Object
Returns:
A String representation of this EndPoint
See Also:
Object.toString()

getAllLinks

public java.util.Set getAllLinks()
Returns all node links.

Specified by:
getAllLinks in interface EndPoint
Returns:
All node links.
See Also:
EndPoint.getAllLinks()