ePOST API

rice.pastry
Class PastryNode

java.lang.Object
  extended by java.util.Observable
      extended by rice.pastry.PastryNode
All Implemented Interfaces:
Destructable, Node, MessageReceiver
Direct Known Subclasses:
DirectPastryNode, DistPastryNode

public abstract class PastryNode
extends java.util.Observable
implements MessageReceiver, Node, Destructable

A Pastry node is single entity in the pastry network.

Version:
$Id: PastryNode.java 3010 2006-02-02 14:10:25Z jeffh $
Author:
Andrew Ladd

Field Summary
protected  java.util.Vector apps
           
protected  NodeHandle localhandle
           
protected  Logger logger
           
protected  NodeId myNodeId
           
 
Constructor Summary
protected PastryNode(NodeId id, Environment e)
          Constructor, with NodeId.
 
Method Summary
 void addLeafSetListener(NodeSetListener listener)
           
 void addLeafSetObserver(java.util.Observer o)
          Deprecated. use addLeafSetListener
 void addRouteSetListener(NodeSetListener listener)
           
 void addRouteSetObserver(java.util.Observer o)
          Deprecated. use addRouteSetListener
abstract  NodeHandle coalesce(NodeHandle newHandle)
           
 void deleteLeafSetListener(NodeSetListener listener)
           
 void deleteLeafSetObserver(java.util.Observer o)
          Deprecated. use deleteLeafSetListener
 void deleteRouteSetObserver(java.util.Observer o)
          Deprecated. use deleteRouteSetListener
 void destroy()
          Method which kills a PastryNode.
 Environment getEnvironment()
          Returns the environment.
 Id getId()
          Returns the Id of this node
 IdFactory getIdFactory()
          Returns a factory for Ids specific to this node's protocol.
 LeafSet getLeafSet()
           
 NodeHandle getLocalHandle()
           
 NodeHandle getLocalNodeHandle()
          Returns a handle to the local node.
 MessageDispatch getMessageDispatch()
          FOR TESTING ONLY - DO NOT USE!
 NodeId getNodeId()
           
 RoutingTable getRoutingTable()
           
abstract  void initiateJoin(NodeHandle bootstrap)
          Overridden by derived classes to initiate the join process
 boolean isClosest(NodeId key)
          Called by the layered Pastry application to check if the local pastry node is the one that is currently closest to the object key id.
 boolean isReady()
           
abstract  void nodeIsReady()
          Overridden by derived classes, and invoked when the node has joined successfully.
 void nodeIsReady(boolean state)
          Overridden by derived classes, and invoked when the node has joined successfully.
 void process(Executable task, Continuation command)
          Schedules a job for processing on the dedicated processing thread, should one exist.
 void receiveMessage(Message msg)
          message receiver interface.
 void registerApp(PastryAppl app)
          Registers an application with this pastry node.
 Endpoint registerApplication(Application application, int port)
          This returns a Endpoint specific to the given application and instance name to the application, which the application can then use in order to send an receive messages.
 Endpoint registerApplication(Application application, java.lang.String instance)
          This returns a VirtualizedNode specific to the given application and instance name to the application, which the application can then use in order to send an receive messages.
 void registerReceiver(Credentials cred, Address address, MessageReceiver receiver)
          Registers a message receiver with this Pastry node.
 void removeRouteSetListener(NodeSetListener listener)
           
abstract  ScheduledMessage scheduleMsg(Message msg, long delay)
          Schedule the specified message to be sent to the local node after a specified delay.
abstract  ScheduledMessage scheduleMsg(Message msg, long delay, long period)
          Schedule the specified message for repeated fixed-delay delivery to the local node, beginning after the specified delay.
abstract  ScheduledMessage scheduleMsgAtFixedRate(Message msg, long delay, long period)
          Schedule the specified message for repeated fixed-rate delivery to the local node, beginning after the specified delay.
abstract  void send(NodeHandle handle, Message message)
           
 void setElements(NodeHandle lh, PastrySecurityManager sm, MessageDispatch md, LeafSet ls, RoutingTable rt)
          Combined accessor method for various members of PastryNode.
 void setMessageDispatch(MessageDispatch md)
           
 void setReady()
           
 void setReady(boolean r)
           
 java.lang.String toString()
           
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

myNodeId

protected NodeId myNodeId

localhandle

protected NodeHandle localhandle

apps

protected java.util.Vector apps

logger

protected Logger logger
Constructor Detail

PastryNode

protected PastryNode(NodeId id,
                     Environment e)
Constructor, with NodeId. Need to set the node's ID before this node is inserted as localHandle.localNode.

Method Detail

coalesce

public abstract NodeHandle coalesce(NodeHandle newHandle)

setElements

public void setElements(NodeHandle lh,
                        PastrySecurityManager sm,
                        MessageDispatch md,
                        LeafSet ls,
                        RoutingTable rt)
Combined accessor method for various members of PastryNode. These are generated by node factories, and assigned here. Other elements specific to the wire protocol are assigned via methods set{RMI,Direct}Elements in the respective derived classes.

Parameters:
lh - Node handle corresponding to this node.
sm - Security manager.
md - Message dispatcher.
ls - Leaf set.
rt - Routing table.

getLocalNodeHandle

public NodeHandle getLocalNodeHandle()
Description copied from interface: Node
Returns a handle to the local node. 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 Node
Returns:
A NodeHandle referring to the local node.

getEnvironment

public Environment getEnvironment()
Description copied from interface: Node
Returns the environment. This allows the nodes to be virtualized within the JVM

Specified by:
getEnvironment in interface Node
Returns:
the environment for this node/app.

getLocalHandle

public NodeHandle getLocalHandle()

getNodeId

public NodeId getNodeId()

isReady

public boolean isReady()

getMessageDispatch

public MessageDispatch getMessageDispatch()
FOR TESTING ONLY - DO NOT USE!


setMessageDispatch

public void setMessageDispatch(MessageDispatch md)

nodeIsReady

public abstract void nodeIsReady()
Overridden by derived classes, and invoked when the node has joined successfully. This one is for backwards compatability. It will soon be deprecated.


nodeIsReady

public void nodeIsReady(boolean state)
Overridden by derived classes, and invoked when the node has joined successfully. This should probably be abstract, but maybe in a later version.

Parameters:
state - true when the node is ready, false when not

initiateJoin

public abstract void initiateJoin(NodeHandle bootstrap)
Overridden by derived classes to initiate the join process

Parameters:
bootstrap - Node handle to bootstrap with.

setReady

public void setReady()

setReady

public void setReady(boolean r)

isClosest

public boolean isClosest(NodeId key)
Called by the layered Pastry application to check if the local pastry node is the one that is currently closest to the object key id.

Parameters:
key - the object key id
Returns:
true if the local node is currently the closest to the key.

getLeafSet

public LeafSet getLeafSet()

getRoutingTable

public RoutingTable getRoutingTable()

addLeafSetObserver

public void addLeafSetObserver(java.util.Observer o)
Deprecated. use addLeafSetListener

Add a leaf set observer to the Pastry node.

Parameters:
o - the observer.

deleteLeafSetObserver

public void deleteLeafSetObserver(java.util.Observer o)
Deprecated. use deleteLeafSetListener

Delete a leaf set observer from the Pastry node.

Parameters:
o - the observer.

addLeafSetListener

public void addLeafSetListener(NodeSetListener listener)

deleteLeafSetListener

public void deleteLeafSetListener(NodeSetListener listener)

addRouteSetObserver

public void addRouteSetObserver(java.util.Observer o)
Deprecated. use addRouteSetListener

Add a route set observer to the Pastry node.

Parameters:
o - the observer.

deleteRouteSetObserver

public void deleteRouteSetObserver(java.util.Observer o)
Deprecated. use deleteRouteSetListener

Delete a route set observer from the Pastry node.

Parameters:
o - the observer.

addRouteSetListener

public void addRouteSetListener(NodeSetListener listener)

removeRouteSetListener

public void removeRouteSetListener(NodeSetListener listener)

receiveMessage

public void receiveMessage(Message msg)
message receiver interface. synchronized so that the external message processing thread and the leafset/route maintenance thread won't interfere with application messages.

Specified by:
receiveMessage in interface MessageReceiver
Parameters:
msg - the message.

registerReceiver

public void registerReceiver(Credentials cred,
                             Address address,
                             MessageReceiver receiver)
Registers a message receiver with this Pastry node.

Parameters:
cred - the credentials.
address - the address that the receiver will be at.
receiver - the message receiver.

registerApp

public void registerApp(PastryAppl app)
Registers an application with this pastry node.

Parameters:
app - the application

scheduleMsg

public abstract ScheduledMessage scheduleMsg(Message msg,
                                             long delay)
Schedule the specified message to be sent to the local node after a specified delay. Useful to provide timeouts.

Parameters:
msg - a message that will be delivered to the local node after the specified delay
delay - time in milliseconds before message is to be delivered
Returns:
the scheduled event object; can be used to cancel the message

scheduleMsg

public abstract ScheduledMessage scheduleMsg(Message msg,
                                             long delay,
                                             long period)
Schedule the specified message for repeated fixed-delay delivery to the local node, beginning after the specified delay. Subsequent executions take place at approximately regular intervals separated by the specified period. Useful to initiate periodic tasks.

Parameters:
msg - a message that will be delivered to the local node after the specified delay
delay - time in milliseconds before message is to be delivered
period - time in milliseconds between successive message deliveries
Returns:
the scheduled event object; can be used to cancel the message

scheduleMsgAtFixedRate

public abstract ScheduledMessage scheduleMsgAtFixedRate(Message msg,
                                                        long delay,
                                                        long period)
Schedule the specified message for repeated fixed-rate delivery to the local node, beginning after the specified delay. Subsequent executions take place at approximately regular intervals, separated by the specified period.

Parameters:
msg - a message that will be delivered to the local node after the specified delay
delay - time in milliseconds before message is to be delivered
period - time in milliseconds between successive message deliveries
Returns:
the scheduled event object; can be used to cancel the message

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

registerApplication

public Endpoint registerApplication(Application application,
                                    java.lang.String instance)
This returns a VirtualizedNode specific to the given application and instance name to the application, which the application can then use in order to send an receive messages.

Specified by:
registerApplication in interface Node
Parameters:
application - The Application
instance - An identifier for a given instance
Returns:
The endpoint specific to this applicationk, which can be used for message sending/receiving.

registerApplication

public Endpoint registerApplication(Application application,
                                    int port)
This returns a Endpoint specific to the given application and instance name to the application, which the application can then use in order to send an receive messages. This method allows advanced developers to specify which "port" on the node they wish their application to register as. This "port" determines which of the applications on top of the node should receive an incoming message.

Specified by:
registerApplication in interface Node
Parameters:
application - The Application
port - The port to use
Returns:
The endpoint specific to this applicationk, which can be used for message sending/receiving.

getId

public Id getId()
Returns the Id of this node

Specified by:
getId in interface Node
Returns:
This node's Id

getIdFactory

public IdFactory getIdFactory()
Returns a factory for Ids specific to this node's protocol.

Specified by:
getIdFactory in interface Node
Returns:
A factory for creating Ids.

process

public void process(Executable task,
                    Continuation command)
Schedules a job for processing on the dedicated processing thread, should one exist. CPU intensive jobs, such as encryption, erasure encoding, or bloom filter creation should never be done in the context of the underlying node's thread, and should only be done via this method.

Parameters:
task - The task to run on the processing thread
command - The command to return the result to once it's done

destroy

public void destroy()
Method which kills a PastryNode. Note, this doesn't implicitly kill the environment. Make sure to call super.destroy() !!!

Specified by:
destroy in interface Destructable

send

public abstract void send(NodeHandle handle,
                          Message message)

ePOST API

Copyright © 2001-2005 - Rice Pastry.