1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package net.anyflow.lannister.topic;
18
19 import java.io.IOException;
20
21 import com.fasterxml.jackson.annotation.JsonIgnore;
22 import com.hazelcast.nio.ObjectDataInput;
23 import com.hazelcast.nio.ObjectDataOutput;
24
25 import net.anyflow.lannister.message.Message;
26 import net.anyflow.lannister.serialization.SerializableFactory;
27
28 public class Notification implements com.hazelcast.nio.serialization.IdentifiedDataSerializable {
29 public final static int ID = 5;
30
31 private String clientId;
32 private Topic topic;
33 private Message message;
34
35 public Notification() {
36 }
37
38 protected Notification(String clientId, Topic topic, Message message) {
39 this.clientId = clientId;
40 this.topic = topic;
41 this.message = message;
42 }
43
44 public String clientId() {
45 return clientId;
46 }
47
48 public Topic topic() {
49 return topic;
50 }
51
52 public Message message() {
53 return message;
54 }
55
56 @JsonIgnore
57 @Override
58 public int getFactoryId() {
59 return SerializableFactory.ID;
60 }
61
62 @Override
63 public int getId() {
64 return ID;
65 }
66
67 @Override
68 public void writeData(ObjectDataOutput out) throws IOException {
69 out.writeUTF(clientId);
70 out.writeBoolean(topic != null);
71 if (topic != null) {
72 topic.writeData(out);
73 }
74 out.writeBoolean(message != null);
75 if (message != null) {
76 message.writeData(out);
77 }
78 }
79
80 @Override
81 public void readData(ObjectDataInput in) throws IOException {
82 clientId = in.readUTF();
83 if (in.readBoolean()) {
84 Topic temp = new Topic();
85 temp.readData(in);
86
87 topic = temp;
88 }
89 if (in.readBoolean()) {
90 Message temp = new Message();
91 temp.readData(in);
92
93 message = temp;
94 }
95 }
96 }