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(Channel
channel) { channel.pipeline().addLast("readTimeoutHandler", newReadTimeoutHandler
(30); channel.pipeline().addLast("myHandler", new MyHandler()); } } // Handler should handle theReadTimeoutException
. public class MyHandler extendsChannelHandlerAdapter
{@Override
public void exceptionCaught(ChannelHandlerContext
ctx,Throwable
cause) throwsException
{ if (cause instanceofReadTimeoutException
) { // do something } else { super.exceptionCaught(ctx, cause); } } }ServerBootstrap
bootstrap = ...; ... bootstrap.childHandler(new MyChannelInitializer()); ...
WriteTimeoutHandler
,
IdleStateHandler
ChannelHandler.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, write
public ReadTimeoutHandler(int timeoutSeconds)
timeoutSeconds
- read timeout in secondspublic void handlerAdded(ChannelHandlerContext ctx) throws Exception
ChannelHandlerAdapter
handlerAdded
in interface ChannelHandler
handlerAdded
in class ChannelHandlerAdapter
Exception
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception
ChannelHandlerAdapter
handlerRemoved
in interface ChannelHandler
handlerRemoved
in class ChannelHandlerAdapter
Exception
public void channelRegistered(ChannelHandlerContext ctx) throws Exception
ChannelHandlerAdapter
ChannelHandlerContext.fireChannelRegistered()
to forward
to the next ChannelHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.channelRegistered
in interface ChannelHandler
channelRegistered
in class ChannelHandlerAdapter
Exception
public void channelActive(ChannelHandlerContext ctx) throws Exception
ChannelHandlerAdapter
ChannelHandlerContext.fireChannelActive()
to forward
to the next ChannelHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.channelActive
in interface ChannelHandler
channelActive
in class ChannelHandlerAdapter
Exception
public void channelInactive(ChannelHandlerContext ctx) throws Exception
ChannelHandlerAdapter
ChannelHandlerContext.fireChannelInactive()
to forward
to the next ChannelHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.channelInactive
in interface ChannelHandler
channelInactive
in class ChannelHandlerAdapter
Exception
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
ChannelHandlerAdapter
ChannelHandlerContext.fireChannelRead(Object)
to forward
to the next ChannelHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.channelRead
in interface ChannelHandler
channelRead
in class ChannelHandlerAdapter
Exception
protected void readTimedOut(ChannelHandlerContext ctx) throws Exception
Exception
Copyright © 2008–2015 The Netty Project. All rights reserved.