Package io.netty.handler.timeout
Class WriteTimeoutHandler
- java.lang.Object
-
- io.netty.channel.ChannelHandlerAdapter
-
- io.netty.channel.ChannelOutboundHandlerAdapter
-
- io.netty.handler.timeout.WriteTimeoutHandler
-
- All Implemented Interfaces:
io.netty.channel.ChannelHandler,io.netty.channel.ChannelOutboundHandler
public class WriteTimeoutHandler extends io.netty.channel.ChannelOutboundHandlerAdapterRaises aWriteTimeoutExceptionwhen 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(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()); ...- 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 voidhandlerRemoved(io.netty.channel.ChannelHandlerContext ctx)voidwrite(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise)protected voidwriteTimedOut(io.netty.channel.ChannelHandlerContext ctx)Is called when a write timeout was detected-
Methods inherited from class io.netty.channel.ChannelOutboundHandlerAdapter
bind, close, connect, deregister, disconnect, flush, read
-
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, exceptionCaught, handlerAdded, isSharable
-
-
-
-
Method Detail
-
write
public void write(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise) throws Exception- Specified by:
writein interfaceio.netty.channel.ChannelOutboundHandler- Overrides:
writein classio.netty.channel.ChannelOutboundHandlerAdapter- Throws:
Exception
-
handlerRemoved
public void handlerRemoved(io.netty.channel.ChannelHandlerContext ctx) throws Exception- Specified by:
handlerRemovedin interfaceio.netty.channel.ChannelHandler- Overrides:
handlerRemovedin classio.netty.channel.ChannelHandlerAdapter- Throws:
Exception
-
-