jetty的請求過程
- ServerConnector.doStart調用open打開ServerSocketChannel
public void open() throws IOException
{
_acceptChannel = openAcceptChannel();
_acceptChannel.configureBlocking(true);
}
- AbstractConnector.doStart創建Acceptor去監聽請求鏈接
protected void doStart() throws Exception{
for (int i = 0; i < _acceptors.length; i++)
{
Acceptor a = new Acceptor(i);
getExecutor().execute(a);
}
}
public void accept(int acceptorID) throws IOException
{
ServerSocketChannel serverChannel = _acceptChannel;
if (serverChannel != null && serverChannel.isOpen())
{
SocketChannel channel = serverChannel.accept();
accepted(channel);
}
}
private void accepted(SocketChannel channel) throws IOException
{
channel.configureBlocking(false);
Socket socket = channel.socket();
configure(socket);
_manager.accept(channel);
}
- SelectorManager選擇selector,並將新的channel註冊進去
public void accept(SelectableChannel channel, Object attachment)
{
final ManagedSelector selector = chooseSelector();
selector.submit(selector.new Accept(channel, attachment));
}
public void update(Selector selector)
{
key = channel.register(selector, 0, attachment);
execute(this);
}
- SelectorManager.doStart方法通過_strategy去啓動SelectorProducer專門消費事件
public Runnable produce()
{
while (true)
{
Runnable task = processSelected();
if (task != null)
return task;
if (!select())
return null;
}
}