public class WriteTimeoutHandler extends ChannelHandlerAdapter
WriteTimeoutException when no data was written within a
certain period of time.
// The connection is closed when there is no outbound traffic // for 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 extendsChannelHandlerAdapter{@Overridepublic void exceptionCaught(ChannelHandlerContextctx,Throwablecause) throwsException{ if (cause instanceofWriteTimeoutException) { // do something } else { super.exceptionCaught(ctx, cause); } } }ServerBootstrapbootstrap = ...; ... bootstrap.childHandler(new MyChannelInitializer()); ...
ReadTimeoutHandler,
IdleStateHandlerChannelHandler.Sharable, ChannelHandler.Skip| 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 |
write(ChannelHandlerContext ctx,
Object msg,
ChannelPromise promise)
Calls
ChannelHandlerContext.write(Object) to forward
to the next ChannelHandler in the ChannelPipeline. |
protected void |
writeTimedOut(ChannelHandlerContext ctx)
Is called when a write timeout was detected
|
bind, channelActive, channelInactive, channelRead, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, close, connect, deregister, disconnect, exceptionCaught, flush, handlerAdded, handlerRemoved, isSharable, read, userEventTriggeredpublic WriteTimeoutHandler(int timeoutSeconds)
timeoutSeconds - write timeout in secondspublic void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception
ChannelHandlerAdapterChannelHandlerContext.write(Object) to forward
to the next ChannelHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.write in interface ChannelHandlerwrite in class ChannelHandlerAdapterctx - the ChannelHandlerContext for which the write operation is mademsg - the message to writepromise - the ChannelPromise to notify once the operation completesException - thrown if an error accourprotected void writeTimedOut(ChannelHandlerContext ctx) throws Exception
ExceptionCopyright © 2008–2015 The Netty Project. All rights reserved.