- java.lang.Object
-
- io.netty5.handler.timeout.WriteTimeoutHandler
-
- All Implemented Interfaces:
ChannelHandler
public class WriteTimeoutHandler extends Object implements ChannelHandler
Raises 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 implementsChannelHandler{@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(ChannelHandlerContext ctx)Gets called after theChannelHandlerwas 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 voidwriteTimedOut(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:ChannelHandlerCalled once a write operation is made. The write operation will write the messages through theChannelPipeline. Those are then ready to be flushed to the actualChannelonceChannel.flush()is called.- Specified by:
writein interfaceChannelHandler- Parameters:
ctx- theChannelHandlerContextfor which the write operation is mademsg- the message to write- Returns:
- the
Futurewhich will be notified once the operation completes.
-
handlerRemoved
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandlerGets called after theChannelHandlerwas removed from the actual context and it doesn't handle events anymore.- Specified by:
handlerRemovedin interfaceChannelHandler- Throws:
Exception
-
writeTimedOut
protected void writeTimedOut(ChannelHandlerContext ctx) throws Exception
Is called when a write timeout was detected- Throws:
Exception
-
-