- java.lang.Object
-
- io.netty5.handler.timeout.WriteTimeoutHandler
-
- All Implemented Interfaces:
ChannelHandler
public class WriteTimeoutHandler extends Object implements ChannelHandler
Raises aWriteTimeoutException
when a write operation cannot finish in a certain period of time.// The connection is closed when a write operation cannot finish in 30 seconds. public class MyChannelInitializer extends
ChannelInitializer
<Channel
> { public void initChannel(Channel
channel) { channel.pipeline().addLast("writeTimeoutHandler", newWriteTimeoutHandler
(30); channel.pipeline().addLast("myHandler", new MyHandler()); } } // Handler should handle theWriteTimeoutException
. public class MyHandler implementsChannelHandler
{@Override
public void exceptionCaught(ChannelHandlerContext
ctx,Throwable
cause) throwsException
{ if (cause instanceofWriteTimeoutException
) { // do something } else { super.exceptionCaught(ctx, cause); } } }ServerBootstrap
bootstrap = ...; ... bootstrap.childHandler(new MyChannelInitializer()); ...- See Also:
ReadTimeoutHandler
,IdleStateHandler
-
-
Constructor Summary
Constructors Constructor Description WriteTimeoutHandler(int timeoutSeconds)
Creates a new instance.WriteTimeoutHandler(long timeout, TimeUnit unit)
Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
handlerRemoved(ChannelHandlerContext ctx)
Gets called after theChannelHandler
was removed from the actual context and it doesn't handle events anymore.Future<Void>
write(ChannelHandlerContext ctx, Object msg)
Called once a write operation is made.protected void
writeTimedOut(ChannelHandlerContext ctx)
Is called when a write timeout was detected-
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, channelActive, channelExceptionCaught, channelInactive, channelInboundEvent, channelRead, channelReadComplete, channelRegistered, channelShutdown, channelUnregistered, channelWritabilityChanged, close, connect, deregister, disconnect, flush, handlerAdded, isSharable, pendingOutboundBytes, read, register, sendOutboundEvent, shutdown
-
-
-
-
Method Detail
-
write
public Future<Void> write(ChannelHandlerContext ctx, Object msg)
Description copied from interface:ChannelHandler
Called once a write operation is made. The write operation will write the messages through theChannelPipeline
. Those are then ready to be flushed to the actualChannel
onceChannel.flush()
is called.- Specified by:
write
in interfaceChannelHandler
- Parameters:
ctx
- theChannelHandlerContext
for which the write operation is mademsg
- the message to write- Returns:
- the
Future
which will be notified once the operation completes.
-
handlerRemoved
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandler
Gets called after theChannelHandler
was removed from the actual context and it doesn't handle events anymore.- Specified by:
handlerRemoved
in interfaceChannelHandler
- Throws:
Exception
-
writeTimedOut
protected void writeTimedOut(ChannelHandlerContext ctx) throws Exception
Is called when a write timeout was detected- Throws:
Exception
-
-