Author: remy.maucherat(a)jboss.com
Date: 2008-10-29 11:34:21 -0400 (Wed, 29 Oct 2008)
New Revision: 827
Modified:
trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
trunk/java/org/apache/catalina/connector/InputBuffer.java
trunk/java/org/apache/coyote/http11/Http11AprProcessor.java
trunk/java/org/apache/coyote/http11/Http11AprProtocol.java
trunk/java/org/apache/coyote/http11/InternalAprInputBuffer.java
trunk/webapps/docs/changelog.xml
Log:
- Refactor processing of a READ event which could follow a BEGIN into the protocol
handler.
Modified: trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
===================================================================
--- trunk/java/org/apache/catalina/connector/CoyoteAdapter.java 2008-10-29 15:31:36 UTC
(rev 826)
+++ trunk/java/org/apache/catalina/connector/CoyoteAdapter.java 2008-10-29 15:34:21 UTC
(rev 827)
@@ -151,7 +151,8 @@
request.setComet(false);
close = true;
}
- if (status == SocketStatus.OPEN_READ) {
+ switch (status) {
+ case OPEN_READ:
if (!request.isComet()) {
// The event has been closed asynchronously, so call end instead
of
// read to cleanup the pipeline
@@ -181,7 +182,8 @@
return true;
}
}
- } else if (status == SocketStatus.OPEN_WRITE) {
+ break;
+ case OPEN_WRITE:
if (!request.isComet()) {
// The event has been closed asynchronously, so call end instead
of
// read to cleanup the pipeline
@@ -190,7 +192,8 @@
} else {
request.getEvent().setType(HttpEvent.EventType.WRITE);
}
- } else if (status == SocketStatus.OPEN_CALLBACK) {
+ break;
+ case OPEN_CALLBACK:
if (!request.isComet()) {
// The event has been closed asynchronously, so call end instead
of
// read to cleanup the pipeline
@@ -201,16 +204,17 @@
} else {
request.getEvent().setType(HttpEvent.EventType.EVENT);
}
- } else if (status == SocketStatus.DISCONNECT) {
+ break;
+ case DISCONNECT:
+ case ERROR:
request.getEvent().setType(HttpEvent.EventType.ERROR);
error = true;
- } else if (status == SocketStatus.ERROR) {
- request.getEvent().setType(HttpEvent.EventType.ERROR);
- error = true;
- } else if (status == SocketStatus.STOP) {
+ break;
+ case STOP:
request.getEvent().setType(HttpEvent.EventType.END);
close = true;
- } else if (status == SocketStatus.TIMEOUT) {
+ break;
+ case TIMEOUT:
if (!request.isComet()) {
// The event has been closed asynchronously, so call end instead
of
// read to cleanup the pipeline
@@ -219,6 +223,7 @@
} else {
request.getEvent().setType(HttpEvent.EventType.TIMEOUT);
}
+ break;
}
req.getRequestProcessor().setWorkerThreadName(Thread.currentThread().getName());
@@ -327,14 +332,7 @@
if (request.isComet()) {
if (!response.isClosed() && !response.isError()) {
res.action(ActionCode.ACTION_COMET_BEGIN, null);
- if (request.ready()) {
- // Invoke a read event right away if there are available
bytes
- if (event(req, res, SocketStatus.OPEN_READ)) {
- comet = true;
- }
- } else {
- comet = true;
- }
+ comet = true;
} else {
// Clear the filter chain, as otherwise it will not be reset
elsewhere
// since this is a Comet request
Modified: trunk/java/org/apache/catalina/connector/InputBuffer.java
===================================================================
--- trunk/java/org/apache/catalina/connector/InputBuffer.java 2008-10-29 15:31:36 UTC (rev
826)
+++ trunk/java/org/apache/catalina/connector/InputBuffer.java 2008-10-29 15:34:21 UTC (rev
827)
@@ -278,7 +278,7 @@
return -1;
}
int available = 0;
- if (state == BYTE_STATE) {
+ if (state != CHAR_STATE) {
available = bb.getLength();
if (request.isComet() && available == 0) {
try {
@@ -289,7 +289,7 @@
// will occur elsewhere
}
}
- } else if (state == CHAR_STATE) {
+ } else {
available = cb.getLength();
if (request.isComet() && available == 0) {
try {
Modified: trunk/java/org/apache/coyote/http11/Http11AprProcessor.java
===================================================================
--- trunk/java/org/apache/coyote/http11/Http11AprProcessor.java 2008-10-29 15:31:36 UTC
(rev 826)
+++ trunk/java/org/apache/coyote/http11/Http11AprProcessor.java 2008-10-29 15:34:21 UTC
(rev 827)
@@ -364,6 +364,11 @@
}
+ public boolean getAvailable() {
+ return inputBuffer.available();
+ }
+
+
/**
* Return compression level.
*/
Modified: trunk/java/org/apache/coyote/http11/Http11AprProtocol.java
===================================================================
--- trunk/java/org/apache/coyote/http11/Http11AprProtocol.java 2008-10-29 15:31:36 UTC
(rev 826)
+++ trunk/java/org/apache/coyote/http11/Http11AprProtocol.java 2008-10-29 15:34:21 UTC
(rev 827)
@@ -598,9 +598,15 @@
// processed by this thread will use either a new or a recycled
// processor.
connections.put(socket, processor);
- proto.endpoint.getCometPoller().add(socket,
processor.getCometTimeout(),
- processor.getReadNotifications(), false, false);
- } else {
+ if (processor.getAvailable() &&
processor.getReadNotifications()) {
+ // Call a read event right away
+ state = event(socket, SocketStatus.OPEN_READ);
+ } else {
+ proto.endpoint.getCometPoller().add(socket,
processor.getCometTimeout(),
+ processor.getReadNotifications(), false, false);
+ }
+ }
+ if (state != SocketState.LONG) {
recycledProcessors.offer(processor);
}
return state;
Modified: trunk/java/org/apache/coyote/http11/InternalAprInputBuffer.java
===================================================================
--- trunk/java/org/apache/coyote/http11/InternalAprInputBuffer.java 2008-10-29 15:31:36
UTC (rev 826)
+++ trunk/java/org/apache/coyote/http11/InternalAprInputBuffer.java 2008-10-29 15:34:21
UTC (rev 827)
@@ -314,6 +314,7 @@
lastActiveFilter = -1;
parsingHeader = true;
swallowInput = true;
+ available = false;
}
@@ -355,6 +356,7 @@
parsingHeader = true;
swallowInput = true;
nonBlocking = false;
+ available = false;
return (lastValid > 0);
@@ -749,6 +751,15 @@
}
+ /**
+ * Available bytes in the buffer ? (these may not translate to application
+ * readable data)
+ */
+ public boolean available() {
+ return (lastValid - pos > 0);
+ }
+
+
// ---------------------------------------------------- InputBuffer Methods
@@ -845,6 +856,7 @@
throw new IOException(sm.getString("iib.failedread"));
}
}
+ available = false;
}
Modified: trunk/webapps/docs/changelog.xml
===================================================================
--- trunk/webapps/docs/changelog.xml 2008-10-29 15:31:36 UTC (rev 826)
+++ trunk/webapps/docs/changelog.xml 2008-10-29 15:34:21 UTC (rev 827)
@@ -117,6 +117,9 @@
<fix>
Cleanup some type oddities in MimeHeaders. (remm)
</fix>
+ <fix>
+ Refactor generation of the READ event which follows a BEGIN into the HTTP
protocol handler. (remm)
+ </fix>
</changelog>
</subsection>
<subsection name="Jasper">