Start port
[iotcloud.git] / version2 / src / C / ArbitrationRound.cc
1 #include"ArbitrationRound.h"
2
3 ArbitrationRound::ArbitrationRound(Commit * _commit, Set<Abort *> * _abortsBefore) {
4   parts = new ArrayList<Entry>();
5   commit = _commit;
6   abortsBefore = _abortsBefore;
7   
8   if (commit != NULL) {
9     commit.createCommitParts();
10     currentSize += commit.getNumberOfParts();
11     }
12   
13   currentSize += abortsBefore.size();
14 }
15
16 void ArbitrationRound::generateParts() {
17   if (didGenerateParts) {
18     return;
19   }
20   parts = new ArrayList<Entry>(abortsBefore);
21   if (commit != NULL) {
22     parts.addAll(commit.getParts().values());
23   }
24 }
25
26 List<Entry *> * ArbitrationRound::getParts() {
27   return parts;
28 }
29
30 void ArbitrationRound::removeParts(List<Entry *> * removeParts) {
31   parts.removeAll(removeParts);
32   didSendPart = true;
33 }
34
35 bool ArbitrationRound::isDoneSending() {
36   if ((commit == NULL) && abortsBefore.isEmpty()) {
37     return true;
38   }
39   
40   return parts.isEmpty();
41 }
42
43 Commit * ArbitrationRound::getCommit() {
44   return commit;
45 }
46   
47 void ArbitrationRound::setCommit(Commit * _commit) {
48   if (commit != NULL) {
49     currentSize -= commit.getNumberOfParts();
50   }
51   commit = _commit;
52   
53   if (commit != NULL) {
54     currentSize += commit.getNumberOfParts();
55   }
56 }
57
58 void ArbitrationRound::addAbort(Abort * abort) {
59   abortsBefore.add(abort);
60   currentSize++;
61 }
62   
63 void ArbitrationRound::addAborts(Set<Abort *> * aborts) {
64   abortsBefore.addAll(aborts);
65   currentSize += aborts.size();
66 }
67   
68 Set<Abort> ArbitrationRound::getAborts() {
69   return abortsBefore;
70 }
71
72 int ArbitrationRound::getAbortsCount() {
73   return abortsBefore.size();
74 }
75
76 int ArbitrationRound::getCurrentSize() {
77   return currentSize;
78 }
79
80 bool ArbitrationRound::isFull() {
81   return currentSize >= MAX_PARTS;
82 }
83   
84 bool ArbitrationRound::didSendPart() {
85   return didSendPart;
86 }
87