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