org.jboss.netty.handler.timeout
类 WriteTimeoutHandler

java.lang.Object
  继承者 org.jboss.netty.channel.SimpleChannelDownstreamHandler
      继承者 org.jboss.netty.handler.timeout.WriteTimeoutHandler
所有已实现的接口:
ChannelDownstreamHandler, ChannelHandler, ExternalResourceReleasable

@ChannelHandler.Sharable
public class WriteTimeoutHandler
extends SimpleChannelDownstreamHandler
implements ExternalResourceReleasable

当在一定的时间周期内没有数据被写则抛出WriteTimeoutException.

 public class MyPipelineFactory implements ChannelPipelineFactory {
 
     private final Timer timer;
 
     public MyPipelineFactory(Timer timer) {
         this.timer = timer;
     }
 
     public ChannelPipeline getPipeline() {
         // 该例子配置30秒读取超时:
         return Channels.pipeline(
             new WriteTimeoutHandler(timer, 30), // timer必须是共享的.
             new MyHandler());
     }
 }
 
 ServerBootstrap bootstrap = ...;
 Timer timer = new HashedWheelTimer();
 ...
 bootstrap.setPipelineFactory(new MyPipelineFactory(timer));
 
ReadTimeoutHandler被创建时Timer会被指定.当你的应用程序关闭,需要手工调用 releaseExternalResources()Timer.stop()关闭.

另请参见:
ReadTimeoutHandler, IdleStateHandler

嵌套类摘要
 
从接口 org.jboss.netty.channel.ChannelHandler 继承的嵌套类/接口
ChannelHandler.Sharable
 
构造方法摘要
WriteTimeoutHandler(Timer timer, int timeoutSeconds)
          创建一个实例.
WriteTimeoutHandler(Timer timer, long timeout, java.util.concurrent.TimeUnit unit)
          创建一个实例.
 
方法摘要
 void releaseExternalResources()
          停止该处理器在构造时指定的Timer.当该Timer被其他对象使用 ,你不能调用该方法.
 void writeRequested(ChannelHandlerContext ctx, MessageEvent e)
          当Channel.write(Object)被调用时调用.
 
从类 org.jboss.netty.channel.SimpleChannelDownstreamHandler 继承的方法
bindRequested, closeRequested, connectRequested, disconnectRequested, handleDownstream, setInterestOpsRequested, unbindRequested
 
从类 java.lang.Object 继承的方法
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

WriteTimeoutHandler

public WriteTimeoutHandler(Timer timer,
                           int timeoutSeconds)
创建一个实例.

参数:
timer - Timer 常常被用于触发计时事件.推荐的Timer实现是 HashedWheelTimer.
timeoutSeconds - 读超时秒数

WriteTimeoutHandler

public WriteTimeoutHandler(Timer timer,
                           long timeout,
                           java.util.concurrent.TimeUnit unit)
创建一个实例.

参数:
timer - Timer 常常被用于触发计时事件.推荐的Timer实现是 HashedWheelTimer.
timeout - 写超时数
unit - 写超时数的TimeUnit
方法详细信息

releaseExternalResources

public void releaseExternalResources()
停止该处理器在构造时指定的Timer.当该Timer被其他对象使用 ,你不能调用该方法.

指定者:
接口 ExternalResourceReleasable 中的 releaseExternalResources

writeRequested

public void writeRequested(ChannelHandlerContext ctx,
                           MessageEvent e)
                    throws java.lang.Exception
从类 SimpleChannelDownstreamHandler 复制的描述
Channel.write(Object)被调用时调用.

覆盖:
SimpleChannelDownstreamHandler 中的 writeRequested
抛出:
java.lang.Exception