Project

General

Profile

Statistics
| Revision:

root / src / messages / DeleteMessage.java

History | View | Annotate | Download (1.59 KB)

1 1 up20150524
package messages;
2
3
4
import chord.ChordManager;
5
import chord.ConnectionInfo;
6
import files.FileHandler;
7
import peer.Peer;
8
9
import java.io.IOException;
10
import java.math.BigInteger;
11
import java.net.UnknownHostException;
12
import java.nio.file.Files;
13
import java.nio.file.Paths;
14
15
public class DeleteMessage extends Message {
16
    private BigInteger hashfile;
17
    private BigInteger originalSender;
18
    private String ipAddress;
19
    private int port;
20
21
    public DeleteMessage(BigInteger hashfile, BigInteger originalSender, String ipAddress, int port){
22
        this.hashfile = hashfile;
23
        this.originalSender = originalSender;
24
        this.ipAddress = ipAddress;
25
        this.port = port;
26
    }
27
    @Override
28
    public void handleMessage() throws IOException {
29
        if(FileHandler.checkFileExists("./peerDisk/peer" + Peer.getPeerAccessPoint() + "-"  + ChordManager.peerHash + "/backup/" + hashfile)){
30
            Files.deleteIfExists(Paths.get("./peerDisk/peer" + Peer.getPeerAccessPoint() + "-"  + ChordManager.peerHash + "/backup/" + hashfile));
31
        }
32
33
        if(ChordManager.peerHash.compareTo(originalSender) != 0)
34
                MessageForwarder.sendMessage(new DeleteMessage(hashfile,originalSender,ChordManager.getFingerTable().get(0).getIp(),ChordManager.getFingerTable().get(0).getPort()));
35
    }
36
37
    @Override
38
    public String toString() {
39
40
        String returnString =  "DELETE " + hashfile + " " + originalSender;
41
42
        return returnString;
43
    }
44
    @Override
45
    public String getIpAddress() {
46
        return ipAddress;
47
    }
48
49
    @Override
50
    public int getPort() {
51
        return port;
52
    }
53
}