API Changes
[iotcloud.git] / version2 / src / java / iotcloud / LastMessage.java
1 package iotcloud;
2
3 import java.nio.ByteBuffer;
4
5 /**
6  * This Entry records the last message sent by a given machine.
7  * @author Brian Demsky <bdemsky@uci.edu>
8  * @version 1.0
9  */
10
11
12 class LastMessage extends Entry {
13         private long machineid;
14         private long seqnum;
15
16         public LastMessage(Slot slot, long _machineid, long _seqnum) {
17                 super(slot);
18                 machineid=_machineid;
19                 seqnum=_seqnum;
20         }
21
22         public long getMachineID() {
23                 return machineid;
24         }
25
26         public long getSequenceNumber() {
27                 return seqnum;
28         }
29
30         static Entry decode(Slot slot, ByteBuffer bb) {
31                 long machineid=bb.getLong();
32                 long seqnum=bb.getLong();
33                 return new LastMessage(slot, machineid, seqnum);
34         }
35
36         public void encode(ByteBuffer bb) {
37                 bb.put(Entry.TypeLastMessage);
38                 bb.putLong(machineid);
39                 bb.putLong(seqnum);
40         }
41
42         public int getSize() {
43                 return 2*Long.BYTES+Byte.BYTES;
44         }
45
46         public byte getType() {
47                 return Entry.TypeLastMessage;
48         }
49
50         public Entry getCopy(Slot s) {
51                 return new LastMessage(s, machineid, seqnum);
52         }
53 }
54
55