Browse Source

Merge pull request #5039 in DESIGN/design from feature/10.0 to research/10.0

* commit '510222a92aa4ba6afb49210b444b23f1b8fdf274':
  REPORT-53900 远程设计自动断开
research/10.0
superman 3 years ago
parent
commit
dff6f1d5fa
  1. 53
      designer-realize/src/main/java/com/fr/design/mainframe/socketio/DesignerSocketIO.java

53
designer-realize/src/main/java/com/fr/design/mainframe/socketio/DesignerSocketIO.java

@ -32,6 +32,8 @@ import javax.swing.*;
import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.util.Timer;
import java.util.TimerTask;
public class DesignerSocketIO {
@ -45,7 +47,7 @@ public class DesignerSocketIO {
if (DesignerEnvManager.getEnvManager().isHttps()) {
showConnectionLostDialog();
}
}
}
});
}
@ -57,6 +59,8 @@ public class DesignerSocketIO {
private static Socket socket = null;
private static Status status = Status.Disconnected;
private static Timer disConnectHintTimer = null;
private static long disConnectHintTimerDelay = 3000;
//维护一个当前工作环境的uri列表
private static String[] uri;
//维护一个关于uri列表的计数器
@ -87,18 +91,19 @@ public class DesignerSocketIO {
createSocket();
}
private static void createSocket(){
private static void createSocket() {
//根据uri和计数器建立连接,并注册监听
try {
if(count<uri.length) {
if (count < uri.length) {
socket = IO.socket(new URI(uri[count]));
socket.on(WorkspaceConstants.WS_LOGRECORD, printLog);
socket.on(WorkspaceConstants.CONFIG_MODIFY, modifyConfig);
socket.on(Socket.EVENT_CONNECT_ERROR, failRetry);
socket.on(Socket.EVENT_DISCONNECT, disConnectHint);
socket.on(Socket.EVENT_CONNECT, handleConnect);
socket.connect();
status = Status.Connected;
}else {
} else {
//表示所有的uri都连接不成功
FineLoggerFactory.getLogger().warn("All uris failed to connect");
}
@ -154,19 +159,41 @@ public class DesignerSocketIO {
}
};
private static final Emitter.Listener handleConnect = new Emitter.Listener() {
@Override
public void call(Object... objects) {
if (disConnectHintTimer != null) {
FineLoggerFactory.getLogger().info("cancel disConnectHintTimer");
disConnectHintTimer.cancel();
}
}
};
//断开连接提醒监听器
private static final Emitter.Listener disConnectHint = new Emitter.Listener() {
@Override
public void call(Object... objects) {
/*
* todo 远程心跳断开不一定 socket 断开 和远程紧密相关的业务都绑定在心跳上切换成心跳断开之后进行提醒
* socket 只用推日志和通知配置变更
*/
FineLoggerFactory.getLogger().error("disConnected args: {}", Arrays.toString(objects));
if (status != Status.Disconnecting) {
showConnectionLostDialog();
}
status = Status.Disconnected;
FineLoggerFactory.getLogger().info("start disConnectHintTimer");
disConnectHintTimer = new Timer();
disConnectHintTimer.schedule(new TimerTask() {
@Override
public void run() {
try {
/*
* todo 远程心跳断开不一定 socket 断开 和远程紧密相关的业务都绑定在心跳上切换成心跳断开之后进行提醒
* socket 只用推日志和通知配置变更
*/
FineLoggerFactory.getLogger().error("disConnected args: {}", Arrays.toString(objects));
if (status != Status.Disconnecting) {
showConnectionLostDialog();
}
status = Status.Disconnected;
} finally {
disConnectHintTimer.cancel();
disConnectHintTimer = null;
}
}
}, disConnectHintTimerDelay);
}
};

Loading…
Cancel
Save