- bool didSendAPartToServer() {
- return didSendAPartToServer;
- }
-
- void resetNextPartToSend() {
- nextPartToSend = 0;
- }
-
- TransactionPart getNextPartToSend() {
- if ((partsPendingSend.size() == 0) || (partsPendingSend.size() == nextPartToSend)) {
- return NULL;
- }
- TransactionPart part = parts.get(partsPendingSend.get(nextPartToSend));
- nextPartToSend++;
- return part;
- }
-
-
- void setServerFailure() {
- hadServerFailure = true;
- }
-
- bool getServerFailure() {
- return hadServerFailure;
- }
-
-
- void resetServerFailure() {
- hadServerFailure = false;
- }
-
-
- void setTransactionStatus(TransactionStatus _transactionStatus) {
- transactionStatus = _transactionStatus;
- }
-
- TransactionStatus getTransactionStatus() {
- return transactionStatus;
- }
-
- void removeSentParts(List<Integer> sentParts) {
- nextPartToSend = 0;
- if(partsPendingSend.removeAll(sentParts))
- {
- didSendAPartToServer = true;
- transactionStatus.setTransactionSequenceNumber(sequenceNumber);
- }
- }
-
- bool didSendAllParts() {
- return partsPendingSend.isEmpty();
- }
-
- Set<KeyValue> getKeyValueUpdateSet() {
- return keyValueUpdateSet;
- }
-
- int getNumberOfParts() {
- return parts.size();
- }
-
- int64_t getMachineId() {
- return machineId;
- }
-
- int64_t getArbitrator() {
- return arbitratorId;
- }
-
- bool isComplete() {
- return isComplete;
- }
-
- Pair<int64_t, int64_t> getId() {
- return transactionId;
- }
-
- void setDead() {
- if (isDead) {
- // Already dead
- return;
- }
-
- // Set dead
- isDead = true;
-
- // Make all the parts of this transaction dead
- for (Integer partNumber : parts.keySet()) {
- TransactionPart part = parts.get(partNumber);
- part.setDead();
- }
- }
-
- TransactionPart getPart(int index) {
- return parts.get(index);
- }
-
- void decodeTransactionData() {
-
- // Calculate the size of the data section
- int dataSize = 0;
- for (int i = 0; i < parts.keySet().size(); i++) {
- TransactionPart tp = parts.get(i);
- dataSize += tp.getDataSize();
- }
-
- char[] combinedData = new char[dataSize];
- int currentPosition = 0;
-
- // Stitch all the data sections together
- for (int i = 0; i < parts.keySet().size(); i++) {
- TransactionPart tp = parts.get(i);
- System.arraycopy(tp.getData(), 0, combinedData, currentPosition, tp.getDataSize());
- currentPosition += tp.getDataSize();
- }
-
- // Decoder Object
- ByteBuffer bbDecode = ByteBuffer.wrap(combinedData);
-
- // Decode how many key value pairs need to be decoded
- int numberOfKVGuards = bbDecode.getInt();
- int numberOfKVUpdates = bbDecode.getInt();
-
- // Decode all the guard key values
- for (int i = 0; i < numberOfKVGuards; i++) {
- KeyValue kv = (KeyValue)KeyValue.decode(bbDecode);
- keyValueGuardSet.add(kv);
- }
-
- // Decode all the updates key values
- for (int i = 0; i < numberOfKVUpdates; i++) {
- KeyValue kv = (KeyValue)KeyValue.decode(bbDecode);
- keyValueUpdateSet.add(kv);
- }
- }
-
- bool evaluateGuard(Map<IoTString, KeyValue> committedKeyValueTable, Map<IoTString, KeyValue> speculatedKeyValueTable, Map<IoTString, KeyValue> pendingTransactionSpeculatedKeyValueTable) {
- for (KeyValue kvGuard : keyValueGuardSet) {
-
- // First check if the key is in the speculative table, this is the value of the latest assumption
- KeyValue kv = NULL;
-
- // If we have a speculation table then use it first
- if (pendingTransactionSpeculatedKeyValueTable != NULL) {
- kv = pendingTransactionSpeculatedKeyValueTable.get(kvGuard.getKey());
- }
-
- // If we have a speculation table then use it first
- if ((kv == NULL) && (speculatedKeyValueTable != NULL)) {
- kv = speculatedKeyValueTable.get(kvGuard.getKey());
- }
-
- if (kv == NULL) {
- // if it is not in the speculative table then check the committed table and use that
- // value as our latest assumption
- kv = committedKeyValueTable.get(kvGuard.getKey());
- }
-
- if (kvGuard.getValue() != NULL) {
- if ((kv == NULL) || (!kvGuard.getValue().equals(kv.getValue()))) {
-
-
- if (kv != NULL) {
- System.out.println(kvGuard.getValue() + " " + kv.getValue());
- } else {
- System.out.println(kvGuard.getValue() + " " + kv);
- }
-
- return false;
- }
- } else {
- if (kv != NULL) {
- return false;
- }
- }
- }
- return true;
- }
+bool Transaction::evaluateGuard(Hashtable<IoTString *, KeyValue *> *committedKeyValueTable, Hashtable<IoTString *, KeyValue *> *speculatedKeyValueTable, Hashtable<IoTString *, KeyValue *> *pendingTransactionSpeculatedKeyValueTable) {
+ for (KeyValue *kvGuard : keyValueGuardSet) {
+
+ // First check if the key is in the speculative table, this is the value of the latest assumption
+ KeyValue kv = NULL;
+
+ // If we have a speculation table then use it first
+ if (pendingTransactionSpeculatedKeyValueTable != NULL) {
+ kv = pendingTransactionSpeculatedKeyValueTable.get(kvGuard.getKey());
+ }
+
+ // If we have a speculation table then use it first
+ if ((kv == NULL) && (speculatedKeyValueTable != NULL)) {
+ kv = speculatedKeyValueTable.get(kvGuard.getKey());
+ }
+
+ if (kv == NULL) {
+ // if it is not in the speculative table then check the committed table and use that
+ // value as our latest assumption
+ kv = committedKeyValueTable.get(kvGuard.getKey());
+ }
+
+ if (kvGuard.getValue() != NULL) {
+ if ((kv == NULL) || (!kvGuard.getValue().equals(kv.getValue()))) {
+
+
+ if (kv != NULL) {
+ System.out.println(kvGuard.getValue() + " " + kv.getValue());
+ } else {
+ System.out.println(kvGuard.getValue() + " " + kv);
+ }
+
+ return false;
+ }
+ } else {
+ if (kv != NULL) {
+ return false;
+ }
+ }
+ }
+ return true;