Package io.netty.handler.timeout
Class ReadTimeoutHandler
- java.lang.Object
-
- io.netty.channel.ChannelHandlerAdapter
-
- io.netty.channel.ChannelInboundHandlerAdapter
-
- io.netty.channel.ChannelDuplexHandler
-
- io.netty.handler.timeout.IdleStateHandler
-
- io.netty.handler.timeout.ReadTimeoutHandler
-
- All Implemented Interfaces:
ChannelHandler,ChannelInboundHandler,ChannelOutboundHandler
public class ReadTimeoutHandler extends IdleStateHandler
Raises aReadTimeoutExceptionwhen 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(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()); ...- See Also:
WriteTimeoutHandler,IdleStateHandler
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
-
Constructor Summary
Constructors Constructor Description ReadTimeoutHandler(int timeoutSeconds)Creates a new instance.ReadTimeoutHandler(long timeout, java.util.concurrent.TimeUnit unit)Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidchannelIdle(ChannelHandlerContext ctx, IdleStateEvent evt)Is called when anIdleStateEventshould be fired.protected voidreadTimedOut(ChannelHandlerContext ctx)Is called when a read timeout was detected.-
Methods inherited from class io.netty.handler.timeout.IdleStateHandler
channelActive, channelInactive, channelRead, channelReadComplete, channelRegistered, getAllIdleTimeInMillis, getReaderIdleTimeInMillis, getWriterIdleTimeInMillis, handlerAdded, handlerRemoved, newIdleStateEvent, resetReadTimeout, resetWriteTimeout, write
-
Methods inherited from class io.netty.channel.ChannelDuplexHandler
bind, close, connect, deregister, disconnect, flush, read
-
Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered
-
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, isSharable
-
-
-
-
Constructor Detail
-
ReadTimeoutHandler
public ReadTimeoutHandler(int timeoutSeconds)
Creates a new instance.- Parameters:
timeoutSeconds- read timeout in seconds
-
ReadTimeoutHandler
public ReadTimeoutHandler(long timeout, java.util.concurrent.TimeUnit unit)Creates a new instance.- Parameters:
timeout- read timeoutunit- theTimeUnitoftimeout
-
-
Method Detail
-
channelIdle
protected final void channelIdle(ChannelHandlerContext ctx, IdleStateEvent evt) throws java.lang.Exception
Description copied from class:IdleStateHandlerIs called when anIdleStateEventshould be fired. This implementation callsChannelHandlerContext.fireUserEventTriggered(Object).- Overrides:
channelIdlein classIdleStateHandler- Throws:
java.lang.Exception
-
readTimedOut
protected void readTimedOut(ChannelHandlerContext ctx) throws java.lang.Exception
Is called when a read timeout was detected.- Throws:
java.lang.Exception
-
-