@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 finalTimer
timer; public MyPipelineFactory(Timer
timer) { this.timer = timer; } publicChannelPipeline
getPipeline() { // An example configuration that implements 30-second write timeout: returnChannels
.pipeline( newWriteTimeoutHandler
(timer, 30), // timer must be shared. new MyHandler()); } }ServerBootstrap
bootstrap = ...;Timer
timer = 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, unbindRequested
public 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 timeout
public void releaseExternalResources()
protected long getTimeoutMillis(MessageEvent e)
e
- the message being writtenpublic void writeRequested(ChannelHandlerContext ctx, MessageEvent e) throws java.lang.Exception
SimpleChannelDownstreamHandler
Channel.write(Object)
is called.writeRequested
在类中 SimpleChannelDownstreamHandler
java.lang.Exception
protected void writeTimedOut(ChannelHandlerContext ctx) throws java.lang.Exception
java.lang.Exception