public class ReadTimeoutHandler extends ChannelHandlerAdapter
ReadTimeoutException when no data was read within a certain
period of time.
// The connection is closed when there is no inbound traffic // for 30 seconds. public class MyChannelInitializer extendsChannelInitializer<Channel> { public void initChannel(Channelchannel) { channel.pipeline().addLast("readTimeoutHandler", newReadTimeoutHandler(30); channel.pipeline().addLast("myHandler", new MyHandler()); } } // Handler should handle theReadTimeoutException. public class MyHandler extendsChannelHandlerAdapter{@Overridepublic void exceptionCaught(ChannelHandlerContextctx,Throwablecause) throwsException{ if (cause instanceofReadTimeoutException) { // do something } else { super.exceptionCaught(ctx, cause); } } }ServerBootstrapbootstrap = ...; ... bootstrap.childHandler(new MyChannelInitializer()); ...
WriteTimeoutHandler,
IdleStateHandlerChannelHandler.Sharable, ChannelHandler.Skip| Constructor and Description |
|---|
ReadTimeoutHandler(int timeoutSeconds)
Creates a new instance.
|
ReadTimeoutHandler(long timeout,
TimeUnit unit)
Creates a new instance.
|
bind, channelReadComplete, channelUnregistered, channelWritabilityChanged, close, connect, deregister, disconnect, exceptionCaught, flush, isSharable, read, userEventTriggered, writepublic ReadTimeoutHandler(int timeoutSeconds)
timeoutSeconds - read timeout in secondspublic void handlerAdded(ChannelHandlerContext ctx) throws Exception
ChannelHandlerAdapterhandlerAdded in interface ChannelHandlerhandlerAdded in class ChannelHandlerAdapterExceptionpublic void handlerRemoved(ChannelHandlerContext ctx) throws Exception
ChannelHandlerAdapterhandlerRemoved in interface ChannelHandlerhandlerRemoved in class ChannelHandlerAdapterExceptionpublic void channelRegistered(ChannelHandlerContext ctx) throws Exception
ChannelHandlerAdapterChannelHandlerContext.fireChannelRegistered() to forward
to the next ChannelHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.channelRegistered in interface ChannelHandlerchannelRegistered in class ChannelHandlerAdapterExceptionpublic void channelActive(ChannelHandlerContext ctx) throws Exception
ChannelHandlerAdapterChannelHandlerContext.fireChannelActive() to forward
to the next ChannelHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.channelActive in interface ChannelHandlerchannelActive in class ChannelHandlerAdapterExceptionpublic void channelInactive(ChannelHandlerContext ctx) throws Exception
ChannelHandlerAdapterChannelHandlerContext.fireChannelInactive() to forward
to the next ChannelHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.channelInactive in interface ChannelHandlerchannelInactive in class ChannelHandlerAdapterExceptionpublic void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
ChannelHandlerAdapterChannelHandlerContext.fireChannelRead(Object) to forward
to the next ChannelHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.channelRead in interface ChannelHandlerchannelRead in class ChannelHandlerAdapterExceptionprotected void readTimedOut(ChannelHandlerContext ctx) throws Exception
ExceptionCopyright © 2008–2015 The Netty Project. All rights reserved.