|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectplanet.generic.commonapi.NetworkImpl
This implementation of Network interface pretends to abstract any network, based with the actual commonapi, of course. This not consider the time (number of steps) for simulation. Only stabilize the network at each join, leave, ... Operationals modes for this network implementation:
Nested Class Summary | |
class |
NetworkImpl.NetworkIterator
This class implements the java.util.Iterator interface and is backed up by TreeMap that contains all existing nodes on the network. |
Constructor Summary | |
NetworkImpl(NodeFactory nodeFactory)
Initialize the network with: No nodes. |
Method Summary | |
boolean |
existNodeWithId(Id id)
Inform if exist on the network one node with Id id. |
void |
failNodes(Id[] nodes)
Runs the stabilization process after each fail node. |
int |
getProximity(Id nodeA,
Id nodeB)
Always returns 1 (one). |
Application |
getRandomApplication(java.lang.String appId)
Gets a reference of some application on any node of the network. |
Node |
getRandomNode(java.util.Random r)
Returns a randomly selected node of actual network. |
int |
getSimulatedSteps()
Gets the actual number of simulated steps. |
java.lang.String |
getTopology()
Gets the actual topology of the underlying network. |
java.util.Iterator |
iterator()
Builds an Iterator to iterate over all nodes of the network. |
void |
joinNode(Node node)
Add the node to the actual network. |
void |
joinNode(Node node,
Id bootstrap)
Adds node to the network, using the node with Id bootstrap to enter it. |
int |
joinNodes(int size)
Add size nodes to the actual network. |
int |
joinNodes(int size,
Id[] bootstrap)
Add size nodes to the actual network. |
void |
leaveNodes(Id[] nodes)
Leave theese nodes for the network. |
protected int[] |
makeRandomIndexes(int max)
Returns an array of indexes in range (0..number of nodes) to use to identify which nodes to select. |
void |
prettyPrintNodes()
Shows only the owner Id, the successor and predecessor for each Node. |
void |
printNodes()
Shows for each Node its printNode(). |
protected boolean |
process()
Process all nodes one step at this network. |
int |
registerApplication(Id[] nodes)
Register the Application specified at properties file to the specified nodes by theirs Ids. |
void |
registerApplicationAll()
Register the Application app to all nodes existing at the underlying network. |
void |
registerApplicationRandom(int nodes)
Register the Application app to radomly at the number of Nodes nodes. |
int |
run(int steps)
Simulate a total number steps steps. |
protected void |
send(Queue messages)
Takes all messages of queue and send to all destination nodes. |
protected boolean |
sendMessages()
Sends all message pending to be delivered by all nodes. |
boolean |
simulate()
Simulate one step. |
int |
size()
Returns the actual number of nodes to the network. |
int |
stabilize()
Stabilize the network. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public NetworkImpl(NodeFactory nodeFactory)
nodeFactory
- NodeFactory implementation to use to build
new nodes with default attributes (specified by properties file).Method Detail |
public void joinNode(Node node) throws InitializationException
joinNode
in interface Network
node
- Node to add to the network.
InitializationException
Network.joinNode(planet.commonapi.Node)
public void joinNode(Node node, Id bootstrap) throws InitializationException
joinNode
in interface Network
node
- Node to add to the network.bootstrap
- Id of the node to use as bootstrap for node.
InitializationException
- if the bootstrap not exists in the network.Network.joinNode(planet.commonapi.Node, planet.commonapi.Id)
public int joinNodes(int size) throws InitializationException
joinNodes
in interface Network
size
- Number of nodes to add to the network.
InitializationException
- if occur some problem with building nodes.Network.joinNodes(int)
public int joinNodes(int size, Id[] bootstrap) throws InitializationException
joinNodes
in interface Network
size
- Number of nodes to add to the network.bootstrap
- Ids of nodes to use as bootstrap for new nodes.
InitializationException
- if occur some problem with building nodes.Network.joinNodes(int, planet.commonapi.Id[])
public void leaveNodes(Id[] nodes) throws InitializationException
leaveNodes
in interface Network
nodes
- Ids for nodes to leave.
InitializationException
- if exists some Id in the array
as parameter that not exists in the network. The message includes
which are of them.Network.leaveNodes(planet.commonapi.Id[])
public void failNodes(Id[] nodes) throws InitializationException
failNodes
in interface Network
nodes
- Node's Ids that must leave the ring.
InitializationException
Network.failNodes(planet.commonapi.Id[])
public void registerApplicationAll() throws InitializationException
registerApplicationAll
in interface Network
InitializationException
Network.registerApplicationAll()
public int registerApplication(Id[] nodes) throws InitializationException
registerApplication
in interface Network
nodes
- Ids of those nodes to register Application app.
InitializationException
Network.registerApplication(planet.commonapi.Id[])
public void registerApplicationRandom(int nodes) throws InitializationException
registerApplicationRandom
in interface Network
nodes
- Number of nodes to radomly select to register the
Application app.
InitializationException
Network.registerApplicationRandom(int)
protected int[] makeRandomIndexes(int max)
max
- Number of indexes generate.
public java.lang.String getTopology()
getTopology
in interface Network
Network.getTopology()
,
Topology
public int size()
size
in interface Network
Network.size()
public void printNodes()
printNodes
in interface Network
public void prettyPrintNodes()
prettyPrintNodes
in interface Network
public int run(int steps)
run
in interface Network
steps
- Number of steps to simulate.
Network.run(int)
public boolean simulate()
simulate
in interface Network
Network.simulate()
protected boolean process()
protected boolean sendMessages()
protected void send(Queue messages)
messages
- Queue with messages to sendQueue
,
Globals
public Node getRandomNode(java.util.Random r)
getRandomNode
in interface Network
r
- Generator of random numbers.
Network.getRandomNode(java.util.Random)
public boolean existNodeWithId(Id id)
existNodeWithId
in interface Network
id
- Id of the node to be search.
Network.existNodeWithId(planet.commonapi.Id)
public int stabilize()
stabilize
in interface Network
Network.stabilize()
public Application getRandomApplication(java.lang.String appId)
getRandomApplication
in interface Network
appId
- Application identification for searching it.
Network.getRandomApplication(java.lang.String)
public java.util.Iterator iterator()
iterator
in interface Network
public int getSimulatedSteps()
getSimulatedSteps
in interface Network
Network.getSimulatedSteps()
public int getProximity(Id nodeA, Id nodeB)
getProximity
in interface Network
nodeA
- First node to evaluate.nodeB
- Second node to evaluate.
Network.getProximity(planet.commonapi.Id, planet.commonapi.Id)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |