8. 架构-server启动流程
Server HandlerWrapper Handler (Container ) Connector
doStart ( )
s u p e r .doStart ( )
handler .s t a r t ( )
init
handlers
connectors [i] . s t a r t ( )
9. 架构-connector启动流程
SelectChannelConnector AggregateLifeCycle SelectManager QueuedThreadPool SelectSet [ ] Acceptor
doStart( )
o p e n( )
创建阻塞ServerSocketChannel
s u p e r.doStart ( )
s t a r t( )
dispatch (runnable )
r u n.doSelect( )
1.检 查、处 理 各 种 事 件
2.根 据Selector事 件 生
成新的事件
dispatch (Acceptor )
r u n.accept( )
ServerSocketChannel .a c c e p t( )
阻 塞 监 听 新s o c k e t连 接
10. 架构-连接建立流程(NIO)
Client Acceptor ( T h r e a d ) SelectSet (T h r e a d ) SelectManager SocketChannel
connect
ServerSocketChannel.
a c c e p t( )
register(SocketChannel)
SelectSet[i] .a d d C h a
n g e(SocketChannel)
SelectSet[i] .
w a k e u p( )
w a k e u p/ timeout
doSelect ( )
判断是否有新事
件,如 果 是 新 的
SocketChannel
channel.register(selector,S
n
electionKey.O P_R E A D,n u l l
l)
createEndPoint( )
SelectChannelEndPoint
来 管 理SocketChannel
11. 架构-处理请求流程
SelectSet (T h r e a d ) SelectChannelEndPoint QueuedThreadPool AsyncHttpConnection HttpParser Server ServletContextHandler
doSelect( )
Selector Read 事 件
schedule( )
dispatch( )
线 程 处 理R e a d 事 件
h a n d l e( )
parseAvailable( )
parseNext( )
headerComplete( )
handleRequest( )
handle( ) h a n d l e(S t r i n g, Request,
H t t p协 议 解 析 完 毕
HttpServletRequest,
HttpServletResponse )
开 始F i l t e r ,Serverlt