edits
[iotcloud.git] / version2 / src / java / iotcloud / Table.java
index b6801c0585e731bc8a4d499a00c973ab7c9c49a2..25b677565f89d8db56c69e4ed30c4d52e1ba6e9c 100644 (file)
@@ -44,6 +44,8 @@ final public class Table {
        private long oldestLiveSlotSequenceNumver = 0;  // Smallest sequence number of the slot with a live entry
        private long localMachineId = 0; // Machine ID of this client device
        private long sequenceNumber = 0; // Largest sequence number a client has received
+       private long localSequenceNumber = 0;
+
        // private int smallestTableStatusSeen = -1; // Smallest Table Status that was seen in the latest slots sent from the server
        // private int largestTableStatusSeen = -1; // Largest Table Status that was seen in the latest slots sent from the server
        private long localTransactionSequenceNumber = 0; // Local sequence number counter for transactions
@@ -242,7 +244,8 @@ final public class Table {
                cloud.initSecurity();
 
                // Create the first insertion into the block chain which is the table status
-               Slot s = new Slot(this, 1, localMachineId);
+               Slot s = new Slot(this, 1, localMachineId, localSequenceNumber);
+               localSequenceNumber++;
                TableStatus status = new TableStatus(s, numberOfSlots);
                s.addEntry(status);
                Slot[] array = cloud.putSlot(s, numberOfSlots);
@@ -522,6 +525,10 @@ final public class Table {
                bufferResizeThreshold = resizeLower - 1 + random.nextInt(numberOfSlots - resizeLower);
        }
 
+       public long getLocalSequenceNumber() {
+               return localSequenceNumber;
+       }
+
 
        boolean lastInsertedNewKey = false;
 
@@ -720,7 +727,6 @@ final public class Table {
                        // While we have stuff that needs inserting into the block chain
                        while ((pendingTransactionQueue.size() > 0) || (pendingSendArbitrationRounds.size() > 0) || (newKey != null)) {
 
-
                                fromRetry = false;
 
                                if (hadPartialSendToServer) {
@@ -735,7 +741,8 @@ final public class Table {
                                }
 
                                // Create the slot
-                               Slot slot = new Slot(this, sequenceNumber + 1, localMachineId, buffer.getSlot(sequenceNumber).getHMAC());
+                               Slot slot = new Slot(this, sequenceNumber + 1, localMachineId, buffer.getSlot(sequenceNumber).getHMAC(), localSequenceNumber);
+                               localSequenceNumber++;
 
                                // Try to fill the slot with data
                                ThreeTuple<Boolean, Integer, Boolean> fillSlotsReturn = fillSlot(slot, false, newKey);
@@ -782,7 +789,7 @@ final public class Table {
 
                                                // New Key was successfully inserted into the block chain so dont want to insert it again
                                                newKey = null;
-                                       } 
+                                       }
 
                                        // Remove the aborts and commit parts that were sent from the pending to send queue
                                        for (Iterator<ArbitrationRound> iter = pendingSendArbitrationRounds.iterator(); iter.hasNext(); ) {
@@ -929,7 +936,8 @@ final public class Table {
                bbEncode.putInt(0);
 
                // Send by local
-               byte[] returnData = cloud.sendLocalData(sendData, localCommunicationInformation.getFirst(), localCommunicationInformation.getSecond());
+               byte[] returnData = cloud.sendLocalData(sendData, localSequenceNumber, localCommunicationInformation.getFirst(), localCommunicationInformation.getSecond());
+               localSequenceNumber++;
 
                if (returnData == null) {
                        // Could not contact server
@@ -990,7 +998,8 @@ final public class Table {
 
 
                // Send by local
-               byte[] returnData = cloud.sendLocalData(sendData, localCommunicationInformation.getFirst(), localCommunicationInformation.getSecond());
+               byte[] returnData = cloud.sendLocalData(sendData, localSequenceNumber, localCommunicationInformation.getFirst(), localCommunicationInformation.getSecond());
+               localSequenceNumber++;
 
                if (returnData == null) {
                        // Could not contact server
@@ -1143,6 +1152,8 @@ final public class Table {
                        entry.encode(bbEncode);
                }
 
+
+               localSequenceNumber++;
                return returnData;
        }
 
@@ -1250,7 +1261,7 @@ final public class Table {
 
                                slot.addEntry(newKeyEntry);
                                inserted = true;
-                       } 
+                       }
                }
 
                // Clear the transactions, aborts and commits that were sent previously
@@ -1971,7 +1982,7 @@ final public class Table {
                                pendingSendArbitrationRounds.clear();
                        } else {
                                for (int i = 0; i < numberToDelete; i++) {
-                                       pendingSendArbitrationRounds.remove(pendingSendArbitrationRounds.size() - 1);
+                                       pendingSendArbitrationRounds.removeIndex(pendingSendArbitrationRounds.size() - 1);
                                }
                        }
 
@@ -2734,4 +2745,4 @@ final public class Table {
                                throw new Error("Server Error: Invalid HMAC Chain" + currSlot + " " + prevSlot);
                }
        }
-}
\ No newline at end of file
+}