2
每當我發現讀取器空閒時間時,我都會寫入超時錯誤。在讀取超時時寫入頻道
public class TimeOutHandler extends IdleStateAwareChannelHandler {
@Override
public void channelIdle(ChannelHandlerContext ctx, IdleStateEvent e) {
if (e.getState() == IdleState.READER_IDLE) {
System.out.println("Reader TimeOut");
HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
response.setHeader(Names.CONTENT_TYPE, "application/json; charset=UTF-8");
response.setContent(ChannelBuffers.copiedBuffer("{\"timeout\":true}", CharsetUtil.UTF_8));
ChannelFuture future = e.getChannel().write(response);
future.addListener(ChannelFutureListener.CLOSE);
}
}
}
處理程序正在工作,但沒有任何信息寫入通道。這種情況可能嗎?
更新:
我管線廠:
public class AsyncServerPipelineFactory implements ChannelPipelineFactory {
static HashedWheelTimer timer = new HashedWheelTimer();
private final ChannelHandler idleStateHandler = new IdleStateHandler(timer, 10, 20, 0);
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline pipeline = Channels.pipeline(idleStateHandler,new TimeOutHandler());
pipeline.addLast("decoder", new HttpRequestDecoder());
pipeline.addLast("encoder", new HttpResponseEncoder());
pipeline.addLast("handler", new HTTPRequestHandler());
return pipeline;
}
}
你能告訴我們你的ChannelPipeline嗎? – 2012-03-29 11:54:15
是的。請。看我的更新 – 2012-03-29 12:30:17
看起來對我來說..爲什麼你認爲它沒有被寫入?你有沒有用wireshark捕捉流量? – 2012-03-30 05:34:41