Commit 4a60f7d1 authored by duanruiming's avatar duanruiming

[update] 信号服务优化

parent be18693d
...@@ -10,13 +10,11 @@ import net.wanji.web.common.util.date.DateStyle; ...@@ -10,13 +10,11 @@ import net.wanji.web.common.util.date.DateStyle;
import net.wanji.web.websocket.WebSocketServer; import net.wanji.web.websocket.WebSocketServer;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.*;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
...@@ -37,26 +35,28 @@ public class SystemServiceStatusTask { ...@@ -37,26 +35,28 @@ public class SystemServiceStatusTask {
@Scheduled(fixedRate = 1 * 60 * 1000) @Scheduled(fixedRate = 1 * 60 * 1000)
public void telnetStatus() throws Exception { public void telnetStatus() throws Exception {
Set<WebSocketServer> webSocketSet = WebSocketServer.getWebSocketSet(Constant.WEBSOCKET_TOPIC_SYS_SERVICE_STATUS);
for (SystemServiceStatusDTO dto : sysList) { if (!CollectionUtils.isEmpty(webSocketSet)) {
String ip = dto.getIp(); for (SystemServiceStatusDTO dto : sysList) {
int port = dto.getPort(); String ip = dto.getIp();
int timeout = dto.getTimeout(); int port = dto.getPort();
int lastStatus = dto.getStatus(); int timeout = dto.getTimeout();
int currentStatus = SocketUtil.telnet(ip, port, timeout) == true ? 0 : 1; int lastStatus = dto.getStatus();
if (currentStatus != lastStatus) { int currentStatus = SocketUtil.telnet(ip, port, timeout) == true ? 0 : 1;
dto.setStatus(currentStatus); if (currentStatus != lastStatus) {
} dto.setStatus(currentStatus);
// 如果正常 每分钟更新状态; 异常 更新异常初始状态 }
if (StringUtils.isBlank(dto.getStartTime()) || dto.getStatus() == 0) { // 如果正常 每分钟更新状态; 异常 更新异常初始状态
LocalDateTime now = LocalDateTime.now(); if (StringUtils.isBlank(dto.getStartTime()) || dto.getStatus() == 0) {
String format = now.format(DateTimeFormatter.ofPattern(DateStyle.YYYY_MM_DD_HH_MM_SS.getValue())); LocalDateTime now = LocalDateTime.now();
dto.setStartTime(format); String format = now.format(DateTimeFormatter.ofPattern(DateStyle.YYYY_MM_DD_HH_MM_SS.getValue()));
dto.setStartDate(new Date()); 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 { ...@@ -170,7 +170,7 @@ public class WebSocketServer {
* @param topic * @param topic
* @throws IOException * @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)) { if (StringUtils.isNotBlank(topic) && webSocketMap.containsKey(topic)) {
try { try {
Set<WebSocketServer> socketSets = webSocketMap.get(topic); 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