@Override public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { Channel channel = ctx.getChannel(); if (!sessions.removeSession(channel.getId())) { Log.error("删除Session失败! sockId: " + channel.getId()); } }
@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { ChannelBuffer buffer = (ChannelBuffer) e.getMessage(); Route route = app.getRouter().parseRoute(getUtf(buffer)); byte[] data = new byte[buffer.readableBytes()]; buffer.readBytes(data); LocalSession localSession = sessions.getSession(ctx.getChannel().getId()).getLocalSession(); byte[] response = server.handle(route, localSession, data); if (response != null) { ctx.getChannel().write(response); } }
@Override public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { Channel channel = ctx.getChannel(); sessions.createSession(channel.getId(), frontendId, channel); }