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 aWriteTimeoutExceptionwhen no data was written within a certain period of time.public class MyPipelineFactory implements
TheChannelPipelineFactory{ 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));Timerwhich was specified when theReadTimeoutHandleris created should be stopped manually by callingreleaseExternalResources()orTimer.stop()when your application shuts down.- See Also:
ReadTimeoutHandler,IdleStateHandler
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classWriteTimeoutHandler.TimeoutCancellerprivate classWriteTimeoutHandler.WriteTimeoutTask-
Nested classes/interfaces inherited from interface org.jboss.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static WriteTimeoutExceptionEXCEPTIONprivate longtimeoutMillisprivate Timertimer
-
Constructor Summary
Constructors Constructor Description WriteTimeoutHandler(Timer timer, int timeoutSeconds)Creates a new instance.WriteTimeoutHandler(Timer timer, long timeout, java.util.concurrent.TimeUnit unit)Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected longgetTimeoutMillis(MessageEvent e)Returns the write timeout of the specified event.voidreleaseExternalResources()Stops theTimerwhich was specified in the constructor of this handler.voidwriteRequested(ChannelHandlerContext ctx, MessageEvent e)Invoked whenChannel.write(Object)is called.protected voidwriteTimedOut(ChannelHandlerContext ctx)-
Methods inherited from class org.jboss.netty.channel.SimpleChannelDownstreamHandler
bindRequested, closeRequested, connectRequested, disconnectRequested, handleDownstream, setInterestOpsRequested, unbindRequested
-
-
-
-
Field Detail
-
EXCEPTION
static final WriteTimeoutException EXCEPTION
-
timer
private final Timer timer
-
timeoutMillis
private final long timeoutMillis
-
-
Constructor Detail
-
WriteTimeoutHandler
public WriteTimeoutHandler(Timer timer, int timeoutSeconds)
Creates a new instance.- Parameters:
timer- theTimerthat is used to trigger the scheduled event. The recommendedTimerimplementation isHashedWheelTimer.timeoutSeconds- write timeout in seconds
-
WriteTimeoutHandler
public WriteTimeoutHandler(Timer timer, long timeout, java.util.concurrent.TimeUnit unit)
Creates a new instance.- Parameters:
timer- theTimerthat is used to trigger the scheduled event. The recommendedTimerimplementation isHashedWheelTimer.timeout- write timeoutunit- theTimeUnitoftimeout
-
-
Method Detail
-
releaseExternalResources
public void releaseExternalResources()
Stops theTimerwhich was specified in the constructor of this handler. You should not call this method if theTimeris in use by other objects.- Specified by:
releaseExternalResourcesin 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 java.lang.Exception
Description copied from class:SimpleChannelDownstreamHandlerInvoked whenChannel.write(Object)is called.- Overrides:
writeRequestedin classSimpleChannelDownstreamHandler- Throws:
java.lang.Exception
-
writeTimedOut
protected void writeTimedOut(ChannelHandlerContext ctx) throws java.lang.Exception
- Throws:
java.lang.Exception
-
-