8000 Assignment3: Some thing fixed some thing needs to still be fixed · rpytel1/distributed-algorithms@4a42e88 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4a42e88

Browse files
author
rpytel1
committed
Assignment3: Some thing fixed some thing needs to still be fixed
1 parent 0d19fcf commit 4a42e88

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

Assignment3/src/assignment3/node/Node.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,12 @@ public void run() {
175175
@Override
176176
public void run() {
177177
try {
178+
Thread.sleep(30);//It is added to preserve order of messages sended from certain node
178179
nodes[link.getReceiver(id)].receive(msg, link);
179180
} catch (RemoteException e) {
180181
e.printStackTrace();
182+
} catch (InterruptedException e) {
183+
e.printStackTrace();
181184
}
182185
}
183186
},
@@ -224,7 +227,7 @@ public void run() {
224227
}
225228
}
226229

227-
private void test() throws RemoteException {
230+
private synchronized void test() throws RemoteException {
228231
System.out.println(id + ":Test");
229232
if (links.stream().anyMatch(p -> p.getState() == LinkState.CANDIDATE_IN_MST)) {
230233
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
341344
testEdge = null;
342345
System.out.println(id + ": Accept " + link.getWeight() + " " + weightBestAdjacent);
343346
if (link.getWeight() < weightBestAdjacent) {
344-
System.out.println(id + ": BestEdge changed from " + bestEdge.getReceiver(id) + "to " + bestEdge.getReceiver(id));
345347
bestEdge = link;
346348
weightBestAdjacent = link.getWeight();
347349
}
@@ -373,6 +375,7 @@ public void run() {
373375
@Override
374376
public synchronized void receiveReport(Message message, Link link) throws RemoteException {
375377
System.out.println(id + ":Receive Report from " + link.getReceiver(id)+" state:"+state);
378+
System.out.println(findCount.get());
376379
if (link.compareTo(inBranch) != 0) {
377380
findCount.getAndDecrement();
378381
System.out.println(id + ": Report " + message.getWeight() + " " + weightBestAdjacent);
@@ -411,7 +414,7 @@ public void run() {
411414
}
412415
}
413416

414-
private void changeRoot() throws RemoteException {
417+
private synchronized void changeRoot() throws RemoteException {
415418
System.out.println(id + ":Change Root");
416419

417420
if (bestEdge.getState() == LinkState.IN_MST) {

Assignment3/src/assignment3/server/Client1.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,5 +119,6 @@ public static void setRegistry() throws NotBoundException, NumberFormatException
119119
Scanner scan = new Scanner(System.in);
120120
scan.nextLine();
121121
myThreads[0].start();
122+
myThreads[1].start();
122123
}
123124
}

tests/edges1.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
0 1 1.5 1000
2-
0 2 1.2 1400
2+
0 2 1.8 1400
33
0 3 1.4 1000
44
0 4 2.0 2000
55
1 2 1.3 1400

0 commit comments

Comments
 (0)
0