root / src / peer / protocols / backup / Backup.java @ 3
History | View | Annotate | Download (663 Bytes)
1 |
package peer.protocols.backup; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
|
5 |
import chunk.Chunk; |
6 |
import peer.Peer; |
7 |
|
8 |
/**
|
9 |
* Backup
|
10 |
*/
|
11 |
public class Backup implements Runnable { |
12 |
|
13 |
private Peer peer;
|
14 |
private File file; |
15 |
private int repDegree; |
16 |
|
17 |
public Backup(Peer peer, String path, int repDegree) { |
18 |
file = new File(path); |
19 |
this.peer = peer;
|
20 |
this.repDegree = repDegree;
|
21 |
} |
22 |
|
23 |
public void backupFile() { |
24 |
Chunk[] chunks = Chunk.splitFile(file, repDegree);
|
25 |
for (int i = 0;i<chunks.length;i++){ |
26 |
BackupChunk backupChunk = new BackupChunk(peer, chunks[i]);
|
27 |
Thread bThread = new Thread(backupChunk); |
28 |
bThread.start(); |
29 |
} |
30 |
} |
31 |
|
32 |
@Override
|
33 |
public void run() { |
34 |
backupFile(); |
35 |
} |
36 |
} |