More edits
[iotcloud.git] / version2 / src / C / Table.cc
index ee3b8bb0438b1f63f5343b4236ce8b2efda9ef1e..424e105690043f40fa83beae1b5d67b39863c2e3 100644 (file)
@@ -325,7 +325,7 @@ bool Table::update()  {
                updateLiveTransactionsAndStatus();
                return true;
        } catch (Exception *e) {
                updateLiveTransactionsAndStatus();
                return true;
        } catch (Exception *e) {
-               SetIterator<int64_t> *kit = getKeyIterator(localCommunicationTable);
+               SetIterator<int64_t, Pair<IoTString *, int32_t> *> *kit = getKeyIterator(localCommunicationTable);
                while (kit->hasNext()) {
                        int64_t m = kit->next();
                        updateFromLocal(m);
                while (kit->hasNext()) {
                        int64_t m = kit->next();
                        updateFromLocal(m);
@@ -468,7 +468,7 @@ bool Table::sendToServer(NewKey *newKey) {
                                                }
                                        }
 
                                                }
                                        }
 
-                                       SetIterator<Transaction *> *trit = getKeyIterator(lastTransactionPartsSent);
+                                       SetIterator<Transaction *, Vector<int> *> *trit = getKeyIterator(lastTransactionPartsSent);
                                        while (trit->hasNext()) {
                                                Transaction *transaction = trit->next();
                                                transaction->resetServerFailure();
                                        while (trit->hasNext()) {
                                                Transaction *transaction = trit->next();
                                                transaction->resetServerFailure();
@@ -527,7 +527,7 @@ bool Table::sendToServer(NewKey *newKey) {
                                                        }
                                                }
 
                                                        }
                                                }
 
-                                               SetIterator<Transaction *> *trit = getKeyIterator(lastTransactionPartsSent);
+                                               SetIterator<Transaction *, Vector<int> *> *trit = getKeyIterator(lastTransactionPartsSent);
                                                while (trit->hasNext()) {
                                                        Transaction *transaction = trit->next();
                                                        transaction->resetServerFailure();
                                                while (trit->hasNext()) {
                                                        Transaction *transaction = trit->next();
                                                        transaction->resetServerFailure();
@@ -557,7 +557,7 @@ bool Table::sendToServer(NewKey *newKey) {
                                        }
                                }
 
                                        }
                                }
 
-                               SetIterator<Transaction *> *trit = getKeyIterator(lastTransactionPartsSent);
+                               SetIterator<Transaction *, Vector<int> *> *trit = getKeyIterator(lastTransactionPartsSent);
                                while (trit->hasNext()) {
                                        Transaction *transaction = trit->next();
                                        transaction->resetServerFailure();
                                while (trit->hasNext()) {
                                        Transaction *transaction = trit->next();
                                        transaction->resetServerFailure();
@@ -612,7 +612,7 @@ bool Table::sendToServer(NewKey *newKey) {
                                                }
                                        }
 
                                                }
                                        }
 
