|
|
@ -32,6 +32,8 @@ import javax.swing.*; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
|
import java.net.URI; |
|
|
|
import java.net.URI; |
|
|
|
import java.net.URL; |
|
|
|
import java.net.URL; |
|
|
|
|
|
|
|
import java.util.Timer; |
|
|
|
|
|
|
|
import java.util.TimerTask; |
|
|
|
|
|
|
|
|
|
|
|
public class DesignerSocketIO { |
|
|
|
public class DesignerSocketIO { |
|
|
|
|
|
|
|
|
|
|
@ -57,6 +59,8 @@ public class DesignerSocketIO { |
|
|
|
|
|
|
|
|
|
|
|
private static Socket socket = null; |
|
|
|
private static Socket socket = null; |
|
|
|
private static Status status = Status.Disconnected; |
|
|
|
private static Status status = Status.Disconnected; |
|
|
|
|
|
|
|
private static Timer disConnectHintTimer = null; |
|
|
|
|
|
|
|
private static long disConnectHintTimerDelay = 3000; |
|
|
|
//维护一个当前工作环境的uri列表
|
|
|
|
//维护一个当前工作环境的uri列表
|
|
|
|
private static String[] uri; |
|
|
|
private static String[] uri; |
|
|
|
//维护一个关于uri列表的计数器
|
|
|
|
//维护一个关于uri列表的计数器
|
|
|
@ -96,6 +100,7 @@ public class DesignerSocketIO { |
|
|
|
socket.on(WorkspaceConstants.CONFIG_MODIFY, modifyConfig); |
|
|
|
socket.on(WorkspaceConstants.CONFIG_MODIFY, modifyConfig); |
|
|
|
socket.on(Socket.EVENT_CONNECT_ERROR, failRetry); |
|
|
|
socket.on(Socket.EVENT_CONNECT_ERROR, failRetry); |
|
|
|
socket.on(Socket.EVENT_DISCONNECT, disConnectHint); |
|
|
|
socket.on(Socket.EVENT_DISCONNECT, disConnectHint); |
|
|
|
|
|
|
|
socket.on(Socket.EVENT_CONNECT, handleConnect); |
|
|
|
socket.connect(); |
|
|
|
socket.connect(); |
|
|
|
status = Status.Connected; |
|
|
|
status = Status.Connected; |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -154,10 +159,26 @@ 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() { |
|
|
|
private static final Emitter.Listener disConnectHint = new Emitter.Listener() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void call(Object... objects) { |
|
|
|
public void call(Object... objects) { |
|
|
|
|
|
|
|
FineLoggerFactory.getLogger().info("start disConnectHintTimer"); |
|
|
|
|
|
|
|
disConnectHintTimer = new Timer(); |
|
|
|
|
|
|
|
disConnectHintTimer.schedule(new TimerTask() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void run() { |
|
|
|
|
|
|
|
try { |
|
|
|
/* |
|
|
|
/* |
|
|
|
* todo 远程心跳断开不一定 socket 断开 和远程紧密相关的业务都绑定在心跳上,切换成心跳断开之后进行提醒, |
|
|
|
* todo 远程心跳断开不一定 socket 断开 和远程紧密相关的业务都绑定在心跳上,切换成心跳断开之后进行提醒, |
|
|
|
* socket 只用推日志和通知配置变更 |
|
|
|
* socket 只用推日志和通知配置变更 |
|
|
@ -167,6 +188,12 @@ public class DesignerSocketIO { |
|
|
|
showConnectionLostDialog(); |
|
|
|
showConnectionLostDialog(); |
|
|
|
} |
|
|
|
} |
|
|
|
status = Status.Disconnected; |
|
|
|
status = Status.Disconnected; |
|
|
|
|
|
|
|
} finally { |
|
|
|
|
|
|
|
disConnectHintTimer.cancel(); |
|
|
|
|
|
|
|
disConnectHintTimer = null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, disConnectHintTimerDelay); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|