root / src / peer / protocols / reclaim / Reclaim.java @ 3
History | View | Annotate | Download (1.07 KB)
1 |
package peer.protocols.reclaim; |
---|---|
2 |
|
3 |
import chunk.Chunk; |
4 |
import disk.ChunkManagement; |
5 |
import peer.Peer; |
6 |
import peer.protocols.backup.BackupChunk; |
7 |
|
8 |
/**
|
9 |
* Reclaim
|
10 |
*/
|
11 |
public class Reclaim implements Runnable { |
12 |
|
13 |
private Peer peer;
|
14 |
private String fileId; |
15 |
private int chunkNo; |
16 |
|
17 |
public Reclaim(Peer peer, String fileId, int chunkNo) { |
18 |
this.peer = peer;
|
19 |
this.fileId = fileId;
|
20 |
this.chunkNo = chunkNo;
|
21 |
} |
22 |
|
23 |
public void reclaim() { |
24 |
Chunk chunk = peer.getDisk().getChunk(fileId, chunkNo); |
25 |
if (chunk != null) { |
26 |
try {
|
27 |
Thread.sleep((long) (Math.random() * 400 + 1)); |
28 |
} catch (InterruptedException e) { |
29 |
e.printStackTrace(); |
30 |
} |
31 |
if (ChunkManagement.getInstance().getStores(fileId, chunkNo) < chunk.getRepDegree()) {
|
32 |
BackupChunk backupChunk = new BackupChunk(peer, chunk);
|
33 |
Thread bThread = new Thread(backupChunk); |
34 |
bThread.start(); |
35 |
} |
36 |
} |
37 |
|
38 |
} |
39 |
|
40 |
@Override
|
41 |
public void run() { |
42 |
reclaim(); |
43 |
} |
44 |
|
45 |
} |