- java.lang.Object
-
- io.netty5.handler.timeout.IdleStateHandler
-
- io.netty5.handler.timeout.ReadTimeoutHandler
-
- All Implemented Interfaces:
io.netty5.channel.ChannelHandler
public class ReadTimeoutHandler extends IdleStateHandler
Raises aReadTimeoutException
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", newReadTimeoutHandler
(30)); channel.pipeline().addLast("myHandler", new MyHandler()); } } // Handler should handle theReadTimeoutException
. public class MyHandler implementsChannelHandler
{@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()); ...- See Also:
WriteTimeoutHandler
,IdleStateHandler
-
-
Constructor Summary
Constructors Constructor Description ReadTimeoutHandler(int timeoutSeconds)
Creates a new instance.ReadTimeoutHandler(long timeout, TimeUnit unit)
Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
channelIdle(io.netty5.channel.ChannelHandlerContext ctx, IdleStateEvent evt)
Is called when anIdleStateEvent
should be fired.protected void
readTimedOut(io.netty5.channel.ChannelHandlerContext ctx)
Is called when a read timeout was detected.-
Methods inherited from class io.netty5.handler.timeout.IdleStateHandler
channelActive, channelInactive, channelRead, channelReadComplete, channelRegistered, getAllIdleTimeInMillis, getReaderIdleTimeInMillis, getWriterIdleTimeInMillis, handlerAdded, handlerRemoved, newIdleStateEvent, write
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.netty5.channel.ChannelHandler
bind, channelExceptionCaught, channelInboundEvent, channelShutdown, channelUnregistered, channelWritabilityChanged, close, connect, deregister, disconnect, flush, isSharable, pendingOutboundBytes, read, register, sendOutboundEvent, shutdown
-
-
-
-
Method Detail
-
channelIdle
protected final void channelIdle(io.netty5.channel.ChannelHandlerContext ctx, IdleStateEvent evt) throws Exception
Description copied from class:IdleStateHandler
Is called when anIdleStateEvent
should be fired. This implementation callsChannelHandlerContext.fireChannelInboundEvent(Object)
.- Overrides:
channelIdle
in classIdleStateHandler
- Throws:
Exception
-
-