Rice Pastry API

rice.pastry.pns
Class PNSApplication

java.lang.Object
  extended by rice.pastry.client.PastryAppl
      extended by rice.pastry.pns.PNSApplication
All Implemented Interfaces:
ProximityListener<NodeHandle>, ProximityNeighborSelector
Direct Known Subclasses:
RendezvousPNSApplication

public class PNSApplication
extends PastryAppl
implements ProximityNeighborSelector, ProximityListener<NodeHandle>

Can request LeafSet, RouteRow, Proximity of nodes, implements the PNS algorithm. Flow: call getLeafSet(...) addToWaitingForLeafSet() cancellable.cancel() removeFromWaitingForLeafSet() TODO: Make use the environment's clock for the wait() calls.

Author:
Jeff Hoye

Field Summary
static int DEFAULT_PROXIMITY
           
protected  Environment environment
           
protected  java.util.Map<NodeHandle,java.lang.Integer> pingCache
          Hashtable which keeps track of temporary ping values, which are only used during the getNearest() method
protected  byte rtBase
           
protected  Timer timer
           
 
Fields inherited from class rice.pastry.client.PastryAppl
address, deserializer, instance, logger, options, receiver, thePastryNode
 
Constructor Summary
PNSApplication(PastryNode pn)
           
PNSApplication(PastryNode pn, Logger logger)
           
 
Method Summary
protected  void addToWaitingForLeafSet(NodeHandle handle, Continuation<LeafSet,java.lang.Exception> c, Cancellable cancelMeWhenSuccess)
           
protected  void addToWaitingForRouteRow(NodeHandle handle, int row, Continuation<RouteSet[],java.lang.Exception> c, Cancellable cancelMeWhenSuccess)
           
 boolean deliverWhenNotReady()
          We always want to receive messages.
 Cancellable getLeafSet(NodeHandle handle, Continuation<LeafSet,java.lang.Exception> c)
          This method returns the remote leafset of the provided handle to the caller, in a protocol-dependent fashion.
 Cancellable getNearest(NodeHandle seed, Continuation<java.util.Collection<NodeHandle>,java.lang.Exception> retToMe)
          This method implements the algorithm in the Pastry locality paper for finding a close node the the current node through iterative leafset and route row requests.
 Cancellable getNearHandles(java.util.Collection<NodeHandle> bootHandles, Continuation<java.util.Collection<NodeHandle>,java.lang.Exception> deliverResultToMe)
           
protected  java.util.List<NodeHandle> getNearHandlesHelper(java.util.List<NodeHandle> handles)
          Helper for getNearHandles Can be overridden to select out any handles that shouldn't be returned.
 Cancellable getProximity(NodeHandle handle, Continuation<java.lang.Integer,java.io.IOException> c, int timeout)
          Non-blocking version, no timeout.
 Cancellable getRouteRow(NodeHandle handle, short row, Continuation<RouteSet[],java.lang.Exception> c)
          Non-blocking version.
 void messageForAppl(Message msg)
          Called by pastry when a message arrives for this application.
 void proximityChanged(NodeHandle i, int newProximity, java.util.Map<java.lang.String,java.lang.Object> options)
           
protected  boolean removeFromWaitingForLeafSet(NodeHandle handle, Continuation<LeafSet,java.lang.Exception> c)
           
protected  boolean removeFromWaitingForRouteRow(NodeHandle handle, int row, Continuation<RouteSet[],java.lang.Exception> c)
           
 java.util.List<NodeHandle> sortedProximityCache()
           
 
Methods inherited from class rice.pastry.client.PastryAppl
accept, canReceiveSocket, connect, destroy, enrouteMessage, finishReceiveSocket, getAddress, getDeserializer, getLeafSet, getNodeHandle, getNodeId, getRoutingTable, isClosest, leafSetChange, notifyReady, receiveMessage, receiveMessageInternal, register, routeMsg, routeMsg, routeMsgDirect, routeSetChange, setDeserializer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PROXIMITY

public static final int DEFAULT_PROXIMITY
See Also:
Constant Field Values

pingCache

