peersim.core
Class GeneralNode

java.lang.Object
  extended by peersim.core.GeneralNode
All Implemented Interfaces:
java.lang.Cloneable, Fallible, Node
Direct Known Subclasses:
ModifiableNode

public class GeneralNode
extends java.lang.Object
implements Node

This is the default Node class that is used to compose the Network.


Parameter Summary
 
Parameters inherited from interface peersim.core.Node
protocol
 
Field Summary
protected  int failstate
          The fail state of the node.
protected  Protocol[] protocol
          The protocols on this node.
 
Fields inherited from interface peersim.core.Fallible
DEAD, DOWN, OK
 
Constructor Summary
GeneralNode(java.lang.String prefix)
          Used to construct the prototype node.
 
Method Summary
 java.lang.Object clone()
          Clones the node.
 int getFailState()
          Returns the state of this object.
 long getID()
          Returns the ID of this node.
 int getIndex()
          Returns the index of this node.
 Protocol getProtocol(int i)
          Returns the i-th protocol in this node.
 int hashCode()
          Implemented as (int)getID().
 boolean isUp()
          Convenience method to check if the node is up and running
 int protocolSize()
          Returns the number of protocols included in this node.
 void setFailState(int failState)
          Sets the fails state of this object.
 void setIndex(int index)
          Sets the index of this node in the internal representation of the node list.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

protocol

protected Protocol[] protocol
The protocols on this node.


failstate

protected int failstate
The fail state of the node.

Constructor Detail

GeneralNode

public GeneralNode(java.lang.String prefix)
Used to construct the prototype node. This class currently does not have specific configuration parameters and so the parameter prefix is not used. It reads the protocol components (components that have type "protocol") from the configuration.

Method Detail

clone

public java.lang.Object clone()
Description copied from interface: Node
Clones the node. It is defined as part of the interface to change the access right to public and to get rid of the throws clause.

Specified by:
clone in interface Node
Overrides:
clone in class java.lang.Object

setFailState

public void setFailState(int failState)
Description copied from interface: Fallible
Sets the fails state of this object. Parameter must be one of the constants defined in interface Fallible.

Specified by:
setFailState in interface Fallible

getFailState

public int getFailState()
Description copied from interface: Fallible
Returns the state of this object. Must be one of the constants defined in interface Fallible.

Specified by:
getFailState in interface Fallible

isUp

public boolean isUp()
Description copied from interface: Fallible
Convenience method to check if the node is up and running

Specified by:
isUp in interface Fallible
Returns:
must return true if and only if getFailState()==OK

getProtocol

public Protocol getProtocol(int i)
Description copied from interface: Node
Returns the i-th protocol in this node. If i is not a valid protocol id (negative or larger than or equal to the number of protocols), then it throws IndexOutOfBoundsException.

Specified by:
getProtocol in interface Node

protocolSize

public int protocolSize()
Description copied from interface: Node
Returns the number of protocols included in this node.

Specified by:
protocolSize in interface Node

getIndex

public int getIndex()
Description copied from interface: Node
Returns the index of this node. It is such that Network.get(n.getIndex()) returns n. This index can change during a simulation, it is not a fixed id. If you need that, use Node.getID().

Specified by:
getIndex in interface Node
See Also:
Network.get(int)

setIndex

public void setIndex(int index)
Description copied from interface: Node
Sets the index of this node in the internal representation of the node list. Applications should not use this method. It is defined as public simply because it is not possible to define it otherwise. Using this method will result in undefined behavior. It is provided for the core system.

Specified by:
setIndex in interface Node

getID

public long getID()
Returns the ID of this node. The IDs are generated using a counter (i.e. they are not random).

Specified by:
getID in interface Node

toString

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

hashCode

public int hashCode()
Implemented as (int)getID().

Overrides:
hashCode in class java.lang.Object