Class WriteTimeoutHandler
java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelOutboundHandlerAdapter
io.netty.handler.timeout.WriteTimeoutHandler
- All Implemented Interfaces:
ChannelHandler, ChannelOutboundHandler
Raises a
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()); ...
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface ChannelHandler
ChannelHandler.Sharable -
Constructor Summary
ConstructorsConstructorDescriptionWriteTimeoutHandler(int timeoutSeconds) Creates a new instance.WriteTimeoutHandler(long timeout, TimeUnit unit) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidDo nothing by default, sub-classes may override this method.voidwrite(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) CallsChannelOutboundInvoker.write(Object, ChannelPromise)to forward to the nextChannelOutboundHandlerin theChannelPipeline.protected voidIs called when a write timeout was detectedMethods inherited from class ChannelOutboundHandlerAdapter
bind, close, connect, deregister, disconnect, flush, readMethods inherited from class ChannelHandlerAdapter
ensureNotSharable, exceptionCaught, handlerAdded, isSharableMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ChannelHandler
exceptionCaught, handlerAdded
-
Constructor Details
-
WriteTimeoutHandler
public WriteTimeoutHandler(int timeoutSeconds) Creates a new instance.- Parameters:
timeoutSeconds- write timeout in seconds
-
WriteTimeoutHandler
-
-
Method Details
-
write
Description copied from class:ChannelOutboundHandlerAdapterCallsChannelOutboundInvoker.write(Object, ChannelPromise)to forward to the nextChannelOutboundHandlerin theChannelPipeline. Sub-classes may override this method to change behavior.- Specified by:
writein interfaceChannelOutboundHandler- Overrides:
writein classChannelOutboundHandlerAdapter- Parameters:
ctx- theChannelHandlerContextfor which the write operation is mademsg- the message to writepromise- theChannelPromiseto notify once the operation completes- Throws:
Exception- thrown if an error occurs
-
handlerRemoved
Description copied from class:ChannelHandlerAdapterDo nothing by default, sub-classes may override this method.- Specified by:
handlerRemovedin interfaceChannelHandler- Overrides:
handlerRemovedin classChannelHandlerAdapter- Throws:
Exception
-
writeTimedOut
Is called when a write timeout was detected- Throws:
Exception
-