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 /*
21    void ArbitrationRound::generateParts() {
22    if (didGenerateParts) {
23     return;
24    }
25    parts = new Vector<Entry *>((Vector<Entry *> *)abortsBefore);
26    if (commit != NULL) {
27     parts->addAll(commit->getParts()->values());
28    }
29    }*/
30
31 Vector<Entry *> *ArbitrationRound::getParts() {
32         return parts;
33 }
34
35 /*
36    void ArbitrationRound::removeParts(Vector<Entry *> * removeParts) {
37    parts->removeAll(removeParts);
38    didSendPart = true;
39    }
40  */
41
42 bool ArbitrationRound::isDoneSending() {
43         if ((commit == NULL) && abortsBefore->isEmpty()) {
44                 return true;
45         }
46
47         return parts->isEmpty();
48 }
49
50 Commit *ArbitrationRound::getCommit() {
51         return commit;
52 }
53
54 void ArbitrationRound::setCommit(Commit *_commit) {
55         if (commit != NULL) {
56                 currentSize -= commit->getNumberOfParts();
57         }
58         commit = _commit;
59
60         if (commit != NULL) {
61                 currentSize += commit->getNumberOfParts();
62         }
63 }
64
65 void ArbitrationRound::addAbort(Abort *abort) {
66         abortsBefore->add(abort);
67         currentSize++;
68 }
69
70 void ArbitrationRound::addAborts(Hashset<Abort *> *aborts) {
71         abortsBefore->addAll(aborts);
72         currentSize += aborts->size();
73 }
74
75 Hashset<Abort *> *ArbitrationRound::getAborts() {
76         return abortsBefore;
77 }
78
79 int ArbitrationRound::getAbortsCount() {
80         return abortsBefore->size();
81 }
82
83 int ArbitrationRound::getCurrentSize() {
84         return currentSize;
85 }
86
87 bool ArbitrationRound::isFull() {
88         return currentSize >= MAX_PARTS;
89 }
90
91 bool ArbitrationRound::getDidSendPart() {
92         return didSendPart;
93 }
94