@@ -175,9 +175,12 @@ public void run() {
175
175
@ Override
176
176
public void run () {
177
177
try {
178
+ Thread .sleep (30 );//It is added to preserve order of messages sended from certain node
178
179
nodes [link .getReceiver (id )].receive (msg , link );
179
180
} catch (RemoteException e ) {
180
181
e .printStackTrace ();
182
+ } catch (InterruptedException e ) {
183
+ e .printStackTrace ();
181
184
}
182
185
}
183
186
},
@@ -224,7 +227,7 @@ public void run() {
224
227
}
225
228
}
226
229
227
- private void test () throws RemoteException {
230
+ private synchronized void test () throws RemoteException {
228
231
System .out .println (id + ":Test" );
229
232
if (links .stream ().anyMatch (p -> p .getState () == LinkState .CANDIDATE_IN_MST )) {
230
233
testEdge = links .stream ().filter (p -> p .getState () == LinkState .CANDIDATE_IN_MST ).min (new LinkComparator ()).get ();
@@ -341,7 +344,6 @@ private synchronized void receiveAccept(Message message, Link link) throws Remot
341
344
testEdge = null ;
342
345
System .out .println (id + ": Accept " + link .getWeight () + " " + weightBestAdjacent );
343
346
if (link .getWeight () < weightBestAdjacent ) {
344
- System .out .println (id + ": BestEdge changed from " + bestEdge .getReceiver (id ) + "to " + bestEdge .getReceiver (id ));
345
347
bestEdge = link ;
346
348
weightBestAdjacent = link .getWeight ();
347
349
}
@@ -373,6 +375,7 @@ public void run() {
373
375
@ Override
374
376
public synchronized void receiveReport (Message message , Link link ) throws RemoteException {
375
377
System .out .println (id + ":Receive Report from " + link .getReceiver (id )+" state:" +state );
378
+ System .out .println (findCount .get ());
376
379
if (link .compareTo (inBranch ) != 0 ) {
377
380
findCount .getAndDecrement ();
378
381
System .out .println (id + ": Report " + message .getWeight () + " " + weightBestAdjacent );
@@ -411,7 +414,7 @@ public void run() {
411
414
}
412
415
}
413
416
414
- private void changeRoot () throws RemoteException {
417
+ private synchronized void changeRoot () throws RemoteException {
415
418
System .out .println (id + ":Change Root" );
416
419
417
420
if (bestEdge .getState () == LinkState .IN_MST ) {
0 commit comments