Mina服务器端启动 -- 1


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服务
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值