Home > Blockchain >  How to make nodes wait till the topology is defined
How to make nodes wait till the topology is defined

Time:11-02

I'm trying to implement a distributed algorithm on JBotSim. When I define the entire topology in my Main class, my algorithm works, but when I draw my graph on the canvas, it seems that first drawn nodes start the algorithm before I finish drawing my graph making my algorithm completely desynchronized.

Any idea how I can fix this issue?

Thank you.

CodePudding user response:

If the topology is started automatically, as in this example,

public static void main(String[] args){
    Topology topology = new Topology();
    new JViewer(topology);
    topology.start();
}

then the topology is already running when you add the nodes. Consequently, the onStart() method on each node is called as soon as you add it to the topology (which indeed, makes them start in a non synchronized way).

One solution here is to remove the call to topology.start() and start the topology manually once all the nodes have been added. This can be done in the context menu (right click > "start execution").

  • Related