Updates
[iotcloud.git] / version2 / src / java / iotcloud / NewKey.java
1 package iotcloud;
2
3 import java.nio.ByteBuffer;
4
5 /**
6  * This Entry records the abort sent by a given machine.
7  * @author Ali Younis <ayounis@uci.edu>
8  * @version 1.0
9  */
10
11
12 class NewKey extends Entry {
13         private IoTString key;
14         private long machineid;
15
16         public NewKey(Slot slot, IoTString _key, long _machineid) {
17                 super(slot);
18                 key = _key;
19                 machineid = _machineid;
20         }
21
22         public long getMachineID() {
23                 return machineid;
24         }
25
26         public IoTString getKey() {
27                 return key;
28         }
29
30         static Entry decode(Slot slot, ByteBuffer bb) {
31                 int keylength = bb.getInt();
32                 byte[] key = new byte[keylength];
33                 bb.get(key);
34                 long machineid = bb.getLong();
35
36                 return new NewKey(slot, IoTString.shallow(key), machineid);
37         }
38
39         public void encode(ByteBuffer bb) {
40                 bb.put(Entry.TypeNewKey);
41                 bb.putInt(key.length());
42                 bb.put(key.internalBytes());
43                 bb.putLong(machineid);
44         }
45
46         public int getSize() {
47                 return Long.BYTES + Byte.BYTES + Integer.BYTES + key.length();
48         }
49
50         public byte getType() {
51                 return Entry.TypeNewKey;
52         }
53
54         public Entry getCopy(Slot s) {
55                 return new NewKey(s, key, machineid);
56         }
57 }