|
|||||||||
| 上一个类 下一个类 | 框架 无框架 | ||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | ||||||||
java.lang.Objectorg.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory
public class NioClientSocketChannelFactory

用于创建基于NIO的客户端ServerSocketChannel的ServerSocketChannelFactory
.它利用引入了NIO非阻塞I/O模式有效率的服务多数量的并发连接.
在NioServerSocketChannelFactory里有两种类型的线程;一种是boss线程和另一种是worker线程.
一个NioClientSocketChannelFactory
有一个boss线程.当请求时会尝试一个连接.一旦连接尝试成功,boss线程就会把接收的Channel传输给由
NioClientSocketChannelFactory管理的worker线程中的一个.
一个NioClientSocketChannelFactory
会有一个或多个worker线程.一个worker线程会以非阻塞模式为一个或多个Channel执行非阻塞的读写操作.
所有线程会从在创建一个NioClientSocketChannelFactory时指定的Executor
获得.boss线程从bossExecutor获得,worker线程从workerExecutor
里获得.因此,你必须确定指定的Executor可以被足够多的线程使用.最好的赌注是指定一个
缓存线程池.
boss线程和worker线程都是延迟获取的,然后当没有任何东西需要处理时释放.当worker线程和boss线程被释放,所有关联的资源如
Selector 也被释放.因此, 要正常的关闭一个服务, 你应该做到以下几点:
releaseExternalResources().RejectedExecutionException
并且相应的资源可能没有适当的释放.
| 构造方法摘要 | |
|---|---|
NioClientSocketChannelFactory(java.util.concurrent.Executor bossExecutor,
java.util.concurrent.Executor workerExecutor)
创建一个实例.调用该构造方法和指定两倍可用处理器的 NioClientSocketChannelFactory(Executor, Executor, int)一样.可以通过
Runtime.availableProcessors()获取可用处理器的数量. |
|
NioClientSocketChannelFactory(java.util.concurrent.Executor bossExecutor,
java.util.concurrent.Executor workerExecutor,
int workerCount)
创建一个实例. |
|
| 方法摘要 | |
|---|---|
SocketChannel |
newChannel(ChannelPipeline pipeline)
创建和打开一个新的 Channel,并使用指定的 ChannelPipeline附加到新的
Channel. |
void |
releaseExternalResources()
释放该工厂依赖的外部资源. |
| 从类 java.lang.Object 继承的方法 |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| 构造方法详细信息 |
|---|
public NioClientSocketChannelFactory(java.util.concurrent.Executor bossExecutor,
java.util.concurrent.Executor workerExecutor)
NioClientSocketChannelFactory(Executor, Executor, int)一样.可以通过
Runtime.availableProcessors()获取可用处理器的数量.
bossExecutor - 执行boss线程的ExecutorworkerExecutor - 执行I/O worker线程的Executor
public NioClientSocketChannelFactory(java.util.concurrent.Executor bossExecutor,
java.util.concurrent.Executor workerExecutor,
int workerCount)
bossExecutor - 执行boss线程的ExecutorworkerExecutor - 执行I/O worker线程的ExecutorworkerCount - I/O worker最大线程数| 方法详细信息 |
|---|
public SocketChannel newChannel(ChannelPipeline pipeline)
ChannelFactory 复制的描述Channel,并使用指定的 ChannelPipeline附加到新的
Channel.
ChannelFactory 中的 newChannelClientSocketChannelFactory 中的 newChannelpipeline - 准备附加到新Channel的ChannelPipeline
public void releaseExternalResources()
ChannelFactory 复制的描述Executor就是外部资源.
当这些资源不被该工厂使用或不是应用程序的一部分时
,你可以很方便的调用该方法去释放所有外部资源.然而如果一个由该工厂管理的打开通道资源被释放时会导致意料.
ChannelFactory 中的 releaseExternalResourcesExternalResourceReleasable 中的 releaseExternalResources
|
|||||||||
| 上一个类 下一个类 | 框架 无框架 | ||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | ||||||||