## 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.

Version:
  $Rev: 2222 $, $Date: 2010-03-24 14:07:27 +0900 (Wed, 24 Mar 2010) $
Author:
  The Netty Project, Trustin Lee
See Also:
  `ReadTimeoutHandler`, `IdleStateHandler`

Nested Class Summary

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

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

Method Summary
`protected long` `getTimeoutMillis(MessageEvent e)`
`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)

### 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`

Copyright © 2008-2010 JBoss, a division of Red Hat, Inc.. All Rights Reserved.