peersim.core
Class IdleProtocol

java.lang.Object
  extended by peersim.core.IdleProtocol
All Implemented Interfaces:
java.lang.Cloneable, Cleanable, Linkable, Protocol

public class IdleProtocol
extends java.lang.Object
implements Protocol, Linkable

A protocol that stores links. It does nothing apart from that. It is useful to model a static link-structure (topology). The only function of this protocol is to serve as a source of neighborhood information for other protocols.


Parameter Summary
capacity
          Initial capacity.
 
Field Summary
protected  int len
          Actual number of neighbors in the array
protected  Node[] neighbors
          Neighbors
 
Constructor Summary
IdleProtocol(java.lang.String s)
           
 
Method Summary
 boolean addNeighbor(Node n)
          Adds given node if it is not already in the network.
 java.lang.Object clone()
          Returns a clone of the protocol.
 boolean contains(Node n)
          Returns true if the given node is a member of the neighbor set.
 int degree()
          Returns the size of the neighbor list.
 Node getNeighbor(int i)
          Returns the neighbor with the given index.
 void onKill()
          Performs cleanup when removed from the network.
 void pack()
          A possibility for optimization.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Parameter Detail

capacity

Initial capacity. Defaults to 10.

Field Detail

neighbors

protected Node[] neighbors
Neighbors


len

protected int len
Actual number of neighbors in the array

Constructor Detail

IdleProtocol

public IdleProtocol(java.lang.String s)
Method Detail

clone

public java.lang.Object clone()
Description copied from interface: Protocol
Returns a clone of the protocol. It is important to pay attention to implement this carefully because in peersim all nodes are generated by cloning except a prototype node. That is, the constructor of protocols is used only to construct the prototype. Initialization can be done via Controls.

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

contains

public boolean contains(Node n)
Description copied from interface: Linkable
Returns true if the given node is a member of the neighbor set.

Specified by:
contains in interface Linkable

addNeighbor

public boolean addNeighbor(Node n)
Adds given node if it is not already in the network. There is no limit to the number of nodes that can be added.

Specified by:
addNeighbor in interface Linkable
Returns:
true if the neighbor has been inserted; false if the node is already a neighbor of this node

getNeighbor

public Node getNeighbor(int i)
Description copied from interface: Linkable
Returns the neighbor with the given index. The contract is that listing the elements from index 0 to index degree()-1 should list each element exactly once if this object is not modified in the meantime. It throws an IndexOutOfBounds exception if i is negative or larger than or equal to Linkable.degree().

Specified by:
getNeighbor in interface Linkable

degree

public int degree()
Description copied from interface: Linkable
Returns the size of the neighbor list.

Specified by:
degree in interface Linkable

pack

public void pack()
Description copied from interface: Linkable
A possibility for optimization. An implementation should try to compress its internal representation. Normally this is called by initializers or other components when no increase in the expected size of the neighborhood can be expected.

Specified by:
pack in interface Linkable

toString

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

onKill

public void onKill()
Description copied from interface: Cleanable
Performs cleanup when removed from the network. This is called by the host node when its fail state is set to Fallible.DEAD. It is very important that after calling this method, NONE of the methods of the implementing object are guaranteed to work any longer. They might throw arbitrary exceptions, etc. The idea is that after calling this, typically no one should access this object. However, as a recommendation, at least toString should be guaranteed to execute normally, to aid debugging.

Specified by:
onKill in interface Cleanable