|
@@ -8,11 +8,14 @@ import java.util.concurrent.ExecutorService;
|
|
import java.util.concurrent.LinkedBlockingQueue;
|
|
import java.util.concurrent.LinkedBlockingQueue;
|
|
import java.util.concurrent.ThreadPoolExecutor;
|
|
import java.util.concurrent.ThreadPoolExecutor;
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.persagy.ibms.core.data.SceneDataObject;
|
|
import com.persagy.ibms.core.data.SceneDataObject;
|
|
import com.persagy.ibms.core.data.SceneDataSet;
|
|
import com.persagy.ibms.core.data.SceneDataSet;
|
|
import com.persagy.ibms.core.data.SceneDataValue;
|
|
import com.persagy.ibms.core.data.SceneDataValue;
|
|
|
|
+import com.persagy.ibms.core.util.ComputeUtil;
|
|
|
|
+import com.persagy.ibms.core.util.PathUtil;
|
|
import com.persagy.ibms.core.util.RWDUtil;
|
|
import com.persagy.ibms.core.util.RWDUtil;
|
|
import com.persagy.ibms.data.sdk.util.ObjectInfo;
|
|
import com.persagy.ibms.data.sdk.util.ObjectInfo;
|
|
import com.persagy.ibms.data.sdk.util.RepositoryContainer;
|
|
import com.persagy.ibms.data.sdk.util.RepositoryContainer;
|
|
@@ -35,6 +38,9 @@ public class WebSocketUtil {
|
|
|
|
|
|
public static Map<String, Map<String, Object>> id2objId2Tag = new ConcurrentHashMap<String, Map<String, Object>>();
|
|
public static Map<String, Map<String, Object>> id2objId2Tag = new ConcurrentHashMap<String, Map<String, Object>>();
|
|
|
|
|
|
|
|
+ public static Map<String, Map<String, Boolean>> path2idList = new ConcurrentHashMap<String, Map<String, Boolean>>();
|
|
|
|
+ public static Map<String, Map<String, Boolean>> id2pathList = new ConcurrentHashMap<String, Map<String, Boolean>>();
|
|
|
|
+
|
|
public static synchronized void ProcessReceive(String id, Object ContentJSON) {
|
|
public static synchronized void ProcessReceive(String id, Object ContentJSON) {
|
|
ProcessDisconnected(id);
|
|
ProcessDisconnected(id);
|
|
|
|
|
|
@@ -45,30 +51,37 @@ public class WebSocketUtil {
|
|
id2objInfoIdList.put(id, objInfoIdList);
|
|
id2objInfoIdList.put(id, objInfoIdList);
|
|
Map<String, Object> objId2Tag = new ConcurrentHashMap<String, Object>();
|
|
Map<String, Object> objId2Tag = new ConcurrentHashMap<String, Object>();
|
|
id2objId2Tag.put(id, objId2Tag);
|
|
id2objId2Tag.put(id, objId2Tag);
|
|
|
|
+ Map<String, Boolean> pathList = new ConcurrentHashMap<String, Boolean>();
|
|
|
|
+ id2pathList.put(id, pathList);
|
|
|
|
+
|
|
JSONArray objArray = (JSONArray) ContentJSON;
|
|
JSONArray objArray = (JSONArray) ContentJSON;
|
|
for (int i = 0; i < objArray.size(); i++) {
|
|
for (int i = 0; i < objArray.size(); i++) {
|
|
JSONObject objJSON = objArray.getJSONObject(i);
|
|
JSONObject objJSON = objArray.getJSONObject(i);
|
|
- String objId = (String) objJSON.get("objId");
|
|
|
|
- if (objJSON.containsKey("websocket_tag")) {
|
|
|
|
- objId2Tag.put(objId, objJSON.get("websocket_tag"));
|
|
|
|
- }
|
|
|
|
- if (objJSON.containsKey("infoCodeArray")) {
|
|
|
|
- JSONArray infoCodeArray = (JSONArray) objJSON.get("infoCodeArray");
|
|
|
|
- for (int ii = 0; ii < infoCodeArray.size(); ii++) {
|
|
|
|
- String infoCode = (String) infoCodeArray.get(ii);
|
|
|
|
- String objInfoId = objId + "-" + infoCode;
|
|
|
|
- if (!objInfoId2idList.containsKey(objInfoId)) {
|
|
|
|
- objInfoId2idList.put(objInfoId, new ConcurrentHashMap<String, Boolean>());
|
|
|
|
- }
|
|
|
|
- objInfoId2idList.get(objInfoId).put(id, true);
|
|
|
|
- objInfoIdList.put(objInfoId, true);
|
|
|
|
|
|
+ // 对象IOT订阅
|
|
|
|
+ if (objJSON.containsKey("objId")) {
|
|
|
|
+ String objId = (String) objJSON.get("objId");
|
|
|
|
+ if (objJSON.containsKey("websocket_tag")) {
|
|
|
|
+ objId2Tag.putIfAbsent(objId, objJSON.get("websocket_tag"));
|
|
}
|
|
}
|
|
- } else {
|
|
|
|
- if (!objId2idList.containsKey(objId)) {
|
|
|
|
- objId2idList.put(objId, new ConcurrentHashMap<String, Boolean>());
|
|
|
|
|
|
+ if (objJSON.containsKey("infoCodeArray")) {
|
|
|
|
+ JSONArray infoCodeArray = (JSONArray) objJSON.get("infoCodeArray");
|
|
|
|
+ for (int ii = 0; ii < infoCodeArray.size(); ii++) {
|
|
|
|
+ String infoCode = (String) infoCodeArray.get(ii);
|
|
|
|
+ String objInfoId = objId + "-" + infoCode;
|
|
|
|
+ objInfoId2idList.putIfAbsent(objInfoId, new ConcurrentHashMap<String, Boolean>());
|
|
|
|
+ objInfoId2idList.get(objInfoId).putIfAbsent(id, true);
|
|
|
|
+ objInfoIdList.putIfAbsent(objInfoId, true);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ objId2idList.putIfAbsent(objId, new ConcurrentHashMap<String, Boolean>());
|
|
|
|
+ objId2idList.get(objId).putIfAbsent(id, true);
|
|
|
|
+ objIdList.putIfAbsent(objId, true);
|
|
}
|
|
}
|
|
- objId2idList.get(objId).put(id, true);
|
|
|
|
- objIdList.put(objId, true);
|
|
|
|
|
|
+ } else if (objJSON.containsKey("path")) {
|
|
|
|
+ JSONArray pathArray = (JSONArray) objJSON.get("path");
|
|
|
|
+ pathList.putIfAbsent(pathArray.toJSONString(), true);
|
|
|
|
+ path2idList.putIfAbsent(pathArray.toJSONString(), new ConcurrentHashMap<String, Boolean>());
|
|
|
|
+ path2idList.get(pathArray.toJSONString()).putIfAbsent(id, true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -76,29 +89,29 @@ public class WebSocketUtil {
|
|
}
|
|
}
|
|
|
|
|
|
public static synchronized void ProcessDisconnected(String id) {
|
|
public static synchronized void ProcessDisconnected(String id) {
|
|
- for (String key : id2objIdList.keySet()) {
|
|
|
|
- Map<String, Boolean> objIdList = id2objIdList.get(key);
|
|
|
|
- for (String objId : objIdList.keySet()) {
|
|
|
|
- Map<String, Boolean> idList = objId2idList.get(objId);
|
|
|
|
- if (idList.containsKey(id)) {
|
|
|
|
- idList.remove(id);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ for (String objId : objId2idList.keySet()) {
|
|
|
|
+ Map<String, Boolean> idList = objId2idList.get(objId);
|
|
|
|
+ idList.remove(id);
|
|
}
|
|
}
|
|
id2objIdList.remove(id);
|
|
id2objIdList.remove(id);
|
|
|
|
|
|
- for (String key : id2objInfoIdList.keySet()) {
|
|
|
|
- Map<String, Boolean> objInfoIdList = id2objInfoIdList.get(key);
|
|
|
|
- for (String objInfoId : objInfoIdList.keySet()) {
|
|
|
|
- Map<String, Boolean> idList = objInfoId2idList.get(objInfoId);
|
|
|
|
- if (idList.containsKey(id)) {
|
|
|
|
- idList.remove(id);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ for (String objInfoId : objInfoId2idList.keySet()) {
|
|
|
|
+ Map<String, Boolean> idList = objInfoId2idList.get(objInfoId);
|
|
|
|
+ idList.remove(id);
|
|
}
|
|
}
|
|
id2objInfoIdList.remove(id);
|
|
id2objInfoIdList.remove(id);
|
|
|
|
|
|
id2objId2Tag.remove(id);
|
|
id2objId2Tag.remove(id);
|
|
|
|
+
|
|
|
|
+ for (String path : path2idList.keySet()) {
|
|
|
|
+ Map<String, Boolean> idList = path2idList.get(path);
|
|
|
|
+ idList.remove(id);
|
|
|
|
+ if (idList.size() == 0) {
|
|
|
|
+ path2idList.remove(path);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ id2pathList.remove(id);
|
|
|
|
+
|
|
idMap.remove(id);
|
|
idMap.remove(id);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -161,7 +174,32 @@ public class WebSocketUtil {
|
|
sendItem.put("websocket_tag", objId2Tag.get(objId));
|
|
sendItem.put("websocket_tag", objId2Tag.get(objId));
|
|
}
|
|
}
|
|
sendArray.add(sendItem);
|
|
sendArray.add(sendItem);
|
|
|
|
+ // 发送
|
|
|
|
+ WebSocketChannelPool.Send(id, sendArray);
|
|
|
|
+ sendArray.clear();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ Map<String, Boolean> pathList = id2pathList.get(id);
|
|
|
|
+ for (String path : pathList.keySet()) {
|
|
|
|
+ JSONArray pathArray = JSON.parseArray(path);
|
|
|
|
+ Object valueObject = ComputeUtil.getValueObject(Repository, pathArray);
|
|
|
|
+ if (valueObject instanceof SceneDataValue) {
|
|
|
|
+ SceneDataValue currData = (SceneDataValue) valueObject;
|
|
|
|
+ int depth = 1;
|
|
|
|
+ if (currData.rel_property != null) {
|
|
|
|
+ depth = Integer.parseInt(currData.rel_property.read_level);
|
|
|
|
+ }
|
|
|
|
+ Object data = currData.toJSON(true, depth);
|
|
|
|
+ JSONObject sendItem = new JSONObject();
|
|
|
|
+ sendItem.put("path", pathArray);
|
|
|
|
+ sendItem.put("data", data);
|
|
|
|
+ sendArray.add(sendItem);
|
|
|
|
+ // 发送
|
|
|
|
+ WebSocketChannelPool.Send(id, sendArray);
|
|
|
|
+ sendArray.clear();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
if (sendArray.size() > 0) {
|
|
if (sendArray.size() > 0) {
|
|
WebSocketChannelPool.Send(id, sendArray);
|
|
WebSocketChannelPool.Send(id, sendArray);
|
|
}
|
|
}
|
|
@@ -173,6 +211,30 @@ public class WebSocketUtil {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public static void ProcessComputeOccur(SceneDataValue sdv) {
|
|
|
|
+ try {
|
|
|
|
+ JSONArray pathArray = new JSONArray();
|
|
|
|
+ PathUtil.getDataPath(sdv, pathArray);
|
|
|
|
+ if (path2idList.containsKey(pathArray.toString())) {
|
|
|
|
+ Map<String, Boolean> idList = path2idList.get(pathArray.toString());
|
|
|
|
+ JSONArray sendArray = new JSONArray();
|
|
|
|
+ JSONObject sendItem = new JSONObject();
|
|
|
|
+ sendItem.put("path", pathArray);
|
|
|
|
+ int depth = 1;
|
|
|
|
+ if (sdv.rel_property != null) {
|
|
|
|
+ depth = Integer.parseInt(sdv.rel_property.read_level);
|
|
|
|
+ }
|
|
|
|
+ Object data = sdv.toJSON(true, depth);
|
|
|
|
+ sendItem.put("data", data);
|
|
|
|
+ for (String id : idList.keySet()) {
|
|
|
|
+ WebSocketChannelPool.Send(id, sendArray);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
public static void ProcessIOTReceived(JSONObject json) {
|
|
public static void ProcessIOTReceived(JSONObject json) {
|
|
try {
|
|
try {
|
|
Runnable runnable = new Runnable() {
|
|
Runnable runnable = new Runnable() {
|