Browse Source

Pull request #6476: REPORT-57521 远程设计时websocket断开情况下的提示优化

Merge in DESIGN/design from ~FANGLEI/design10.0:release/11.0 to release/11.0

* commit '1f78cadeeba88faa4aac5f6f94bf5d3d2f3e42f7':
  REPORT-57521 切换环境的代码放到edt线程
  REPORT-57521
  REPORT-57521
  REPORT-57521 去掉websocket断开提示延迟
  REPORT-57521
  REPORT-57521 远程设计时websocket断开情况下的提示优化
bugfix/11.0
fanglei 3 years ago
parent
commit
7e6f2de035
  1. 88
      designer-realize/src/main/java/com/fr/design/mainframe/socketio/DesignerSocketIO.java

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

@ -3,11 +3,14 @@ package com.fr.design.mainframe.socketio;
import com.fr.config.RemoteConfigEvent; import com.fr.config.RemoteConfigEvent;
import com.fr.decision.webservice.utils.DecisionServiceConstants; import com.fr.decision.webservice.utils.DecisionServiceConstants;
import com.fr.design.DesignerEnvManager; import com.fr.design.DesignerEnvManager;
import com.fr.design.EnvChangeEntrance;
import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.env.DesignerWorkspaceInfo; import com.fr.design.env.DesignerWorkspaceInfo;
import com.fr.design.env.DesignerWorkspaceInfoContext; import com.fr.design.env.DesignerWorkspaceInfoContext;
import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ilable.UILabel;
import com.fr.design.i18n.Toolkit; import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.loghandler.DesignerLogger; import com.fr.design.mainframe.loghandler.DesignerLogger;
import com.fr.design.mainframe.share.ui.base.MouseClickListener; import com.fr.design.mainframe.share.ui.base.MouseClickListener;
import com.fr.design.mainframe.toast.DesignerToastMsgUtil; import com.fr.design.mainframe.toast.DesignerToastMsgUtil;
@ -21,10 +24,16 @@ import com.fr.log.FineLoggerFactory;
import com.fr.report.RemoteDesignConstants; import com.fr.report.RemoteDesignConstants;
import com.fr.serialization.SerializerHelper; import com.fr.serialization.SerializerHelper;
import com.fr.stable.ArrayUtils; import com.fr.stable.ArrayUtils;
import com.fr.stable.StableUtils;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import com.fr.third.apache.log4j.spi.LoggingEvent; import com.fr.third.apache.log4j.spi.LoggingEvent;
import com.fr.third.org.apache.http.client.config.RequestConfig;
import com.fr.third.org.apache.http.client.methods.CloseableHttpResponse;
import com.fr.third.org.apache.http.client.methods.HttpGet;
import com.fr.third.org.apache.http.conn.ssl.NoopHostnameVerifier; import com.fr.third.org.apache.http.conn.ssl.NoopHostnameVerifier;
import com.fr.third.org.apache.http.conn.ssl.TrustSelfSignedStrategy; import com.fr.third.org.apache.http.conn.ssl.TrustSelfSignedStrategy;
import com.fr.third.org.apache.http.impl.client.CloseableHttpClient;
import com.fr.third.org.apache.http.impl.client.HttpClients;
import com.fr.third.org.apache.http.ssl.SSLContexts; import com.fr.third.org.apache.http.ssl.SSLContexts;
import com.fr.web.WebSocketConfig; import com.fr.web.WebSocketConfig;
import com.fr.web.socketio.WebSocketProtocol; import com.fr.web.socketio.WebSocketProtocol;
@ -39,7 +48,9 @@ import io.socket.emitter.Emitter;
import javax.net.ssl.SSLContext; import javax.net.ssl.SSLContext;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.JOptionPane;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.UIManager;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Color; import java.awt.Color;
import java.awt.Cursor; import java.awt.Cursor;
@ -52,7 +63,6 @@ import java.net.URL;
import java.security.KeyStore; import java.security.KeyStore;
import java.util.Arrays; import java.util.Arrays;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask;
public class DesignerSocketIO { public class DesignerSocketIO {
@ -69,6 +79,7 @@ public class DesignerSocketIO {
private static Status status = Status.Disconnected; private static Status status = Status.Disconnected;
private static Timer disConnectHintTimer = null; private static Timer disConnectHintTimer = null;
private static long disConnectHintTimerDelay = 3000; private static long disConnectHintTimerDelay = 3000;
private static final int TIMEOUT = 5000;
//维护一个当前工作环境的uri列表 //维护一个当前工作环境的uri列表
private static String[] uri; private static String[] uri;
//维护一个关于uri列表的计数器 //维护一个关于uri列表的计数器
@ -195,7 +206,7 @@ public class DesignerSocketIO {
private static final Emitter.Listener failRetry = new Emitter.Listener() { private static final Emitter.Listener failRetry = new Emitter.Listener() {
@Override @Override
public void call(Object... args) { public void call(Object... args) {
showConnectionLostDialog(); showSocketDisconnectToast();
printLog(args, PrintEventLogImpl.WARN, "failed args: {}"); printLog(args, PrintEventLogImpl.WARN, "failed args: {}");
status = Status.Disconnecting; status = Status.Disconnecting;
socket.close(); socket.close();
@ -234,30 +245,27 @@ public class DesignerSocketIO {
@Override @Override
public void call(Object... objects) { public void call(Object... objects) {
FineLoggerFactory.getLogger().info("start disConnectHintTimer"); FineLoggerFactory.getLogger().info("start disConnectHintTimer");
disConnectHintTimer = new Timer(); /*
disConnectHintTimer.schedule(new TimerTask() { * todo 远程心跳断开不一定 socket 断开 和远程紧密相关的业务都绑定在心跳上切换成心跳断开之后进行提醒
@Override * socket 只用推日志和通知配置变更
public void run() { */
try { printLog(objects, PrintEventLogImpl.ERROR, "disConnected args: {}");
/* if (status != Status.Disconnecting) {
* todo 远程心跳断开不一定 socket 断开 和远程紧密相关的业务都绑定在心跳上切换成心跳断开之后进行提醒 dealWithSocketDisconnect();
* socket 只用推日志和通知配置变更 }
*/ status = Status.Disconnected;
printLog(objects, PrintEventLogImpl.ERROR, "disConnected args: {}");
if (status != Status.Disconnecting) {
showConnectionLostDialog();
}
status = Status.Disconnected;
} finally {
disConnectHintTimer.cancel();
disConnectHintTimer = null;
}
}
}, disConnectHintTimerDelay);
} }
}; };
private static void showConnectionLostDialog() { private static void dealWithSocketDisconnect() {
if (checkRPCConnect()) {
showSocketDisconnectToast();
} else {
showRPCDisconnectDialog();
}
}
private static void showSocketDisconnectToast() {
try { try {
UIUtil.invokeLaterIfNeeded(new Runnable() { UIUtil.invokeLaterIfNeeded(new Runnable() {
@Override @Override
@ -293,6 +301,40 @@ public class DesignerSocketIO {
return jPanel; return jPanel;
} }
private static void showRPCDisconnectDialog() {
UIUtil.invokeLaterIfNeeded(new Runnable() {
@Override
public void run() {
FineJOptionPane.showMessageDialog(
DesignerContext.getDesignerFrame(),
Toolkit.i18nText("Fine-Design_Basic_Remote_Disconnected"),
UIManager.getString("OptionPane.messageDialogTitle"),
JOptionPane.ERROR_MESSAGE,
UIManager.getIcon("OptionPane.errorIcon"));
EnvChangeEntrance.getInstance().chooseEnv();
}
});
}
private static boolean checkRPCConnect() {
CloseableHttpClient httpclient = HttpClients.createDefault();
WorkspaceConnectionInfo info = getConnectionInfo();
HttpGet httpGet = new HttpGet(StableUtils.pathJoin(info.getUrl(), WorkspaceConstants.CONTROLLER_PREFIX, WorkspaceConstants.VT));
RequestConfig requestConfig = RequestConfig
.custom()
.setConnectTimeout(TIMEOUT)
.setConnectionRequestTimeout(TIMEOUT)
.build();
httpGet.setConfig(requestConfig);
try {
CloseableHttpResponse response = httpclient.execute(httpGet);
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e, e.getMessage());
return false;
}
return true;
}
//配置变更监听器 //配置变更监听器
private static final Emitter.Listener modifyConfig = new Emitter.Listener() { private static final Emitter.Listener modifyConfig = new Emitter.Listener() {
@Override @Override

Loading…
Cancel
Save