Package org.jboss.netty.handler.timeout
Class WriteTimeoutHandler
- java.lang.Object
-
- org.jboss.netty.channel.SimpleChannelDownstreamHandler
-
- org.jboss.netty.handler.timeout.WriteTimeoutHandler
-
- All Implemented Interfaces:
ChannelDownstreamHandler
,ChannelHandler
,ExternalResourceReleasable
@Sharable public class WriteTimeoutHandler extends SimpleChannelDownstreamHandler implements ExternalResourceReleasable
Raises aWriteTimeoutException
when no data was written within a certain period of time.public class MyPipelineFactory implements
TheChannelPipelineFactory
{ 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 theReadTimeoutHandler
is created should be stopped manually by callingreleaseExternalResources()
orTimer.stop()
when your application shuts down.- See Also:
ReadTimeoutHandler
,IdleStateHandler
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.jboss.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
-
Constructor Summary
Constructors Constructor Description WriteTimeoutHandler(Timer timer, int timeoutSeconds)
Creates a new instance.WriteTimeoutHandler(Timer timer, long timeout, TimeUnit unit)
Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected long
getTimeoutMillis(MessageEvent e)
Returns the write timeout of the specified event.void
releaseExternalResources()
Stops theTimer
which was specified in the constructor of this handler.void
writeRequested(ChannelHandlerContext ctx, MessageEvent e)
Invoked whenChannel.write(Object)
is called.protected void
writeTimedOut(ChannelHandlerContext ctx)
-
Methods inherited from class org.jboss.netty.channel.SimpleChannelDownstreamHandler
bindRequested, closeRequested, connectRequested, disconnectRequested, handleDownstream, setInterestOpsRequested, unbindRequested
-
-
-
-
Constructor Detail
-
WriteTimeoutHandler
public WriteTimeoutHandler(Timer timer, int timeoutSeconds)
Creates a new instance.- Parameters:
timer
- theTimer
that is used to trigger the scheduled event. The recommendedTimer
implementation isHashedWheelTimer
.timeoutSeconds
- write timeout in seconds
-
WriteTimeoutHandler
public WriteTimeoutHandler(Timer timer, long timeout, TimeUnit unit)
Creates a new instance.- Parameters:
timer
- theTimer
that is used to trigger the scheduled event. The recommendedTimer
implementation isHashedWheelTimer
.timeout
- write timeoutunit
- theTimeUnit
oftimeout
-
-
Method Detail
-
releaseExternalResources
public void releaseExternalResources()
Stops theTimer
which was specified in the constructor of this handler. You should not call this method if theTimer
is in use by other objects.- Specified by:
releaseExternalResources
in interfaceExternalResourceReleasable
-
getTimeoutMillis
protected long getTimeoutMillis(MessageEvent e)
Returns the write timeout of the specified event. By default, this method returns the timeout value you specified in the constructor. Override this method to determine the timeout value depending on the message being written.- Parameters:
e
- the message being written
-
writeRequested
public void writeRequested(ChannelHandlerContext ctx, MessageEvent e) throws Exception
Description copied from class:SimpleChannelDownstreamHandler
Invoked whenChannel.write(Object)
is called.- Overrides:
writeRequested
in classSimpleChannelDownstreamHandler
- Throws:
Exception
-
writeTimedOut
protected void writeTimedOut(ChannelHandlerContext ctx) throws Exception
- Throws:
Exception
-
-