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 a
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.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classprivate final classNested classes/interfaces inherited from interface ChannelHandler
ChannelHandler.Sharable -
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final WriteTimeoutExceptionprivate final longprivate final Timer -
Constructor Summary
ConstructorsConstructorDescriptionWriteTimeoutHandler(Timer timer, int timeoutSeconds) Creates a new instance.WriteTimeoutHandler(Timer timer, long timeout, TimeUnit unit) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected longReturns the write timeout of the specified event.voidStops theTimerwhich was specified in the constructor of this handler.voidInvoked whenChannel.write(Object)is called.protected voidMethods inherited from class SimpleChannelDownstreamHandler
bindRequested, closeRequested, connectRequested, disconnectRequested, handleDownstream, setInterestOpsRequested, unbindRequested
-
Field Details
-
EXCEPTION
-
timer
-
timeoutMillis
private final long timeoutMillis
-
-
Constructor Details
-
WriteTimeoutHandler
Creates a new instance.- Parameters:
timer- theTimerthat is used to trigger the scheduled event. The recommendedTimerimplementation isHashedWheelTimer.timeoutSeconds- write timeout in seconds
-
WriteTimeoutHandler
-
-
Method Details
-
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
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
Description copied from class:SimpleChannelDownstreamHandlerInvoked whenChannel.write(Object)is called.- Overrides:
writeRequestedin classSimpleChannelDownstreamHandler- Throws:
Exception
-
writeTimedOut
- Throws:
Exception
-