|
|
@ -3,7 +3,6 @@ package com.hnac.hzims.operational.config.ws; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.hnac.hzims.operational.config.vo.MessageParamVo; |
|
|
|
import com.hnac.hzims.operational.config.vo.MessageParamVo; |
|
|
|
import com.hnac.hzims.operational.station.service.IRealMonitorService; |
|
|
|
import com.hnac.hzims.operational.station.service.IRealMonitorService; |
|
|
|
import lombok.SneakyThrows; |
|
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springblade.core.tool.utils.ObjectUtil; |
|
|
|
import org.springblade.core.tool.utils.ObjectUtil; |
|
|
|
import org.springblade.core.tool.utils.StringUtil; |
|
|
|
import org.springblade.core.tool.utils.StringUtil; |
|
|
@ -14,25 +13,20 @@ import org.springframework.web.socket.WebSocketSession; |
|
|
|
import org.springframework.web.socket.handler.TextWebSocketHandler; |
|
|
|
import org.springframework.web.socket.handler.TextWebSocketHandler; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
|
import java.util.concurrent.Executors; |
|
|
|
|
|
|
|
import java.util.concurrent.ScheduledExecutorService; |
|
|
|
|
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @author ysj |
|
|
|
|
|
|
|
*/ |
|
|
|
@Slf4j |
|
|
|
@Slf4j |
|
|
|
public class MessageHandler extends TextWebSocketHandler { |
|
|
|
public class MessageHandler extends TextWebSocketHandler { |
|
|
|
|
|
|
|
|
|
|
|
private ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor(); |
|
|
|
private final Long defaultRealDataRefreshTime = 20000L; |
|
|
|
|
|
|
|
|
|
|
|
private Long defaultRealDataRefreshTime = 20000L; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private IRealMonitorService monitorService; |
|
|
|
private IRealMonitorService monitorService; |
|
|
|
|
|
|
|
|
|
|
|
private WebSocketSession session; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void afterConnectionEstablished(WebSocketSession session) { |
|
|
|
public void afterConnectionEstablished(WebSocketSession session) { |
|
|
|
this.session = session; |
|
|
|
|
|
|
|
String[] split = session.getUri().toString().split("/"); |
|
|
|
String[] split = session.getUri().toString().split("/"); |
|
|
|
String uid = split[split.length - 1]; |
|
|
|
String uid = split[split.length - 1]; |
|
|
|
SessionManager.add(uid, session); |
|
|
|
SessionManager.add(uid, session); |
|
|
@ -45,21 +39,17 @@ public class MessageHandler extends TextWebSocketHandler { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void afterConnectionClosed(WebSocketSession session, CloseStatus status) { |
|
|
|
public void afterConnectionClosed(WebSocketSession session, CloseStatus status) { |
|
|
|
SessionManager.removeAndClose(session.getId()); |
|
|
|
SessionManager.removeAndClose(session.getId()); |
|
|
|
if (SocketPool.pool.containsKey(session.getId())) { |
|
|
|
|
|
|
|
SocketPool.pool.remove(session.getId()); |
|
|
|
SocketPool.pool.remove(session.getId()); |
|
|
|
} |
|
|
|
|
|
|
|
log.info("sessionId: " + session.getId()); |
|
|
|
log.info("sessionId: " + session.getId()); |
|
|
|
log.info("uri: " + session.getUri()); |
|
|
|
log.info("uri: " + session.getUri()); |
|
|
|
log.info("session closed successful!"); |
|
|
|
log.info("session closed successful!"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception { |
|
|
|
public void handleTransportError(WebSocketSession session, Throwable exception) { |
|
|
|
SessionManager.removeAndClose(session.getId()); |
|
|
|
SessionManager.removeAndClose(session.getId()); |
|
|
|
if (SocketPool.pool.containsKey(session.getId())) { |
|
|
|
|
|
|
|
SocketPool.pool.remove(session.getId()); |
|
|
|
SocketPool.pool.remove(session.getId()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected void handleTextMessage(WebSocketSession session, TextMessage textMessage) throws IOException { |
|
|
|
protected void handleTextMessage(WebSocketSession session, TextMessage textMessage) throws IOException { |
|
|
|