1 protected boolean processSocket(Socket socket) {
2 // Process the request from this socket
3 try {
4 SocketWrapper<Socket> wrapper = new SocketWrapper<Socket>(socket);
5 wrapper.setKeepAliveLeft(getMaxKeepAliveRequests());
6 // During shutdown, executor may be null - avoid NPE
7 if (!running) {
8 returnfalse;
9 }
10 getExecutor().execute(new SocketProcessor(wrapper));
11 } catch (RejectedExecutionException x) {
12 log.warn("Socket processing request was rejected for:"+socket,x);
13 returnfalse;
14 } catch (Throwable t) {
15 ExceptionUtils.handleThrowable(t);
16 // This means we got an OOM or similar creating a thread, or that
17 // the pool and its queue are full
18 log.error(sm.getString("endpoint.process.fail"), t);
19 returnfalse;
20 }
21 returntrue;
22 }
public Http11Protocol() {
endpoint = new JIoEndpoint();
cHandler = new Http11ConnectionHandler(this);
((JIoEndpoint) endpoint).setHandler(cHandler);
setSoLinger(Constants.DEFAULT_CONNECTION_LINGER);
setSoTimeout(Constants.DEFAULT_CONNECTION_TIMEOUT);
setTcpNoDelay(Constants.DEFAULT_TCP_NO_DELAY);
}
所以需要到
org.apache.coyote.http11.Http11Protocol
类的静态内部类 Http11ConnectionHandler 中找到 process 方法的定义,但当前定义里面没有,这个方法是在其父类
org.apache.coyote.AbstractProtocol.AbstractConnectionHandler
中定义的:
1 public SocketState process(SocketWrapper<S> socket,
2 SocketStatus status) {
3 Processor<S> processor = connections.remove(socket.getSocket());
4
5 if (status == SocketStatus.DISCONNECT && processor == null) {
6 //nothing more to be done endpoint requested a close
7 //and there are no object associated with this connection
8 return SocketState.CLOSED;
9 }
10
11 socket.setAsync(false);
12
13 try {
14 if (processor == null) {
15 processor = recycledProcessors.poll();
16 }
17 if (processor == null) {
18 processor = createProcessor();
19 }
20
21 initSsl(socket, processor);
22
23 SocketState state = SocketState.CLOSED;
24 do {
25 if (status == SocketStatus.DISCONNECT &&
26 !processor.isComet()) {
27 // Do nothing here, just wait for it to get recycled
28 // Don't do this for Comet we need to generate an end
29 // event (see BZ 54022)
30 } else if (processor.isAsync() ||
31 state == SocketState.ASYNC_END) {
32 state = processor.asyncDispatch(status);
33 } else if (processor.isComet()) {
34 state = processor.event(status);
35 } else if (processor.isUpgrade()) {
36 state = processor.upgradeDispatch();
37 } else {
38 state = processor.process(socket);
39 }
40
41 if (state != SocketState.CLOSED && processor.isAsync()) {
42 state = processor.asyncPostProcess();
43 }
44
45 if (state == SocketState.UPGRADING) {
46 // Get the UpgradeInbound handler
47 UpgradeInbound inbound = processor.getUpgradeInbound();
48 // Release the Http11 processor to be re-used
49 release(socket, processor, false, false);
50 // Create the light-weight upgrade processor
51 processor = createUpgradeProcessor(socket, inbound);
52 inbound.onUpgradeComplete();
53 }
54 } while (state == SocketState.ASYNC_END ||
55 state == SocketState.UPGRADING);
56
57 if (state == SocketState.LONG) {
58 // In the middle of processing a request/response. Keep the
59 // socket associated with the processor. Exact requirements
60 // depend on type of long poll
61 longPoll(socket, processor);
62 } else if (state == SocketState.OPEN) {
63 // In keep-alive but between requests. OK to recycle
64 // processor. Continue to poll for the next request.
65 release(socket, processor, false, true);
66 } else if (state == SocketState.SENDFILE) {
67 // Sendfile in progress. If it fails, the socket will be
68 // closed. If it works, the socket will be re-added to the
69 // poller
70 release(socket, processor, false, false);
71 } else if (state == SocketState.UPGRADED) {
72 // Need to keep the connection associated with the processor
73 longPoll(socket, processor);
74 } else {
75 // Connection closed. OK to recycle the processor.
76 if (!(processor instanceof UpgradeProcessor)) {
77 release(socket, processor, true, false);
78 }
79 }
80 return state;
81 } catch(java.net.SocketException e) {
82 // SocketExceptions are normal
83 getLog().debug(sm.getString(
84 "abstractConnectionHandler.socketexception.debug"), e);
85 } catch (java.io.IOException e) {
86 // IOExceptions are normal
87 getLog().debug(sm.getString(
88 "abstractConnectionHandler.ioexception.debug"), e);
89 }
90 // Future developers: if you discover any other
91 // rare-but-nonfatal exceptions, catch them here, and log as
92 // above.
93 catch (Throwable e) {
94 ExceptionUtils.handleThrowable(e);
95 // any other exception or error is odd. Here we log it
96 // with "ERROR" level, so it will show up even on
97 // less-than-verbose logs.
98 getLog().error(
99 sm.getString("abstractConnectionHandler.error"), e);
100 }
101 // Don't try to add upgrade processors back into the pool
102 if (!(processor instanceof UpgradeProcessor)) {
103 release(socket, processor, true, false);
104 }
105 return SocketState.CLOSED;
106 }