01: //========================================================================
02: // Parts Copyright 2006 Mort Bay Consulting Pty. Ltd.
03: //------------------------------------------------------------------------
04: // Licensed under the Apache License, Version 2.0 (the "License");
05: // you may not use this file except in compliance with the License.
06: // You may obtain a copy of the License at
07: // http://www.apache.org/licenses/LICENSE-2.0
08: // Unless required by applicable law or agreed to in writing, software
09: // distributed under the License is distributed on an "AS IS" BASIS,
10: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11: // See the License for the specific language governing permissions and
12: // limitations under the License.
13: //========================================================================
14:
15: package org.mortbay.jetty.grizzly;
16:
17: import com.sun.enterprise.web.connector.grizzly.SelectorThread;
18: import com.sun.enterprise.web.connector.grizzly.StreamAlgorithm;
19: import java.io.IOException;
20: import com.sun.enterprise.web.connector.grizzly.XAReadTask;
21: import java.net.Socket;
22: import java.nio.channels.SocketChannel;
23: import java.nio.channels.spi.AbstractSelectableChannel;
24: import java.util.logging.Level;
25:
26: /**
27: * Prepare the <code>SocketChannel</code> for reading, and delegates the
28: * parsing works to the <code>JettyProcessorTask</code>
29: *
30: * @author Jeanfrancois Atcand
31: * @author gregw
32: */
33: public class JettyReadTask extends XAReadTask {
34:
35: public boolean executeProcessorTask() throws IOException {
36: boolean registerKey = false;
37:
38: if (SelectorThread.logger().isLoggable(Level.FINEST))
39: SelectorThread.logger().log(Level.FINEST,
40: "executeProcessorTask");
41:
42: /**
43: * TODO: File caching support? if ( algorithm.getHandler() != null &&
44: * algorithm.getHandler() .handle(null, Handler.REQUEST_BUFFERED) ==
45: * Handler.BREAK ){ return true; }
46: */
47:
48: // Get a processor task. If the processorTask != null, that means we
49: // failed to load all the bytes in a single channel.read().
50: if (processorTask == null) {
51: attachProcessor(selectorThread.getProcessorTask());
52: } else {
53: configureProcessorTask();
54: }
55:
56: try {
57: // The socket might not have been read entirely and the parsing
58: // will fail, so we need to respin another event.
59: registerKey = processorTask.process(inputStream, null);
60: } catch (Exception e) {
61: SelectorThread.logger().log(Level.SEVERE,
62: "readTask.processException", e);
63: registerKey = true;
64: } finally {
65:
66: // if registerKey, that means we were'nt able to parse the request
67: // properly because the bytes were not all read, so we need to
68: // call again the Selector.
69: if (registerKey) {
70: inKeepAliveProcess = false;
71: if (processorTask.isError()) {
72: byteBuffer = algorithm
73: .rollbackParseState(byteBuffer);
74: return true;
75: } else {
76: byteBuffer.clear();
77: }
78: }
79: }
80:
81: return registerKey;
82: }
83: }
|