root / src / chord / Stabilize.java
History | View | Annotate | Download (951 Bytes)
1 |
package chord; |
---|---|
2 |
|
3 |
import chord.ChordManager; |
4 |
import chord.ConnectionInfo; |
5 |
import messages.GetPredecessorMessage; |
6 |
import messages.MessageForwarder; |
7 |
import peer.Peer; |
8 |
|
9 |
import java.net.InetAddress; |
10 |
|
11 |
public class Stabilize implements Runnable { |
12 |
@Override
|
13 |
public void run() { |
14 |
try {
|
15 |
if(ChordManager.getFingerTable().get(0).getPort() == Peer.port && ChordManager.predecessor != null){ |
16 |
ChordManager.getFingerTable().set(0, ChordManager.predecessor);
|
17 |
} else if(ChordManager.getFingerTable().get(0).getPort() != Peer.port ){ |
18 |
MessageForwarder.sendMessage(new GetPredecessorMessage(new ConnectionInfo(null, InetAddress.getLocalHost().getHostAddress(),Peer.port), ChordManager.getFingerTable().get(0).getIp() , ChordManager.getFingerTable().get(0).getPort())); |
19 |
} |
20 |
} catch (Exception e) { |
21 |
e.printStackTrace(); |
22 |
} |
23 |
} |
24 |
} |