forked from voldemort/voldemort
/
ClientInfo.java
168 lines (139 loc) · 4.91 KB
/
ClientInfo.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package voldemort.client;
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.net.InetAddress;
import java.net.UnknownHostException;
import org.apache.log4j.Logger;
public class ClientInfo implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
protected static final Logger logger = Logger.getLogger(ClientInfo.class);
private long bootstrapTime;
private String storeName;
private String context;
private int sequence;
private String localHostName;
private String deploymentPath;
private long updateTime;
private String releaseVersion;
public ClientInfo(String storeName,
String clientContext,
int clientSequence,
long bootstrapTime,
String version) {
this.bootstrapTime = bootstrapTime;
this.storeName = storeName;
this.context = clientContext;
this.sequence = clientSequence;
this.localHostName = createHostName();
this.deploymentPath = createDeploymentPath();
this.updateTime = bootstrapTime;
this.releaseVersion = version;
if(logger.isDebugEnabled()) {
logger.debug(this.toString());
}
}
private String createDeploymentPath() {
String currentPath = null;
try {
currentPath = new File(".").getCanonicalPath();
} catch(IOException e) {
logger.warn("Unable to obtain client deployment path due to the following error:");
logger.warn(e.getMessage());
}
return currentPath;
}
private String createHostName() {
String hostName = null;
try {
InetAddress host = InetAddress.getLocalHost();
hostName = host.getHostName();
} catch(UnknownHostException e) {
logger.warn("Unable to obtain client hostname due to the following error:");
logger.warn(e.getMessage());
}
return hostName;
}
public void setStoreName(String storeName) {
this.storeName = storeName;
}
public String getStoreName() {
return storeName;
}
public void setBootstrapTime(long bootstrapTime) {
this.bootstrapTime = bootstrapTime;
}
public long getBootstrapTime() {
return bootstrapTime;
}
public void setContext(String clientContext) {
this.context = clientContext;
}
public String getContext() {
return context;
}
public void setClientSequence(int clientSequence) {
this.sequence = clientSequence;
}
public int getClientSequence() {
return sequence;
}
public void setDeploymentPath(String deploymentPath) {
this.deploymentPath = deploymentPath;
}
public String getDeploymentPath() {
return deploymentPath;
}
public void setLocalHostName(String localHostName) {
this.localHostName = localHostName;
}
public String getLocalHostName() {
return localHostName;
}
public void setUpdateTime(long updateTime) {
this.updateTime = updateTime;
}
public long getUpdateTime() {
return this.updateTime;
}
public void setReleaseVersion(String version) {
this.releaseVersion = version;
}
public String getReleaseVersion() {
return this.releaseVersion;
}
@Override
public boolean equals(Object object) {
if(this == object)
return true;
if(object == null)
return false;
if(!object.getClass().equals(ClientInfo.class))
return false;
ClientInfo clientInfo = (ClientInfo) object;
return (this.bootstrapTime == clientInfo.bootstrapTime)
&& (this.context.equals(clientInfo.context))
&& (this.deploymentPath.equals(clientInfo.deploymentPath))
&& (this.localHostName.equals(clientInfo.localHostName))
&& (this.sequence == clientInfo.sequence)
&& (this.storeName.equals(clientInfo.storeName))
&& (this.updateTime == clientInfo.updateTime)
&& (this.releaseVersion == clientInfo.releaseVersion);
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("boostrapTime[").append(bootstrapTime).append("], ");
builder.append("context[").append(context).append("], ");
builder.append("deploymentPath[").append(deploymentPath).append("], ");
builder.append("localHostName[").append(localHostName).append("], ");
builder.append("sequence[").append(sequence).append("], ");
builder.append("storeName[").append(storeName).append("], ");
builder.append("updateTime[").append(updateTime).append("], ");
builder.append("releaseVersion[").append(releaseVersion).append("]");
return builder.toString();
}
}