Project

General

Profile

Statistics
| Revision:

root / src / messages / LookupMessage.java

History | View | Annotate | Download (1.19 KB)

1
package messages;
2

    
3
import chord.ChordManager;
4
import chord.ConnectionInfo;
5
import peer.Peer;
6

    
7
import java.net.InetAddress;
8
import java.net.UnknownHostException;
9

    
10
public class LookupMessage extends Message {
11
    private ConnectionInfo ci;
12
    private String ipAddress;
13
    private int port;
14

    
15
    public LookupMessage(ConnectionInfo ci,String ipAddress,int port) {
16
        this.ci = ci;
17
        this.ipAddress = ipAddress;
18
        this.port = port;
19
    }
20

    
21
    @Override
22
    public void handleMessage() throws UnknownHostException {
23
        if(ChordManager.getFingerTable().get(0).getPort() == Peer.port) {
24
            MessageForwarder.sendMessage(new SucessorMessage(ci.getHashedKey().toString(),new ConnectionInfo(ChordManager.peerHash, InetAddress.getLocalHost().getHostAddress(),Peer.port), ci.getIp(), ci.getPort()));
25
        } else {
26
            Message message = ChordManager.searchSuccessor2(ci);
27
            MessageForwarder.sendMessage(message);
28
        }
29
    }
30

    
31
    @Override
32
    public String getIpAddress() {
33
        return this.ipAddress;
34
    }
35

    
36
    @Override
37
    public int getPort() {
38
        return this.port;
39
    }
40

    
41
    @Override
42
    public String toString() {
43
        return "LOOKUP " + this.ci;
44
    }
45
}