Pu Zhibing
7 天以前 1ee76c252f2dbba62e0ec34cccf9eaac51de9083
ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/netty/client/ChannelMap.java
@@ -9,7 +9,6 @@
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
 * @author zhibing.pu
@@ -36,7 +35,13 @@
    * @param channel
    */
   public static void addClientChannel(int key, Channel channel) {
      if(null == CLIENT_ID_MAP){
         CLIENT_ID_MAP = new HashMap<>();
      }
      CLIENT_ID_MAP.put(key, channel.id());
      if(null == CLIENT_GROUP){
         CLIENT_GROUP = new DefaultChannelGroup("Jtt809Client", GlobalEventExecutor.INSTANCE);
      }
      CLIENT_GROUP.add(channel);
   }
   
@@ -48,9 +53,15 @@
    * @return
    */
   public static Channel getClientChannel(int key) {
      if(null == CLIENT_ID_MAP){
         CLIENT_ID_MAP = new HashMap<>();
      }
      ChannelId channelId = CLIENT_ID_MAP.get(key);
      if (null == channelId) {
         return null;
      }
      if(null == CLIENT_GROUP){
         CLIENT_GROUP = new DefaultChannelGroup("Jtt809Client", GlobalEventExecutor.INSTANCE);
      }
      Channel channel = CLIENT_GROUP.find(channelId);
      return channel;
@@ -64,7 +75,13 @@
    * @param channel
    */
   public static void addServerChannel(int key, Channel channel) {
      if(null == SERVER_ID_MAP){
         SERVER_ID_MAP = new HashMap<>();
      }
      SERVER_ID_MAP.put(key, channel.id());
      if(null == SERVER_GROUP){
         SERVER_GROUP = new DefaultChannelGroup("Jtt809Server", GlobalEventExecutor.INSTANCE);
      }
      SERVER_GROUP.add(channel);
   }
   
@@ -92,6 +109,9 @@
    * @param req
    */
   public static void addIpAndPort(int key, UPConnect req) {
      if(null == IP_PORT){
         IP_PORT = new HashMap<>();
      }
      IP_PORT.put(key, req);
   }
   
@@ -102,6 +122,9 @@
    * @param key
    */
   public static UPConnect getIpAndPort(int key) {
      if(null == IP_PORT){
         IP_PORT = new HashMap<>();
      }
      return IP_PORT.get(key);
   }
   
@@ -112,6 +135,9 @@
    * @return
    */
   public static Integer getTimes(int key) {
      if(null == TIMES){
         TIMES = new HashMap<>();
      }
      return TIMES.get(key);
   }
   
@@ -122,6 +148,9 @@
    * @return
    */
   public static int saveTimes(int key, int t) {
      if(null == TIMES){
         TIMES = new HashMap<>();
      }
      return TIMES.put(key, t);
   }
}