Deleted Redundent Files
[iotcloud.git] / src2 / java / iotcloud / PendingTransaction.java
index 5253a94f841cc7c36c5e70c88e78ee67a9a9400e..c3c41c553b4f80b06078c787f4fd2a7c994e1f6c 100644 (file)
@@ -14,6 +14,7 @@ class PendingTransaction {
 
     private Set<KeyValue> keyValueUpdateSet;
     private Guard guard;
+    private long arbitrator = -1;
 
     public PendingTransaction() {
         keyValueUpdateSet = new HashSet<KeyValue>();
@@ -26,20 +27,38 @@ class PendingTransaction {
      */
     public void addKV(KeyValue newKV) {
 
+        KeyValue rmKV = null;
+
         // Make sure there are no duplicates
         for (KeyValue kv : keyValueUpdateSet) {
             if (kv.getKey().equals(newKV.getKey())) {
 
                 // Remove key if we are adding a newer version of the same key
-                keyValueUpdateSet.remove(kv);
+                rmKV = kv;
                 break;
             }
         }
 
+        // Remove key if we are adding a newer version of the same key
+        if (rmKV != null) {
+            keyValueUpdateSet.remove(rmKV);
+        }
+
         // Add the key to the hash set
         keyValueUpdateSet.add(newKV);
     }
 
+    public boolean checkArbitrator(long arb) {
+        if (arbitrator == -1) {
+            arbitrator = arb;
+            return true;
+        }
+
+        return arb == arbitrator;
+    }
+
+
+
     /**
      * Get the key value update set
      *