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.fasterxml.jackson.annotation.JsonProperty;
23 import com.hazelcast.nio.ObjectDataInput;
24 import com.hazelcast.nio.ObjectDataOutput;
25
26 import net.anyflow.lannister.serialization.SerializableFactory;
27
28 public class TopicSubscriber implements com.hazelcast.nio.serialization.IdentifiedDataSerializable {
29 public static final TopicSubscribers NEXUS = new TopicSubscribers();
30 public static final int ID = 7;
31 @JsonProperty
32 private String clientId;
33 @JsonProperty
34 private String topicName;
35
36 public TopicSubscriber() {
37 }
38
39 public TopicSubscriber(String clientId, String topicName) {
40 this.clientId = clientId;
41 this.topicName = topicName;
42 }
43
44 public String key() {
45 return TopicSubscribers.key(topicName, clientId);
46 }
47
48 public String clientId() {
49 return clientId;
50 }
51
52 public String topicName() {
53 return topicName;
54 }
55
56 @JsonIgnore
57 @Override
58 public int getFactoryId() {
59 return SerializableFactory.ID;
60 }
61
62 @JsonIgnore
63 @Override
64 public int getId() {
65 return ID;
66 }
67
68 @Override
69 public void writeData(ObjectDataOutput out) throws IOException {
70 out.writeUTF(topicName);
71 out.writeUTF(clientId);
72 }
73
74 @Override
75 public void readData(ObjectDataInput in) throws IOException {
76 topicName = in.readUTF();
77 clientId = in.readUTF();
78 }
79
80 @Override
81 public String toString() {
82 return new StringBuilder().append("clientId=").append(clientId).append(", topicName=").append(topicName)
83 .toString();
84 }
85 }