|
@@ -28,7 +28,6 @@ import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
import java.util.concurrent.CountDownLatch;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @Description:
|
|
@@ -49,7 +48,7 @@ public class TcpServiceImplV2 implements TcpServiceV2 {
|
|
|
/**
|
|
|
* 初始化实例集合
|
|
|
*/
|
|
|
- private static ConcurrentHashMap<String, ConcurrentHashMap<String, Object>> serverMap = new ConcurrentHashMap<>();
|
|
|
+ private static final ConcurrentHashMap<String, ConcurrentHashMap<String, Object>> serverMap = new ConcurrentHashMap<>();
|
|
|
|
|
|
/**
|
|
|
* 启动并返回所有数据
|
|
@@ -61,15 +60,14 @@ public class TcpServiceImplV2 implements TcpServiceV2 {
|
|
|
*/
|
|
|
@Override
|
|
|
public AjaxResult openAndReturnAllData(List<String> ips, String busUuid, String userId) {
|
|
|
- Integer count = 0;
|
|
|
+ int count = 0;
|
|
|
try {
|
|
|
CountDownLatch countDownLatch = new CountDownLatch(ips.size());
|
|
|
System.err.println(serverMap);
|
|
|
// 启动扫描线程
|
|
|
for (String ip : ips) {
|
|
|
count++;
|
|
|
- Integer finalCount = count;
|
|
|
- CountDownLatch errCountDownLatch = countDownLatch;
|
|
|
+ int finalCount = count;
|
|
|
List<JSONObject> list = new ArrayList<>();
|
|
|
ThreadPoolManager.execute(() -> {
|
|
|
try {
|
|
@@ -106,17 +104,13 @@ public class TcpServiceImplV2 implements TcpServiceV2 {
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
- if (errCountDownLatch != null) {
|
|
|
- errCountDownLatch.countDown();
|
|
|
- }
|
|
|
+ countDownLatch.countDown();
|
|
|
throw new BaseException(MessageFormat.format(RFIDConstant.SERVER_START_ERR, ip));
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- if (countDownLatch != null) {
|
|
|
- countDownLatch.await();
|
|
|
- }
|
|
|
+ countDownLatch.await();
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
@@ -143,15 +137,14 @@ public class TcpServiceImplV2 implements TcpServiceV2 {
|
|
|
// rabbitmqService.send(testData);
|
|
|
|
|
|
|
|
|
- Integer count = 0;
|
|
|
+ int count = 0;
|
|
|
try {
|
|
|
CountDownLatch countDownLatch = new CountDownLatch(ips.size());
|
|
|
System.err.println(serverMap);
|
|
|
// 启动扫描线程
|
|
|
for (String ip : ips) {
|
|
|
count++;
|
|
|
- Integer finalCount = count;
|
|
|
- CountDownLatch errCountDownLatch = countDownLatch;
|
|
|
+ int finalCount = count;
|
|
|
ConcurrentHashMap<String, JSONObject> map = new ConcurrentHashMap<>();
|
|
|
ThreadPoolManager.execute(() -> {
|
|
|
try {
|
|
@@ -177,7 +170,7 @@ public class TcpServiceImplV2 implements TcpServiceV2 {
|
|
|
jsonObject.put("messageId", IdUtils.fastSimpleUUID());
|
|
|
jsonObject.put("msgSource", MsgSourceEnum.MSG_SOURCE_2.getKey());
|
|
|
jsonObject.put("userId", userId);
|
|
|
- jsonObject.put("notices", map.values().stream().collect(Collectors.toList()));
|
|
|
+ jsonObject.put("notices", new ArrayList<>(map.values()));
|
|
|
rabbitmqService.send(jsonObject);
|
|
|
System.err.println("jsonObject--:" + jsonObject.toJSONString());
|
|
|
|
|
@@ -186,17 +179,13 @@ public class TcpServiceImplV2 implements TcpServiceV2 {
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
- if (errCountDownLatch != null) {
|
|
|
- errCountDownLatch.countDown();
|
|
|
- }
|
|
|
+ countDownLatch.countDown();
|
|
|
throw new BaseException(MessageFormat.format(RFIDConstant.SERVER_START_ERR, ip));
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- if (countDownLatch != null) {
|
|
|
- countDownLatch.await();
|
|
|
- }
|
|
|
+ countDownLatch.await();
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
@@ -206,16 +195,13 @@ public class TcpServiceImplV2 implements TcpServiceV2 {
|
|
|
|
|
|
/**
|
|
|
* 关闭多台
|
|
|
- *
|
|
|
- * @param client
|
|
|
- * @return
|
|
|
*/
|
|
|
@Override
|
|
|
public AjaxResult closeMore(RFIDClient client) {
|
|
|
ConcurrentHashMap<String, JSONObject> dataMap = new ConcurrentHashMap<>();
|
|
|
List<JSONObject> list = new ArrayList<>();
|
|
|
|
|
|
- Integer count = 0;
|
|
|
+ int count = 0;
|
|
|
List<String> ips = RFIDConfig.getTcp().getIps();
|
|
|
try {
|
|
|
if (client == null) {
|
|
@@ -228,8 +214,7 @@ public class TcpServiceImplV2 implements TcpServiceV2 {
|
|
|
// 关闭线程
|
|
|
for (String ip : ips) {
|
|
|
count++;
|
|
|
- Integer finalCount = count;
|
|
|
- CountDownLatch finalCountDownLatch = countDownLatch;
|
|
|
+ int finalCount = count;
|
|
|
try {
|
|
|
// redis tcp数据缓存key
|
|
|
String dataRedisKey = MessageFormat.format(RedisKeyConstant.RFID_TCP_DATA_REDIS_CACHE_PREFIX, ip + "-" + finalCount);
|
|
@@ -262,20 +247,16 @@ public class TcpServiceImplV2 implements TcpServiceV2 {
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
} finally {
|
|
|
- if (finalCountDownLatch != null) {
|
|
|
- finalCountDownLatch.countDown();
|
|
|
- }
|
|
|
+ countDownLatch.countDown();
|
|
|
}
|
|
|
}
|
|
|
// System.err.println("最终总结果数量--:" + dataMap.size());
|
|
|
|
|
|
if (MapUtils.isNotEmpty(dataMap)) {
|
|
|
- list = dataMap.values().stream().collect(Collectors.toList());
|
|
|
+ list = new ArrayList<>(dataMap.values());
|
|
|
}
|
|
|
|
|
|
- if (countDownLatch != null) {
|
|
|
- countDownLatch.await();
|
|
|
- }
|
|
|
+ countDownLatch.await();
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|