10000 New type of messages added and some other methods implemented for node. · rpytel1/distributed-algorithms@091a9f9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 091a9f9

Browse files
author
LENOVO-PC\Vasilis
committed
New type of messages added and some other methods implemented for node.
1 parent 4d85f1e commit 091a9f9

File tree

3 files changed

+32
-5
lines changed
Filter options

3 files changed

+32
-5
lines changed

Assignment3/src/assignment3/message/Message.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,37 @@ public class Message implements Serializable {
1313

1414

1515
private double fName;
16+
private double bestWeight;
1617
private NodeState senderState;
1718

1819
public Message() {
1920
}
2021

22+
// constructor for ACCEPT, REJECT and CHANGE_ROOT messages
23+
public Message(MessageType type) {
24+
this.type = type;
25+
}
26+
27+
// constructor for CONNECT messages
2128
public Message(MessageType type, int level) {
2229
this.type = type;
2330
this.level = level;
2431
}
2532

33+
// constructor for REPORT messages
34+
public Message(MessageType type, double weight) {
35+
this.type = type;
36+
this.bestWeight = weight;
37+
}
38+
39+
// constructor for TEST messages
2640
public Message(MessageType type, int level, double name) {
2741
this.type = type;
2842
this.level = level;
2943
fName = name;
3044
}
3145

46+
//constructor for INITIATE messages
3247
public Message(MessageType type, int level, double name, NodeState s) {
3348
this.type = type;
3449
this.level = level;

Assignment3/src/assignment3/message/MessageType.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ public enum MessageType {
55
TEST,
66
ACCEPT,
77
CHANGE_ROOT,
8-
CONNECT
8+
CONNECT,
9+
REPORT
910
}

Assignment3/src/assignment3/node/Node.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class Node extends UnicastRemoteObject implements IComponent {
2626
private Queue<Link> links;
2727
private Queue<Link> moeCandidatesList;
2828

29-
private int weightBestAdjecent;
29+
private double weightBestAdjacent;
3030
private Link bestEdge;
3131
private Link testEdge;
3232
private Link inBranch;
@@ -66,6 +66,9 @@ public void receive(Message message, Link link) throws RemoteException {
6666
case INITIATE:
6767
receiveInitiate(message, link);
6868
break;
69+
case REPORT:
70+
receiveReport(message, link);
71+
break;
6972
case CHANGE_ROOT:
7073
receiveChangeRoot(message, link);
7174
break;
@@ -101,7 +104,7 @@ private void receiveInitiate(Message message, Link link) throws RemoteException
101104
state = message.getSenderState();
102105
inBranch = link;
103106
bestEdge = null;//TODO: NIL
104-
weightBestAdjecent = -10000; // - INFINITY
107+
weightBestAdjacent = -10000; // - INFINITY
105108

106109
for (Link adjescentLink : this.links) {//TODO: Not sure if this is the correct one list of links
107110
if (adjescentLink != link && adjescentLink.getState() == LinkState.IN_MST) {
@@ -136,11 +139,19 @@ private void receiveReject(Message message, Link link) {
136139
}
137140

138141
private void receiveAccept(Message message, Link link) {
139-
142+
testEdge = null;
143+
if (link.getWeight() < weightBestAdjacent){
144+
bestEdge = link;
145+
weightBestAdjacent = link.getWeight();
146+
}
147+
report();
140148
}
141149

142150
private void report() {
143-
151+
if (findCount==0 && testEdge.equals(null)){
152+
this.state = NodeState.FOUND;
153+
Message msg = new Message(MessageType.REPORT, weightBestAdjacent);
154+
}
144155
}
145156

146157
private void receiveReport(Message message, Link link) {

0 commit comments

Comments
 (0)
0