@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.ChannelHandler.Sharable| 构造器和说明 |
|---|
WriteTimeoutHandler(Timer timer,
int timeoutSeconds)
Creates a new instance.
|
WriteTimeoutHandler(Timer timer,
long timeout,
java.util.concurrent.TimeUnit unit)
Creates a new instance.
|
| 限定符和类型 | 方法和说明 |
|---|---|
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 WriteTimeoutHandler(Timer timer, long timeout, java.util.concurrent.TimeUnit unit)
timer - the Timer that is used to trigger the scheduled event.
The recommended Timer implementation is HashedWheelTimer.timeout - write timeoutunit - the TimeUnit of timeoutpublic void releaseExternalResources()
protected long getTimeoutMillis(MessageEvent e)
e - the message being writtenpublic void writeRequested(ChannelHandlerContext ctx, MessageEvent e) throws java.lang.Exception
SimpleChannelDownstreamHandlerChannel.write(Object) is called.writeRequested 在类中 SimpleChannelDownstreamHandlerjava.lang.Exceptionprotected void writeTimedOut(ChannelHandlerContext ctx) throws java.lang.Exception
java.lang.Exception