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
从类 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