From: Brian Demsky Date: Sat, 23 Jul 2016 21:17:29 +0000 (-0700) Subject: updates X-Git-Url: http://plrg.eecs.uci.edu/git/?p=iotcloud.git;a=commitdiff_plain;h=632737b8234665649bd24c647037e4f0425bc0c9 updates --- diff --git a/src/java/iotcloud/IoTString.java b/src/java/iotcloud/IoTString.java index 37fba1b..11e86e2 100644 --- a/src/java/iotcloud/IoTString.java +++ b/src/java/iotcloud/IoTString.java @@ -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; + } } diff --git a/src/java/iotcloud/KeyValue.java b/src/java/iotcloud/KeyValue.java index 36a56dc..6f620fa 100644 --- a/src/java/iotcloud/KeyValue.java +++ b/src/java/iotcloud/KeyValue.java @@ -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() { diff --git a/src/java/iotcloud/LastMessage.java b/src/java/iotcloud/LastMessage.java index 23e6bcd..9ea9bcc 100644 --- a/src/java/iotcloud/LastMessage.java +++ b/src/java/iotcloud/LastMessage.java @@ -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 index 0000000..1c81444 --- /dev/null +++ b/src/java/iotcloud/Pair.java @@ -0,0 +1,23 @@ +package iotcloud; + +public class Pair { + 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+">"; + } +} diff --git a/src/java/iotcloud/Slot.java b/src/java/iotcloud/Slot.java index 8815a5b..848edb3 100644 --- a/src/java/iotcloud/Slot.java +++ b/src/java/iotcloud/Slot.java @@ -84,6 +84,10 @@ class Slot { return seqnum; } + long getMachineID() { + return machineid; + } + byte[] getBytes() { return null; } diff --git a/src/java/iotcloud/Table.java b/src/java/iotcloud/Table.java index 679421e..ae4ed16 100644 --- a/src/java/iotcloud/Table.java +++ b/src/java/iotcloud/Table.java @@ -6,7 +6,7 @@ import javax.crypto.*; public class Table { int numslots; - HashMap table=new HashMap(); + HashMap table=new HashMap(); HashMap lastmessage=new HashMap(); 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: