Rice Pastry API

rice.pastry.dist
Class DistNodeHandle

java.lang.Object
  |
  +--java.util.Observable
        |
        +--rice.p2p.commonapi.NodeHandle
              |
              +--rice.pastry.NodeHandle
                    |
                    +--rice.pastry.dist.DistNodeHandle
All Implemented Interfaces:
LocalNodeI, MessageReceiver, java.util.Observer, java.io.Serializable
Direct Known Subclasses:
RMINodeHandle, WireNodeHandle

public abstract class DistNodeHandle
extends NodeHandle
implements java.util.Observer

Abstract class for handles to "real" remote nodes. This class abstracts out the node handle verification which is necessary in the "real" pastry protocols, since NodeHandles are sent across the wire.

Version:
$Id: DistNodeHandle.java,v 1.14 2003/08/25 04:30:30 amislove Exp $
Author:
Alan Mislove
See Also:
Serialized Form

Field Summary
protected  java.net.InetSocketAddress address
           
protected  boolean alive
           
static int DEFAULT_DISTANCE
           
protected  boolean isInPool
           
protected  boolean isLocal
           
protected  rice.pastry.NodeId nodeId
           
 
Fields inherited from class rice.pastry.NodeHandle
localnode
 
Fields inherited from class rice.p2p.commonapi.NodeHandle
DECLARED_DEAD, DECLARED_LIVE, PROXIMITY_CHANGED
 
Fields inherited from interface rice.pastry.LocalNodeI
pending
 
Constructor Summary
DistNodeHandle(rice.pastry.NodeId nodeId, java.net.InetSocketAddress address)
          Constructor
 
Method Summary
 void addObserver(java.util.Observer o)
           
 void afterSetLocalNode()
          Method called from LocalNode after localnode is set to non-null.
protected  void clearChanged()
           
 int countObservers()
           
protected  void debug(java.lang.String s)
          Prints out nicely formatted debug messages.
 void deleteObserver(java.util.Observer o)
           
 void deleteObservers()
           
 boolean equals(java.lang.Object obj)
          Equivalence relation for nodehandles.
 java.net.InetSocketAddress getAddress()
          Returns the IP address and port of the remote node.
 boolean getIsInPool()
          Returns whether or not this node handle is the one in the node handle pool.
 rice.pastry.NodeId getNodeId()
          Gets the nodeId of this Pastry node.
 boolean hasChanged()
           
 int hashCode()
          Hash codes for node handles.
 boolean isAlive()
          Returns the last known liveness information about the Pastry node associated with this handle.
 void markAlive()
          Marks this handle as alive (if dead earlier), and reset distance to infinity.
 void markDead()
          Mark this handle as dead (if alive earlier), and reset distance to infinity.
 void notifyObservers()
           
 void notifyObservers(java.lang.Object arg)
           
 boolean ping()
          Ping the node.
protected abstract  boolean pingImpl()
          Ping the node.
 int proximity()
          Returns the last known proximity information about the Pastry node associated with this handle.
 void receiveMessage(rice.pastry.messaging.Message message)
          Called to send a message to the node corresponding to this handle.
protected abstract  void receiveMessageImpl(rice.pastry.messaging.Message message)
          Called to send a message to the node corresponding to this handle.
protected  void setChanged()
           
 void setIsInPool(boolean iip)
          Sets whether or not this node handle is in the node handle pool.
protected  void setProximity(int value)
          Method which is designed to be called by subclassses whenever there is a change in the distance metric.
 java.lang.String toString()
          Returns a String representation of this DistNodeHandle.
protected abstract  java.lang.String toStringImpl()
          Returns a String representation of this DistNodeHandle.
 void update(java.util.Observable o, java.lang.Object obj)
           
 
Methods inherited from class rice.pastry.NodeHandle
assertLocalNode, getId, getLocalNode, setLocalNode
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_DISTANCE

public static int DEFAULT_DISTANCE

nodeId

protected rice.pastry.NodeId nodeId

address

protected java.net.InetSocketAddress address

isInPool

protected transient boolean isInPool

alive

protected transient boolean alive

isLocal

protected transient boolean isLocal
Constructor Detail

DistNodeHandle

public DistNodeHandle(rice.pastry.NodeId nodeId,
                      java.net.InetSocketAddress address)
Constructor

Parameters:
nodeId - This node handle's node Id.
Method Detail

getNodeId

public final rice.pastry.NodeId getNodeId()
Gets the nodeId of this Pastry node.

Specified by:
getNodeId in class NodeHandle
Returns:
the node id.

afterSetLocalNode

public void afterSetLocalNode()
Method called from LocalNode after localnode is set to non-null. Updates the isLocal and alive variables.

Overrides:
afterSetLocalNode in class NodeHandle

isAlive

