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 LastMessage.decode(slot, bb);
46 case TypeRejectedMessage:
47 return RejectedMessage.decode(slot, bb);
50 return TableStatus.decode(slot, bb);
53 throw new Error("Unrecognized Entry Type: " + type);
58 * Returns true if the Entry object is still live.
61 public boolean isLive() {
66 * Flags the entry object as dead. Also decrements the live count
70 public void setDead() {
72 parentslot.decrementLiveCount();
76 * Serializes the Entry object into the byte buffer.
79 abstract void encode(ByteBuffer bb);
82 * Returns the size in bytes the entry object will take in the byte
86 abstract int getSize();
89 * Returns a byte encoding the type of the entry object.
92 abstract byte getType();
95 * Returns a copy of the Entry that can be added to a different slot.
97 abstract Entry getCopy(Slot s);