planet.simulate
Class NetworkSimulator

java.lang.Object
  extended byplanet.simulate.NetworkSimulator
All Implemented Interfaces:
ISimulator, java.io.Serializable

public class NetworkSimulator
extends java.lang.Object
implements ISimulator, java.io.Serializable

The simulator is the main class. It controls the events to execute them at the opportune moment and controls the network.

The operational model consists of building a network with the actual specified parametres at properties files under root directory 'conf'.

Then, this simulator modifies the network by invoking different methods.

The information that is contained by this simulator is the time (number of steps) of the simulation and the IScheduler specified by constructor.

Author:
Pedro García, Carles Pairot, Ruben Mondejar, Jordi Pujol
See Also:
Serialized Form

Constructor Summary
NetworkSimulator(IScheduler timer)
          Constructor, create a new simulation with a determinate event scheduler and a new network.
NetworkSimulator(IScheduler timer, Network net)
          Constructor, create a new simulation with a determinate event scheduler
NetworkSimulator(IScheduler timer, Network net, java.lang.String factoriesProperties, java.lang.String simProperties, java.lang.String chordProperties)
          Constructor that generates a new instance of Network and prepares its simulation using the parameters specified in the properties file.
 
Method Summary
 void addNode(Id id, Id bootstrap)
          Create and joins a new node to the simulated network.
 void addNode(Node node, Id bootstrap)
          Joins a new node to the simulated network.
 Network getInternalNetwork()
          Returns a reference of the internal network.
 int getSizeNetwork()
          Return the size of the network
 void parseEvents(java.util.Vector events)
          Prepares all events to simulate from a events vector
 void parseFail(IEvent aEvent)
          Prepares the fail event to simulate from a event interface
 void parseJoin(IEvent aEvent)
          Prepares the join event to simulate from a event interface
 void parseLeave(IEvent aEvent)
          Prepares the leave event to simulate from a event interface
 void printNodes()
           
 void run(int steps)
          Executes the events at the opportune moment, controls the nodes, while they join, go away, they fail,and handles to the messages and the message queues
 void saveState()
          Serialize the actual state.
 boolean simulate()
          Executes only one step of simulation.
 void stabilize()
          Make a simple loop that make the stabilization of the actual network.
 void stop()
          Do nothing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NetworkSimulator

public NetworkSimulator(IScheduler timer)
                 throws InitializationException
Constructor, create a new simulation with a determinate event scheduler and a new network.

Parameters:
timer - Scheduler with the all events to simulate
See Also:
IScheduler

NetworkSimulator

public NetworkSimulator(IScheduler timer,
                        Network net)
                 throws InitializationException
Constructor, create a new simulation with a determinate event scheduler

Parameters:
timer - Scheduler with the all events to simulate
See Also:
IScheduler

NetworkSimulator

public NetworkSimulator(IScheduler timer,
                        Network net,
                        java.lang.String factoriesProperties,
                        java.lang.String simProperties,
                        java.lang.String chordProperties)
                 throws InitializationException
Constructor that generates a new instance of Network and prepares its simulation using the parameters specified in the properties file.

Parameters:
timer - IScheduler with events.
factoriesProperties - Property file with all parameters for factories.
simProperties - Property file with all parameters for simulator.
chordProperties - Property file with all parameters for Chord.
Throws:
InitializationException - if occur any problem during initialization.
Method Detail

run

public void run(int steps)
         throws InitializationException
Executes the events at the opportune moment, controls the nodes, while they join, go away, they fail,and handles to the messages and the message queues

Specified by:
run in interface ISimulator
Parameters:
steps - number of steps that the simulation lasts
Throws:
InitializationException

saveState

public void saveState()
Serialize the actual state.


simulate

public boolean simulate()
                 throws InitializationException
Executes only one step of simulation.

Returns:
return true if the simulation is not been finished.
Throws:
InitializationException

stabilize

public void stabilize()
               throws InitializationException
Make a simple loop that make the stabilization of the actual network. That is:
     while (simulate());
 

Throws:
InitializationException - if occur any problem during simulation.

addNode

public void addNode(Node node,
                    Id bootstrap)
             throws InitializationException
Joins a new node to the simulated network.

Parameters:
node - New node to add to the network.
bootstrap - Id of the any node in the network
Throws:
InitializationException

printNodes

public void printNodes()

addNode

public void addNode(Id id,
                    Id bootstrap)
             throws InitializationException
Create and joins a new node to the simulated network.

Parameters:
id - Id of the new node
bootstrap - Id of the any node in the network
Throws:
InitializationException

parseEvents

public void parseEvents(java.util.Vector events)
                 throws InitializationException
Prepares all events to simulate from a events vector

Parameters:
events - Vector of events
Throws:
InitializationException

parseJoin

public void parseJoin(IEvent aEvent)
               throws InitializationException
Prepares the join event to simulate from a event interface

Parameters:
aEvent - IEvent
Throws:
InitializationException
See Also:
IEvent

parseLeave

public void parseLeave(IEvent aEvent)
                throws InitializationException
Prepares the leave event to simulate from a event interface

Parameters:
aEvent - IEvent
Throws:
InitializationException
See Also:
IEvent

parseFail

public void parseFail(IEvent aEvent)
               throws InitializationException
Prepares the fail event to simulate from a event interface

Parameters:
aEvent - IEvent
Throws:
InitializationException
See Also:
IEvent

stop

public void stop()
Do nothing.

Specified by:
stop in interface ISimulator
See Also:
ISimulator.stop()

getSizeNetwork

public int getSizeNetwork()
Return the size of the network

Returns:
size int of the number of nodes

getInternalNetwork

public Network getInternalNetwork()
Returns a reference of the internal network.

Returns:
A reference of the internal network.