2 import java.nio.ByteBuffer;
5 * Generic class that wraps all the different types of information
6 * that can be stored in a Slot.
7 * @author Brian Demsky <bdemsky@uci.edu>
11 abstract class Entry implements Liveness {
14 static final byte TypeCommit = 1;
15 static final byte TypeAbort = 2;
16 static final byte TypeTransaction = 3;
17 static final byte TypeNewKey = 4;
18 static final byte TypeLastMessage = 5;
19 static final byte TypeRejectedMessage = 6;
20 static final byte TypeTableStatus = 7;
24 /* Records whether the information is still live or has been
25 superceded by a newer update. */
27 private boolean islive = true;
28 private Slot parentslot;
30 public Entry(Slot _parentslot) {
31 parentslot = _parentslot;
35 * Static method for decoding byte array into Entry objects. First
36 * byte tells the type of entry.
39 static Entry decode(Slot slot, ByteBuffer bb) {
44 return Commit.decode(slot, bb);
47 return Abort.decode(slot, bb);
50 return Transaction.decode(slot, bb);
53 return NewKey.decode(slot, bb);
56 return LastMessage.decode(slot, bb);
58 case TypeRejectedMessage:
59 return RejectedMessage.decode(slot, bb);
62 return TableStatus.decode(slot, bb);
65 throw new Error("Unrecognized Entry Type: " + type);
70 * Returns true if the Entry object is still live.
73 public boolean isLive() {
78 * Flags the entry object as dead. Also decrements the live count
82 public void setDead() {
85 return; // already dead
90 if (parentslot != null) {
91 parentslot.decrementLiveCount();
96 * Serializes the Entry object into the byte buffer.
99 abstract void encode(ByteBuffer bb);
102 * Returns the size in bytes the entry object will take in the byte
106 abstract int getSize();
109 * Returns a byte encoding the type of the entry object.
112 abstract byte getType();
115 * Returns a copy of the Entry that can be added to a different slot.
117 abstract Entry getCopy(Slot s);