public class WriteTimeoutHandler
extends io.netty.channel.ChannelOutboundHandlerAdapter
WriteTimeoutException 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 extendsChannelInitializer<Channel> { public void initChannel(Channelchannel) { channel.pipeline().addLast("writeTimeoutHandler", newWriteTimeoutHandler(30); channel.pipeline().addLast("myHandler", new MyHandler()); } } // Handler should handle theWriteTimeoutException. public class MyHandler extendsChannelDuplexHandler{@Overridepublic void exceptionCaught(ChannelHandlerContextctx,Throwablecause) throwsException{ if (cause instanceofWriteTimeoutException) { // do something } else { super.exceptionCaught(ctx, cause); } } }ServerBootstrapbootstrap = ...; ... bootstrap.childHandler(new MyChannelInitializer()); ...
ReadTimeoutHandler,
IdleStateHandler| Constructor and Description |
|---|
WriteTimeoutHandler(int timeoutSeconds)
Creates a new instance.
|
WriteTimeoutHandler(long timeout,
TimeUnit unit)
Creates a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
void |
handlerRemoved(io.netty.channel.ChannelHandlerContext ctx) |
void |
write(io.netty.channel.ChannelHandlerContext ctx,
Object msg,
io.netty.channel.ChannelPromise promise) |
protected void |
writeTimedOut(io.netty.channel.ChannelHandlerContext ctx)
Is called when a write timeout was detected
|
bind, close, connect, deregister, disconnect, flush, readensureNotSharable, exceptionCaught, handlerAdded, isSharablepublic WriteTimeoutHandler(int timeoutSeconds)
timeoutSeconds - write timeout in secondspublic void write(io.netty.channel.ChannelHandlerContext ctx,
Object msg,
io.netty.channel.ChannelPromise promise)
throws Exception
write in interface io.netty.channel.ChannelOutboundHandlerwrite in class io.netty.channel.ChannelOutboundHandlerAdapterExceptionpublic void handlerRemoved(io.netty.channel.ChannelHandlerContext ctx)
throws Exception
handlerRemoved in interface io.netty.channel.ChannelHandlerhandlerRemoved in class io.netty.channel.ChannelHandlerAdapterExceptionCopyright © 2008–2019 The Netty Project. All rights reserved.