You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
799 B
34 lines
799 B
|
3 years ago
|
package com.bx.imserver.netty;
|
||
|
3 years ago
|
|
||
|
|
import io.netty.channel.ChannelHandlerContext;
|
||
|
|
|
||
|
3 years ago
|
import java.util.Map;
|
||
|
3 years ago
|
import java.util.concurrent.ConcurrentHashMap;
|
||
|
|
|
||
|
|
|
||
|
3 years ago
|
public class UserChannelCtxMap {
|
||
|
3 years ago
|
|
||
|
3 years ago
|
/*
|
||
|
|
* 维护userId和ctx的关联关系,格式:Map<userId,ctx>
|
||
|
|
*/
|
||
|
|
private static Map<Long, ChannelHandlerContext> channelMap = new ConcurrentHashMap();
|
||
|
3 years ago
|
|
||
|
|
public static void addChannelCtx(Long userId,ChannelHandlerContext ctx){
|
||
|
|
channelMap.put(userId,ctx);
|
||
|
|
}
|
||
|
|
|
||
|
|
public static void removeChannelCtx(Long userId){
|
||
|
3 years ago
|
if(userId != null){
|
||
|
|
channelMap.remove(userId);
|
||
|
|
}
|
||
|
3 years ago
|
}
|
||
|
|
|
||
|
|
public static ChannelHandlerContext getChannelCtx(Long userId){
|
||
|
3 years ago
|
if(userId == null){
|
||
|
|
return null;
|
||
|
|
}
|
||
|
3 years ago
|
return channelMap.get(userId);
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|