rice.p2p.past
Class PastImpl

java.lang.Object
  extended byrice.p2p.past.PastImpl
All Implemented Interfaces:
Application, Past, ReplicationManagerClient

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


Field Summary
protected  Endpoint endpoint
           
protected  IdFactory factory
           
protected  java.util.logging.Logger log
           
static int MESSAGE_TIMEOUT
           
protected  ReplicationManagerImpl replicaManager
           
protected  int replicationFactor
           
protected  StorageManager storage
           
 
Constructor Summary
PastImpl(Node node, StorageManager manager, int replicas, java.lang.String instance)
          Constructor for Past
 
Method Summary
 void deliver(Id id, Message message)
          This method is called on the application at the destination node for the given id.
 boolean exists(Id id)
          This upcall should return whether or not the given id is currently stored by the client.
 void fetch(Id id, Continuation command)
          This upcall is invoked to tell the client to fetch the given id, and to call the given command with the boolean result once the fetch is completed.
 void fetch(PastContentHandle handle, Continuation command)
          Retrieves the object associated with a given content handle.
 boolean forward(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.
 NodeHandle getLocalNodeHandle()
          get the nodeHandle of the local Past node
 Replication getReplicaManager()
          Returns the replica manager for this Past instance.
 int getReplicationFactor()
          Returns the number of replicas used in this Past
 StorageManager getStorageManager()
          Returns this Past's storage manager.
 void insert(PastContent obj, Continuation command)
          Inserts an object with the given ID into this instance of Past.
 void lookup(Id id, Continuation command)
          Retrieves the object stored in this instance of Past with the given ID.
 void lookupHandles(Id id, int max, Continuation command)
          Retrieves the handles of up to max replicas of the object stored in this instance of Past with the given ID.
 void remove(Id id, Continuation command)
          This upcall is to notify the client that the given id can be safely removed from the storage.
 IdSet scan(IdRange range)
          This upcall should return the set of keys that the application currently stores in this range.
 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
 

Field Detail

MESSAGE_TIMEOUT

public static int MESSAGE_TIMEOUT

endpoint

protected Endpoint endpoint

storage

protected StorageManager storage

replicationFactor

protected int replicationFactor

replicaManager

protected ReplicationManagerImpl replicaManager

factory

protected IdFactory factory

log

protected java.util.logging.Logger log
Constructor Detail

PastImpl

public PastImpl(Node node,
                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(PastContent obj,
                   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(Id id,
                   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(Id id,
                          int max,
                          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(PastContentHandle handle,
                  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

getLocalNodeHandle

public 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(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(Id id,
                    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(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(Id id,
                  Continuation command)
This upcall is invoked to tell the client to fetch the given id, and to call the given command with the boolean result once the fetch is completed. The client *MUST* call the command at some point in the future, as the manager waits for the command to return before continuing.

Specified by:
fetch in interface ReplicationManagerClient
Parameters:
id - The id to fetch

remove

public void remove(Id id,
                   Continuation command)
This upcall is to notify the client that the given id can be safely removed from the storage. The client may choose to perform advanced behavior, such as caching the object, or may simply delete it.

Specified by:
remove in interface ReplicationManagerClient
Parameters:
id - The id to remove

scan

public IdSet scan(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 Past
Parameters:
range - the requested range
Returns:
The set of ids

exists

public boolean exists(Id id)
This upcall should return whether or not the given id is currently stored by the client.

Specified by:
exists in interface ReplicationManagerClient
Parameters:
id - The id in question
Returns:
Whether or not the id exists

getReplicaManager

public Replication 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 StorageManager getStorageManager()
Returns this Past's storage manager. Should *ONLY* be used for testing. Messing with this will cause unknown behavior.

Returns:
This Past's storage manager.





Imprint-Dataprotection