use of io.jpom.socket.client.NodeClient in project Jpom by dromara.
the class NodeUpdateHandler method pullNodeList.
private void pullNodeList(WebSocketSession session, String ids) {
List<String> split = StrUtil.split(ids, StrUtil.COMMA);
List<NodeModel> nodeModelList = nodeService.listById(split);
if (nodeModelList == null) {
this.onError(session, "没有查询到节点信息:" + ids);
return;
}
for (NodeModel model : nodeModelList) {
NodeClient nodeClient = clientMap.get(model.getId());
if (nodeClient != null) {
//
nodeClient.close();
}
Map<String, Object> attributes = session.getAttributes();
String url = NodeForward.getSocketUrl(model, NodeUrl.NodeUpdate, (UserModel) attributes.get("userInfo"));
// 连接节点
ThreadUtil.execute(() -> {
try {
NodeClient client = new NodeClient(url, model, session);
clientMap.put(model.getId(), client);
} catch (Exception e) {
DefaultSystemLog.getLog().error("创建插件端连接失败", e);
}
});
}
}
use of io.jpom.socket.client.NodeClient in project Jpom by dromara.
the class NodeUpdateHandler method destroy.
@Override
public void destroy(WebSocketSession session) {
for (String key : clientMap.keySet()) {
NodeClient client = clientMap.get(key);
if (client.isOpen()) {
client.close();
}
}
clientMap.clear();
//
super.destroy(session);
}
use of io.jpom.socket.client.NodeClient in project Jpom by dromara.
the class NodeUpdateHandler method updateNodeItem.
private void updateNodeItem(String id, WebSocketSession session, AgentFileModel agentFileModel, boolean http) {
try {
NodeModel node = nodeService.getByKey(id);
if (node == null) {
this.onError(session, "没有对应的节点:" + id);
return;
}
NodeClient client = clientMap.get(node.getId());
if (client == null) {
this.onError(session, "对应的插件端还没有被初始化:" + id);
return;
}
if (client.isOpen()) {
if (http) {
this.updateNodeItemHttp(node, session, agentFileModel);
} else {
this.updateNodeItemWebSocket(client, id, session, agentFileModel);
}
} else {
this.onError(session, "节点连接丢失");
}
} catch (Exception e) {
DefaultSystemLog.getLog().error("升级失败:" + id, e);
this.onError(session, "节点升级失败:" + e.getMessage());
}
}
Aggregations