|
|||||||||
| 上一个类 下一个类 | 框架 无框架 | ||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | ||||||||
java.lang.Objectorg.jboss.netty.handler.execution.ExecutionHandler
@ChannelHandler.Sharable public class ExecutionHandler

转发一个上游ChannelEvent到一个Executor.
当你的ChannelHandler执行一个需要长时间阻塞操作或访问一个非CPU绑定的业务逻辑如数据库访问时
ExecutionHandler经常被使用.在一个管道里没有使用ExecutionHandler
的运行这些操作会导致在I/O期间出现间断,因为一个I/O线程不能执行I/O,除非你的处理器返回控制权给I/O线程.
大多数情况下,一个ExecutionHandler和
OrderedMemoryAwareThreadPoolExecutor是成对出现的,因为它保证事件执行的正确顺序和防止加载出现
OutOfMemoryError:
public class DatabaseGatewayPipelineFactory implements请参考ChannelPipelineFactory{ private finalExecutionHandlerexecutionHandler; public DatabaseGatewayPipelineFactory(ExecutionHandlerexecutionHandler) { this.executionHandler = executionHandler; } publicChannelPipelinegetPipeline() { returnChannels.pipeline( new DatabaseGatewayProtocolEncoder(), new DatabaseGatewayProtocolDecoder(), executionHandler, // Must be shared new DatabaseQueryingHandler()); } } ... public static void main(String[] args) {ServerBootstrapbootstrap = ...; ...ExecutionHandlerexecutionHandler = newExecutionHandler( newOrderedMemoryAwareThreadPoolExecutor(16, 1048576, 1048576)) bootstrap.setPipelineFactory( new DatabaseGatewayPipelineFactory(executionHandler)); ... bootstrap.bind(...); ... while (!isServerReadyToShutDown()) { // ... wait ... } bootstrap.releaseExternalResources(); executionHandler.releaseExternalResources(); }
OrderedMemoryAwareThreadPoolExecutor了解更多关于如何保证事件顺序.
ExecutionHandler到管道里实现另一种线程模型如SEDA.
Executor实现OrderedMemoryAwareThreadPoolExecutor,不过你也可以使用其他
Executor实现.然而,你必须注意其他的Executor
实现可能会中断你的应该程序,因为他们通常不会维护事件执行顺序也不会于I/O线程交互的控制传入通信以及避免OutOfMemoryError.
| 嵌套类摘要 |
|---|
| 从接口 org.jboss.netty.channel.ChannelHandler 继承的嵌套类/接口 |
|---|
ChannelHandler.Sharable |
| 构造方法摘要 | |
|---|---|
ExecutionHandler(java.util.concurrent.Executor executor)
使用指定的 Executor创建一个新实例.如果不确定则指定一个
OrderedMemoryAwareThreadPoolExecutor. |
|
| 方法摘要 | |
|---|---|
java.util.concurrent.Executor |
getExecutor()
返回在构造方法指定的 Executor. |
void |
handleDownstream(ChannelHandlerContext ctx,
ChannelEvent e)
处理指定的下游事件. |
void |
handleUpstream(ChannelHandlerContext context,
ChannelEvent e)
处理一个指定的上游事件. |
void |
releaseExternalResources()
关闭在构造方法指定的 Executor和等待它的终止. |
| 从类 java.lang.Object 继承的方法 |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| 构造方法详细信息 |
|---|
public ExecutionHandler(java.util.concurrent.Executor executor)
Executor创建一个新实例.如果不确定则指定一个
OrderedMemoryAwareThreadPoolExecutor.
| 方法详细信息 |
|---|
public java.util.concurrent.Executor getExecutor()
Executor.
public void releaseExternalResources()
Executor和等待它的终止.
ExternalResourceReleasable 中的 releaseExternalResources
public void handleUpstream(ChannelHandlerContext context,
ChannelEvent e)
throws java.lang.Exception
ChannelUpstreamHandler 复制的描述
ChannelUpstreamHandler 中的 handleUpstreamcontext - 处理器的上下文对象e - 要处理或拦截的事件
java.lang.Exception
public void handleDownstream(ChannelHandlerContext ctx,
ChannelEvent e)
throws java.lang.Exception
ChannelDownstreamHandler 复制的描述
ChannelDownstreamHandler 中的 handleDownstreamctx - 处理器的上下文对象e - 要处理或拦截的事件
java.lang.Exception
|
|||||||||
| 上一个类 下一个类 | 框架 无框架 | ||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | ||||||||