cindy源码阅读(5)打开服务端SessionAcceptor




可以看到一个是阻塞的,一个是非阻塞的。BlockingSessionAcceptor的采用的是socket的accept,这个是会阻塞的。
而NonBlockingSessionAcceptor采用的session的封装,session.start().complete();session.start()得到的是个future,所以这个异步非阻塞的。
NonBlockingSessionAcceptor:
public synchronized void start() {
        if (getAcceptorHandler() == null)
            throw new IllegalStateException("acceptor handler is null");
        if (isStarted())
            return;

        ServerSocketChannel channel = null;
        try {
            channel = ServerSocketChannel.open();
            setServerSocketOptions(channel.socket());
            counter.set(0);
            session.setChannel(channel);
            session.start().complete();
        } catch (IOException e) {
            ChannelUtils.close(channel);
            exceptionCaught(e);
        }
    }

猜你喜欢

转载自huangyunbin.iteye.com/blog/1866342
今日推荐