Old leave strategy.

This commit is contained in:
senft-lap 2012-11-23 16:14:39 +01:00
parent 9c08ffb131
commit d359ccb961

View File

@ -91,26 +91,49 @@ public class Node {
}
/**
* Circularly link all neighbors, remove itself form all neighbors and exit.
* This node circularly links all neighbors (no mesh!) and removes itself
* from the network.
*/
public void leave() {
LOGGER.info("Name: " + getName()
+ ", Leaving... Announcing to my neighbors: " + neighbors);
LOGGER.info("Name: " + getName() + ", Leaving...");
// loop over each neighbor i
for (int i = 0; i < neighbors.size(); i++) {
for (int j = 0; j < neighbors.size(); j++) {
if(i != j){
try {
// send all neighbors j to neighbor i
putAddrInBuf(buf, neighbors.get(j));
try {
if (neighbors.size() > 2) {
if (i == 0) {
putAddrInBuf(buf, neighbors.get(1));
channel.send(buf, neighbors.get(i));
putAddrInBuf(buf, neighbors.get(neighbors.size() - 1));
channel.send(buf, neighbors.get(i));
} else if (i == neighbors.size() - 1) {
putAddrInBuf(buf, neighbors.get(0));
channel.send(buf, neighbors.get(i));
putAddrInBuf(buf, neighbors.get(i - 1));
channel.send(buf, neighbors.get(i));
} else {
putAddrInBuf(buf, neighbors.get(i - 1));
channel.send(buf, neighbors.get(i));
putAddrInBuf(buf, neighbors.get(i + 1));
channel.send(buf, neighbors.get(i));
} catch (IOException e) {
e.printStackTrace();
}
} else if (neighbors.size() == 2) {
putAddrInBuf(buf, neighbors.get(Math.abs(i - 1)));
channel.send(buf, neighbors.get(i));
}
} catch (IOException e) {
e.printStackTrace();
}
// send LEAVE to neighbor i
buf.clear();
buf.put(MessageType.LEAVE);
buf.flip();
@ -121,8 +144,6 @@ public class Node {
e.printStackTrace();
}
}
// Destroy thread
try {
if (thread != null) {
udpListen.terminate();