HttpHeartbeatServiceImpl.java
2.3 KB
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
package com.taover.heartbeat.adaptor;
import javax.servlet.http.HttpServletRequest;
import com.taover.heartbeat.HeartbeatManager;
import com.taover.heartbeat.bean.ClientRequest;
import com.taover.heartbeat.bean.Instance;
import com.taover.util.UtilLog;
import com.taover.util.bean.ResultInfo;
import com.taover.util.bean.UtilResultInfo;
public class HttpHeartbeatServiceImpl implements HttpHeartbeatService {
public HttpHeartbeatServiceImpl() {}
/**
* 处理客户端心跳请求
* @param clientRequest
* @return
*/
@Override
public ResultInfo registryClient(HttpServletRequest request) {
try {
HeartbeatManager.registryClient(ClientRequest.createClientRequest(request));
return UtilResultInfo.getSuccess("");
}catch (Exception e) {
return UtilResultInfo.getFailure(e.getMessage());
}
}
/**
* 刷新客户端状态
*/
@Override
public void flushClientStatus() {
try {
HeartbeatManager.flushClientStatus();
}catch (Exception e) {
UtilLog.errorForException(e, this.getClass());
}
}
/**
* 向服务器发送心跳
*/
@Override
public void sendServerHeartbeat() {
try {
HeartbeatManager.sendServerHeartbeat();
}catch (Exception e) {
UtilLog.errorForException(e, this.getClass());
}
}
@Override
public void registryServers(String code, String servers, Integer fixRateSec, Integer maxWaitSec) throws Exception{
if(servers == null || servers.trim().equals("")) {
return;
}
String[] serverSplit = servers.split(",");
if(code == null || code.trim().equals("")) {
throw new Exception("property[heartbeat.clientCode] is blank");
}
if(fixRateSec == null) {
fixRateSec = Instance.DEFAULT_FIX_RATE_SEC;
}
if(maxWaitSec == null) {
maxWaitSec = Instance.DEFAULT_MAX_WAIT_SEC;
}
for(String serverItem: serverSplit) {
if(code == null || code.trim().equals("") || !serverItem.toLowerCase().startsWith("http")) {
continue;
}
try {
HeartbeatManager.registryServers(code, serverItem, fixRateSec, maxWaitSec);
}catch (Exception e) {
UtilLog.errorForException(e, this.getClass());
}
}
}
@Override
public void setReformData(String emailTo, String weixinWxid, String mobile) {
try {
HeartbeatManager.setReformData(emailTo, weixinWxid, mobile);
}catch (Exception e) {
UtilLog.errorForException(e, this.getClass());
}
}
}