
@ChannelHandler.Sharable public class WriteTimeoutHandler extends SimpleChannelDownstreamHandler implements ExternalResourceReleasable
WriteTimeoutException when no data was written within a
certain period of time.
public class MyPipelineFactory implementsTheChannelPipelineFactory{ private finalTimertimer; public MyPipelineFactory(Timertimer) { this.timer = timer; } publicChannelPipelinegetPipeline() { // An example configuration that implements 30-second write timeout: returnChannels.pipeline( newWriteTimeoutHandler(timer, 30), // timer must be shared. new MyHandler()); } }ServerBootstrapbootstrap = ...;Timertimer = newHashedWheelTimer(); ... bootstrap.setPipelineFactory(new MyPipelineFactory(timer));
Timer which was specified when the ReadTimeoutHandler is
created should be stopped manually by calling releaseExternalResources()
or Timer.stop() when your application shuts down.ReadTimeoutHandler,
IdleStateHandlerChannelHandler.Sharable| Constructor and Description |
|---|
WriteTimeoutHandler(Timer timer,
int timeoutSeconds)
Creates a new instance.
|
WriteTimeoutHandler(Timer timer,
long timeout,
TimeUnit unit)
Creates a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
protected long |
getTimeoutMillis(MessageEvent e)
Returns the write timeout of the specified event.
|
void |
releaseExternalResources()
Stops the
Timer which was specified in the constructor of this
handler. |
void |
writeRequested(ChannelHandlerContext ctx,
MessageEvent e)
Invoked when
Channel.write(Object) is called. |
protected void |
writeTimedOut(ChannelHandlerContext ctx) |
bindRequested, closeRequested, connectRequested, disconnectRequested, handleDownstream, setInterestOpsRequested, unbindRequestedpublic WriteTimeoutHandler(Timer timer, int timeoutSeconds)
timer - the Timer that is used to trigger the scheduled event.
The recommended Timer implementation is HashedWheelTimer.timeoutSeconds - write timeout in secondspublic void releaseExternalResources()
Timer which was specified in the constructor of this
handler. You should not call this method if the Timer is in use
by other objects.releaseExternalResources in interface ExternalResourceReleasableprotected long getTimeoutMillis(MessageEvent e)
e - the message being writtenpublic void writeRequested(ChannelHandlerContext ctx, MessageEvent e) throws Exception
SimpleChannelDownstreamHandlerChannel.write(Object) is called.writeRequested in class SimpleChannelDownstreamHandlerExceptionprotected void writeTimedOut(ChannelHandlerContext ctx) throws Exception
ExceptionCopyright © 2008-2013 The Netty Project. All Rights Reserved.