root / StoredTask.java @ 1
History | View | Annotate | Download (1.01 KB)
1 | 1 | up20150476 | import java.util.concurrent.ConcurrentHashMap; |
---|---|---|---|
2 | |||
3 | /**
|
||
4 | * StoredTask
|
||
5 | */
|
||
6 | public class StoredTask implements Runnable { |
||
7 | |||
8 | private Peer peer;
|
||
9 | private String fileId; |
||
10 | private int chunkNo; |
||
11 | private MCListener mc;
|
||
12 | |||
13 | StoredTask(Peer peer, String fileId, String version, int chunkNo, MCListener mc) { |
||
14 | this.peer = peer;
|
||
15 | this.fileId = fileId;
|
||
16 | this.chunkNo = chunkNo;
|
||
17 | this.mc = mc;
|
||
18 | } |
||
19 | |||
20 | @Override
|
||
21 | public void run() { |
||
22 | //Update the perceived replication degree for this chunk
|
||
23 | if (!this.peer.repDegMap.containsKey(this.fileId)) |
||
24 | this.peer.repDegMap.put(this.fileId, new ConcurrentHashMap<>()); |
||
25 | |||
26 | if(!this.peer.repDegMap.get(this.fileId).containsKey(this.chunkNo)) |
||
27 | this.peer.repDegMap.get(this.fileId).put(this.chunkNo, 0); |
||
28 | |||
29 | this.peer.repDegMap.get(this.fileId).put(this.chunkNo, this.peer.repDegMap.get(this.fileId).get(this.chunkNo)+1); |
||
30 | this.mc.print("RepDegMap("+chunkNo+") = "+this.peer.repDegMap.get(fileId).get(chunkNo)); |
||
31 | |||
32 | this.mc.print("STORED protocol finished"); |
||
33 | } |
||
34 | } |