8000 New methods implementations added to Node · rpytel1/distributed-algorithms@1412361 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1412361

Browse files
author
LENOVO-PC\Vasilis
committed
New methods implementations added to Node
1 parent 091a9f9 commit 1412361

File tree

2 files changed

+47
-6
lines changed

2 files changed

+47
-6
lines changed

Assignment3/src/assignment3/message/Message.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ public void setfName(double fName) {
9191
this.fName = fName;
9292
}
9393

94+
public double getWeight() {
95+
return bestWeight;
96+
}
97+
98+
public void setWeight(double weight) {
99+
this.bestWeight = weight;
100+
}
101+
94102
public NodeState getSenderState() {
95103
return senderState;
96104
}

Assignment3/src/assignment3/node/Node.java

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ private void receiveReject(Message message, Link link) {
138138

139139
}
140140

141-
private void receiveAccept(Message message, Link link) {
141+
private void receiveAccept(Message message, Link link) throws RemoteException {
142142
testEdge = null;
143143
if (link.getWeight() < weightBestAdjacent){
144144
bestEdge = link;
@@ -147,22 +147,55 @@ private void receiveAccept(Message message, Link link) {
147147
report();
148148
}
149149

150-
private void report() {
150+
private void report() throws RemoteException {
151151
if (findCount==0 && testEdge.equals(null)){
152152
this.state = NodeState.FOUND;
153153
Message msg = new Message(MessageType.REPORT, weightBestAdjacent);
154+
nodes[inBranch.getReceiver(id)].receive(msg, inBranch);
154155
}
155156
}
156157

157-
private void receiveReport(Message message, Link link) {
158-
158+
private void receiveReport(Message message, Link link) throws RemoteException {
159+
if (!link.equals(inBranch)){
160+
findCount -=1;
161+
if (message.getWeight() < weightBestAdjacent){
162+
weightBestAdjacent = message.getWeight();
163+
bestEdge = link;
164+
}
165+
report();
166+
}
167+
else{
168+
if (this.state == NodeState.FIND){
169+
// TODO: append message to the message queue
170+
}
171+
else{
172+
if (message.getWeight() > weightBestAdjacent)
173+
changeRoot();
174+
else{
175+
if (message.getWeight() == weightBestAdjacent &&
176+
weightBestAdjacent == Double.POSITIVE_INFINITY){
177+
// TODO: HALT
178+
}
179+
}
180+
}
181+
}
159182
}
160183

161184
private void changeRoot() {
162-
185+
if (bestEdge.getState() == LinkState.IN_MST){
186+
Message msg = new Message(MessageType.CHANGE_ROOT);
187+
// TODO: check if bestEdge is adjacent to the node
188+
nodes[bestEdge.getReceiver(id)].receiveChangeRoot(msg, bestEdge);
189+
}
190+
else{
191+
Message msg = new Message(MessageType.CONNECT, level);
192+
// TODO: check if bestEdge is adjacent to the node
193+
nodes[bestEdge.getReceiver(id)].receiveChangeRoot(msg, bestEdge);
194+
bestEdge.setState(LinkState.IN_MST);
195+
}
163196
}
164197

165198
private void receiveChangeRoot(Message message, Link link) {
166-
199+
changeRoot();
167200
}
168201
}

0 commit comments

Comments
 (0)
0