updates
authorBrian Demsky <bdemsky@plrg.eecs.uci.edu>
Sat, 23 Jul 2016 21:17:29 +0000 (14:17 -0700)
committerBrian Demsky <bdemsky@plrg.eecs.uci.edu>
Sat, 23 Jul 2016 21:17:29 +0000 (14:17 -0700)
src/java/iotcloud/IoTString.java
src/java/iotcloud/KeyValue.java
src/java/iotcloud/LastMessage.java
src/java/iotcloud/Pair.java [new file with mode: 0644]
src/java/iotcloud/Slot.java
src/java/iotcloud/Table.java

index 37fba1b54b9b39b0bb0d045af61fd548fa247dd6..11e86e2cc62d05a36b5836ee608a498156f947a5 100644 (file)
@@ -6,6 +6,9 @@ public class IoTString {
        byte[] array;
        int hashcode;
 
+       private IoTString() {
+       }
+       
        public IoTString(byte[] _array) {
                array=(byte[]) _array.clone();
                hashcode=Arrays.hashCode(array);
@@ -16,6 +19,17 @@ public class IoTString {
                hashcode=Arrays.hashCode(array);
        }
 
+       static IoTString shallow(byte[] _array) {
+               IoTString i=new IoTString();
+               i.array = _array;
+               i.hashcode = Arrays.hashCode(_array);
+               return i;
+       }
+
+       byte[] internalBytes() {
+               return array;
+       }
+       
        public int hashCode() {
                return hashcode;
        }
@@ -35,4 +49,8 @@ public class IoTString {
                }
                return false;
        }
+
+       public int length() {
+               return array.length;
+       }
 }
index 36a56dce99ef45bcbd9fd29eba167c6537bd821f..6f620fab9e4f7260d2cf354e37cca133d041a915 100644 (file)
@@ -2,12 +2,21 @@ package iotcloud;
 import java.nio.ByteBuffer;
 
 class KeyValue extends Entry {
-       byte[] key;
-       byte[] value;
-       KeyValue(byte[] _key, byte[] _value) {
+       private IoTString key;
+       private IoTString value;
+       
+       KeyValue(IoTString _key, IoTString _value) {
                key=_key;
                value=_value;
        }
+
+       IoTString getKey() {
+               return key;
+       }
+
+       IoTString getValue() {
+               return value;
+       }
        
        static Entry decode(ByteBuffer bb) {
                int keylength=bb.getInt();
@@ -16,19 +25,19 @@ class KeyValue extends Entry {
                byte[] value=new byte[valuelength];
                bb.get(key);
                bb.get(value);
-               return new KeyValue(key, value);
+               return new KeyValue(IoTString.shallow(key), IoTString.shallow(value));
        }
 
        void encode(ByteBuffer bb) {
                bb.put(Entry.TypeKeyValue);
-               bb.putInt(key.length);
-               bb.putInt(value.length);
-               bb.put(key);
-               bb.put(value);
+               bb.putInt(key.length());
+               bb.putInt(value.length());
+               bb.put(key.internalBytes());
+               bb.put(value.internalBytes());
        }
 
        int getSize() {
-               return 2*Integer.BYTES+key.length+value.length+Byte.BYTES;
+               return 2*Integer.BYTES+key.length()+value.length()+Byte.BYTES;
        }
 
        byte getType() {
index 23e6bcdedb8d0607a11c543134ad7b1a37863c35..9ea9bcc27aa9724485f8942530141b6ed0140c46 100644 (file)
@@ -11,6 +11,14 @@ class LastMessage extends Entry {
                seqnum=_seqnum;
        }
 
+       long getMachineID() {
+               return machineid;
+       }
+
+       long getSequenceNumber() {
+               return seqnum;
+       }
+       
        static Entry decode(ByteBuffer bb) {
                long machineid=bb.getLong();
                long seqnum=bb.getLong();
diff --git a/src/java/iotcloud/Pair.java b/src/java/iotcloud/Pair.java
new file mode 100644 (file)
index 0000000..1c81444
--- /dev/null
@@ -0,0 +1,23 @@
+package iotcloud;
+
+public class Pair<A,B> {
+  private A a;
+  private B b;
+
+  public Pair(A a, B b) {
+    this.a=a;
+    this.b=b;
+  }
+
+  public A getFirst() {
+    return a;
+  }
+
+  public B getSecond() {
+    return b;
+  }
+
+  public String toString() {
+    return "<"+a+","+b+">";
+  }
+}
index 8815a5bcbf42784fe1075bf575a86a19858d2779..848edb31f936d05a54a7dcaa6dd171dc85daa8a1 100644 (file)
@@ -84,6 +84,10 @@ class Slot {
                return seqnum;
        }
 
+       long getMachineID() {
+               return machineid;
+       }
+       
        byte[] getBytes() {
                return null;
        }
index 679421ec518cb0c739a5de139c4653fc05881fa9..ae4ed164e2823d1ae6afae2d9a1cb1230d2cfb42 100644 (file)
@@ -6,7 +6,7 @@ import javax.crypto.*;
 
 public class Table {
        int numslots;
-       HashMap<IoTString, IoTString> table=new HashMap<IoTString, IoTString>();
+       HashMap<IoTString, KeyValue> table=new HashMap<IoTString, KeyValue>();
        HashMap<Long, Long> lastmessage=new HashMap<Long, Long>();
        SlotBuffer buffer;
        CloudComm cloud;
@@ -71,22 +71,33 @@ public class Table {
        }
 
        void processEntry(KeyValue entry, SlotIndexer indexer, Slot slot) {
-
+               IoTString key=entry.getKey();
+               KeyValue oldvalue=table.get(key);
+               if (oldvalue != null) {
+                       oldvalue.setDead();
+               }
+               table.put(key, entry);
        }
 
        void processEntry(LastMessage entry, SlotIndexer indexer, Slot slot) {
-
+               updateLastMessage(entry.getMachineID(), entry.getSequenceNumber(), null, entry);
        }
 
        void processEntry(RejectedMessage entry, SlotIndexer indexer, Slot slot) {
-
+               
        }
 
        void processEntry(TableStatus entry, SlotIndexer indexer, Slot slot) {
 
+       }
+
+       void updateLastMessage(long machineid, long seqnum, Slot slot, LastMessage entry) {
+               
        }
        
        void processSlot(SlotIndexer indexer, Slot slot) {
+               updateLastMessage(slot.getMachineID(), slot.getSequenceNumber(), slot, null);
+
                for(Entry entry : slot.getEntries()) {
                        switch(entry.getType()) {
                        case Entry.TypeKeyValue: