@Override public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception { if (e instanceof IdleStateEvent) { channelIdle(ctx, (IdleStateEvent) e); } else { super.handleUpstream(ctx, e); } }
@Override public void channelIdle(ChannelHandlerContext ctx, IdleStateEvent e) throws Exception { if (e.getState().equals(IdleState.WRITER_IDLE)) { e.getChannel().write(ChannelBuffers.wrappedBuffer("* OK Hang in there..\r\n".getBytes("US-ASCII"))); } super.channelIdle(ctx, e); }
@Override public void channelIdle(ChannelHandlerContext ctx, IdleStateEvent e) throws Exception { // check if the client did nothing for too long if (e.getState().equals(IdleState.ALL_IDLE)) { ImapSession session = (ImapSession) attributes.get(ctx.getChannel()); InetSocketAddress address = (InetSocketAddress) ctx.getChannel().getRemoteAddress(); LOGGER.info("Logout client {} ({}) because it idled for too long...", address.getHostName(), address.getAddress().getHostAddress()); // logout the client session.logout(); // close the channel ctx.getChannel().close(); } super.channelIdle(ctx, e); }
/** * This method is called whenever the communication data flow is idle and * the session timeout limit is over. */ @Override public void channelIdle(ChannelHandlerContext ctx, IdleStateEvent e) throws Exception { OdetteFtpSession session = ChannelContext.SESSION.get(ctx.getChannel()); // session is terminated by timeout OdetteFtpVersion version = session.getVersion(); ProtocolHandler handler = getProtocolHandlerByVersion(version); // TODO perhaps we may specify the timeout period in release message handler.abort(session, EndSessionReason.TIME_OUT, null); super.channelIdle(ctx, e); }