byte[] array;
int hashcode;
+ private IoTString() {
+ }
+
public IoTString(byte[] _array) {
array=(byte[]) _array.clone();
hashcode=Arrays.hashCode(array);
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;
}
}
return false;
}
+
+ public int length() {
+ return array.length;
+ }
}
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();
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() {
seqnum=_seqnum;
}
+ long getMachineID() {
+ return machineid;
+ }
+
+ long getSequenceNumber() {
+ return seqnum;
+ }
+
static Entry decode(ByteBuffer bb) {
long machineid=bb.getLong();
long seqnum=bb.getLong();
--- /dev/null
+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+">";
+ }
+}
return seqnum;
}
+ long getMachineID() {
+ return machineid;
+ }
+
byte[] getBytes() {
return null;
}
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;
}
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: