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 {
13 static final byte TypeCommitPart = 1;
14 static final byte TypeAbort = 2;
15 static final byte TypeTransactionPart = 3;
16 static final byte TypeNewKey = 4;
17 static final byte TypeLastMessage = 5;
18 static final byte TypeRejectedMessage = 6;
19 static final byte TypeTableStatus = 7;
23 /* Records whether the information is still live or has been
24 superceded by a newer update. */
26 private boolean islive = true;
27 protected Slot parentslot;
29 public Entry(Slot _parentslot) {
30 parentslot = _parentslot;
34 * Static method for decoding byte array into Entry objects. First
35 * byte tells the type of entry.
37 static Entry decode(Slot slot, ByteBuffer bb) {
42 return CommitPart.decode(slot, bb);
45 return Abort.decode(slot, bb);
47 case TypeTransactionPart:
48 return TransactionPart.decode(slot, bb);
51 return NewKey.decode(slot, bb);
54 return LastMessage.decode(slot, bb);
56 case TypeRejectedMessage:
57 return RejectedMessage.decode(slot, bb);
60 return TableStatus.decode(slot, bb);
63 throw new Error("Unrecognized Entry Type: " + type);
68 * Returns true if the Entry object is still live.
70 public boolean isLive() {
76 * Flags the entry object as dead. Also decrements the live count
79 public void setDead() {
82 return; // already dead
87 if (parentslot != null) {
88 parentslot.decrementLiveCount();
94 * Serializes the Entry object into the byte buffer.
96 abstract void encode(ByteBuffer bb);
100 * Returns the size in bytes the entry object will take in the byte
103 abstract int getSize();
107 * Returns a byte encoding the type of the entry object.
109 abstract byte getType();
113 * Returns a copy of the Entry that can be added to a different slot.
115 abstract Entry getCopy(Slot s);