Block Chain Transactions, Commits multiple parts version
[iotcloud.git] / version2 / src / java / iotcloud / Entry.java
index c5a680783c0ba2408f6e918dfb6bc1175864721a..dd9e75b2f4afc9c32e4649497f258aad49c2e626 100644 (file)
@@ -10,10 +10,9 @@ import java.nio.ByteBuffer;
 
 abstract class Entry implements Liveness {
 
-
-       static final byte TypeCommit = 1;
+       static final byte TypeCommitPart = 1;
        static final byte TypeAbort = 2;
-       static final byte TypeTransaction = 3;
+       static final byte TypeTransactionPart = 3;
        static final byte TypeNewKey = 4;
        static final byte TypeLastMessage = 5;
        static final byte TypeRejectedMessage = 6;
@@ -25,7 +24,7 @@ abstract class Entry implements Liveness {
                 superceded by a newer update.  */
 
        private boolean islive = true;
-       private Slot parentslot;
+       protected Slot parentslot;
 
        public Entry(Slot _parentslot) {
                parentslot = _parentslot;
@@ -35,19 +34,18 @@ abstract class Entry implements Liveness {
         * 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 TypeCommit:
-                       return Commit.decode(slot, bb);
+               case TypeCommitPart:
+                       return CommitPart.decode(slot, bb);
 
                case TypeAbort:
                        return Abort.decode(slot, bb);
 
-               case TypeTransaction:
-                       return Transaction.decode(slot, bb);
+               case TypeTransactionPart:
+                       return TransactionPart.decode(slot, bb);
 
                case TypeNewKey:
                        return NewKey.decode(slot, bb);
@@ -69,16 +67,15 @@ abstract class Entry implements Liveness {
        /**
         * Returns true if the Entry object is still live.
         */
-
        public boolean isLive() {
                return islive;
        }
 
+
        /**
         * Flags the entry object as dead.  Also decrements the live count
         * of the parent slot.
         */
-
        public void setDead() {
 
                if (!islive ) {
@@ -86,31 +83,34 @@ abstract class Entry implements Liveness {
                }
 
                islive = false;
-               parentslot.decrementLiveCount();
+
+               if (parentslot != null) {
+                       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);
-
 }