Fixed bugs, local communication HMAC added in
[iotcloud.git] / version2 / src / java / iotcloud / Transaction.java
index b3a04900e41ff6cb2a6f8cc1ab482c2b8bbfc052..8494625a2907546414115568fea6240df9e7c146 100644 (file)
@@ -14,6 +14,7 @@ class Transaction {
     private Set<Integer> missingParts = null;
     private List<Integer> partsPendingSend = null;
     private boolean isComplete = false;
+    private boolean hasLastPart = false;
     private Set<KeyValue> keyValueGuardSet = null;
     private Set<KeyValue> keyValueUpdateSet = null;
     private boolean isDead = false;
@@ -28,6 +29,8 @@ class Transaction {
 
     private TransactionStatus transactionStatus = null;
 
+    private boolean hadServerFailure = false;
+
     public Transaction() {
         parts = new HashMap<Integer, TransactionPart>();
         keyValueGuardSet = new HashSet<KeyValue>();
@@ -71,6 +74,7 @@ class Transaction {
             previoslySeenPart.setDead();
         } else if (newPart.isLastPart()) {
             missingParts = new HashSet<Integer>();
+            hasLastPart = true;
 
             for (int i = 0; i < newPart.getPartNumber(); i++) {
                 if (parts.get(i) == null) {
@@ -79,7 +83,7 @@ class Transaction {
             }
         }
 
-        if (!isComplete) {
+        if (!isComplete && hasLastPart) {
 
             // We have seen this part so remove it from the set of missing parts
             missingParts.remove(newPart.getPartNumber());
@@ -142,6 +146,21 @@ class Transaction {
         return part;
     }
 
+
+    public void setServerFailure() {
+        hadServerFailure = true;
+    }
+
+    public boolean getServerFailure() {
+        return hadServerFailure;
+    }
+
+
+    public void resetServerFailure() {
+        hadServerFailure = false;
+    }
+
+
     public void setTransactionStatus(TransactionStatus _transactionStatus) {
         transactionStatus = _transactionStatus;
     }
@@ -268,6 +287,14 @@ class Transaction {
 
             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 {