1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package net.anyflow.lannister.message;
18
19 import java.io.IOException;
20 import java.util.Date;
21
22 import com.fasterxml.jackson.annotation.JsonFormat;
23 import com.fasterxml.jackson.annotation.JsonProperty;
24 import com.hazelcast.nio.ObjectDataInput;
25 import com.hazelcast.nio.ObjectDataOutput;
26
27 import net.anyflow.lannister.Literals;
28
29 public abstract class MessageStatus implements com.hazelcast.nio.serialization.IdentifiedDataSerializable {
30
31 @JsonProperty
32 private String messageKey;
33 @JsonProperty
34 private String clientId;
35 @JsonProperty
36 private int messageId;
37 @JsonProperty
38 private String topicName;
39 @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = Literals.DATE_DEFAULT_FORMAT, timezone = Literals.DATE_DEFAULT_TIMEZONE)
40 @JsonProperty
41 private Date createTime;
42 @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = Literals.DATE_DEFAULT_FORMAT, timezone = Literals.DATE_DEFAULT_TIMEZONE)
43 @JsonProperty
44 protected Date updateTime;
45
46 public MessageStatus() {
47 }
48
49 protected MessageStatus(String messageKey, String clientId, int messageId, String topicName) {
50 this.messageKey = messageKey;
51 this.clientId = clientId;
52 this.messageId = messageId;
53 this.topicName = topicName;
54 this.createTime = new Date();
55 this.updateTime = createTime;
56 }
57
58 public abstract String key();
59
60 public String messageKey() {
61 return messageKey;
62 }
63
64 public String clientId() {
65 return clientId;
66 }
67
68 public String topicName() {
69 return topicName;
70 }
71
72 public int messageId() {
73 return messageId;
74 }
75
76 public Date createTime() {
77 return createTime;
78 }
79
80 public Date updateTime() {
81 return updateTime;
82 }
83
84 @Override
85 public void writeData(ObjectDataOutput out) throws IOException {
86 out.writeUTF(messageKey);
87 out.writeUTF(clientId);
88 out.writeInt(messageId);
89 out.writeUTF(topicName);
90 out.writeLong(createTime != null ? createTime.getTime() : Long.MIN_VALUE);
91 out.writeLong(updateTime != null ? updateTime.getTime() : Long.MIN_VALUE);
92 }
93
94 @Override
95 public void readData(ObjectDataInput in) throws IOException {
96 messageKey = in.readUTF();
97 clientId = in.readUTF();
98 messageId = in.readInt();
99 topicName = in.readUTF();
100
101 long rawLong = in.readLong();
102 createTime = rawLong != Long.MIN_VALUE ? new Date(rawLong) : null;
103
104 rawLong = in.readLong();
105 updateTime = rawLong != Long.MIN_VALUE ? new Date(rawLong) : null;
106 }
107 }