Project

General

Profile

Statistics
| Revision:

root / src / messages / BackupInitMessage.java

History | View | Annotate | Download (1.44 KB)

1
package messages;
2

    
3
import chord.ChordManager;
4
import chord.ConnectionInfo;
5

    
6
import java.math.BigInteger;
7

    
8
public class BackupInitMessage extends Message {
9
    private ConnectionInfo ci;
10
    private String filename;
11
    private int repDegree;
12
    private BigInteger hashFile;
13
    private String ipAddress;
14
    private int port;
15

    
16
    public BackupInitMessage(ConnectionInfo ci,BigInteger hashFile, int repDegree, String filename,String ipAddress,int port) {
17
        this.hashFile = hashFile;
18
        this.repDegree = repDegree;
19
        this.ci = ci;
20
        this.filename = filename;
21
        this.ipAddress = ipAddress;
22
        this.port = port;
23
    }
24

    
25
    @Override
26
    public String toString() {
27
        return "BACKUP-INIT" + this.hashFile + " " + " " + this.filename + " " + this.repDegree;
28
    }
29
    @Override
30
    public String getIpAddress() {
31
        return this.ipAddress;
32
    }
33

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

    
39
    public void handleMessage() {
40

    
41
       Message res = ChordManager.searchSuccessor2(ci);
42
       if(res instanceof SucessorMessage) {
43
           MessageForwarder.sendMessage(new BackupReadyMessage(((SucessorMessage) res).getCi(),this.hashFile, this.repDegree, this.filename,ci.getIp(),ci.getPort()));
44
       } else if(res instanceof LookupMessage){
45
           MessageForwarder.sendMessage(new BackupInitMessage(ci,this.hashFile,this.repDegree,this.filename,res.getIpAddress(),res.getPort()));
46
       }
47
    }
48
}