Deleted Redundent Files
[iotcloud.git] / src / java / iotcloud / Entry.java
index 9f85bacec872ef10af0a4a1978d774b533285613..70f90ee60e7f57d072a76f15e569466df9d34cf1 100644 (file)
@@ -1,29 +1,94 @@
 package iotcloud;
 import java.nio.ByteBuffer;
 
-abstract class Entry {
+/**
+ * Generic class that wraps all the different types of information
+ * that can be stored in a Slot.
+ * @author Brian Demsky <bdemsky@uci.edu>
+ * @version 1.0
+ */
+
+abstract class Entry implements Liveness {
        static final byte TypeKeyValue = 1;
        static final byte TypeLastMessage = 2;
        static final byte TypeRejectedMessage = 3;
        static final byte TypeTableStatus = 4;
 
-       static Entry decode(ByteBuffer bb) {
+       /* Records whether the information is still live or has been
+                superceded by a newer update.  */
+
+       private boolean islive = true;
+       private Slot parentslot;
+
+       Entry(Slot _parentslot) {
+               parentslot = _parentslot;
+       }
+
+       /**
+        * Static method for decoding byte array into Entry objects.  First
+        * byte tells the type of entry.
+        */
+
+       static Entry decode(Slot slot, ByteBuffer bb) {
                byte type=bb.get();
                switch(type) {
                case TypeKeyValue:
-                       return KeyValue.decode(bb);
+                       return KeyValue.decode(slot, bb);
+
                case TypeLastMessage:
-                       return LastMessage.decode(bb);
+                       return LastMessage.decode(slot, bb);
+
                case TypeRejectedMessage:
-                       return RejectedMessage.decode(bb);
+                       return RejectedMessage.decode(slot, bb);
+
                case TypeTableStatus:
-                       return TableStatus.decode(bb);
+                       return TableStatus.decode(slot, bb);
+
                default:
                        throw new Error("Unrecognized Entry Type: "+type);
                }
        }
 
+       /**
+        * Returns true if the Entry object is still live.
+        */
+
+       boolean isLive() {
+               return islive;
+       }
+
+       /**
+        * Flags the entry object as dead.  Also decrements the live count
+        * of the parent slot.
+        */
+
+       void setDead() {
+               islive = false;
+               parentslot.decrementLiveCount();
+       }
+
+       /**
+        * Serializes the Entry object into the byte buffer.
+        */
+
        abstract void encode(ByteBuffer bb);
 
+       /**
+        * Returns the size in bytes the entry object will take in the byte
+        * array.
+        */
+
        abstract int getSize();
+
+       /**
+        * Returns a byte encoding the type of the entry object.
+        */
+
+       abstract byte getType();
+
+       /**
+        * Returns a copy of the Entry that can be added to a different slot.
+        */
+       abstract Entry getCopy(Slot s);
+
 }