public final boolean isAlive()
Returns the last known liveness information about the Pastry node associated with this handle. Invoking this method does not cause network activity. This method is designed to be called by clients using the node handle, and is provided in order to ensure that the right node handle is being talked to.

Specified by:
isAlive in class NodeHandle
Returns:
true if the node is alive, false otherwise.

markAlive

public final void markAlive()
Marks this handle as alive (if dead earlier), and reset distance to infinity. If node is already marked as alive, this does nothing.


markDead

public final void markDead()
Mark this handle as dead (if alive earlier), and reset distance to infinity. If node is already marked as deas, this method does nothing.


proximity

public final int proximity()
Returns the last known proximity information about the Pastry node associated with this handle. Invoking this method does not cause network activity. This method is designed to be called by clients using the node handle, and is provided in order to ensure that the right node handle is being talked to. Smaller values imply greater proximity. The exact nature and interpretation of the proximity metric implementation-specific.

Specified by:
proximity in class NodeHandle
Returns:
the proximity metric value

setProximity

protected final void setProximity(int value)
Method which is designed to be called by subclassses whenever there is a change in the distance metric. This is done in order to abstract out the notification of the observers of a distance metric change.

Parameters:
value - The new distance value

ping

public final boolean ping()
Ping the node. Refreshes the cached liveness status and proximity value of the Pastry node associated with this. Invoking this method causes network activity. This method is designed to be called by clients using the node handle, and is provided in order to ensure that the right node handle is being talked to.

Specified by:
ping in class NodeHandle
Returns:
true if node is currently alive.

pingImpl

protected abstract boolean pingImpl()
Ping the node. Refreshes the cached liveness status and proximity value of the Pastry node associated with this. Invoking this method causes network activity. This method is to be run by the node handle which is in the NodeHandlePool.

Returns:
true if node is currently alive.

getAddress

public java.net.InetSocketAddress getAddress()
Returns the IP address and port of the remote node.

Returns:
The InetSocketAddress of the remote node.

receiveMessage

public final void receiveMessage(rice.pastry.messaging.Message message)
Called to send a message to the node corresponding to this handle. This method is designed to be called by clients using the node handle, and is provided in order to ensure that the right node handle is being talked to.

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

receiveMessageImpl

protected abstract void receiveMessageImpl(rice.pastry.messaging.Message message)
Called to send a message to the node corresponding to this handle. This method is to be run by the node handle which is in the NodeHandlePool.


toString

public final java.lang.String toString()
Returns a String representation of this DistNodeHandle. This method is designed to be called by clients using the node handle, and is provided in order to ensure that the right node handle is being talked to.

Overrides:
toString in class java.lang.Object
Returns:
A String representation of the node handle.

toStringImpl

protected abstract java.lang.String toStringImpl()
Returns a String representation of this DistNodeHandle. This method is to be run by the node handle which is in the NodeHandlePool.

Returns:
A String representation of the node handle.

getIsInPool

public boolean getIsInPool()
Returns whether or not this node handle is the one in the node handle pool.

Returns:
Whether or not this node handle is in the pool.

setIsInPool

public void setIsInPool(boolean iip)
Sets whether or not this node handle is in the node handle pool.

Parameters:
iip - Whether or not this node handle is in the node handle pool.

equals

public boolean equals(java.lang.Object obj)
Equivalence relation for nodehandles. They are equal if and only if their corresponding NodeIds are equal.

Specified by:
equals in class NodeHandle
Parameters:
obj - the other nodehandle .
Returns:
true if they are equal, false otherwise.

hashCode

public int hashCode()
Hash codes for node handles. It is the hashcode of their corresponding NodeId's.

Specified by:
hashCode in class NodeHandle
Returns:
a hash code.

debug

protected void debug(java.lang.String s)
Prints out nicely formatted debug messages.

Parameters:
s - The message to print.

addObserver

public void addObserver(java.util.Observer o)
Overrides:
addObserver in class java.util.Observable

countObservers

public int countObservers()
Overrides:
countObservers in class java.util.Observable

deleteObserver

public void deleteObserver(java.util.Observer o)
Overrides:
deleteObserver in class java.util.Observable

deleteObservers

public void deleteObservers()
Overrides:
deleteObservers in class java.util.Observable

hasChanged

public boolean hasChanged()
Overrides:
hasChanged in class java.util.Observable

notifyObservers

public void notifyObservers()
Overrides:
notifyObservers in class java.util.Observable

notifyObservers

public void notifyObservers(java.lang.Object arg)
Overrides:
notifyObservers in class java.util.Observable

setChanged

protected void setChanged()
Overrides:
setChanged in class java.util.Observable

clearChanged

protected void clearChanged()
Overrides:
clearChanged in class java.util.Observable

update

public void update(java.util.Observable o,
                   java.lang.Object obj)
Specified by:
update in interface java.util.Observer

Rice Pastry API

Copyright © 2001 - Rice Pastry.


Imprint-Dataprotection