example.newscast
Class SimpleNewscast

java.lang.Object
  extended by example.newscast.SimpleNewscast
All Implemented Interfaces:
java.lang.Cloneable, CDProtocol, Cleanable, Linkable, Protocol

public class SimpleNewscast
extends java.lang.Object
implements CDProtocol, Linkable

This class represents the information stored by a node in the simplified newscast system (i.e., used just as a topology manager)


Parameter Summary
cache
          Cache size.
 
Constructor Summary
SimpleNewscast(java.lang.String n)
           
 
Method Summary
 boolean addNeighbor(Node node)
          Add a neighbor to the current set of neighbors.
 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()
          Might be less than cache size.
 Node getNeighbor(int i)
          Does not check if the index is out of bound (larger than degree())
 void nextCycle(Node n, int protocolID)
          A protocol which is defined by performing an algorithm in more or less regular periodic intervals.
 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

cache

Cache size.

Constructor Detail

SimpleNewscast

public SimpleNewscast(java.lang.String n)
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

getNeighbor

public Node getNeighbor(int i)
Does not check if the index is out of bound (larger than degree())

Specified by:
getNeighbor in interface Linkable

degree

public int degree()
Might be less than cache size.

Specified by:
degree in interface Linkable

addNeighbor

public boolean addNeighbor(Node node)
Description copied from interface: Linkable
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.

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

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

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

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

nextCycle

public void nextCycle(Node n,
                      int protocolID)
Description copied from interface: CDProtocol
A protocol which is defined by performing an algorithm in more or less regular periodic intervals. This method is called by the simulator engine once in each cycle with the appropriate parameters.

Specified by:
nextCycle in interface CDProtocol
Parameters:
n - the node on which this component is run
protocolID - the id of this protocol in the protocol array

toString

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