planet.generic.commonapi
Class NodeHandleImpl

java.lang.Object
  extended byjava.util.Observable
      extended byplanet.commonapi.NodeHandle
          extended byplanet.generic.commonapi.NodeHandleImpl
All Implemented Interfaces:
java.lang.Comparable, java.io.Serializable

public class NodeHandleImpl
extends NodeHandle
implements java.lang.Comparable

NodeHandle for node. Being so simple his API, surely will be able to be reused for different nodes. It only mantain the Node Id and a flag that informs if the related Node is alive.

Author:
Jordi Pujol Date: 13/05/2004
See Also:
Serialized Form

Field Summary
 
Fields inherited from class planet.commonapi.NodeHandle
DECLARED_DEAD, DECLARED_LIVE, PROXIMITY_CHANGED
 
Constructor Summary
NodeHandleImpl()
           
 
Method Summary
 int compareTo(java.lang.Object obj)
          Returns less than, equals than or greater than zero if this Id is less than, equals than or greater than obj Id.
 boolean equals(java.lang.Object obj)
          Overwrites this method to reflect the comparison between the related Id's.
 Id getId()
          Gets the Id of the related node
 int getProximity()
          Always returns one as proximity between any two nodes.
 int hashCode()
          Overwrites this method to reflect the hash code of the related Id.
 boolean isAlive()
          Inform if the related node is alive.
 void setAlive(boolean alive)
          Updates the alive flag.
 NodeHandle setValues(Id newValue)
          Sets the 'newValue' Id and the flag alive to true.
 NodeHandle setValues(Id newValue, boolean alive)
          Sets the values for this NodeHandle.
 java.lang.String toString()
          Returns the String representation of this NodeHandle
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NodeHandleImpl

public NodeHandleImpl()
Method Detail

getId

public Id getId()
Gets the Id of the related node

Specified by:
getId in class NodeHandle
Returns:
Id of the node
See Also:
NodeHandle.getId()

isAlive

public boolean isAlive()
Inform if the related node is alive.

Specified by:
isAlive in class NodeHandle
Returns:
true if the related node is alive. false in other case.
See Also:
NodeHandle.isAlive()

setAlive

public void setAlive(boolean alive)
Updates the alive flag.

Specified by:
setAlive in class NodeHandle
Parameters:
alive - New value for the alive flag.
See Also:
NodeHandle.setAlive(boolean)

toString

public java.lang.String toString()
Returns the String representation of this NodeHandle

Returns:
String representation with the nodeId and alive flag.
See Also:
Object.toString()

getProximity

public int getProximity()
Always returns one as proximity between any two nodes.

Specified by:
getProximity in class NodeHandle
Returns:
Always one
See Also:
NodeHandle.getProximity()

equals

public boolean equals(java.lang.Object obj)
Overwrites this method to reflect the comparison between the related Id's. That is:
return getId().equals(((NodeHandle)obj).getId());

Parameters:
obj - NodeHandle to be compared.
Returns:
true if and only if the related Id's are equals. false in other case.
See Also:
Object.equals(java.lang.Object)

compareTo

public int compareTo(java.lang.Object obj)
Returns less than, equals than or greater than zero if this Id is less than, equals than or greater than obj Id.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
obj - Another NodeHandle
Returns:
Less than, equals than or greater than zero.
See Also:
Comparable.compareTo(java.lang.Object)

hashCode

public int hashCode()
Overwrites this method to reflect the hash code of the related Id. That is:
return getId().hashCode();

Returns:
The hash code of the related Id.
See Also:
Object.hashCode()

setValues

public NodeHandle setValues(Id newValue)
Sets the 'newValue' Id and the flag alive to true.

Specified by:
setValues in class NodeHandle
Parameters:
newValue - New Id.
Returns:
The same instance, after being updated.
See Also:
NodeHandle.setValues(planet.commonapi.Id)

setValues

public NodeHandle setValues(Id newValue,
                            boolean alive)
Sets the values for this NodeHandle.

Specified by:
setValues in class NodeHandle
Parameters:
newValue - The new Id
alive - If the NodeHandle is alive
Returns:
The same instance, after being updated.
See Also:
NodeHandle.setValues(planet.commonapi.Id, boolean)