4 import java.util.HashSet;
6 import javax.script.ScriptException;
7 import java.lang.NullPointerException;
10 class PendingTransaction {
12 private Set<KeyValue> keyValueUpdateSet = null;
13 private Set<KeyValue> keyValueGuardSet = null;
14 private long arbitrator = -1;
16 public PendingTransaction() {
17 keyValueUpdateSet = new HashSet<KeyValue>();
18 keyValueGuardSet = new HashSet<KeyValue>();
22 * Add a new key value to the updates
25 public void addKV(KeyValue newKV) {
29 // Make sure there are no duplicates
30 for (KeyValue kv : keyValueUpdateSet) {
31 if (kv.getKey().equals(newKV.getKey())) {
33 // Remove key if we are adding a newer version of the same key
39 // Remove key if we are adding a newer version of the same key
41 keyValueUpdateSet.remove(rmKV);
44 // Add the key to the hash set
45 keyValueUpdateSet.add(newKV);
50 * Add a new key value to the guard set
53 public void addKVGuard(KeyValue newKV) {
54 // Add the key to the hash set
55 keyValueGuardSet.add(newKV);
59 * Checks if the arbitrator is the same
62 public boolean checkArbitrator(long arb) {
63 if (arbitrator == -1) {
68 return arb == arbitrator;
72 * Get the transaction arbitrator
75 public long getArbitrator() {
80 * Get the key value update set
83 public Set<KeyValue> getKVUpdates() {
84 return keyValueUpdateSet;
89 * Get the key value update set
92 public Set<KeyValue> getKVGuard() {
93 return keyValueGuardSet;