Мне нужно заменить Mina на netty, но я не понимаю Какую роль играет IOSession в mina
public static ConcurrentHashMap<Long, IoSession> sessionsConcurrentHashMap = new ConcurrentHashMap<Long, IoSession>();
sessionsConcurrentHashMap.get(session.getId()).setAttribute("SN", SerialNumber);
как я могу реализовать этот код в netty, спасибо!
старый код
public class AttendanceServerHandler extends IoHandlerAdapter {
private static final Logger LOGGER = LoggerFactory.getLogger(AttendanceServerHandler.class);
public static ConcurrentHashMap<Long, IoSession> sessionsConcurrentHashMap = new ConcurrentHashMap<Long, IoSession>();
public AttendanceServerHandler() {
System.out.println("init - 10733 port");
}
@Override
public void messageReceived(IoSession session, Object message)
throws Exception {
if (!"".equals(message.toString())) {
String Answer = message.toString();
if (Answer.startsWith("PostRecord")) {
String SerialNumber = FaceId_Item.GetKeyValue(Answer, "sn");
sessionsConcurrentHashMap.get(session.getId()).setAttribute("SN", SerialNumber);
session.write("Return(result=\"success\" postphoto=\"false\")");
} else if (Answer.startsWith("Record")) {
String serialNumber = sessionsConcurrentHashMap.get(session.getId()).getAttribute("SN").toString();
if ("".equals(FaceId_Item.GetKeyValue(Answer, "id"))) {
session.write("Return(result=\"success\")");
session.close();//FIXME session.closeNow()
}
}
} else if (Answer.startsWith("PostEmployee")) {
session.write("Return(result=\"success\" postphoto=\"false\")");
} else if (Answer.startsWith("Employee")) {
session.write("Return(result=\"success\" postphoto=\"false\")");
} else if (Answer.startsWith("GetRequest")) {
} else if (Answer.startsWith("Quit")) {
session.close();//FIXME session.closeNow()
}
}
}
@Override
public void messageSent(IoSession session, Object message) throws Exception {
super.messageSent(session, message);
}
@Override
public void sessionCreated(IoSession session) throws Exception {
sessionsConcurrentHashMap.put(session.getId(), session);
super.sessionCreated(session);
}
@Override
public void sessionOpened(IoSession session) throws Exception {
super.sessionOpened(session);
}
@Override
public void sessionClosed(IoSession session) throws Exception {
sessionsConcurrentHashMap.remove(session.getId());
super.sessionClosed(session);
}
@Override
public void sessionIdle(IoSession session, IdleStatus status)
throws Exception {
super.sessionIdle(session, status);
if (session.isConnected()) {
session.close(true);
}
}
@Override
public void exceptionCaught(IoSession session, Throwable cause)
throws Exception {
super.exceptionCaught(session, cause);
if (session.isConnected()) {
session.close(true);
}
}