liujie
8 天以前 c1d4849a2cc28cc50c5405f2382a5e4bf008b891
MessagePushTravel/src/main/java/com/sinata/push/util/echo/NettyChannelMap.java
@@ -8,8 +8,8 @@
import java.util.concurrent.ConcurrentHashMap;
public class NettyChannelMap {
   protected static Map<String, ChannelHandlerContext> map = new ConcurrentHashMap<>();
   public static Map<String, ChannelHandlerContext> map = new ConcurrentHashMap<>();
   public static Map<String, ChannelHandlerContext> ctxMap = new HashMap<>();//单点登录存储的通道
@@ -78,6 +78,9 @@
    */
   @SuppressWarnings("rawtypes")
   public static synchronized void remove(ChannelHandlerContext value) {
      if(null == value){
         return;
      }
      Set<String> strings = map.keySet();
      for(String key : strings){
         ChannelHandlerContext channelHandlerContext = map.get(key);
@@ -91,6 +94,23 @@
   }
   public static synchronized void remove_(ChannelHandlerContext value) {
      Set<String> strings = ctxMap.keySet();
      for(String key : strings){
         ChannelHandlerContext channelHandlerContext = ctxMap.get(key);
         String s = channelHandlerContext.channel().remoteAddress().toString();
         String s1 = value.channel().remoteAddress().toString();
         if(s.equals(s1)){
            channelHandlerContext.close();//关闭通道
            ctxMap.remove(key);
         }
      }
   }
   public static synchronized void remove_(String key) {
      ctxMap.remove(key);
   }
   
   /**
@@ -113,4 +133,9 @@
      map.put(key, value);
   }
   public static synchronized void update_(String key, ChannelHandlerContext value) {
      ctxMap.put(key, value);
   }
}