Rice Pastry API

rice.tutorial.lookup
Class LookupService

java.lang.Object
  extended by rice.tutorial.lookup.LookupService
All Implemented Interfaces:
Application

public class LookupService
extends java.lang.Object
implements Application

The LookupService provides a way to find out what nodes are responsible for a given Id. It does this by routing a request across the ring, doing a replicaSet lookup at the destination, and sending the result back. It is perhaps the simplest useful application.

Author:
jstewart

Nested Class Summary
static class LookupService.NodeLookupQuery
          The query message
static class LookupService.NodeLookupResponse
          The response message
static class LookupService.NodeLookupTimeout
          This is a message used internally for implementing timeouts
static class LookupService.NodeLookupTimeoutException
          Returned by continuations handed to requestNodeHandles when a request times out.
 
Constructor Summary
LookupService(Node node)
          Build a LookupService application with the default lookup timeout
LookupService(Node node, long timeout)
          Build a LookupService application with a specified timeout
 
Method Summary
 void deliver(Id id, Message message)
          This method is called on the application at the destination node for the given id.
 boolean forward(RouteMessage message)
          This Application always forwards its messages
 void requestNodeHandle(Id id, Continuation<NodeHandle,java.lang.Exception> cont)
          Find the primary replica of a key.
 void requestNodeHandles(Id id, int num, Continuation<NodeHandleSet,java.lang.Exception> cont)
          Requests a replicaSet from a node across the ring.
protected  void sendMessage(int seq, Id id, int num, Continuation<NodeHandleSet,java.lang.Exception> cont, long timeout)
          This does the internal processing for requestNodeHandle(s).
protected  void sendMessageWithRetries(Id id, int num, Continuation<NodeHandleSet,java.lang.Exception> cont)
           
 void update(NodeHandle handle, boolean joined)
          This method is invoked to inform the application that the given node has either joined or left the neighbor set of the local node, as the set would be returned by the neighborSet call.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LookupService

public LookupService(Node node,
                     long timeout)
Build a LookupService application with a specified timeout

Parameters:
node - the local node
timeout - query timeout in milliseconds

LookupService

public LookupService(Node node)
Build a LookupService application with the default lookup timeout

Parameters:
node - the local node
Method Detail

forward

public boolean forward(RouteMessage message)
This Application always forwards its messages

Specified by:
forward in interface Application
Parameters:
message - The message being sent, containing an internal message along with a destination key and nodeHandle next hop.
Returns:
Whether or not to forward the message further
See Also:
Application.forward(rice.p2p.commonapi.RouteMessage)

deliver

public void deliver(Id id,
                    Message message)
Description copied from interface: Application
This method is called on the application at the destination node for the given id.

Specified by:
deliver in interface Application
Parameters:
id - The destination id of the message
message - The message being sent

update

public void update(NodeHandle handle,
                   boolean joined)
Description copied from interface: Application
This method is invoked to inform the application that the given node has either joined or left the neighbor set of the local node, as the set would be returned by the neighborSet call.

Specified by:
update in interface Application
Parameters:
handle - The handle that has joined/left
joined - Whether the node has joined or left

requestNodeHandles

public void requestNodeHandles(Id id,
                               int num,
                               Continuation<NodeHandleSet,java.lang.Exception> cont)
Requests a replicaSet from a node across the ring. This method will return via its continuation the set of num NodeHandles that are in id's replicaSet. Calling requestNodeHandles with a num of 1 will return the node currently responsible for Id id. If there is a network problem or the Id of interest is not currently owned by any node (for example due to churn in the overlay), the continuation will receive a NodeLookupTimeoutException.

Parameters:
id - the Id of interest
num - the number of nodes to return
cont - the continuation to return the result to

sendMessageWithRetries

protected void sendMessageWithRetries(Id id,
                                      int num,
                                      Continuation<NodeHandleSet,java.lang.Exception> cont)

sendMessage

protected void sendMessage(int seq,
                           Id id,
                           int num,
                           Continuation<NodeHandleSet,java.lang.Exception> cont,
                           long timeout)
This does the internal processing for requestNodeHandle(s). It adds the continuation to the pending table, updates the sequence number, schedules this timeout, and finally sends the actual message.

Parameters:
id - the Id of interest
num - the number of nodes to return
cont - the continuation to return the result to

requestNodeHandle

public void requestNodeHandle(Id id,
                              Continuation<NodeHandle,java.lang.Exception> cont)
Find the primary replica of a key. This is the node with the Id closest to the key in pastry. This method will return via its continuation the NodeHandle that is closest to id. If there is a network problem or the Id of interest is not currently owned by any node (for example due to churn in the overlay), the continuation will receive a NodeLookupTimeoutException.

Parameters:
id - the Id of interest
cont - the continuation to return the result to

Rice Pastry API

Copyright © 2001-2005 - Rice Pastry.


Imprint-Dataprotection