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 implementsChannelHandler{@Overridepublic void exceptionCaught(ChannelHandlerContextctx,Throwablecause) throwsException{ if (cause instanceofReadTimeoutException) { // do something } else { super.exceptionCaught(ctx, cause); } } }ServerBootstrapbootstrap = ...; ... bootstrap.childHandler(new MyChannelInitializer()); ...
WriteTimeoutHandler, IdleStateHandler
| Modifier and Type | Field and Description |
|---|---|
| private boolean |
| Access | Constructor and Description |
|---|---|
| public | |
| public | ReadTimeoutHandler(long
read timeout timeout, TimeUnit the unit)TimeUnit of timeoutCreates a new instance. |
| Modifier and Type | Method and Description |
|---|---|
| protected final void | channelIdle(ChannelHandlerContext ctx, IdleStateEvent evt)
Overrides io. IdleStateEvent should be fired.
|
| protected void |
| closed | back to summary |
|---|---|
| private boolean closed | |
| ReadTimeoutHandler | back to summary |
|---|---|
| public ReadTimeoutHandler(int timeoutSeconds) Creates a new instance.
| |
| ReadTimeoutHandler | back to summary |
|---|---|
| public ReadTimeoutHandler(long timeout, TimeUnit unit) Creates a new instance. | |
| channelIdle | back to summary |
|---|---|
| protected final void channelIdle(ChannelHandlerContext ctx, IdleStateEvent evt) throws Exception Overrides io. Doc from io. Is called when an
| |
| readTimedOut | back to summary |
|---|---|
| protected void readTimedOut(ChannelHandlerContext ctx) throws Exception Is called when a read timeout was detected. | |