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()); } } }