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 a
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.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
private final class
Nested classes/interfaces inherited from interface org.jboss.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final WriteTimeoutException
private final long
private 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 long
Returns the write timeout of the specified event.void
Stops theTimer
which was specified in the constructor of this handler.void
Invoked whenChannel.write(Object)
is called.protected void
Methods inherited from class org.jboss.netty.channel.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
- theTimer
that is used to trigger the scheduled event. The recommendedTimer
implementation isHashedWheelTimer
.timeoutSeconds
- write timeout in seconds
-
WriteTimeoutHandler
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 Details
-
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
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:SimpleChannelDownstreamHandler
Invoked whenChannel.write(Object)
is called.- Overrides:
writeRequested
in classSimpleChannelDownstreamHandler
- Throws:
Exception
-
writeTimedOut
- Throws:
Exception
-