|
|
|
@ -19,6 +19,7 @@ import com.fr.workspace.Workspace;
|
|
|
|
|
import com.fr.workspace.WorkspaceEvent; |
|
|
|
|
import com.fr.workspace.base.WorkspaceConstants; |
|
|
|
|
import com.fr.workspace.connect.WorkspaceConnectionInfo; |
|
|
|
|
import com.fr.workspace.engine.channel.WorkspaceChannelFactory; |
|
|
|
|
import com.fr.workspace.engine.exception.WorkspaceConnectionException; |
|
|
|
|
|
|
|
|
|
import javax.swing.JOptionPane; |
|
|
|
@ -36,18 +37,20 @@ public class RPCConnectHandlerCenter {
|
|
|
|
|
private static volatile boolean alerting = false; |
|
|
|
|
private static final int TIMEOUT = 5000; |
|
|
|
|
|
|
|
|
|
private static Listener<Workspace> listener = new Listener<Workspace>() { |
|
|
|
|
@Override |
|
|
|
|
public void on(Event event, Workspace workspace) { |
|
|
|
|
//暂时先不做重连处理,3次RPC连接失败后提示切换工作目录
|
|
|
|
|
showRPCDisconnectDialog(); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 开启事件监听 |
|
|
|
|
*/ |
|
|
|
|
public static void startListener() { |
|
|
|
|
if (!WorkContext.getCurrent().isLocal()) { |
|
|
|
|
EventDispatcher.listen(WorkspaceEvent.LostConnect, new Listener<Workspace>() { |
|
|
|
|
@Override |
|
|
|
|
public void on(Event event, Workspace workspace) { |
|
|
|
|
//暂时先不做重连处理,3次RPC连接失败后提示切换工作目录
|
|
|
|
|
showRPCDisconnectDialog(); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
EventDispatcher.listen(WorkspaceEvent.LostConnect, listener); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -59,12 +62,27 @@ public class RPCConnectHandlerCenter {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 连接检测,从DesignerSocketIO中移过来的 |
|
|
|
|
* RPC连接测试 |
|
|
|
|
* |
|
|
|
|
* @param info 连接信息 |
|
|
|
|
* @return 是否连接成功 |
|
|
|
|
*/ |
|
|
|
|
public static boolean checkRPCConnect(WorkspaceConnectionInfo info) { |
|
|
|
|
try { |
|
|
|
|
return WorkspaceChannelFactory.testConnection(info); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
FineLoggerFactory.getLogger().error(e, e.getMessage()); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* http连接检测,从DesignerSocketIO中移过来的,先保留着 |
|
|
|
|
* |
|
|
|
|
* @param info 连接信息 |
|
|
|
|
* @return 是否连接成功 |
|
|
|
|
*/ |
|
|
|
|
public static boolean checkHttpConnect(WorkspaceConnectionInfo info) { |
|
|
|
|
CloseableHttpClient httpclient = HttpClients.createDefault(); |
|
|
|
|
HttpGet httpGet = new HttpGet(StableUtils.pathJoin(info.getUrl(), WorkspaceConstants.CONTROLLER_PREFIX, WorkspaceConstants.VT)); |
|
|
|
|
RequestConfig requestConfig = RequestConfig |
|
|
|
@ -129,4 +147,13 @@ public class RPCConnectHandlerCenter {
|
|
|
|
|
private static boolean isErrorStatus(int status) { |
|
|
|
|
return status >= 500 && status <= 600; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 停止事件监听 |
|
|
|
|
*/ |
|
|
|
|
public static void stopListener() { |
|
|
|
|
if (!WorkContext.getCurrent().isLocal()) { |
|
|
|
|
EventDispatcher.stopListen(listener); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|