/
AsyncMessage.java
77 lines (60 loc) · 2.03 KB
/
AsyncMessage.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package com.yahoo.pasc.paxos.messages;
import java.util.Arrays;
import com.yahoo.pasc.CloneableDeep;
import com.yahoo.pasc.EqualsDeep;
public class AsyncMessage extends PaxosMessage implements CloneableDeep<AsyncMessage>, EqualsDeep<AsyncMessage> {
private static final long serialVersionUID = -8514053535510009861L;
private int clientId;
private int serverId;
private long timestamp;
private byte[] message;
public AsyncMessage(int clientId, int serverId, long timestamp, byte[] message) {
super();
this.clientId = clientId;
this.serverId = serverId;
this.timestamp = timestamp;
this.message = message;
}
public int getClientId() {
return clientId;
}
public void setClientId(int clientId) {
this.clientId = clientId;
}
public long getTimestamp() {
return timestamp;
}
public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}
public int getServerId() {
return serverId;
}
public void setServerId(int serverId) {
this.serverId = serverId;
}
public byte[] getMessage() {
return message;
}
public void setMessage(byte[] message) {
this.message = message;
}
@Override
public AsyncMessage cloneDeep() {
byte[] msgArray = new byte[this.message.length];
System.arraycopy(this.message, 0, msgArray, 0, msgArray.length);
return new AsyncMessage(this.clientId, this.serverId, this.timestamp, msgArray);
}
@Override
public boolean equalsDeep(AsyncMessage other) {
if (!Arrays.equals(other.message, this.message)) {
return false;
}
return (this.clientId == other.clientId && this.serverId == other.serverId && this.timestamp == other.timestamp);
}
@Override
public String toString() {
return "AsyncMessage [clientId=" + clientId + ", serverId=" + serverId + ", timestamp=" + timestamp
+ ", message=" + Arrays.toString(message) + "]";
}
}