|
@@ -1,45 +1,30 @@
|
|
|
package com.fdkk.sxz.webApi.socketController;
|
|
|
|
|
|
|
|
|
-import cn.hutool.core.thread.ThreadUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
-import cn.hutool.json.JSONArray;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.fdkk.sxz.entity.ComponentModelUploadEntity;
|
|
|
-import com.fdkk.sxz.util.OkHttpUtils;
|
|
|
import com.fdkk.sxz.util.RedisUtil;
|
|
|
import com.fdkk.sxz.webApi.service.IComponentModelUploadService;
|
|
|
import io.netty.handler.codec.http.HttpHeaders;
|
|
|
import io.netty.handler.timeout.IdleStateEvent;
|
|
|
-import lombok.SneakyThrows;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import net.oschina.j2cache.CacheChannel;
|
|
|
-import net.oschina.j2cache.CacheObject;
|
|
|
-import net.oschina.j2cache.CacheProviderHolder;
|
|
|
-import net.oschina.j2cache.Command;
|
|
|
-import net.oschina.j2cache.cluster.ClusterPolicy;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
-import org.springframework.util.MultiValueMap;
|
|
|
import org.yeauty.annotation.*;
|
|
|
import org.yeauty.pojo.Session;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
import java.util.Map;
|
|
|
-import java.util.Properties;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
-import java.util.concurrent.ExecutorService;
|
|
|
-import java.util.concurrent.Future;
|
|
|
|
|
|
/**
|
|
|
* @author XieWj
|
|
|
*/
|
|
|
-@ServerEndpoint(path = "/wss/componentWSS/", port = "8889")
|
|
|
+@ServerEndpoint(path = "/wss/componentWSS/", port = "${ws.port}")
|
|
|
@Slf4j
|
|
|
public class ComponentSocket {
|
|
|
|
|
@@ -47,7 +32,7 @@ public class ComponentSocket {
|
|
|
private String mainUrl;
|
|
|
|
|
|
|
|
|
- private static Map<String, ComponentSocket> ComponentSocketMap = new ConcurrentHashMap<>();
|
|
|
+ private static Map<String, ComponentSocket> componentSocketMap = new ConcurrentHashMap<>();
|
|
|
|
|
|
@Autowired
|
|
|
private RedisUtil redisUtil;
|
|
@@ -79,7 +64,6 @@ public class ComponentSocket {
|
|
|
@OnOpen
|
|
|
public void onOpen(Session session, HttpHeaders headers, @PathVariable Map pathMap) {
|
|
|
log.info("new connection, sessionId-{},Host-{}", session.id(), headers.get("Host"));
|
|
|
- isStop = true;
|
|
|
}
|
|
|
|
|
|
@OnClose
|
|
@@ -94,7 +78,9 @@ public class ComponentSocket {
|
|
|
@OnError
|
|
|
public void onError(Session session, Throwable throwable) {
|
|
|
throwable.printStackTrace();
|
|
|
- thread.interrupt();
|
|
|
+ if (thread != null) {
|
|
|
+ thread.interrupt();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public void toDo(Session session, String message) throws InterruptedException {
|
|
@@ -106,8 +92,8 @@ public class ComponentSocket {
|
|
|
if (session.isOpen()) {
|
|
|
String status = data.getStr("status");
|
|
|
if (StrUtil.equals(status, "query")) {
|
|
|
- if (redisUtil.hasKey("componetUploadStatus::id::" + id)) {
|
|
|
- String ObjStatus = redisUtil.get("componetUploadStatus::id::" + id);
|
|
|
+ if (redisUtil.hasKey("componentUploadStatus:id:" + id)) {
|
|
|
+ String ObjStatus = redisUtil.get("componentUploadStatus:id:" + id);
|
|
|
if (StrUtil.equals(ObjStatus, "done")) {
|
|
|
extracted(session, data, id);
|
|
|
return;
|
|
@@ -125,14 +111,14 @@ public class ComponentSocket {
|
|
|
}
|
|
|
|
|
|
if (Thread.currentThread().isInterrupted()) {
|
|
|
- log.info("i has interputed");
|
|
|
+ log.info("i has isInterrupted");
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
//连接关闭直接return
|
|
|
isStop = false;
|
|
|
- ComponentSocketMap.remove("id" + data.getInt("id") + "session" + session.id());
|
|
|
+ componentSocketMap.remove("id" + data.getInt("id") + "session" + session.id());
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
@@ -148,7 +134,7 @@ public class ComponentSocket {
|
|
|
res.set("code", 0);
|
|
|
session.sendText(res.toString());
|
|
|
//连接关闭直接return
|
|
|
- ComponentSocketMap.remove("id" + data.getInt("id") + "session" + session.id());
|
|
|
+ componentSocketMap.remove("id" + data.getInt("id") + "session" + session.id());
|
|
|
Thread.yield();
|
|
|
}
|
|
|
|
|
@@ -162,8 +148,8 @@ public class ComponentSocket {
|
|
|
JSONObject data = JSONUtil.parseObj(message);
|
|
|
res.set("msg", "is Json");
|
|
|
isStop = true;
|
|
|
- if (!ComponentSocketMap.containsKey("id" + data.getInt("id") + "session" + session.id())) {
|
|
|
- ComponentSocketMap.put("id" + data.getInt("id") + "session" + session.id(), this);
|
|
|
+ if (!componentSocketMap.containsKey("id" + data.getInt("id") + "session" + session.id())) {
|
|
|
+ componentSocketMap.put("id" + data.getInt("id") + "session" + session.id(), this);
|
|
|
thread = new Thread(() -> {
|
|
|
try {
|
|
|
toDo(session, message);
|