0
|
1 package suikwasha.distributedalgorithm.simulator;
|
|
2
|
|
3 import java.util.concurrent.atomic.AtomicLong;
|
|
4 import java.util.concurrent.atomic.AtomicReference;
|
|
5
|
|
6 import suikwasha.distributedalgorithm.framework.MessageChain;
|
|
7
|
|
8 public class Summary
|
|
9 {
|
|
10 private final AtomicLong messageComplexity;
|
|
11 private final AtomicLong bitComplexity;
|
|
12 private final AtomicReference<MessageChain> longestMessageChain;
|
|
13
|
|
14 public Summary()
|
|
15 {
|
|
16 messageComplexity = new AtomicLong(0);
|
|
17 bitComplexity = new AtomicLong(0);
|
|
18 longestMessageChain = new AtomicReference<MessageChain>(MessageChain.NIL_MESSAGECHAIN);
|
|
19 }
|
|
20
|
|
21 public void incrementMessageCount()
|
|
22 {
|
|
23 messageComplexity.incrementAndGet();
|
|
24 }
|
|
25
|
|
26 public void addMessageBitCount(long _size)
|
|
27 {
|
|
28 bitComplexity.addAndGet(_size);
|
|
29 }
|
|
30
|
|
31 public long getCurrentMessageComplexity()
|
|
32 {
|
|
33 return messageComplexity.get();
|
|
34 }
|
|
35
|
|
36 public long getCurrentBitComplexity()
|
|
37 {
|
|
38 return bitComplexity.get();
|
|
39 }
|
|
40
|
|
41 public MessageChain getLongestMessageChain()
|
|
42 {
|
|
43 return longestMessageChain.get();
|
|
44 }
|
|
45
|
|
46 public boolean trySetMessageChain(MessageChain _chain)
|
|
47 {
|
|
48 MessageChain currentLongestChain;
|
|
49 do{
|
|
50 currentLongestChain = longestMessageChain.get();
|
|
51 if(currentLongestChain.getMessageCount() > _chain.getMessageCount()){
|
|
52 return false;
|
|
53 }
|
|
54 }while(!longestMessageChain.compareAndSet(currentLongestChain,_chain));
|
|
55
|
|
56 return true;
|
|
57 }
|
|
58
|
|
59 public void print()
|
|
60 {
|
|
61 System.out.println("Summary:");
|
|
62 System.out.println(String.format("MessageComplexity :\t\t%d",messageComplexity.get()));
|
1
|
63 System.out.println(String.format("MessageBitComplexity :\t\t%d",bitComplexity.get()));
|
0
|
64 System.out.println(String.format("TimeComplexity :\t\t%d",longestMessageChain.get().getMessageCount()));
|
|
65 }
|
|
66 }
|