edits
authorbdemsky <bdemsky@uci.edu>
Fri, 19 Jan 2018 06:28:16 +0000 (22:28 -0800)
committerbdemsky <bdemsky@uci.edu>
Fri, 19 Jan 2018 06:28:16 +0000 (22:28 -0800)
version2/src/C/CommitPart.cc
version2/src/C/CommitPart.h

index 1394f32..c0d50fa 100644 (file)
+#include "CommitPart.h"
+
+
+CommitPart::CommitPart(Slot* s, int64_t _machineId, int64_t _sequenceNumber, int64_t _transactionSequenceNumber, int _partNumber, Array<char>* _data, bool _isLastPart) :
+       Entry(s),
+       machineId(_machineId),
+       sequenceNumber(_sequenceNumber),
+       transactionSequenceNumber(_transactionSequenceNumber),
+       partNumber(_partNumber),
+       isLastPart(_isLastPart),
+       data(_data),
+       partId(new Pair<int64_t int32_t>(sequenceNumber, partNumber)),
+       commitId(new Pair<int64_t, int64_t>(machineId, sequenceNumber)) {
+}
 
-
-
-
-class CommitPart extends Entry {
-
-       // Max size of the part excluding the fixed size header
-       static final int MAX_NON_HEADER_SIZE = 512;
-
-
-       // Sequence number of the transaction this commit is for, -1 if not a cloud transaction
-       int64_t machineId = -1;         // Machine Id of the device that made the commit
-       int64_t sequenceNumber = -1;    // commit sequence number for this arbitrator
-       int64_t transactionSequenceNumber = -1;
-       int partNumber = -1;    // Parts position in the
-       bool isLastPart = false;
-       char[] data = NULL;
-
-       Pair<int64_t int32_t> partId = NULL;
-       Pair<int64_t, int64_t> commitId = NULL;
-
-
-       CommitPart(Slot s, int64_t _machineId, int64_t _sequenceNumber, int64_t _transactionSequenceNumber, int _partNumber, char[] _data, bool _isLastPart) {
-               super(s);
-               machineId = _machineId;
-               sequenceNumber = _sequenceNumber;
-               transactionSequenceNumber = _transactionSequenceNumber;
-               partNumber = _partNumber;
-               isLastPart = _isLastPart;
-               data = _data;
-
-               partId = new Pair<int64_t int32_t>(sequenceNumber, partNumber);
-               commitId = new Pair<int64_t, int64_t>(machineId, sequenceNumber);
-       }
-
-       int getSize() {
-               if (data == NULL) {
-                       return (3 * sizeof(int64_t)) + (2 * sizeof(int32_t)) + (2 * sizeof(char));
-               }
-               return (3 * sizeof(int64_t)) + (2 * sizeof(int32_t)) + (2 * sizeof(char)) + data.length;
-       }
-
-       void setSlot(Slot s) {
-               parentslot = s;
-       }
-
-       int getPartNumber() {
-               return partNumber;
+int CommitPart::getSize() {
+       if (data == NULL) {
+               return (3 * sizeof(int64_t)) + (2 * sizeof(int32_t)) + (2 * sizeof(char));
        }
+       return (3 * sizeof(int64_t)) + (2 * sizeof(int32_t)) + (2 * sizeof(char)) + data->length();
+}
 
-       int getDataSize() {
-               return data.length;
-       }
+void CommitPart::setSlot(Slot s) {
+       parentslot = s;
+}
 
-       char[] getData() {
-               return data;
-       }
+int CommitPart::getPartNumber() {
+       return partNumber;
+}
 
-       Pair<int64_t int32_t> getPartId() {
-               return partId;
-       }
+int CommitPart::getDataSize() {
+       return data->length();
+}
 
-       Pair<int64_t, int64_t> getCommitId() {
-               return commitId;
-       }
+Array<char> * CommitPart::getData() {
+       return data;
+}
 
-       bool isLastPart() {
-               return isLastPart;
-       }
+Pair<int64_t int32_t> * CommitPart::getPartId() {
+       return partId;
+}
 
-       int64_t getMachineId() {
-               return machineId;
-       }
+Pair<int64_t, int64_t> *CommitPart::getCommitId() {
+       return commitId;
+}
 
-       int64_t getTransactionSequenceNumber() {
-               return transactionSequenceNumber;
-       }
+bool CommitPart::isLastPart() {
+       return isLastPart;
+}
 
-       int64_t getSequenceNumber() {
-               return sequenceNumber;
-       }
+int64_t CommitPart::getMachineId() {
+       return machineId;
+}
 
-       static Entry decode(Slot s, ByteBuffer bb) {
-               int64_t machineId = bb->getLong();
-               int64_t sequenceNumber = bb->getLong();
-               int64_t transactionSequenceNumber = bb->getLong();
-               int partNumber = bb->getInt();
-               int dataSize = bb->getInt();
-               bool isLastPart = bb->get() == 1;
+int64_t CommitPart::getTransactionSequenceNumber() {
+       return transactionSequenceNumber;
+}
 
-               // Get the data
-               char[] data = new char[dataSize];
-               bb->get(data);
+int64_t CommitPart::getSequenceNumber() {
+       return sequenceNumber;
+}
 
-               return new CommitPart(s, machineId, sequenceNumber, transactionSequenceNumber, partNumber, data, isLastPart);
-       }
+Entry* CommitPart_decode(Slot* s, ByteBuffer* bb) {
+       int64_t machineId = bb->getLong();
+       int64_t sequenceNumber = bb->getLong();
+       int64_t transactionSequenceNumber = bb->getLong();
+       int partNumber = bb->getInt();
+       int dataSize = bb->getInt();
+       bool isLastPart = bb->get() == 1;
+       
+       // Get the data
+       Array<char> * data = new Array<char>(dataSize);
+       bb->get(data);
+       
+       return new CommitPart(s, machineId, sequenceNumber, transactionSequenceNumber, partNumber, data, isLastPart);
+}
 
-       void encode(ByteBuffer bb) {
-               bb->put(Entry.TypeCommitPart);
-               bb->putLong(machineId);
-               bb->putLong(sequenceNumber);
-               bb->putLong(transactionSequenceNumber);
-               bb->putInt(partNumber);
-               bb->putInt(data.length);
-
-               if (isLastPart) {
-                       bb->put((char)1);
-               } else {
-                       bb->put((char)0);
-               }
-
-               bb->put(data);
-       }
+void CommitPart::encode(ByteBuffer bb) {
+       bb->put(TypeCommitPart);
+       bb->putLong(machineId);
+       bb->putLong(sequenceNumber);
+       bb->putLong(transactionSequenceNumber);
+       bb->putInt(partNumber);
+       bb->putInt(data.length);
+       
+       if (isLastPart) {
+               bb->put((char)1);
+       } else {
+               bb->put((char)0);
+       }
+       
+       bb->put(data);
+}
 
-       char getType() {
-               return Entry.TypeCommitPart;
-       }
+char CommitPart::getType() {
+       return TypeCommitPart;
+}
 
-       Entry getCopy(Slot s) {
-               return new CommitPart(s, machineId, sequenceNumber, transactionSequenceNumber, partNumber, data, isLastPart);
-       }
+Entry *CommitPart::getCopy(Slot *s) {
+       return new CommitPart(s, machineId, sequenceNumber, transactionSequenceNumber, partNumber, data, isLastPart);
 }
index 32a418b..34341c7 100644 (file)
+#ifndef COMMITPART_H
+#define COMMITPART_H
+#include "common.h"
+#include "Entry.h"
 
+// Max size of the part excluding the fixed size header
+#define CommitPart_MAX_NON_HEADER_SIZE 512
 
-
-
-class CommitPart extends Entry {
-
-       // Max size of the part excluding the fixed size header
-       public static final int MAX_NON_HEADER_SIZE = 512;
-
-
+class CommitPart : public Entry {
+ private:
        // Sequence number of the transaction this commit is for, -1 if not a cloud transaction
-       private int64_t machineId = -1;         // Machine Id of the device that made the commit
-       private int64_t sequenceNumber = -1;    // commit sequence number for this arbitrator
-       private int64_t transactionSequenceNumber = -1;
-       private int partNumber = -1;    // Parts position in the
-       private bool isLastPart = false;
-       private char[] data = NULL;
-
-       private Pair<int64_t int32_t> partId = NULL;
-       private Pair<int64_t, int64_t> commitId = NULL;
-
-
-       public CommitPart(Slot s, int64_t _machineId, int64_t _sequenceNumber, int64_t _transactionSequenceNumber, int _partNumber, char[] _data, bool _isLastPart) {
-               super(s);
-               machineId = _machineId;
-               sequenceNumber = _sequenceNumber;
-               transactionSequenceNumber = _transactionSequenceNumber;
-               partNumber = _partNumber;
-               isLastPart = _isLastPart;
-               data = _data;
-
-               partId = new Pair<int64_t int32_t>(sequenceNumber, partNumber);
-               commitId = new Pair<int64_t, int64_t>(machineId, sequenceNumber);
-       }
-
-       public int getSize() {
-               if (data == NULL) {
-                       return (3 * sizeof(int64_t)) + (2 * sizeof(int32_t)) + (2 * sizeof(char));
-               }
-               return (3 * sizeof(int64_t)) + (2 * sizeof(int32_t)) + (2 * sizeof(char)) + data.length;
-       }
-
-       public void setSlot(Slot s) {
-               parentslot = s;
-       }
-
-       public int getPartNumber() {
-               return partNumber;
-       }
-
-       public int getDataSize() {
-               return data.length;
-       }
-
-       public char[] getData() {
-               return data;
-       }
-
-       public Pair<int64_t int32_t> getPartId() {
-               return partId;
-       }
-
-       public Pair<int64_t, int64_t> getCommitId() {
-               return commitId;
-       }
-
-       public bool isLastPart() {
-               return isLastPart;
-       }
-
-       public int64_t getMachineId() {
-               return machineId;
-       }
-
-       public int64_t getTransactionSequenceNumber() {
-               return transactionSequenceNumber;
-       }
-
-       public int64_t getSequenceNumber() {
-               return sequenceNumber;
-       }
-
-       static Entry decode(Slot s, ByteBuffer bb) {
-               int64_t machineId = bb->getLong();
-               int64_t sequenceNumber = bb->getLong();
-               int64_t transactionSequenceNumber = bb->getLong();
-               int partNumber = bb->getInt();
-               int dataSize = bb->getInt();
-               bool isLastPart = bb->get() == 1;
-
-               // Get the data
-               char[] data = new char[dataSize];
-               bb->get(data);
-
-               return new CommitPart(s, machineId, sequenceNumber, transactionSequenceNumber, partNumber, data, isLastPart);
-       }
-
-       public void encode(ByteBuffer bb) {
-               bb->put(Entry.TypeCommitPart);
-               bb->putLong(machineId);
-               bb->putLong(sequenceNumber);
-               bb->putLong(transactionSequenceNumber);
-               bb->putInt(partNumber);
-               bb->putInt(data.length);
-
-               if (isLastPart) {
-                       bb->put((char)1);
-               } else {
-                       bb->put((char)0);
-               }
-
-               bb->put(data);
-       }
-
-       public char getType() {
-               return Entry.TypeCommitPart;
-       }
-
-       public Entry getCopy(Slot s) {
-               return new CommitPart(s, machineId, sequenceNumber, transactionSequenceNumber, partNumber, data, isLastPart);
-       }
-}
+       int64_t machineId;              // Machine Id of the device that made the commit
+       int64_t sequenceNumber; // commit sequence number for this arbitrator
+       int64_t transactionSequenceNumber;
+       int32_t partNumber;     // Parts position in the
+       bool isLastPart;
+       Array<char> * data;
+       
+       Pair<int64_t int32_t> * partId;
+       Pair<int64_t, int64_t> * commitId;
+       
+ public:
+       CommitPart(Slot *s, int64_t _machineId, int64_t _sequenceNumber, int64_t _transactionSequenceNumber, int _partNumber, Array<char>* _data, bool _isLastPart);
+       int getSize();
+       void setSlot(Slot *s);
+       int getPartNumber();
+       int getDataSize();
+       Array<char> * getData();
+       Pair<int64_t int32_t> * getPartId();
+       Pair<int64_t, int64_t> * getCommitId();
+       bool isLastPart();
+       int64_t getMachineId();
+       int64_t getTransactionSequenceNumber();
+       int64_t getSequenceNumber();
+       void encode(ByteBuffer *bb);
+       char getType();
+       Entry* getCopy(Slot *s);
+};
+
+Entry * CommitPart_decode(Slot * s, ByteBuffer *bb);
+#endif