1.1.1.1 请求到响应界面流
请求处理的过程主要是将所有的东西解析成流,转化成对应的http报文,所以在这里我先不关注servlet因为它最终也就是解析成流里面的数据
processKey里面最终执行的是processSocket,它是线从缓存中获取对应的线程池,没有的话就创建一个,然后进行执行
protected boolean processSocket(KeyAttachmentattachment, SocketStatus status, boolean dispatch) {
try {
if (attachment== null) {
return false;
}
SocketProcessor sc = processorCache.pop();
if ( sc == null ) sc = new SocketProcessor(attachment, status);
else sc.reset(attachment, status);
Executor executor =getExecutor();
if (dispatch &&executor != null) {
executor.execute(sc);
} else {
sc.run();
}
} catch (RejectedExecutionExceptionree) {
log.warn(sm.getString("endpoint.executor.fail", attachment.getSocket()), ree);
return false;
} catch (Throwablet) {
ExceptionUtils.handleThrowable(t);
// This means we got anOOM or similar creating a thread, or that
// the pool and its queue arefull
log.error(sm.getString("endpoint.process.fail"), t);
return false;
}
return true;
}
在上面描述的线程中,响应到页面主要是先构建对应的缓冲流,然后将缓冲流中的数据写入到sockt通道,这样就实现到了页面,具体操作逻辑如下:(自下向上执行)
下面我将与流相关的几步,进行一下讲述:
process:,AbstractProtocol$AbstractConnectionHandler (org.apache.coyote)
if (processor == null) {
processor = createProcessor();
}
protected Http11Processor createProcessor() {
Http11Processor processor = new Http11Processor(
proto.getMaxHttpHeaderSize(), (JIoEndpoint)proto.endpoint,
proto.getMaxTrailerSize(), proto.getAllowedTrailerHeadersAsSet(),
proto.getMaxExtensionSize(), proto.getMaxSwallowSize());
proto.configureProcessor(processor);
// BIO specificconfiguration
processor.setDisableKeepAlivePercentage(proto.getDisableKeepAlivePercentage());
register(processor);
return processor;