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

index 1acda0b..b738715 100644 (file)
+#include "TransactionPart.h"
 
-
-class TransactionPart extends Entry {
-
-       // Max size of the part excluding the fixed size header
-       static final int MAX_NON_HEADER_SIZE = 512;
-
-       int64_t sequenceNumber = -1;
-       int64_t machineId = -1;
-       int64_t arbitratorId = -1;
-       int64_t clientLocalSequenceNumber = -1;         // Sequence number of the transaction that this is a part of
-       int partNumber = -1;    // Parts position in the
-       bool isLastPart = false;
-
-       Pair<int64_t, int64_t> transactionId = NULL;
-       Pair<int64_t int32_t> partId = NULL;
-
-       char[] data = NULL;
-
-       TransactionPart(Slot s, int64_t _machineId, int64_t _arbitratorId, int64_t _clientLocalSequenceNumber, int _partNumber, char[] _data, bool _isLastPart) {
-               super(s);
-               machineId = _machineId;
-               arbitratorId = _arbitratorId;
-               clientLocalSequenceNumber = _clientLocalSequenceNumber;
-               partNumber = _partNumber;
-               data = _data;
-               isLastPart = _isLastPart;
-
-               transactionId = new Pair<int64_t, int64_t>(machineId, clientLocalSequenceNumber);
-               partId = new Pair<int64_t int32_t>(clientLocalSequenceNumber, partNumber);
-
-       }
-
-       int getSize() {
-               if (data == NULL) {
-                       return (4 * sizeof(int64_t)) + (2 * sizeof(int32_t)) + (2 * sizeof(char));
-               }
-               return (4 * sizeof(int64_t)) + (2 * sizeof(int32_t)) + (2 * sizeof(char)) + data.length;
-       }
-
-       void setSlot(Slot s) {
-               parentslot = s;
-       }
-
-       Pair<int64_t, int64_t> getTransactionId() {
-               return transactionId;
-       }
-
-       int64_t getArbitratorId() {
-               return arbitratorId;
+int TransactionPart::getSize() {
+       if (data == NULL) {
+               return (4 * sizeof(int64_t)) + (2 * sizeof(int32_t)) + (2 * sizeof(char));
        }
+       return (4 * sizeof(int64_t)) + (2 * sizeof(int32_t)) + (2 * sizeof(char)) + data.length;
+}
 
-       Pair<int64_t int32_t> getPartId() {
-               return partId;
-       }
+void TransactionPart::setSlot(Slot* s) {
+       parentslot = s;
+}
 
-       int getPartNumber() {
-               return partNumber;
-       }
+Pair<int64_t, int64_t>* TransactionPart::getTransactionId() {
+       return transactionId;
+}
 
-       int getDataSize() {
-               return data.length;
-       }
+int64_t TransactionPart::getArbitratorId() {
+       return arbitratorId;
+}
 
-       char[] getData() {
-               return data;
-       }
+Pair<int64_t int32_t>* TransactionPart::getPartId() {
+       return partId;
+}
 
-       bool isLastPart() {
-               return isLastPart;
-       }
+int TransactionPart::getPartNumber() {
+       return partNumber;
+}
 
-       int64_t getMachineId() {
-               return machineId;
-       }
+int TransactionPart::getDataSize() {
+       return data.length;
+}
 
-       int64_t getClientLocalSequenceNumber() {
-               return clientLocalSequenceNumber;
-       }
+Array<char>* TransactionPart::getData() {
+       return data;
+}
 
+bool TransactionPart::isLastPart() {
+       return isLastPart;
+}
 
-       int64_t getSequenceNumber() {
-               return sequenceNumber;
-       }
+int64_t TransactionPart::getMachineId() {
+       return machineId;
+}
 
-       void setSequenceNumber(int64_t _sequenceNumber) {
-               sequenceNumber = _sequenceNumber;
-       }
+int64_t TransactionPart::getClientLocalSequenceNumber() {
+       return clientLocalSequenceNumber;
+}
 
-       static Entry decode(Slot s, ByteBuffer bb) {
-               int64_t sequenceNumber = bb->getLong();
-               int64_t machineId = bb->getLong();
-               int64_t arbitratorId = bb->getLong();
-               int64_t clientLocalSequenceNumber = 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);
-
-               TransactionPart returnTransactionPart = new TransactionPart(s, machineId, arbitratorId, clientLocalSequenceNumber, partNumber, data, isLastPart);
-               returnTransactionPart.setSequenceNumber(sequenceNumber);
-
-               return returnTransactionPart;
-       }
+int64_t TransactionPart::getSequenceNumber() {
+       return sequenceNumber;
+}
 
-       void encode(ByteBuffer bb) {
-               bb->put(Entry.TypeTransactionPart);
-               bb->putLong(sequenceNumber);
-               bb->putLong(machineId);
-               bb->putLong(arbitratorId);
-               bb->putLong(clientLocalSequenceNumber);
-               bb->putInt(partNumber);
-               bb->putInt(data.length);
-
-               if (isLastPart) {
-                       bb->put((char)1);
-               } else {
-                       bb->put((char)0);
-               }
-
-               bb->put(data);
-       }
+void TransactionPart::setSequenceNumber(int64_t _sequenceNumber) {
+       sequenceNumber = _sequenceNumber;
+}
 
-       char getType() {
-               return Entry.TypeTransactionPart;
-       }
+Entry* TransactionPart_decode(Slot* s, ByteBuffer* bb) {
+       int64_t sequenceNumber = bb->getLong();
+       int64_t machineId = bb->getLong();
+       int64_t arbitratorId = bb->getLong();
+       int64_t clientLocalSequenceNumber = 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);
+       
+       TransactionPart returnTransactionPart = new TransactionPart(s, machineId, arbitratorId, clientLocalSequenceNumber, partNumber, data, isLastPart);
+       returnTransactionPart.setSequenceNumber(sequenceNumber);
+       
+       return returnTransactionPart;
+}
 
