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 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:
  • Field Details

    • EXCEPTION

      static final WriteTimeoutException EXCEPTION
    • timer

      private final Timer timer
    • timeoutMillis

      private final long timeoutMillis
  • Constructor Details

    • 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 Details