@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.ReadTimeoutHandler
,
IdleStateHandler
ChannelHandler.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, 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 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 ExternalResourceReleasable
protected long getTimeoutMillis(MessageEvent e)
e
- the message being writtenpublic void writeRequested(ChannelHandlerContext ctx, MessageEvent e) throws Exception
SimpleChannelDownstreamHandler
Channel.write(Object)
is called.writeRequested
in class SimpleChannelDownstreamHandler
Exception
protected void writeTimedOut(ChannelHandlerContext ctx) throws Exception
Exception
Copyright © 2008-2015 The Netty Project. All Rights Reserved.