--- /dev/null
+#include "ArbitrationRound.h"
+#include "Commit.h"
+#include "CommitPart.h"
+
+ArbitrationRound::ArbitrationRound(Commit *_commit, Hashset<Abort *> *_abortsBefore) :
+ abortsBefore(_abortsBefore),
+ parts(new Vector<Entry *>()),
+ commit(_commit),
+ currentSize(0),
+ didSendPart(false),
+ didGenerateParts(false) {
+
+ if (commit != NULL) {
+ commit->createCommitParts();
+ currentSize += commit->getNumberOfParts();
+ }
+
+ currentSize += abortsBefore->size();
+}
+
+ArbitrationRound::~ArbitrationRound() {
+ delete abortsBefore;
+ uint partsSize = parts->size();
+ for (uint i = 0; i < partsSize; i++) {
+ Entry * part = parts->get(i);
+ part->releaseRef();
+ }
+ delete parts;
+ if (commit != NULL)
+ delete commit;
+}
+
+void ArbitrationRound::generateParts() {
+ if (didGenerateParts) {
+ return;
+ }
+ uint partsSize = parts->size();
+ for (uint i = 0; i < partsSize; i++) {
+ Entry * part = parts->get(i);
+ part->releaseRef();
+ }
+ parts->clear();
+ SetIterator<Abort *, Abort *> *abit = abortsBefore->iterator();
+ while (abit->hasNext())
+ parts->add((Entry *)abit->next());
+ delete abit;
+ if (commit != NULL) {
+ Vector<CommitPart *> *cParts = commit->getParts();
+ uint cPartsSize = cParts->size();
+ for (uint i = 0; i < cPartsSize; i++) {
+ CommitPart * part = cParts->get(i);
+ part->acquireRef();
+ parts->add((Entry *)part);
+ }
+ }
+}
+
+Vector<Entry *> *ArbitrationRound::getParts() {
+ return parts;
+}
+
+void ArbitrationRound::removeParts(Vector<Entry *> *removeParts) {
+ uint size = removeParts->size();
+ for(uint i=0; i < size; i++) {
+ Entry * e = removeParts->get(i);
+ if (parts->remove(e))
+ e->releaseRef();
+ }
+ didSendPart = true;
+}
+
+
+bool ArbitrationRound::isDoneSending() {
+ if ((commit == NULL) && abortsBefore->isEmpty()) {
+ return true;
+ }
+ return parts->isEmpty();
+}
+
+Commit *ArbitrationRound::getCommit() {
+ return commit;
+}
+
+void ArbitrationRound::setCommit(Commit *_commit) {
+ if (commit != NULL) {
+ currentSize -= commit->getNumberOfParts();
+ }
+ commit = _commit;
+
+ if (commit != NULL) {
+ currentSize += commit->getNumberOfParts();
+ }
+}
+
+void ArbitrationRound::addAbort(Abort *abort) {
+ abortsBefore->add(abort);
+ currentSize++;
+}
+
+void ArbitrationRound::addAborts(Hashset<Abort *> *aborts) {
+ abortsBefore->addAll(aborts);
+ currentSize += aborts->size();
+}
+
+Hashset<Abort *> *ArbitrationRound::getAborts() {
+ return abortsBefore;
+}
+
+int ArbitrationRound::getAbortsCount() {
+ return abortsBefore->size();
+}
+
+int ArbitrationRound::getCurrentSize() {
+ return currentSize;
+}
+
+bool ArbitrationRound::isFull() {
+ return currentSize >= ArbitrationRound_MAX_PARTS;
+}
+
+bool ArbitrationRound::getDidSendPart() {
+ return didSendPart;
+}