Commit 4a60f7d1 authored by duanruiming's avatar duanruiming

[update] 信号服务优化

parent be18693d
......@@ -10,13 +10,11 @@ import net.wanji.web.common.util.date.DateStyle;
import net.wanji.web.websocket.WebSocketServer;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
/**
......@@ -37,26 +35,28 @@ public class SystemServiceStatusTask {
@Scheduled(fixedRate = 1 * 60 * 1000)
public void telnetStatus() throws Exception {
for (SystemServiceStatusDTO dto : sysList) {
String ip = dto.getIp();
int port = dto.getPort();
int timeout = dto.getTimeout();
int lastStatus = dto.getStatus();
int currentStatus = SocketUtil.telnet(ip, port, timeout) == true ? 0 : 1;
if (currentStatus != lastStatus) {
dto.setStatus(currentStatus);
}
// 如果正常 每分钟更新状态; 异常 更新异常初始状态
if (StringUtils.isBlank(dto.getStartTime()) || dto.getStatus() == 0) {
LocalDateTime now = LocalDateTime.now();
String format = now.format(DateTimeFormatter.ofPattern(DateStyle.YYYY_MM_DD_HH_MM_SS.getValue()));
dto.setStartTime(format);
dto.setStartDate(new Date());
Set<WebSocketServer> webSocketSet = WebSocketServer.getWebSocketSet(Constant.WEBSOCKET_TOPIC_SYS_SERVICE_STATUS);
if (!CollectionUtils.isEmpty(webSocketSet)) {
for (SystemServiceStatusDTO dto : sysList) {
String ip = dto.getIp();
int port = dto.getPort();
int timeout = dto.getTimeout();
int lastStatus = dto.getStatus();
int currentStatus = SocketUtil.telnet(ip, port, timeout) == true ? 0 : 1;
if (currentStatus != lastStatus) {
dto.setStatus(currentStatus);
}
// 如果正常 每分钟更新状态; 异常 更新异常初始状态
if (StringUtils.isBlank(dto.getStartTime()) || dto.getStatus() == 0) {
LocalDateTime now = LocalDateTime.now();
String format = now.format(DateTimeFormatter.ofPattern(DateStyle.YYYY_MM_DD_HH_MM_SS.getValue()));
dto.setStartTime(format);
dto.setStartDate(new Date());
}
}
List<SystemServiceStatusDTO> sort = sysList.stream().sorted(Comparator.comparing(SystemServiceStatusDTO::getStartDate)).collect(Collectors.toList());
WebSocketServer.sendTopicInfo2All(JSON.toJSONString(sort), Constant.WEBSOCKET_TOPIC_SYS_SERVICE_STATUS);
}
List<SystemServiceStatusDTO> sort = sysList.stream().sorted(Comparator.comparing(SystemServiceStatusDTO::getStartDate)).collect(Collectors.toList());
WebSocketServer.sendInfo2All(JSON.toJSONString(sort), Constant.WEBSOCKET_TOPIC_SYS_SERVICE_STATUS);
}
}
......@@ -170,7 +170,7 @@ public class WebSocketServer {
* @param topic
* @throws IOException
*/
public static void sendInfo2All(String message, String topic) throws IOException {
public static void sendTopicInfo2All(String message, String topic) throws IOException {
if (StringUtils.isNotBlank(topic) && webSocketMap.containsKey(topic)) {
try {
Set<WebSocketServer> socketSets = webSocketMap.get(topic);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment