edits
[iotcloud.git] / version2 / src / C / Transaction.h
1 #ifndef TRANSACTION_H
2 #define TRANSACTION_H
3 #include "common.h"
4
5 class Transaction {
6 private:
7         Hashtable<int32_t, TransactionPart *> *parts = NULL;
8         Hashset<int32_t> *missingParts = NULL;
9         Vector<int32_t> *partsPendingSend = NULL;
10         bool isComplete = false;
11         bool hasLastPart = false;
12         Hashset<KeyValue *> *keyValueGuardSet = NULL;
13         Hashset<KeyValue *> *keyValueUpdateSet = NULL;
14         bool isDead = false;
15         int64_t sequenceNumber = -1;
16         int64_t clientLocalSequenceNumber = -1;
17         int64_t arbitratorId = -1;
18         int64_t machineId = -1;
19         Pair<uint64_t, uint64_t> *transactionId = NULL;
20         int nextPartToSend = 0;
21         bool didSendAPartToServer = false;
22         TransactionStatus *transactionStatus = NULL;
23         bool hadServerFailure = false;
24         void decodeTransactionData();
25
26 public:
27         Transaction();
28         void addPartEncode(TransactionPart *newPart);
29         void addPartDecode(TransactionPart *newPart);
30         void addUpdateKV(KeyValue *kv);
31         void addGuardKV(KeyValue *kv);
32         int64_t getSequenceNumber();
33         void setSequenceNumber(int64_t _sequenceNumber);
34         int64_t getClientLocalSequenceNumber();
35         Hashtable<int32_t, TransactionPart *> *getParts();
36         bool didSendAPartToServer();
37         void resetNextPartToSend();
38         TransactionPart *getNextPartToSend();
39         void setServerFailure();
40         bool getServerFailure();
41         void resetServerFailure();
42         void setTransactionStatus(TransactionStatus *_transactionStatus);
43         TransactionStatus *getTransactionStatus();
44         void removeSentParts(Vector<int32_t> *sentParts);
45         bool didSendAllParts();
46         Hashset<KeyValue *> *getKeyValueUpdateSet();
47         int getNumberOfParts();
48         int64_t getMachineId();
49         int64_t getArbitrator();
50         bool isComplete();
51         Pair<int64_t, int64_t> *getId();
52         void setDead();
53         TransactionPart *getPart(int32_t index);
54         bool evaluateGuard(Hashtable<IoTString *, KeyValue *> *committedKeyValueTable, Hashtable<IoTString *, KeyValue *> *speculatedKeyValueTable, Hashtable<IoTString *, KeyValue *> *pendingTransactionSpeculatedKeyValueTable);
55 };
56 #endif