peersim.core
Interface Linkable

All Superinterfaces:
Cleanable
All Known Implementing Classes:
IdleProtocol, OracleIdleProtocol, SimpleNewscast

public interface Linkable
extends Cleanable

Instances of classes implementing this interface can form networks (graphs) in the simulator framework. The interface is similar to one of a container (containing neighbors), only the types of the contained elements have to be Node. The neighbor collection is defined in a random access list style, but it must follow the contract of a set too (elements must be unique).

Also note that there is no possibility to remove elements from the neighbor set. This is because removal is usually costly and it does not make sense in the context of our applications, where this interface is used for 1) initialization and 2) providing an interface for other protocols for accessing the neighbor list. Protocols that manage links remove, refresh, etc their link set internally or through custom methods. Therefore it would only put an unnecessary burden on implementors.


Method Summary
 boolean addNeighbor(Node neighbour)
          Add a neighbor to the current set of neighbors.
 boolean contains(Node neighbor)
          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 pack()
          A possibility for optimization.
 
Methods inherited from interface peersim.core.Cleanable
onKill
 

Method Detail

degree

int degree()
Returns the size of the neighbor list.


getNeighbor

Node getNeighbor(int i)
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 degree().


addNeighbor

boolean addNeighbor(Node neighbour)
Add a neighbor to the current set of neighbors. If neighbor is not yet a neighbor but it cannot be added from other reasons, this method should not return normally, that is, it must throw a runtime exception.

Returns:
true if the neighbor has been inserted; false if the node is already a neighbor of this node

contains

boolean contains(Node neighbor)
Returns true if the given node is a member of the neighbor set.


pack

void pack()
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.