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

    @ChannelHandler.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 implements ChannelPipelineFactory {

         private final Timer timer;

         public MyPipelineFactory(Timer timer) {
             this.timer = timer;
         }

         public ChannelPipeline getPipeline() {
             // An example configuration that implements 30-second write timeout:
             return Channels.pipeline(
                 new WriteTimeoutHandler(timer, 30), // timer must be shared.
                 new MyHandler());
         }
     }

     ServerBootstrap bootstrap = ...;
     Timer timer = new HashedWheelTimer();
     ...
     bootstrap.setPipelineFactory(new MyPipelineFactory(timer));

The `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:
  `ReadTimeoutHandler`, `IdleStateHandler`

### Nested Class Summary

### Nested classes/interfaces inherited from interface org.jboss.netty.channel.ChannelHandler

`ChannelHandler.Sharable`

### Constructor Summary

Constructors
Constructor and Description
`WriteTimeoutHandler(Timer timer, int timeoutSeconds)` Creates a new instance.
`WriteTimeoutHandler(Timer timer, long timeout, TimeUnit unit)` Creates a new instance.

### Method Summary

Methods
`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)`

### Methods inherited from class org.jboss.netty.channel.SimpleChannelDownstreamHandler

`bindRequested, closeRequested, connectRequested, disconnectRequested, handleDownstream, setInterestOpsRequested, unbindRequested`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### WriteTimeoutHandler

    public WriteTimeoutHandler(Timer timer,
                       int timeoutSeconds)

Creates a new instance.

Parameters:
  `timer` - the `Timer` that is used to trigger the scheduled event. The recommended `Timer` implementation is `HashedWheelTimer`.
  `timeoutSeconds` - write timeout in seconds

#### WriteTimeoutHandler

    public WriteTimeoutHandler(Timer timer,
                       long timeout,
                       TimeUnit unit)

Creates a new instance.

Parameters:
  `timer` - the `Timer` that is used to trigger the scheduled event. The recommended `Timer` implementation is `HashedWheelTimer`.
  `timeout` - write timeout
  `unit` - the `TimeUnit` of `timeout`

### Method Detail

#### releaseExternalResources

    public void releaseExternalResources()

Stops the `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.

Specified by:
  `releaseExternalResources` in interface `ExternalResourceReleasable`

#### 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 when `Channel.write(Object)` is called.

Overrides:
  `writeRequested` in class `SimpleChannelDownstreamHandler`
Throws:
  `Exception`

#### writeTimedOut

    protected void writeTimedOut(ChannelHandlerContext ctx)
                          throws Exception

Throws:
  `Exception`