Project

General

Profile

Statistics
| Revision:

root / src / chord / CheckPredecessor.java @ 1

History | View | Annotate | Download (1002 Bytes)

1 1 up20150524
package chord;
2
3
import chord.ChordManager;
4
import chord.ConnectionInfo;
5
import messages.MessageForwarder;
6
import messages.PingMessage;
7
import peer.Peer;
8
9
import java.net.InetAddress;
10
11
public class CheckPredecessor implements Runnable{
12
    public static boolean dead;
13
    private int timeout;
14
15
    public CheckPredecessor(int timeout){
16
        this.timeout = timeout;
17
    }
18
19
    @Override
20
    public void run(){
21
        synchronized(this){
22
            if (ChordManager.predecessor != null) {
23
                try {
24
                    MessageForwarder.sendMessage(new PingMessage(new ConnectionInfo(null, InetAddress.getLocalHost().getHostAddress(), Peer.port), ChordManager.predecessor.getIp(), ChordManager.predecessor.getPort()));
25
                    this.wait(timeout);
26
                } catch (Exception e) {
27
                    e.printStackTrace();
28
                }
29
                if (dead) {
30
                    ChordManager.predecessor = null;
31
                }
32
            }
33
        }
34
    }
35
}