Rice Pastry API

rice.p2p.past
Class PastImpl

java.lang.Object
  |
  +--rice.p2p.past.PastImpl
All Implemented Interfaces:
Application, Past, RMClient

public class PastImpl
extends java.lang.Object
implements Past, Application, RMClient

Version:
$Id: PastImpl.java,v 1.19 2003/10/22 03:14:00 amislove Exp $
Author:
Alan Mislove, Ansley Post, Peter Druschel

Field Summary
protected  rice.p2p.commonapi.Endpoint endpoint
           
protected  rice.p2p.commonapi.IdFactory factory
           
protected  java.util.logging.Logger log
           
static int MESSAGE_TIMEOUT
           
protected  rice.p2p.commonapi.IdSet pending
           
protected  rice.rm.RM replicaManager
           
protected  int replicationFactor
           
protected  rice.persistence.StorageManager storage
           
 
Constructor Summary
PastImpl(rice.p2p.commonapi.Node node, rice.persistence.StorageManager manager, int replicas, java.lang.String instance)
          Constructor for Past
 
Method Summary
 void deliver(rice.p2p.commonapi.Id id, rice.p2p.commonapi.Message message)
          This method is called on the application at the destination node for the given id.
 void fetch(rice.pastry.IdSet keySet)
          This upcall is invoked to notify the application that is should fetch the cooresponding keys in this set, since the node is now responsible for these keys also.
 void fetch(rice.p2p.past.PastContentHandle handle, rice.Continuation command)
          Retrieves the object associated with a given content handle.
 boolean forward(rice.p2p.commonapi.RouteMessage message)
          This method is invoked on applications when the underlying node is about to forward the given message with the provided target to the specified next hop.
 rice.p2p.commonapi.NodeHandle getLocalNodeHandle()
          get the nodeHandle of the local Past node
 rice.rm.RM getReplicaManager()
          Returns the replica manager for this Past instance.
 int getReplicationFactor()
          Returns the number of replicas used in this Past
 rice.persistence.StorageManager getStorageManager()
          Returns this Past's storage manager.
 void insert(rice.p2p.past.PastContent obj, rice.Continuation command)
          Inserts an object with the given ID into this instance of Past.
 void isResponsible(rice.pastry.IdRange range)
          This upcall is to notify the application of the range of keys for which it is responsible.
 void lookup(rice.p2p.commonapi.Id id, rice.Continuation command)
          Retrieves the object stored in this instance of Past with the given ID.
 void lookupHandles(rice.p2p.commonapi.Id id, int max, rice.Continuation command)
          Retrieves the handles of up to max replicas of the object stored in this instance of Past with the given ID.
 void rmIsReady(rice.rm.RM rm)
          This upcall is simply to denote that the underlying replica manager (rm) is ready.
 rice.p2p.commonapi.IdSet scan(rice.p2p.commonapi.IdRange range)
          Return the ids of objects stored in this instance of Past on the *local* node, with ids in a given range.
 rice.pastry.IdSet scan(rice.pastry.IdRange range)
          This upcall should return the set of keys that the application currently stores in this range.
 void update(rice.p2p.commonapi.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
 

Field Detail

MESSAGE_TIMEOUT

public static int MESSAGE_TIMEOUT

endpoint

protected rice.p2p.commonapi.Endpoint endpoint

storage

protected rice.persistence.StorageManager storage

replicationFactor

protected int replicationFactor

replicaManager

protected rice.rm.RM replicaManager

factory

protected rice.p2p.commonapi.IdFactory factory

pending

protected rice.p2p.commonapi.IdSet pending

log

protected java.util.logging.Logger log
Constructor Detail

PastImpl

public PastImpl(rice.p2p.commonapi.Node node,
                rice.persistence.StorageManager manager,
                int replicas,
                java.lang.String instance)
Constructor for Past

Parameters:
node - The node below this Past implementation
manager - The storage manager to be used by Past
replicas - The number of object replicas
instance - The unique instance name of this Past
Method Detail

insert

public void insert(rice.p2p.past.PastContent obj,
                   rice.Continuation command)
Inserts an object with the given ID into this instance of Past. Asynchronously returns a PastException to command, if the operation was unsuccessful. If the operation was successful, a Boolean[] is returned representing the responses from each of the replicas which inserted the object.

Specified by:
insert in interface Past
Parameters:
obj - the object to be inserted
command - Command to be performed when the result is received

lookup

public void lookup(rice.p2p.commonapi.Id id,
                   rice.Continuation command)
Retrieves the object stored in this instance of Past with the given ID. Asynchronously returns a PastContent object as the result to the provided Continuation, or a PastException. This method is provided for convenience; its effect is identical to a lookupHandles() and a subsequent fetch() to the handle that is nearest in the network. The client must authenticate the object. In case of failure, an alternate replica of the object can be obtained via lookupHandles() and fetch(). This method is not safe if the object is immutable and storage nodes are not trusted. In this case, clients should used the lookUpHandles method to obtains the handles of all primary replicas and determine which replica is fresh in an application-specific manner.

Specified by:
lookup in interface Past
Parameters:
id - the key to be queried
command - Command to be performed when the result is received

lookupHandles

public void lookupHandles(rice.p2p.commonapi.Id id,
                          int max,
                          rice.Continuation command)
Retrieves the handles of up to max replicas of the object stored in this instance of Past with the given ID. Asynchronously returns an array of PastContentHandles as the result to the provided Continuation, or a PastException. Each replica handle is obtained from a different primary storage root for the the given key. If max exceeds the replication factor r of this Past instance, only r replicas are returned. This method will return a PastContentHandle[] array containing all of the handles.

Specified by:
lookupHandles in interface Past
Parameters:
id - the key to be queried
max - the maximal number of replicas requested
command - Command to be performed when the result is received

fetch

public void fetch(rice.p2p.past.PastContentHandle handle,
                  rice.Continuation command)
Retrieves the object associated with a given content handle. Asynchronously returns a PastContent object as the result to the provided Continuation, or a PastException. The client must authenticate the object. In case of failure, an alternate replica can be obtained using a different handle obtained via lookupHandles().

Specified by:
fetch in interface Past
Parameters:
command - Command to be performed when the result is received
handle - the key to be queried

scan

public rice.p2p.commonapi.IdSet scan(rice.p2p.commonapi.IdRange range)
Return the ids of objects stored in this instance of Past on the *local* node, with ids in a given range. The IdSet returned contains the Ids of the stored objects.

Specified by:
scan in interface Past
Parameters:
range - The range to query
Returns:
The set of ids

getLocalNodeHandle

public rice.p2p.commonapi.NodeHandle getLocalNodeHandle()
get the nodeHandle of the local Past node

Specified by:
getLocalNodeHandle in interface Past
Returns:
the nodehandle

getReplicationFactor

public int getReplicationFactor()
Returns the number of replicas used in this Past

Specified by:
getReplicationFactor in interface Past
Returns:
the number of replicas for each object

forward

public boolean forward(rice.p2p.commonapi.RouteMessage message)
This method is invoked on applications when the underlying node is about to forward the given message with the provided target to the specified next hop. Applications can change the contents of the message, specify a different nextHop (through re-routing), or completely terminate the message.

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

deliver

public void deliver(rice.p2p.commonapi.Id id,
                    rice.p2p.commonapi.Message message)
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(rice.p2p.commonapi.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.

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

fetch

public void fetch(rice.pastry.IdSet keySet)
This upcall is invoked to notify the application that is should fetch the cooresponding keys in this set, since the node is now responsible for these keys also.

Specified by:
fetch in interface RMClient
Parameters:
keySet - set containing the keys that needs to be fetched

rmIsReady

public void rmIsReady(rice.rm.RM rm)
This upcall is simply to denote that the underlying replica manager (rm) is ready. The 'rm' should henceforth be used by this RMClient to issue the downcalls on the RM interface.

Specified by:
rmIsReady in interface RMClient
Parameters:
rm - the instance of the Replica Manager

isResponsible

public void isResponsible(rice.pastry.IdRange range)
This upcall is to notify the application of the range of keys for which it is responsible. The application might choose to react to call by calling a scan(complement of this range) to the persistance manager and get the keys for which it is not responsible and call delete on the persistance manager for those objects.

Specified by:
isResponsible in interface RMClient
Parameters:
range - the range of keys for which the local node is currently responsible

scan

public rice.pastry.IdSet scan(rice.pastry.IdRange range)
This upcall should return the set of keys that the application currently stores in this range. Should return a empty IdSet (not null), in the case that no keys belong to this range.

Specified by:
scan in interface RMClient
Parameters:
range - the requested range

getReplicaManager

public rice.rm.RM getReplicaManager()
Returns the replica manager for this Past instance. Should *ONLY* be used for testing. Messing with this will cause unknown behavior.

Returns:
This Past's replica manager

getStorageManager

public rice.persistence.StorageManager getStorageManager()
Returns this Past's storage manager.

Returns:
This Past's storage manager.

Rice Pastry API

Copyright © 2001 - Rice Pastry.


Imprint-Dataprotection