newscast
Class ReducedNewscast

java.lang.Object
  extended by newscast.ReducedNewscast
All Implemented Interfaces:
java.lang.Cloneable, peersim.cdsim.CDProtocol, peersim.core.Linkable, peersim.core.Protocol

public class ReducedNewscast
extends java.lang.Object
implements peersim.cdsim.CDProtocol, peersim.core.Linkable

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


Field Summary
protected  boolean active
          True if active
protected  peersim.core.Node[] cache
          Neighbors currently in the cache
static java.lang.String PAR_CACHE
          config parameter name for the cache size
static java.lang.String PAR_LINK
          config parameter name for the cache size
protected static peersim.core.Node[] tn
          Temp array for merging.
protected static int[] ts
          Temp array for merging.
protected  int[] tstamps
          Time stamps currently in the cache
 
Constructor Summary
ReducedNewscast(java.lang.String n)
           
 
Method Summary
protected  int _degree()
          Normally it does the same as degree().
 boolean addNeighbor(peersim.core.Node node)
           
 void cleanInactive(int pid)
           
 java.lang.Object clone()
           
protected static boolean contains(int size, peersim.core.Node peer)
           
 boolean contains(peersim.core.Node n)
           
 void copyFrom(ReducedNewscast peer)
           
 int degree()
          Might be less than cache size.
 peersim.core.Node getNeighbor(int i)
          Does not check if the index is out of bound (larger than degree())
protected  peersim.core.Node getPeer()
          Returns a peer node which is accessible (has ok fail state).
protected  void merge(peersim.core.Node thisNode, ReducedNewscast peer, peersim.core.Node peerNode, int timestamp)
          Merge the content of two nodes and adds a new version of the identifier.
 void nextCycle(peersim.core.Node n, int protocolID)
           
 void pack()
           
 void removeNeighbor(int i)
           
 void removeNeighbor(peersim.core.Node node)
           
 void reset(peersim.core.Node n)
           
 void setActive(boolean active)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

tn

protected static peersim.core.Node[] tn
Temp array for merging. Its size is the same as the cache size.


ts

protected static int[] ts
Temp array for merging. Its size is the same as the cache size.


PAR_CACHE

public static final java.lang.String PAR_CACHE
config parameter name for the cache size

See Also:
Constant Field Values

PAR_LINK

public static final java.lang.String PAR_LINK
config parameter name for the cache size

See Also:
Constant Field Values

cache

protected peersim.core.Node[] cache
Neighbors currently in the cache


tstamps

protected int[] tstamps
Time stamps currently in the cache


active

protected boolean active
True if active

Constructor Detail

ReducedNewscast

public ReducedNewscast(java.lang.String n)
Method Detail

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Specified by:
clone in interface peersim.core.Protocol
Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException

getPeer

protected peersim.core.Node getPeer()
Returns a peer node which is accessible (has ok fail state). This implementation starts with a random node. If that is not reachable, proceed first towards the older and then younger nodes until the first reachable is found.

Returns:
null if no accessible peers are found, the peer otherwise.

merge

protected void merge(peersim.core.Node thisNode,
                     ReducedNewscast peer,
                     peersim.core.Node peerNode,
                     int timestamp)
Merge the content of two nodes and adds a new version of the identifier. The result is in the static temporary arrays. The first element is not defined, it is reserved for the freshest new updates so it will be different for peer and this. The elements of the static temporary arrays will not contain neither peerNode nor thisNode.

Parameters:
thisNode - the node that hosts this newscast protocol instance (process)
peer - The peer with which we perform cache exchange
peerNode - the node that hosts the peer newscast protocol instance
timestamp - the timestamp now

contains

protected static boolean contains(int size,
                                  peersim.core.Node peer)

_degree

protected int _degree()
Normally it does the same as degree(). It is necessary to allow other implementations of degree() in extending classes which fool the system into thinking that the graph is different from what it is. Methods of this class should use this as degree.


getNeighbor

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

Specified by:
getNeighbor in interface peersim.core.Linkable

removeNeighbor

public void removeNeighbor(int i)

removeNeighbor

public void removeNeighbor(peersim.core.Node node)

reset

public void reset(peersim.core.Node n)

degree

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

Specified by:
degree in interface peersim.core.Linkable

addNeighbor

public boolean addNeighbor(peersim.core.Node node)
Specified by:
addNeighbor in interface peersim.core.Linkable

pack

public void pack()
Specified by:
pack in interface peersim.core.Linkable

contains

public boolean contains(peersim.core.Node n)
Specified by:
contains in interface peersim.core.Linkable

setActive

public void setActive(boolean active)

nextCycle

public void nextCycle(peersim.core.Node n,
                      int protocolID)
Specified by:
nextCycle in interface peersim.cdsim.CDProtocol

cleanInactive

public void cleanInactive(int pid)

copyFrom

public void copyFrom(ReducedNewscast peer)

toString

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