Bug fixes + tabbing
[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 ArbitrationRound::~ArbitrationRound() {
21         delete abortsBefore;
22         delete parts;
23 }
24
25 void ArbitrationRound::generateParts() {
26         if (didGenerateParts) {
27                 return;
28         }
29         parts = new Vector<Entry *>();
30         SetIterator<Abort *, Abort *> *abit = abortsBefore->iterator();
31         while (abit->hasNext())
32                 parts->add((Entry *)abit->next());
33         delete abit;
34         if (commit != NULL) {
35                 Vector<CommitPart *> *cParts = commit->getParts();
36                 uint cPartsSize = cParts->size();
37                 for (uint i = 0; i < cPartsSize; i++) {
38                         parts->add((Entry *)cParts->get(i));
39                 }
40         }
41 }
42
43 Vector<Entry *> *ArbitrationRound::getParts() {
44         return parts;
45 }
46
47 void ArbitrationRound::removeParts(Vector<Entry *> *removeParts) {
48         parts->removeAll(removeParts);
49         didSendPart = true;
50 }
51
52
53 bool ArbitrationRound::isDoneSending() {
54         if ((commit == NULL) && abortsBefore->isEmpty()) {
55                 return true;
56         }
57         return parts->isEmpty();
58 }
59
60 Commit *ArbitrationRound::getCommit() {
61         return commit;
62 }
63
64 void ArbitrationRound::setCommit(Commit *_commit) {
65         if (commit != NULL) {
66                 currentSize -= commit->getNumberOfParts();
67         }
68         commit = _commit;
69
70         if (commit != NULL) {
71                 currentSize += commit->getNumberOfParts();
72         }
73 }
74
75 void ArbitrationRound::addAbort(Abort *abort) {
76         abortsBefore->add(abort);
77         currentSize++;
78 }
79
80 void ArbitrationRound::addAborts(Hashset<Abort *> *aborts) {
81         abortsBefore->addAll(aborts);
82         currentSize += aborts->size();
83 }
84
85 Hashset<Abort *> *ArbitrationRound::getAborts() {
86         return abortsBefore;
87 }
88
89 int ArbitrationRound::getAbortsCount() {
90         return abortsBefore->size();
91 }
92
93 int ArbitrationRound::getCurrentSize() {
94         return currentSize;
95 }
96
97 bool ArbitrationRound::isFull() {
98         return currentSize >= ArbitrationRound_MAX_PARTS;
99 }
100
101 bool ArbitrationRound::getDidSendPart() {
102         return didSendPart;
103 }