peersim.core
Class Network

java.lang.Object
  extended by peersim.core.Network

public class Network
extends java.lang.Object

This class forms the basic framework of all simulations. This is a static singleton which is based on the assumption that we will simulate only one overlay network at a time. This allows us to reduce memory usage in many cases by allowing all the components to directly reach the fields of this class without having to store a reference.

The network is a set of nodes implemented via an array list for the sake of efficiency. Each node has an array of protocols. The protocols within a node can interact directly as defined by their implementation, and can be imagined as processes running in a common local environment (i.e. the node). This class is called a "network" because, although it is only a set of nodes, in most simulations there is at least one Linkable protocol that defines connections between nodes. In fact, such a Linkable protocol layer can be accessed through a Graph view using OverlayGraph.


Parameter Summary
network.node
          This config property defines the node class to be used.
network.initialCapacity
          This config property defines the initial capacity of the overlay network.
network.size
          This config property defines the initial size of the overlay network.
 
Field Summary
static Node prototype
          The prototype node which is used to populate the simulation via cloning.
 
Method Summary
static void add(Node n)
          The node will be appended to the end of the list.
static Node get(int index)
          Returns node with the given index.
static int getCapacity()
          Returns the maximal number of nodes that can be stored without reallocating the underlying array to increase capacity.
static Node remove()
          The node at the end of the list is removed.
static Node remove(int i)
          The node with the given index is removed.
static void reset()
          Reads configuration parameters, constructs the prototype node, and populates the network by cloning the prototype.
static void setCapacity(int newSize)
          Sets the capacity of the internal array storing the nodes.
static void shuffle()
          Shuffles the node array.
static int size()
          Number of nodes currently in the network
static void sort(java.util.Comparator<? super Node> c)
          Sorts the node array.
static void swap(int i, int j)
          Swaps the two nodes at the given indexes.
static void test()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Parameter Detail

network.node

This config property defines the node class to be used. If not set, then GeneralNode will be used.


network.initialCapacity

This config property defines the initial capacity of the overlay network. If not set then the value of "network.size" will be used. The main purpose of this parameter is that it allows for optimization. In the case of scenarios when the network needs to grow, setting this to the maximal expected size of the network avoids reallocation of memory during the growth of the network.

See Also:
getCapacity()

network.size

This config property defines the initial size of the overlay network. This property is required.

Field Detail

prototype

public static Node prototype
The prototype node which is used to populate the simulation via cloning. After all the nodes have been cloned, Control components can be applied to perform any further initialization.

Method Detail

reset

public static void reset()
Reads configuration parameters, constructs the prototype node, and populates the network by cloning the prototype.


size

public static int size()
Number of nodes currently in the network


setCapacity

public static void setCapacity(int newSize)
Sets the capacity of the internal array storing the nodes. The nodes will remain the same in the same order. If the new capacity is less than the old size of the node list, than the end of the list is cut. The nodes that get removed via this cutting are removed through remove().


getCapacity

public static int getCapacity()
Returns the maximal number of nodes that can be stored without reallocating the underlying array to increase capacity.


add

public static void add(Node n)
The node will be appended to the end of the list. If necessary, the capacity of the internal array is increased.


get

public static Node get(int index)
Returns node with the given index. Note that the same node will normally have a different index in different times. This can be used as a random access iterator. This method does not perform range checks to increase efficiency. The maximal valid index is size().


remove

public static Node remove()
The node at the end of the list is removed. Returns the removed node. It also sets the fail state of the node to Fallible.DEAD.


remove

public static Node remove(int i)
The node with the given index is removed. Returns the removed node. It also sets the fail state of the node to Fallible.DEAD.

Look out: the index of the other nodes will not change (the right hand side of the list is not shifted to the left) except that of the last node. Only the last node is moved to the given position and will get index i.


swap

public static void swap(int i,
                        int j)
Swaps the two nodes at the given indexes.


shuffle

public static void shuffle()
Shuffles the node array. The index of each node is updated accordingly.


sort

public static void sort(java.util.Comparator<? super Node> c)
Sorts the node array. The index of each node is updated accordingly.

Parameters:
c - The comparator to be used for sorting the nodes. If null, the natural order of the nodes is used.

test

public static void test()