-       Entry getCopy(Slot s) {
+void TransactionPart::encode(ByteBuffer* bb) {
+       bb->put(Entry.TypeTransactionPart);
+       bb->putLong(sequenceNumber);
+       bb->putLong(machineId);
+       bb->putLong(arbitratorId);
+       bb->putLong(clientLocalSequenceNumber);
+       bb->putInt(partNumber);
+       bb->putInt(data.length);
+       
+       if (isLastPart) {
+               bb->put((char)1);
+       } else {
+               bb->put((char)0);
+       }
+       
+       bb->put(data);
+}
 
-               TransactionPart copyTransaction = new TransactionPart(s, machineId, arbitratorId, clientLocalSequenceNumber, partNumber, data, isLastPart);
-               copyTransaction.setSequenceNumber(sequenceNumber);
+char TransactionPart::getType() {
+       return TypeTransactionPart;
+}
 
-               return copyTransaction;
-       }
+Entry * TransactionPart::getCopy(Slot *s) {
+       TransactionPart* copyTransaction = new TransactionPart(s, machineId, arbitratorId, clientLocalSequenceNumber, partNumber, data, isLastPart);
+       copyTransaction.setSequenceNumber(sequenceNumber);
+       
+       return copyTransaction;
 }
index b89b57c..5e2d84a 100644 (file)
-
-
-class TransactionPart extends Entry {
-
-       // Max size of the part excluding the fixed size header
-       public static final int MAX_NON_HEADER_SIZE = 512;
-
-       private int64_t sequenceNumber = -1;
-       private int64_t machineId = -1;
-       private int64_t arbitratorId = -1;
-       private int64_t clientLocalSequenceNumber = -1;         // Sequence number of the transaction that this is a part of
-       private int partNumber = -1;    // Parts position in the
-       private bool isLastPart = false;
-
-       private Pair<int64_t, int64_t> transactionId = NULL;
-       private Pair<int64_t int32_t> partId = NULL;
-
-       private char[] data = NULL;
-
-       public TransactionPart(Slot s, int64_t _machineId, int64_t _arbitratorId, int64_t _clientLocalSequenceNumber, int _partNumber, char[] _data, bool _isLastPart) {
-               super(s);
-               machineId = _machineId;
-               arbitratorId = _arbitratorId;
-               clientLocalSequenceNumber = _clientLocalSequenceNumber;
-               partNumber = _partNumber;
-               data = _data;
-               isLastPart = _isLastPart;
-
-               transactionId = new Pair<int64_t, int64_t>(machineId, clientLocalSequenceNumber);
-               partId = new Pair<int64_t int32_t>(clientLocalSequenceNumber, partNumber);
-
-       }
-
-       public int getSize() {
-               if (data == NULL) {
-                       return (4 * sizeof(int64_t)) + (2 * sizeof(int32_t)) + (2 * sizeof(char));
-               }
-               return (4 * sizeof(int64_t)) + (2 * sizeof(int32_t)) + (2 * sizeof(char)) + data.length;
-       }
-
-       public void setSlot(Slot s) {
-               parentslot = s;
-       }
-
-       public Pair<int64_t, int64_t> getTransactionId() {
-               return transactionId;
-       }
-
-       public int64_t getArbitratorId() {
-               return arbitratorId;
-       }
-
-       public Pair<int64_t int32_t> getPartId() {
-               return partId;
-       }
-
-       public int getPartNumber() {
-               return partNumber;
-       }
-
-       public int getDataSize() {
-               return data.length;
-       }
-
-       public char[] getData() {
-               return data;
-       }
-
-       public bool isLastPart() {
-               return isLastPart;
-       }
-
-       public int64_t getMachineId() {
-               return machineId;
-       }
-
-       public int64_t getClientLocalSequenceNumber() {
-               return clientLocalSequenceNumber;
-       }
-
-
-       public int64_t getSequenceNumber() {
-               return sequenceNumber;
-       }
-
-       public void setSequenceNumber(int64_t _sequenceNumber) {
-               sequenceNumber = _sequenceNumber;
-       }
-
-       static Entry decode(Slot s, ByteBuffer bb) {
-               int64_t sequenceNumber = bb->getLong();
-               int64_t machineId = bb->getLong();
-               int64_t arbitratorId = bb->getLong();
-               int64_t clientLocalSequenceNumber = 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);
-
-               TransactionPart returnTransactionPart = new TransactionPart(s, machineId, arbitratorId, clientLocalSequenceNumber, partNumber, data, isLastPart);
-               returnTransactionPart.setSequenceNumber(sequenceNumber);
-
-               return returnTransactionPart;
-       }
-
-       public void encode(ByteBuffer bb) {
-               bb->put(Entry.TypeTransactionPart);
-               bb->putLong(sequenceNumber);
-               bb->putLong(machineId);
-               bb->putLong(arbitratorId);
-               bb->putLong(clientLocalSequenceNumber);
-               bb->putInt(partNumber);
-               bb->putInt(data.length);
-
-               if (isLastPart) {
-                       bb->put((char)1);
-               } else {
-                       bb->put((char)0);
+#ifndef TRANSACTIONPART_H
+#define TRANSACTIONPART_H
+#include "common.h"
+#include "Entry.h"
+
+// Max size of the part excluding the fixed size header
+#define TransactionPart_MAX_NON_HEADER_SIZE 512
+
+class TransactionPart : public Entry {
+ private:
+       int64_t sequenceNumber = -1;
+       int64_t machineId = -1;
+       int64_t arbitratorId = -1;
+       int64_t clientLocalSequenceNumber = -1;         // Sequence number of the transaction that this is a part of
+       int partNumber = -1;    // Parts position in the
+       bool isLastPart = false;
+       
+       Pair<int64_t, int64_t> * transactionId = NULL;
+       Pair<int64_t int32_t> * partId = NULL;
+       
+       Array<char> * data = NULL;
+
+ public:
+ TransactionPart(Slot *s, int64_t _machineId, int64_t _arbitratorId, int64_t _clientLocalSequenceNumber, int _partNumber, Array<char>* _data, bool _isLastPart) : Entry(s),
+               sequenceNumber(-1),
+               machineId( _machineId),
+               arbitratorId(_arbitratorId),
+               clientLocalSequenceNumber(_clientLocalSequenceNumber),
+               partNumber(_partNumber),
+               isLastPart(_isLastPart)
+               transactionId(new Pair<int64_t, int64_t>(machineId, clientLocalSequenceNumber)),
+               partId(new Pair<int64_t int32_t>(clientLocalSequenceNumber, partNumber)),
+               data(_data) {
                }
-
-               bb->put(data);
-       }
-
-       public char getType() {
-               return Entry.TypeTransactionPart;
-       }
-
-       public Entry getCopy(Slot s) {
-
-               TransactionPart copyTransaction = new TransactionPart(s, machineId, arbitratorId, clientLocalSequenceNumber, partNumber, data, isLastPart);
-               copyTransaction.setSequenceNumber(sequenceNumber);
-
-               return copyTransaction;
-       }
-}
+       
+       int getSize();
+       void setSlot(Slot s);
+       Pair<int64_t, int64_t> * getTransactionId();
+       int64_t getArbitratorId();
+       Pair<int64_t int32_t>* getPartId();
+       int getPartNumber();
+       int getDataSize();
+       Array<char>* getData();
+       bool isLastPart();
+       int64_t getMachineId();
+       int64_t getClientLocalSequenceNumber();
+       int64_t getSequenceNumber();
+       void setSequenceNumber(int64_t _sequenceNumber);
+       void encode(ByteBuffer *bb);
+       char getType();
+       Entry* getCopy(Slot *s);
+};
+
+Entry * TransactionPart_decode(Slot* s, ByteBuffer* bb);
+#endif