Mina服务器端启动 -- 1
程序员文章站
2024-01-06 17:27:46
...
SocketAcceptor acceptor = new NioSocketAcceptor();
public NioSocketAcceptor() { super(new DefaultSocketSessionConfig(), NioProcessor.class); //初始化前面设置在AbstractIoService 中的 sessionConfig ((DefaultSocketSessionConfig) getSessionConfig()).init(this); }
protected AbstractPollingIoAcceptor(IoSessionConfig sessionConfig, Class<? extends IoProcessor<T>> processorClass) { // new SimpleIoProcessorPool 新建 processor -- 处理线程 this(sessionConfig, null, new SimpleIoProcessorPool<T>(processorClass), true); }
//绑定端口 acceptor.bind(new InetSocketAddress(PORT));
AbstractIoAcceptor 的 public final void bind(Iterable<? extends SocketAddress> localAddresses) 方法中
boundAddresses.addAll(bindInternal(localAddressesCopy));
protected final Set<SocketAddress> bindInternal( List<? extends SocketAddress> localAddresses) throws Exception { // Create a bind request as a Future operation. When the selector // have handled the registration, it will signal this future. AcceptorOperationFuture request = new AcceptorOperationFuture( localAddresses); // adds the Registration request to the queue for the Workers // to handle //添加请求到注册列表 registerQueue.add(request); // creates the Acceptor instance and has the local // executor kick it off. //开始用线程监听通道 startupAcceptor(); // As we just started the acceptor, we have to unblock the select() // in order to process the bind request we just have added to the // registerQueue. wakeup(); // Now, we wait until this request is completed. request.awaitUninterruptibly(); if (request.getException() != null) { throw request.getException(); } // Update the local addresses. // setLocalAddresses() shouldn't be called from the worker thread // because of deadlock. Set<SocketAddress> newLocalAddresses = new HashSet<SocketAddress>(); for (H handle:boundHandles.values()) { newLocalAddresses.add(localAddress(handle)); } return newLocalAddresses; }
startupAcceptor 中启动了一个 Acceptor 启动Socket服务
推荐阅读
-
Mina服务器端启动 -- 1
-
Mina服务器端启动 -- 1
-
apmserv 1、Apache启动失败,请检查相关配置。2、MySQL5.1启动失败,请检查相关配置。该怎么处理
-
apmserv 1、Apache启动失败,请检查相关配置。2、MySQL5.1启动失败,请检查相关配置。该如何解决
-
Apache Mina 学习笔记(1) - 入门
-
REPLICATRORA_1保持ABENDED状态,无法启动问题处理
-
电脑开机要按f1才能继续启动进入系统的解决方法
-
开机时需要按F1或F2键后才能继续启动的解决方法汇总
-
神舟战神k550d i7d1笔记本怎么用u盘启动
-
神舟战神k550d i7d1笔记本怎么用u盘启动