root / src / messages / RestoreInitMessage.java
History | View | Annotate | Download (1.43 KB)
1 |
package messages; |
---|---|
2 |
|
3 |
import chord.ChordManager; |
4 |
import chord.ConnectionInfo; |
5 |
|
6 |
import java.math.BigInteger; |
7 |
import java.net.UnknownHostException; |
8 |
|
9 |
public class RestoreInitMessage extends Message { |
10 |
private ConnectionInfo ci;
|
11 |
private BigInteger hashFile; |
12 |
private String filename; |
13 |
private String ipAddress; |
14 |
private int port; |
15 |
|
16 |
public RestoreInitMessage(ConnectionInfo ci, BigInteger hashFile,String filename, String ipAddress, int port) { |
17 |
this.hashFile = hashFile;
|
18 |
this.filename = filename;
|
19 |
this.ci = ci;
|
20 |
this.ipAddress = ipAddress;
|
21 |
this.port = port;
|
22 |
} |
23 |
|
24 |
@Override
|
25 |
public String toString() { |
26 |
return "RESTORE-INIT" + this.ci + " " + this.hashFile + " " + this.filename; |
27 |
} |
28 |
|
29 |
@Override
|
30 |
public void handleMessage() throws UnknownHostException { |
31 |
|
32 |
Message res = ChordManager.searchSuccessor2(ci); |
33 |
|
34 |
if(res instanceof SucessorMessage) { |
35 |
MessageForwarder.sendMessage(new RestoreMessage(ci,this.hashFile, this.filename,((SucessorMessage) res).getCi().getIp(),((SucessorMessage) res).getCi().getPort())); |
36 |
} else if(res instanceof LookupMessage){ |
37 |
MessageForwarder.sendMessage(new RestoreInitMessage(ci,this.hashFile,this.filename, res.getIpAddress(),res.getPort())); |
38 |
} |
39 |
|
40 |
} |
41 |
|
42 |
@Override
|
43 |
public String getIpAddress() { |
44 |
return ipAddress;
|
45 |
} |
46 |
|
47 |
@Override
|
48 |
public int getPort() { |
49 |
return port;
|
50 |
} |
51 |
} |