节点升级 socket 锁调整

This commit is contained in:
bwcx_jzy 2021-09-18 23:01:25 +08:00
parent 410637e1eb
commit 33eb189ab0
2 changed files with 10 additions and 8 deletions

View File

@ -63,7 +63,7 @@ public class NodeClient extends WebSocketClient {
public void onMessage(String message) {
try {
// 不能并发向同一个客户端发送消息 @author jzy 2021-08-03
synchronized (NodeUpdateHandler.class) {
synchronized (session.getId()) {
session.sendMessage(new TextMessage(message));
}
} catch (IOException e) {

View File

@ -71,12 +71,14 @@ public class NodeUpdateHandler extends BaseProxyHandler {
Map<String, Object> attributes = session.getAttributes();
String url = NodeForward.getSocketUrl(model, NodeUrl.NodeUpdate, (UserModel) attributes.get("userInfo"));
// 连接节点
try {
NodeClient client = new NodeClient(url, model, session);
clientMap.put(model.getId(), client);
} catch (Exception e) {
DefaultSystemLog.getLog().error("创建插件端连接失败", e);
}
ThreadUtil.execute(() -> {
try {
NodeClient client = new NodeClient(url, model, session);
clientMap.put(model.getId(), client);
} catch (Exception e) {
DefaultSystemLog.getLog().error("创建插件端连接失败", e);
}
});
}
}
@ -190,7 +192,7 @@ public class NodeUpdateHandler extends BaseProxyHandler {
private void sendMsg(WebSocketMessageModel model, WebSocketSession session) {
try {
synchronized (NodeUpdateHandler.class) {
synchronized (session.getId()) {
session.sendMessage(new TextMessage(model.toString()));
}
} catch (Exception e) {