Author: remy.maucherat(a)jboss.com
Date: 2008-01-31 06:44:51 -0500 (Thu, 31 Jan 2008)
New Revision: 412
Modified:
trunk/java/org/apache/catalina/connector/CometEventImpl.java
trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
trunk/java/org/apache/catalina/valves/CometConnectionManagerValve.java
trunk/java/org/apache/comet/CometEvent.java
Log:
- Get rid of event subtype. This removes the need to separate TIMEOUT from the other ERROR
types.
Also removes the different sorts of END events, which are quite pointless.
Modified: trunk/java/org/apache/catalina/connector/CometEventImpl.java
===================================================================
--- trunk/java/org/apache/catalina/connector/CometEventImpl.java 2008-01-31 07:30:52 UTC
(rev 411)
+++ trunk/java/org/apache/catalina/connector/CometEventImpl.java 2008-01-31 11:44:51 UTC
(rev 412)
@@ -62,11 +62,6 @@
protected EventType eventType = EventType.BEGIN;
- /**
- * Event sub type.
- */
- protected EventSubType eventSubType = null;
-
// --------------------------------------------------------- Public Methods
/**
@@ -77,14 +72,10 @@
response = null;
}
- public void setEventType(EventType eventType) {
+ public void setType(EventType eventType) {
this.eventType = eventType;
}
- public void setEventSubType(EventSubType eventSubType) {
- this.eventSubType = eventSubType;
- }
-
public void close() throws IOException {
if (request == null) {
throw new
IllegalStateException(sm.getString("cometEvent.nullRequest"));
@@ -93,11 +84,7 @@
response.finishResponse();
}
- public EventSubType getEventSubType() {
- return eventSubType;
- }
-
- public EventType getEventType() {
+ public EventType getType() {
return eventType;
}
@@ -129,9 +116,7 @@
StringBuffer buf = new StringBuffer("CometEventImpl[");
buf.append(super.toString());
buf.append("] Event:");
- buf.append(getEventType());
- buf.append(" SubType:");
- buf.append(getEventSubType());
+ buf.append(getType());
return buf.toString();
}
Modified: trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
===================================================================
--- trunk/java/org/apache/catalina/connector/CoyoteAdapter.java 2008-01-31 07:30:52 UTC
(rev 411)
+++ trunk/java/org/apache/catalina/connector/CoyoteAdapter.java 2008-01-31 11:44:51 UTC
(rev 412)
@@ -146,8 +146,7 @@
if (response.isClosed()) {
// The event has been closed asynchronously, so call end instead
of
// read to cleanup the pipeline
- request.getEvent().setEventType(CometEvent.EventType.END);
- request.getEvent().setEventSubType(null);
+ request.getEvent().setType(CometEvent.EventType.END);
} else {
try {
// Fill the read buffer of the servlet layer
@@ -158,11 +157,9 @@
error = true;
}
if (read) {
- request.getEvent().setEventType(CometEvent.EventType.READ);
- request.getEvent().setEventSubType(null);
+ request.getEvent().setType(CometEvent.EventType.READ);
} else if (error) {
- request.getEvent().setEventType(CometEvent.EventType.ERROR);
-
request.getEvent().setEventSubType(CometEvent.EventSubType.CLIENT_DISCONNECT);
+ request.getEvent().setType(CometEvent.EventType.ERROR);
} else {
// Data was present on the socket, but it did not translate
into actual
// entity body bytes
@@ -173,42 +170,33 @@
if (response.isClosed()) {
// The event has been closed asynchronously, so call end instead
of
// read to cleanup the pipeline
- request.getEvent().setEventType(CometEvent.EventType.END);
- request.getEvent().setEventSubType(null);
+ request.getEvent().setType(CometEvent.EventType.END);
} else {
- request.getEvent().setEventType(CometEvent.EventType.WRITE);
- request.getEvent().setEventSubType(null);
+ request.getEvent().setType(CometEvent.EventType.WRITE);
}
} else if (status == SocketStatus.OPEN_CALLBACK) {
if (response.isClosed()) {
// The event has been closed asynchronously, so call end instead
of
// read to cleanup the pipeline
- request.getEvent().setEventType(CometEvent.EventType.END);
- request.getEvent().setEventSubType(null);
+ request.getEvent().setType(CometEvent.EventType.END);
} else {
- request.getEvent().setEventType(CometEvent.EventType.EVENT);
- request.getEvent().setEventSubType(null);
+ request.getEvent().setType(CometEvent.EventType.EVENT);
}
} else if (status == SocketStatus.DISCONNECT) {
- request.getEvent().setEventType(CometEvent.EventType.ERROR);
-
request.getEvent().setEventSubType(CometEvent.EventSubType.CLIENT_DISCONNECT);
+ request.getEvent().setType(CometEvent.EventType.ERROR);
error = true;
} else if (status == SocketStatus.ERROR) {
- request.getEvent().setEventType(CometEvent.EventType.ERROR);
-
request.getEvent().setEventSubType(CometEvent.EventSubType.IOEXCEPTION);
+ request.getEvent().setType(CometEvent.EventType.ERROR);
error = true;
} else if (status == SocketStatus.STOP) {
- request.getEvent().setEventType(CometEvent.EventType.END);
-
request.getEvent().setEventSubType(CometEvent.EventSubType.SERVER_SHUTDOWN);
+ request.getEvent().setType(CometEvent.EventType.END);
} else if (status == SocketStatus.TIMEOUT) {
if (response.isClosed()) {
// The event has been closed asynchronously, so call end instead
of
// read to cleanup the pipeline
- request.getEvent().setEventType(CometEvent.EventType.END);
- request.getEvent().setEventSubType(null);
+ request.getEvent().setType(CometEvent.EventType.END);
} else {
- request.getEvent().setEventType(CometEvent.EventType.ERROR);
-
request.getEvent().setEventSubType(CometEvent.EventSubType.TIMEOUT);
+ request.getEvent().setType(CometEvent.EventType.TIMEOUT);
}
}
@@ -220,8 +208,7 @@
if (!error && !response.isClosed() &&
(request.getAttribute(Globals.EXCEPTION_ATTR) != null)) {
// An unexpected exception occurred while processing the event, so
// error should be called
- request.getEvent().setEventType(CometEvent.EventType.ERROR);
- request.getEvent().setEventSubType(null);
+ request.getEvent().setType(CometEvent.EventType.ERROR);
error = true;
connector.getContainer().getPipeline().getFirst().event(request,
response, request.getEvent());
}
@@ -232,8 +219,7 @@
// If this was a read and not all bytes have been read, or if no
data
// was read from the connector, then it is an error
log.error(sm.getString("coyoteAdapter.read"));
- request.getEvent().setEventType(CometEvent.EventType.ERROR);
-
request.getEvent().setEventSubType(CometEvent.EventSubType.IOEXCEPTION);
+ request.getEvent().setType(CometEvent.EventType.ERROR);
error = true;
connector.getContainer().getPipeline().getFirst().event(request,
response, request.getEvent());
}
Modified: trunk/java/org/apache/catalina/valves/CometConnectionManagerValve.java
===================================================================
--- trunk/java/org/apache/catalina/valves/CometConnectionManagerValve.java 2008-01-31
07:30:52 UTC (rev 411)
+++ trunk/java/org/apache/catalina/valves/CometConnectionManagerValve.java 2008-01-31
11:44:51 UTC (rev 412)
@@ -215,8 +215,7 @@
for (int i = 0; i < connectionInfos.length; i++) {
ConnectionInfo connectionInfo = connectionInfos[i];
try {
- ((CometEventImpl)
connectionInfo.event).setEventType(CometEvent.EventType.END);
- ((CometEventImpl)
connectionInfo.event).setEventSubType(CometEvent.EventSubType.WEBAPP_RELOAD);
+ ((CometEventImpl)
connectionInfo.event).setType(CometEvent.EventType.END);
getNext().event(connectionInfo.request,
connectionInfo.response, connectionInfo.event);
connectionInfo.event.close();
} catch (Exception e) {
@@ -304,9 +303,8 @@
ok = true;
} finally {
if (!ok || response.isClosed()
- || (event.getEventType() == CometEvent.EventType.END)
- || (event.getEventType() == CometEvent.EventType.ERROR
- && !(event.getEventSubType() ==
CometEvent.EventSubType.TIMEOUT))) {
+ || (event.getType() == CometEvent.EventType.END)
+ || (event.getType() == CometEvent.EventType.ERROR)) {
// Remove from tracked list, the connection is done
HttpSession session = request.getSession(true);
synchronized (session) {
@@ -346,8 +344,7 @@
for (int i = 0; i < connectionInfos.length; i++) {
ConnectionInfo connectionInfo = connectionInfos[i];
try {
- ((CometEventImpl)
connectionInfo.event).setEventType(CometEvent.EventType.END);
- ((CometEventImpl)
connectionInfo.event).setEventSubType(CometEvent.EventSubType.SESSION_END);
+ ((CometEventImpl)
connectionInfo.event).setType(CometEvent.EventType.END);
getNext().event(connectionInfo.request, connectionInfo.response,
connectionInfo.event);
connectionInfo.event.close();
} catch (Exception e) {
Modified: trunk/java/org/apache/comet/CometEvent.java
===================================================================
--- trunk/java/org/apache/comet/CometEvent.java 2008-01-31 07:30:52 UTC (rev 411)
+++ trunk/java/org/apache/comet/CometEvent.java 2008-01-31 11:44:51 UTC (rev 412)
@@ -65,6 +65,8 @@
* been initialized in the begin method should be reset. After this event has
* been processed, the request and response objects, as well as all their dependent
* objects will be recycled and used to process other requests.</li>
+ * <li>TIMEOUT - the connection timed out, but the connection will not be
closed unless
+ * the servlet uses the close method of the event</li>
* <li>EVENT - Event will be called by the container after the resume() method
is called,
* during which any operations can be performed, including closing the Comet
connection
* using the close() method.</li>
@@ -74,30 +76,10 @@
* method always returns true.</li>
* </ul>
*/
- public enum EventType {BEGIN, READ, END, ERROR, WRITE, EVENT}
+ public enum EventType { BEGIN, READ, END, TIMEOUT, ERROR, WRITE, EVENT }
/**
- * Enumeration containing event sub categories.
- * <br>
- * END events sub types:
- * <ul>
- * <li>WEBAPP_RELOAD - the web application is being reloaded</li>
- * <li>SERVER_SHUTDOWN - the server is shutting down</li>
- * <li>SESSION_END - the servlet ended the session</li>
- * </ul>
- * ERROR events sub types:
- * <ul>
- * <li>TIMEOUT - the connection timed out; note that this ERROR type is not
fatal, and
- * the connection will not be closed unless the servlet uses the close method of
the event</li>
- * <li>CLIENT_DISCONNECT - the client connection was closed</li>
- * <li>IOEXCEPTION - an IO exception occurred, such as invalid content, for
example, an invalid chunk block</li>
- * </ul>
- */
- public enum EventSubType { TIMEOUT, CLIENT_DISCONNECT, IOEXCEPTION, WEBAPP_RELOAD,
SERVER_SHUTDOWN, SESSION_END }
-
-
- /**
* Returns the HttpServletRequest.
*
* @return HttpServletRequest
@@ -117,24 +99,16 @@
* @return EventType
* @see #EventType
*/
- public EventType getEventType();
+ public EventType getType();
/**
- * Returns the sub type of this event.
- *
- * @return EventSubType
- * @see #EventSubType
- */
- public EventSubType getEventSubType();
-
- /**
* Ends the request, which marks the end of the comet session. This will send
* back to the client a notice that the server has no more data to send
* as part of this request. If this method is called from a Tomcat provided thread
* (during the processing of an event), the container will not call an END event.
* If this method is called asynchronously, an END event will be sent to the
* servlet (note that this event will be sent whenever another event would have
- * been sent, such as a READ or ERROR/TIMEOUT event).
+ * been sent, such as a READ or TIMEOUT event).
*
* @throws IOException if an IO exception occurs
*/
@@ -143,7 +117,7 @@
/**
* This method sets the timeout in milliseconds of idle time on the connection.
* The timeout is reset every time data is received from the connection. If a timeout
occurs, the
- * servlet will receive an ERROR/TIMEOUT event which will not result in automatically
closing
+ * servlet will receive an TIMEOUT event which will not result in automatically
closing
* the event (the event may be closed using the close() method).
*
* @param timeout The timeout in milliseconds for this connection, must be a positive
value, larger than 0