protected java.util.Map<NodeHandle,java.lang.Integer> pingCache
Hashtable which keeps track of temporary ping values, which are only used during the getNearest() method


rtBase

protected final byte rtBase

environment

protected Environment environment

timer

protected Timer timer
Constructor Detail

PNSApplication

public PNSApplication(PastryNode pn)

PNSApplication

public PNSApplication(PastryNode pn,
                      Logger logger)
Method Detail

deliverWhenNotReady

public boolean deliverWhenNotReady()
We always want to receive messages.

Overrides:
deliverWhenNotReady in class PastryAppl
Returns:
false unless the node is a service

messageForAppl

public void messageForAppl(Message msg)
Description copied from class: PastryAppl
Called by pastry when a message arrives for this application.

Specified by:
messageForAppl in class PastryAppl
Parameters:
msg - the message that is arriving.

getNearHandles

public Cancellable getNearHandles(java.util.Collection<NodeHandle> bootHandles,
                                  Continuation<java.util.Collection<NodeHandle>,java.lang.Exception> deliverResultToMe)
Specified by:
getNearHandles in interface ProximityNeighborSelector

getNearHandlesHelper

protected java.util.List<NodeHandle> getNearHandlesHelper(java.util.List<NodeHandle> handles)
Helper for getNearHandles Can be overridden to select out any handles that shouldn't be returned.

Parameters:
handles -
Returns:

getLeafSet

public Cancellable getLeafSet(NodeHandle handle,
                              Continuation<LeafSet,java.lang.Exception> c)
This method returns the remote leafset of the provided handle to the caller, in a protocol-dependent fashion. Note that this method may block while sending the message across the wire. Non-blocking version.

Parameters:
handle - The node to connect to
c - Continuation to return the LeafSet to
Returns:
Throws:
java.io.IOException

addToWaitingForLeafSet

protected void addToWaitingForLeafSet(NodeHandle handle,
                                      Continuation<LeafSet,java.lang.Exception> c,
                                      Cancellable cancelMeWhenSuccess)

removeFromWaitingForLeafSet

protected boolean removeFromWaitingForLeafSet(NodeHandle handle,
                                              Continuation<LeafSet,java.lang.Exception> c)

getRouteRow

public Cancellable getRouteRow(NodeHandle handle,
                               short row,
                               Continuation<RouteSet[],java.lang.Exception> c)
Non-blocking version.

Parameters:
handle -
row -
c -
Returns:
Throws:
java.io.IOException

addToWaitingForRouteRow

protected void addToWaitingForRouteRow(NodeHandle handle,
                                       int row,
                                       Continuation<RouteSet[],java.lang.Exception> c,
                                       Cancellable cancelMeWhenSuccess)

removeFromWaitingForRouteRow

protected boolean removeFromWaitingForRouteRow(NodeHandle handle,
                                               int row,
                                               Continuation<RouteSet[],java.lang.Exception> c)

getProximity

public Cancellable getProximity(NodeHandle handle,
                                Continuation<java.lang.Integer,java.io.IOException> c,
                                int timeout)
Non-blocking version, no timeout. TODO: Make this fail early if faulty.

Parameters:
handle -
c -

proximityChanged

public void proximityChanged(NodeHandle i,
                             int newProximity,
                             java.util.Map<java.lang.String,java.lang.Object> options)
Specified by:
proximityChanged in interface ProximityListener<NodeHandle>

sortedProximityCache

public java.util.List<NodeHandle> sortedProximityCache()

getNearest

public Cancellable getNearest(NodeHandle seed,
                              Continuation<java.util.Collection<NodeHandle>,java.lang.Exception> retToMe)
This method implements the algorithm in the Pastry locality paper for finding a close node the the current node through iterative leafset and route row requests. The seed node provided is any node in the network which is a member of the pastry ring. This algorithm is designed to work in a protocol-independent manner, using the getResponse(Message) method provided by subclasses.

Parameters:
seed - Any member of the pastry ring
Returns:
A node suitable to boot off of (which is close the this node)

Rice Pastry API

Copyright © 2001-2005 - Rice Pastry.


Imprint-Dataprotection