root / StateTask.java @ 1
History | View | Annotate | Download (2.56 KB)
1 |
import java.io.IOException; |
---|---|
2 |
import java.net.DatagramSocket; |
3 |
import java.util.concurrent.ConcurrentHashMap; |
4 |
|
5 |
/**
|
6 |
* StateTask
|
7 |
*/
|
8 |
public class StateTask implements Runnable { |
9 |
|
10 |
private Peer peer;
|
11 |
|
12 |
StateTask(Peer peer) { |
13 |
peer.getMCaddress(); |
14 |
peer.getMCport(); |
15 |
this.peer = peer;
|
16 |
} |
17 |
|
18 |
@Override
|
19 |
public void run() { |
20 |
try {
|
21 |
DatagramSocket socket = new DatagramSocket(); |
22 |
|
23 |
System.out.println("FILES:"); |
24 |
for (String i : this.peer.fileMap.keySet()) { |
25 |
System.out.println("Pathname: " + i); |
26 |
System.out.println("Backup service id: " + this.peer.fileMap.get(i).getFileId()); |
27 |
System.out.println("Desired replication degree: " + this.peer.fileMap.get(i).getDesiredReplicationDegree()); |
28 |
System.out.println();
|
29 |
System.out.println("Chunks: "); |
30 |
System.out.println();
|
31 |
ConcurrentHashMap<Integer, Chunk> currentChunkMap = this.peer.fileMap.get(i).getChunksMap(); |
32 |
for (Integer j : currentChunkMap.keySet()) { |
33 |
System.out.println("Id: " + j); |
34 |
System.out.println("Perceived replication degree: " + this.peer.repDegMap.get(this.peer.fileMap.get(i).getFileId()).get(j)); |
35 |
System.out.println();
|
36 |
} |
37 |
System.out.println();
|
38 |
} |
39 |
|
40 |
System.out.println();
|
41 |
System.out.println();
|
42 |
System.out.println("STORED CHUNKS: "); |
43 |
for (String k : this.peer.chunksMap.keySet()){ |
44 |
System.out.println("FileId: " + k); |
45 |
for(Integer j: this.peer.chunksMap.get(k).getChunksMap().keySet()) { |
46 |
System.out.println("Id: " + j); |
47 |
System.out.println("Size: " + this.peer.chunksMap.get(k).getChunksMap().get(j).getSize()); |
48 |
if(this.peer.repDegMap.containsKey(k)) |
49 |
System.out.println("Perceived replication degree: " + this.peer.repDegMap.get(k).get(j)); |
50 |
else
|
51 |
System.out.println("Perceived replication degree: Unknown"); |
52 |
System.out.println();
|
53 |
} |
54 |
System.out.println();
|
55 |
} |
56 |
|
57 |
System.out.println("PEER " + this.peer.getSenderId() + "'S STORAGE CAPACITY: " + this.peer.getStorageCapacity()); |
58 |
System.out.println("PEER " + this.peer.getSenderId() + "'S STORAGE USED: " + this.peer.getStorageUsed()); |
59 |
System.out.println();
|
60 |
|
61 |
|
62 |
|
63 |
socket.close(); |
64 |
this.peer.print("STATE protocol finished"); |
65 |
} catch (IOException e) { |
66 |
e.printStackTrace(); |
67 |
} |
68 |
} |
69 |
} |