public class ReadTimeoutHandler extends IdleStateHandler
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 extendsChannelDuplexHandler{@Overridepublic void exceptionCaught(ChannelHandlerContextctx,Throwablecause) throwsException{ if (cause instanceofReadTimeoutException) { // do something } else { super.exceptionCaught(ctx, cause); } } }ServerBootstrapbootstrap = ...; ... bootstrap.childHandler(new MyChannelInitializer()); ...
WriteTimeoutHandler,
IdleStateHandler| Constructor and Description |
|---|
ReadTimeoutHandler(int timeoutSeconds)
Creates a new instance.
|
ReadTimeoutHandler(long timeout,
TimeUnit unit)
Creates a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
channelIdle(io.netty.channel.ChannelHandlerContext ctx,
IdleStateEvent evt)
Is called when an
IdleStateEvent should be fired. |
protected void |
readTimedOut(io.netty.channel.ChannelHandlerContext ctx)
Is called when a read timeout was detected.
|
channelActive, channelInactive, channelRead, channelReadComplete, channelRegistered, getAllIdleTimeInMillis, getReaderIdleTimeInMillis, getWriterIdleTimeInMillis, handlerAdded, handlerRemoved, newIdleStateEvent, writebind, close, connect, deregister, disconnect, flush, readchannelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggeredpublic ReadTimeoutHandler(int timeoutSeconds)
timeoutSeconds - read timeout in secondsprotected final void channelIdle(io.netty.channel.ChannelHandlerContext ctx,
IdleStateEvent evt)
throws Exception
IdleStateHandlerIdleStateEvent should be fired. This implementation calls
ChannelHandlerContext.fireUserEventTriggered(Object).channelIdle in class IdleStateHandlerExceptionCopyright © 2008–2019 The Netty Project. All rights reserved.