-                                       SetIterator<Transaction *> *trit = getKeyIterator(lastTransactionPartsSent);
+                                       SetIterator<Transaction *, Vector<int> *> *trit = getKeyIterator(lastTransactionPartsSent);
                                        while (trit->hasNext()) {
                                                Transaction *transaction = trit->next();
                                                transaction->resetServerFailure();
                                        while (trit->hasNext()) {
                                                Transaction *transaction = trit->next();
                                                transaction->resetServerFailure();
@@ -640,7 +640,7 @@ bool Table::sendToServer(NewKey *newKey) {
                                        }
                                        delete trit;
                                } else {
                                        }
                                        delete trit;
                                } else {
-                                       SetIterator<Transaction *> *trit = getKeyIterator(lastTransactionPartsSent);
+                                       SetIterator<Transaction *, Vector<int> *> *trit = getKeyIterator(lastTransactionPartsSent);
                                        while (trit->hasNext()) {
                                                Transaction *transaction = trit->next();
                                                transaction->resetServerFailure();
                                        while (trit->hasNext()) {
                                                Transaction *transaction = trit->next();
                                                transaction->resetServerFailure();
@@ -691,7 +691,7 @@ bool Table::sendToServer(NewKey *newKey) {
 
                        if (needsResize) {
                                // Reset which transaction to send
 
                        if (needsResize) {
                                // Reset which transaction to send
-                               SetIterator<Transaction *> *trit = getKeyIterator(transactionPartsSent);
+                               SetIterator<Transaction *, Vector<int> *> *trit = getKeyIterator(transactionPartsSent);
                                while (trit->hasNext()) {
                                        Transaction *transaction = trit->next();
                                        transaction->resetNextPartToSend();
                                while (trit->hasNext()) {
                                        Transaction *transaction = trit->next();
                                        transaction->resetNextPartToSend();
@@ -747,7 +747,7 @@ bool Table::sendToServer(NewKey *newKey) {
                                }
                                pendingSendArbitrationRounds->setSize(oldcount);
 
                                }
                                pendingSendArbitrationRounds->setSize(oldcount);
 
-                               SetIterator<Transaction *> *trit = getKeyIterator(transactionPartsSent);
+                               SetIterator<Transaction *, Vector<int> *> *trit = getKeyIterator(transactionPartsSent);
                                while (trit->hasNext()) {
                                        Transaction *transaction = trit->next();
                                        transaction->resetServerFailure();
                                while (trit->hasNext()) {
                                        Transaction *transaction = trit->next();
                                        transaction->resetServerFailure();
@@ -770,7 +770,7 @@ bool Table::sendToServer(NewKey *newKey) {
                                delete trit;
                        } else {
                                // Reset which transaction to send
                                delete trit;
                        } else {
                                // Reset which transaction to send
-                               SetIterator<Transaction *> *trit = getKeyIterator(transactionPartsSent);
+                               SetIterator<Transaction *, Vector<int> *> *trit = getKeyIterator(transactionPartsSent);
                                while (trit->hasNext()) {
                                        Transaction *transaction = trit->next();
                                        transaction->resetNextPartToSend();
                                while (trit->hasNext()) {
                                        Transaction *transaction = trit->next();
                                        transaction->resetNextPartToSend();
@@ -794,9 +794,9 @@ bool Table::sendToServer(NewKey *newKey) {
                }
 
        } catch (ServerException *e) {
                }
 
        } catch (ServerException *e) {
-               if (e->getType() != ServerException->TypeInputTimeout) {
+               if (e->getType() != ServerException_TypeInputTimeout) {
                        // Nothing was able to be sent to the server so just clear these data structures
                        // Nothing was able to be sent to the server so just clear these data structures
-                       SetIterator<Transaction *> *trit = getKeyIterator(transactionPartsSent);
+                       SetIterator<Transaction *, Vector<int> *> *trit = getKeyIterator(transactionPartsSent);
                        while (trit->hasNext()) {
                                Transaction *transaction = trit->next();
                                transaction->resetNextPartToSend();
                        while (trit->hasNext()) {
                                Transaction *transaction = trit->next();
                                transaction->resetNextPartToSend();
@@ -812,7 +812,7 @@ bool Table::sendToServer(NewKey *newKey) {
                        hadPartialSendToServer = true;
 
                        // Nothing was able to be sent to the server so just clear these data structures
                        hadPartialSendToServer = true;
 
                        // Nothing was able to be sent to the server so just clear these data structures
-                       SetIterator<Transaction *> *trit = getKeyIterator(transactionPartsSent);
+                       SetIterator<Transaction *, Vector<int> *> *trit = getKeyIterator(transactionPartsSent);
                        while (trit->hasNext()) {
                                Transaction *transaction = trit->next();
                                transaction->resetNextPartToSend();
                        while (trit->hasNext()) {
                                Transaction *transaction = trit->next();
                                transaction->resetNextPartToSend();
@@ -840,7 +840,7 @@ bool Table::updateFromLocal(int64_t machineId) {
        int sendDataSize = sizeof(int32_t) + sizeof(int64_t);
 
        int64_t lastArbitrationDataLocalSequenceNumber = (int64_t) -1;
        int sendDataSize = sizeof(int32_t) + sizeof(int64_t);
 
        int64_t lastArbitrationDataLocalSequenceNumber = (int64_t) -1;
-       if (lastArbitrationDataLocalSequenceNumberSeenFromArbitrator->get(machineId) != NULL) {
+       if (lastArbitrationDataLocalSequenceNumberSeenFromArbitrator->contains(machineId)) {
                lastArbitrationDataLocalSequenceNumber = lastArbitrationDataLocalSequenceNumberSeenFromArbitrator->get(machineId);
        }
 
                lastArbitrationDataLocalSequenceNumber = lastArbitrationDataLocalSequenceNumberSeenFromArbitrator->get(machineId);
        }
 
@@ -852,7 +852,7 @@ bool Table::updateFromLocal(int64_t machineId) {
        bbEncode->putInt(0);
 
        // Send by local
        bbEncode->putInt(0);
 
        // Send by local
-       Array<char> *returnData = cloud->sendLocalData(sendData, localSequenceNumber, localCommunicationInformation.getFirst(), localCommunicationInformation.getSecond());
+       Array<char> *returnData = cloud->sendLocalData(sendData, localSequenceNumber, localCommunicationInformation->getFirst(), localCommunicationInformation->getSecond());
        localSequenceNumber++;
 
        if (returnData == NULL) {
        localSequenceNumber++;
 
        if (returnData == NULL) {
@@ -883,19 +883,24 @@ bool Table::updateFromLocal(int64_t machineId) {
 Pair<bool, bool> Table::sendTransactionToLocal(Transaction *transaction) {
 
        // Get the devices local communications
 Pair<bool, bool> Table::sendTransactionToLocal(Transaction *transaction) {
 
        // Get the devices local communications
-       if (!localCommunicationTable->contains(machineId))
+       if (!localCommunicationTable->contains(transaction->getArbitrator()))
                return Pair<bool, bool>(true, false);
        
                return Pair<bool, bool>(true, false);
        
-       Pair<IoTString *, int32_t> localCommunicationInformation = localCommunicationTable->get(transaction->getArbitrator());
+       Pair<IoTString *, int32_t> localCommunicationInformation = localCommunicationTable->get(transaction->getArbitrator());
 
        // Get the size of the send data
        int sendDataSize = sizeof(int32_t) + sizeof(int64_t);
 
        // Get the size of the send data
        int sendDataSize = sizeof(int32_t) + sizeof(int64_t);
-       for (TransactionPart *part : transaction->getParts()->values()) {
-               sendDataSize += part->getSize();
+       {
+               Vector<TransactionPart *> * tParts = transaction->getParts();
+               uint tPartsSize = tParts->size();
+               for (uint i = 0; i < tPartsSize; i++) {
+                       TransactionPart * part = tParts->get(i);
+                       sendDataSize += part->getSize();
+               }
        }
 
        int64_t lastArbitrationDataLocalSequenceNumber = (int64_t) -1;
        }
 
        int64_t lastArbitrationDataLocalSequenceNumber = (int64_t) -1;
-       if (lastArbitrationDataLocalSequenceNumberSeenFromArbitrator->get(transaction->getArbitrator()) != NULL) {
+       if (lastArbitrationDataLocalSequenceNumberSeenFromArbitrator->contains(transaction->getArbitrator())) {
                lastArbitrationDataLocalSequenceNumber = lastArbitrationDataLocalSequenceNumberSeenFromArbitrator->get(transaction->getArbitrator());
        }
 
                lastArbitrationDataLocalSequenceNumber = lastArbitrationDataLocalSequenceNumberSeenFromArbitrator->get(transaction->getArbitrator());
        }
 
@@ -906,13 +911,17 @@ Pair<bool, bool> Table::sendTransactionToLocal(Transaction *transaction) {
        // Encode the data
        bbEncode->putLong(lastArbitrationDataLocalSequenceNumber);
        bbEncode->putInt(transaction->getParts()->size());
        // Encode the data
        bbEncode->putLong(lastArbitrationDataLocalSequenceNumber);
        bbEncode->putInt(transaction->getParts()->size());
-       for (TransactionPart *part : transaction->getParts()->values()) {
-               part->encode(bbEncode);
+       {
+               Vector<TransactionPart *> * tParts = transaction->getParts();
+               uint tPartsSize = tParts->size();
+               for (uint i = 0; i < tPartsSize; i++) {
+                       TransactionPart * part = tParts->get(i);
+                       part->encode(bbEncode);
+               }
        }
 
        }
 
-
        // Send by local
        // Send by local
-       Array<char> *returnData = cloud->sendLocalData(sendData, localSequenceNumber, localCommunicationInformation.getFirst(), localCommunicationInformation.getSecond());
+       Array<char> *returnData = cloud->sendLocalData(sendData, localSequenceNumber, localCommunicationInformation->getFirst(), localCommunicationInformation->getSecond());
        localSequenceNumber++;
 
        if (returnData == NULL) {
        localSequenceNumber++;
 
        if (returnData == NULL) {
@@ -994,7 +1003,7 @@ Array<char> *Table::acceptDataFromLocal(Array<char> *data) {
 
                // Transaction was sent to the server so keep track of it to prevent double commit
                if (transaction->getSequenceNumber() != -1) {
 
                // Transaction was sent to the server so keep track of it to prevent double commit
                if (transaction->getSequenceNumber() != -1) {
-                       offlineTransactionsCommittedAndAtServer->add(transaction->getId());
+                       offlineTransactionsCommittedAndAtServer->add(new Pair<int64_t, int64_t>(transaction->getId()));
                }
        }
 
                }
        }
 
@@ -1262,7 +1271,7 @@ void Table::doRejectedMessages(Slot *s) {
                 * there is already a sufficient entry in the queue (e->g->,
                 * equalsto value of true and same sequence number)->  */
 
                 * there is already a sufficient entry in the queue (e->g->,
                 * equalsto value of true and same sequence number)->  */
 
-               int64_t old_seqn = rejectedSlotVector->firstElement();
+               int64_t old_seqn = rejectedSlotVector->get(0);
                if (rejectedSlotVector->size() > Table_REJECTED_THRESHOLD) {
                        int64_t new_seqn = rejectedSlotVector->lastElement();
                        RejectedMessage *rm = new RejectedMessage(s, s->getSequenceNumber(), localMachineId, old_seqn, new_seqn, false);
                if (rejectedSlotVector->size() > Table_REJECTED_THRESHOLD) {
                        int64_t new_seqn = rejectedSlotVector->lastElement();
                        RejectedMessage *rm = new RejectedMessage(s, s->getSequenceNumber(), localMachineId, old_seqn, new_seqn, false);
@@ -1645,7 +1654,7 @@ void Table::arbitrateFromServer() {
                        // Guard evaluated as true
 
                        // Update the local changes so we can make the commit
                        // Guard evaluated as true
 
                        // Update the local changes so we can make the commit
-                       SetIterator<KeyValue *> *kvit = getKeyIterator(transaction->getKeyValueUpdateSet());
+                       SetIterator<KeyValue *, KeyValue *> *kvit = transaction->getKeyValueUpdateSet()->iterator();
                        while (kvit->hasNext()) {
                                KeyValue *kv = kvit->next();
                                speculativeTableTmp->put(kv->getKey(), kv);
                        while (kvit->hasNext()) {
                                KeyValue *kv = kvit->next();
                                speculativeTableTmp->put(kv->getKey(), kv);
@@ -1743,7 +1752,7 @@ Pair<bool, bool> Table::arbitrateOnLocalTransaction(Transaction *transaction) {
                localArbitrationSequenceNumber++;
 
                // Update the local changes so we can make the commit
                localArbitrationSequenceNumber++;
 
                // Update the local changes so we can make the commit
-               SetIterator<KeyValue *> *kvit = getKeyIterator(transaction->getKeyValueUpdateSet());
+               SetIterator<KeyValue *, KeyValue *> *kvit = transaction->getKeyValueUpdateSet()->iterator();
                while (kvit->hasNext()) {
                        KeyValue *kv = kvit->next();
                        newCommit->addKV(kv);
                while (kvit->hasNext()) {
                        KeyValue *kv = kvit->next();
                        newCommit->addKV(kv);
@@ -2037,12 +2046,14 @@ bool Table::updateCommittedTable() {
                        // Get what commits should be edited, these are the commits that
                        // have live values for their keys
                        Hashset<Commit *> *commitsToEdit = new Hashset<Commit *>();
                        // Get what commits should be edited, these are the commits that
                        // have live values for their keys
                        Hashset<Commit *> *commitsToEdit = new Hashset<Commit *>();
-                       SetIterator<KeyValue *> *kvit = getKeyIterator(commit->getKeyValueUpdateSet());
-                       while (kvit->hasNext()) {
-                               KeyValue *kv = kvit->next();
-                               commitsToEdit->add(liveCommitsByKeyTable->get(kv->getKey()));
+                       {
+                               SetIterator<KeyValue *, KeyValue *, uintptr_t, 0, hashKeyValue, equalsKeyValue> *kvit = commit->getKeyValueUpdateSet()->iterator();
+                               while (kvit->hasNext()) {
+                                       KeyValue *kv = kvit->next();
+                                       commitsToEdit->add(liveCommitsByKeyTable->get(kv->getKey()));
+                               }
+                               delete kvit;
                        }
                        }
-                       delete kvit;
                        commitsToEdit->remove(NULL);            // remove NULL since it could be in this set
 
                        // Update each previous commit that needs to be updated
                        commitsToEdit->remove(NULL);            // remove NULL since it could be in this set
 
                        // Update each previous commit that needs to be updated
@@ -2052,12 +2063,14 @@ bool Table::updateCommittedTable() {
                                if (previousCommit->isLive()) {
 
                                        // Update which keys in the old commits are still live
                                if (previousCommit->isLive()) {
 
                                        // Update which keys in the old commits are still live
-                                       SetIterator<KeyValue *> *kvit = getKeyIterator(commit->getKeyValueUpdateSet());
-                                       while (kvit->hasNext()) {
-                                               KeyValue *kv = kvit->next();
-                                               previousCommit->invalidateKey(kv->getKey());
+                                       {
+                                               SetIterator<KeyValue *, KeyValue *, uintptr_t, 0, hashKeyValue, equalsKeyValue> *kvit = commit->getKeyValueUpdateSet()->iterator();
+                                               while (kvit->hasNext()) {
+                                                       KeyValue *kv = kvit->next();
+                                                       previousCommit->invalidateKey(kv->getKey());
+                                               }
+                                               delete kvit;
                                        }
                                        }
-                                       delete kvit;
                                        
                                        // if the commit is now dead then remove it
                                        if (!previousCommit->isLive()) {
                                        
                                        // if the commit is now dead then remove it
                                        if (!previousCommit->isLive()) {
@@ -2079,13 +2092,15 @@ bool Table::updateCommittedTable() {
                        didProcessANewCommit = true;
 
                        // Update the committed table of keys and which commit is using which key
                        didProcessANewCommit = true;
 
                        // Update the committed table of keys and which commit is using which key
-                       SetIterator<KeyValue *> *kvit = getKeyIterator(commit->getKeyValueUpdateSet());
-                       while (kvit->hasNext()) {
-                               KeyValue *kv = kvit->next();
-                               committedKeyValueTable->put(kv->getKey(), kv);
-                               liveCommitsByKeyTable->put(kv->getKey(), commit);
+                       {
+                               SetIterator<KeyValue *, KeyValue *, uintptr_t, 0, hashKeyValue, equalsKeyValue> *kvit = commit->getKeyValueUpdateSet()->iterator();
+                               while (kvit->hasNext()) {
+                                       KeyValue *kv = kvit->next();
+                                       committedKeyValueTable->put(kv->getKey(), kv);
+                                       liveCommitsByKeyTable->put(kv->getKey(), commit);
+                               }
+                               delete kvit;
                        }
                        }
-                       delete kvit;
                }
        }
 
                }
        }
 
@@ -2158,12 +2173,14 @@ bool Table::updateSpeculativeTable(bool didProcessNewCommits) {
 
                if (transaction->evaluateGuard(committedKeyValueTable, speculatedKeyValueTable, NULL)) {
                        // Guard evaluated to true so update the speculative table
 
                if (transaction->evaluateGuard(committedKeyValueTable, speculatedKeyValueTable, NULL)) {
                        // Guard evaluated to true so update the speculative table
-                       SetIterator<KeyValue *> *kvit = getKeyIterator(commit->getKeyValueUpdateSet());
-                       while (kvit->hasNext()) {
-                               KeyValue *kv = kvit->next();
-                               speculatedKeyValueTable->put(kv->getKey(), kv);
+                       {
+                               SetIterator<KeyValue *, KeyValue *> *kvit = transaction->getKeyValueUpdateSet()->iterator();
+                               while (kvit->hasNext()) {
+                                       KeyValue *kv = kvit->next();
+                                       speculatedKeyValueTable->put(kv->getKey(), kv);
+                               }
+                               delete kvit;
                        }
                        }
-                       delete kvit;
                }
        }
 
                }
        }
 
@@ -2209,7 +2226,7 @@ void Table::updatePendingTransactionSpeculativeTable(bool didProcessNewCommitsOr
 
                if (transaction->evaluateGuard(committedKeyValueTable, speculatedKeyValueTable, pendingTransactionSpeculatedKeyValueTable)) {
                        // Guard evaluated to true so update the speculative table
 
                if (transaction->evaluateGuard(committedKeyValueTable, speculatedKeyValueTable, pendingTransactionSpeculatedKeyValueTable)) {
                        // Guard evaluated to true so update the speculative table
-                       SetIterator<KeyValue *> *kvit = getKeyIterator(commit->getKeyValueUpdateSet());
+                       SetIterator<KeyValue *, KeyValue *> *kvit = transaction->getKeyValueUpdateSet()->iterator();
                        while (kvit->hasNext()) {
                                KeyValue *kv = kvit->next();
                                pendingTransactionSpeculatedKeyValueTable->put(kv->getKey(), kv);
                        while (kvit->hasNext()) {
                                KeyValue *kv = kvit->next();
                                pendingTransactionSpeculatedKeyValueTable->put(kv->getKey(), kv);
@@ -2433,7 +2450,7 @@ void Table::processEntry(Abort *entry) {
        if ((entry->getSequenceNumber() != -1) && (lastMessageTable->get(entry->getTransactionMachineId()).getFirst() >= entry->getSequenceNumber())) {
                // The machine already saw this so it is dead
                entry->setDead();
        if ((entry->getSequenceNumber() != -1) && (lastMessageTable->get(entry->getTransactionMachineId()).getFirst() >= entry->getSequenceNumber())) {
                // The machine already saw this so it is dead
                entry->setDead();
-               liveAbortTable->remove(entry->getAbortId());
+               liveAbortTable->remove(&entry->getAbortId());
 
                if (entry->getTransactionArbitrator() == localMachineId) {
                        liveAbortsGeneratedByLocal->remove(entry->getArbitratorLocalSequenceNumber());
 
                if (entry->getTransactionArbitrator() == localMachineId) {
                        liveAbortsGeneratedByLocal->remove(entry->getArbitratorLocalSequenceNumber());
@@ -2442,7 +2459,7 @@ void Table::processEntry(Abort *entry) {
        }
 
        // Update the last arbitration data that we have seen so far
        }
 
        // Update the last arbitration data that we have seen so far
-       if (lastArbitrationDataLocalSequenceNumberSeenFromArbitrator->get(entry->getTransactionArbitrator()) != NULL) {
+       if (lastArbitrationDataLocalSequenceNumberSeenFromArbitrator->contains(entry->getTransactionArbitrator())) {
                int64_t lastArbitrationSequenceNumber = lastArbitrationDataLocalSequenceNumberSeenFromArbitrator->get(entry->getTransactionArbitrator());
                if (entry->getSequenceNumber() > lastArbitrationSequenceNumber) {
                        // Is larger
                int64_t lastArbitrationSequenceNumber = lastArbitrationDataLocalSequenceNumberSeenFromArbitrator->get(entry->getTransactionArbitrator());
                if (entry->getSequenceNumber() > lastArbitrationSequenceNumber) {
                        // Is larger
@@ -2537,7 +2554,7 @@ void Table::processEntry(CommitPart *entry) {
  * our own last message or that other clients have not had a rollback
  * on the last message->
  */
  * our own last message or that other clients have not had a rollback
  * on the last message->
  */
-void Table::updateLastMessage(int64_t machineId, int64_t seqNum, Liveness *liveness, bool acceptUpdatesToLocal, Hashset<intr64_t> *machineSet) {
+void Table::updateLastMessage(int64_t machineId, int64_t seqNum, Liveness *liveness, bool acceptUpdatesToLocal, Hashset<int64_t> *machineSet) {
        // We have seen this machine ID
        machineSet->remove(machineId);
 
        // We have seen this machine ID
        machineSet->remove(machineId);
 
@@ -2547,7 +2564,9 @@ void Table::updateLastMessage(int64_t machineId, int64_t seqNum, Liveness *liven
        if (watchset != NULL) {
                // Go through each rejected message that this machine Id has not
                // seen yet
        if (watchset != NULL) {
                // Go through each rejected message that this machine Id has not
                // seen yet
-               for (Iterator<RejectedMessage *> *rmit = watchset->iterator(); rmit->hasNext(); ) {
+
+               SetIterator<RejectedMessage *, RejectedMessage *> *rmit = watchset->iterator();
+               while(rmit->hasNext()) {
                        RejectedMessage *rm = rmit->next();
                        // If this machine Id has seen this rejected message->->->
                        if (rm->getSequenceNumber() <= seqNum) {
                        RejectedMessage *rm = rmit->next();
                        // If this machine Id has seen this rejected message->->->
                        if (rm->getSequenceNumber() <= seqNum) {
@@ -2557,6 +2576,7 @@ void Table::updateLastMessage(int64_t machineId, int64_t seqNum, Liveness *liven
                                rm->removeWatcher(machineId);
                        }
                }
                                rm->removeWatcher(machineId);
                        }
                }
+               delete rmit;
        }
 
        // Set dead the abort
        }
 
        // Set dead the abort
@@ -2572,29 +2592,33 @@ void Table::updateLastMessage(int64_t machineId, int64_t seqNum, Liveness *liven
        }
        if (machineId == localMachineId) {
                // Our own messages are immediately dead->
        }
        if (machineId == localMachineId) {
                // Our own messages are immediately dead->
-               if (liveness instanceof LastMessage) {
+               char livenessType = liveness->getType();
+               if (livenessType==TypeLastMessage) {
                        ((LastMessage *)liveness)->setDead();
                        ((LastMessage *)liveness)->setDead();
-               } else if (liveness instanceof Slot) {
+               } else if (livenessType == TypeSlot) {
                        ((Slot *)liveness)->setDead();
                } else {
                        throw new Error("Unrecognized type");
                }
        }
        // Get the old last message for this device
                        ((Slot *)liveness)->setDead();
                } else {
                        throw new Error("Unrecognized type");
                }
        }
        // Get the old last message for this device
-       Pair<int64_t, Liveness *> lastMessageEntry = lastMessageTable->put(machineId, Pair<int64_t, Liveness *>(seqNum, liveness));
+       Pair<int64_t, Liveness *> * lastMessageEntry = lastMessageTable->put(machineId, new Pair<int64_t, Liveness *>(seqNum, liveness));
        if (lastMessageEntry == NULL) {
                // If no last message then there is nothing else to process
                return;
        }
 
        if (lastMessageEntry == NULL) {
                // If no last message then there is nothing else to process
                return;
        }
 
-       int64_t lastMessageSeqNum = lastMessageEntry.getFirst();
-       Liveness *lastEntry = lastMessageEntry.getSecond();
-
+       int64_t lastMessageSeqNum = lastMessageEntry->getFirst();
+       Liveness *lastEntry = lastMessageEntry->getSecond();
+       delete lastMessageEntry;
+       
        // If it is not our machine Id since we already set ours to dead
        if (machineId != localMachineId) {
        // If it is not our machine Id since we already set ours to dead
        if (machineId != localMachineId) {
-               if (lastEntry instanceof LastMessage) {
+               char lastEntryType = lastEntry->getType();
+               
+               if (lastEntryType == TypeLastMessage) {
                        ((LastMessage *)lastEntry)->setDead();
                        ((LastMessage *)lastEntry)->setDead();
-               } else if (lastEntry instanceof Slot) {
+               } else if (lastEntryType == TypeSlot) {
                        ((Slot *)lastEntry)->setDead();
                } else {
                        throw new Error("Unrecognized type");
                        ((Slot *)lastEntry)->setDead();
                } else {
                        throw new Error("Unrecognized type");