|
@@ -15,20 +15,29 @@ import java.util.concurrent.ConcurrentHashMap;
|
|
|
@Slf4j
|
|
|
public class Iec104ServerHandler extends SimpleChannelInboundHandler<Iec104Message> {
|
|
|
|
|
|
- private Map<String, Iec104Session> sessionMap = new ConcurrentHashMap<>();
|
|
|
+ private static Map<String, Iec104Session> sessionMap = new ConcurrentHashMap<>();
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
|
|
+
|
|
|
+ int counter = sessionMap.size();
|
|
|
+ if (counter > 100) {
|
|
|
+ ctx.close();
|
|
|
+ log.warn("连接数达到上限!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
// 注册Session
|
|
|
Iec104Session session = new Iec104Session(ctx);
|
|
|
if (sessionMap.containsKey(session.getId())) {
|
|
|
+ log.info("这种情况应该不会出现!");
|
|
|
sessionMap.get(session.getId()).stop();
|
|
|
}
|
|
|
|
|
|
sessionMap.put(session.getId(), session);
|
|
|
- log.info("建立新连接,sessionid = " + session.getId());
|
|
|
- log.info("当前连接数:" + sessionMap.keySet().size());
|
|
|
+ log.info("建立新连接,sessionid = " + session.getId() + ", total = " + sessionMap.size());
|
|
|
+ //log.info("当前连接数:" + sessionMap.keySet().size());
|
|
|
}
|
|
|
|
|
|
@Override
|