Top Description Fields Constructors Methods
io.netty.handler.timeout

public Class ReadTimeoutHandler

extends IdleStateHandler
Class Inheritance
Imports
io.netty.bootstrap.ServerBootstrap, io.netty.channel.Channel, .ChannelDuplexHandler, .ChannelHandlerContext, .ChannelInitializer, java.util.concurrent.TimeUnit

Raises a 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 extends ChannelInitializer<Channel> {
    public void initChannel(Channel channel) {
        channel.pipeline().addLast("readTimeoutHandler", new ReadTimeoutHandler(30));
        channel.pipeline().addLast("myHandler", new MyHandler());
    }
}

// Handler should handle the ReadTimeoutException.
public class MyHandler extends ChannelDuplexHandler {
    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
            throws Exception {
        if (cause instanceof ReadTimeoutException) {
            // do something
        } else {
            super.exceptionCaught(ctx, cause);
        }
    }
}

ServerBootstrap bootstrap = ...;
...
bootstrap.childHandler(new MyChannelInitializer());
...
See Also
WriteTimeoutHandler, IdleStateHandler

Field Summary

Modifier and TypeField and Description
private boolean

Constructor Summary

AccessConstructor and Description
public
ReadTimeoutHandler(int
read timeout in seconds
timeoutSeconds
)

Creates a new instance.

public
ReadTimeoutHandler(long
read timeout
timeout
,
TimeUnit
the TimeUnit of timeout
unit
)

Creates a new instance.

Method Summary

Modifier and TypeMethod and Description
protected final void
protected void
readTimedOut(ChannelHandlerContext ctx)

Is called when a read timeout was detected.

Inherited from io.netty.handler.timeout.IdleStateHandler:
channelActivechannelInactivechannelReadchannelReadCompletechannelRegisteredgetAllIdleTimeInMillisgetReaderIdleTimeInMillisgetWriterIdleTimeInMillishandlerAddedhandlerRemovednewIdleStateEventresetReadTimeoutresetWriteTimeoutscheduleticksInNanoswrite

Field Detail

closedback to summary
private boolean closed

Constructor Detail

ReadTimeoutHandlerback to summary
public ReadTimeoutHandler(int timeoutSeconds)

Creates a new instance.

Parameters
timeoutSeconds:int

read timeout in seconds

ReadTimeoutHandlerback to summary
public ReadTimeoutHandler(long timeout, TimeUnit unit)

Creates a new instance.

Parameters
timeout:long

read timeout

unit:TimeUnit

the TimeUnit of timeout

Method Detail

channelIdleback to summary
protected final void channelIdle(ChannelHandlerContext ctx, IdleStateEvent evt) throws Exception

Overrides io.netty.handler.timeout.IdleStateHandler.channelIdle.

Doc from io.netty.handler.timeout.IdleStateHandler.channelIdle.

Is called when an IdleStateEvent should be fired. This implementation calls ChannelHandlerContext#fireUserEventTriggered(Object).

Annotations
@Override
readTimedOutback to summary
protected void readTimedOut(ChannelHandlerContext ctx) throws Exception

Is called when a read timeout was detected.