|
@@ -12,6 +12,7 @@ import java.text.SimpleDateFormat;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
+import java.util.UUID;
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -49,6 +50,7 @@ public class DiscardServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
|
|
|
public static Map<String, String> channelMap = new HashMap<String, String>();
|
|
|
public static Map<String, Channel> manageChannelMap = new HashMap<>();
|
|
|
+ public static Map<Channel, String> channelMapOfChannelKey = new HashMap<>();
|
|
|
public static Map<String, String> commandCopy = new HashMap<>();
|
|
|
|
|
|
@Autowired
|
|
@@ -71,7 +73,7 @@ public class DiscardServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
String deviceId = advice.getDeviceId();
|
|
|
String adviceType = advice.getAdviceType();
|
|
|
Channel channel = ctx.channel();
|
|
|
- String deviceIdInMap = channelMap.get(channel.id().asLongText());
|
|
|
+ String deviceIdInMap = channelMapOfChannelKey.get(channel);
|
|
|
if (deviceIdInMap == null) {
|
|
|
manageLink(channel, deviceId);
|
|
|
}
|
|
@@ -100,19 +102,20 @@ public class DiscardServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void manageLink(Channel channel, String deviceIdInMap) {
|
|
|
- String channelId = channel.id().asLongText();
|
|
|
+ private void manageLink(Channel channel, String deviceId) {
|
|
|
+ String channelId = UUID.randomUUID().toString();
|
|
|
manageChannelMap.put(channelId, channel);
|
|
|
- channelMap.put(channelId, deviceIdInMap);
|
|
|
+ channelMap.put(channelId, deviceId);
|
|
|
+ channelMapOfChannelKey.put(channel, deviceId);
|
|
|
logger.info("链接管理,链接id [{}]", channelId);
|
|
|
|
|
|
ConnectMsg cMsg = new ConnectMsg("10.27.118.76", channelId);
|
|
|
try (Jedis jedis = jedisPool.getResource()) {
|
|
|
jedis.select(15);
|
|
|
String insertKey = PREFIX_LINK + "10.27.118.76";
|
|
|
- String selectKey = PREFIX_DEVICE + deviceIdInMap;
|
|
|
+ String selectKey = PREFIX_DEVICE + deviceId;
|
|
|
|
|
|
- jedis.set(insertKey, deviceIdInMap);
|
|
|
+ jedis.set(insertKey, deviceId);
|
|
|
jedis.set(selectKey, StringUtil.convert2String(cMsg));
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getLocalizedMessage());
|