Author: remy.maucherat(a)jboss.com
Date: 2009-03-21 21:32:22 -0400 (Sat, 21 Mar 2009)
New Revision: 967
Modified:
trunk/java/org/apache/catalina/connector/HttpEventImpl.java
trunk/java/org/apache/catalina/connector/InputBuffer.java
trunk/java/org/apache/catalina/connector/OutputBuffer.java
trunk/java/org/apache/catalina/connector/Request.java
trunk/java/org/apache/catalina/connector/RequestFacade.java
trunk/java/org/apache/catalina/core/ApplicationFilterFactory.java
trunk/java/org/apache/catalina/core/BaseAnnotationScanner.java
trunk/java/org/apache/catalina/core/StandardWrapperValve.java
trunk/java/org/apache/catalina/valves/EventOrAsyncConnectionManagerValve.java
trunk/webapps/docs/aio.xml
Log:
- More comet -> event.
- Implement some more trivial Servlet 3.0 stuff.
- Use the new async dispatcher type for all event filtering, which is a lot better than
plain request.
Modified: trunk/java/org/apache/catalina/connector/HttpEventImpl.java
===================================================================
--- trunk/java/org/apache/catalina/connector/HttpEventImpl.java 2009-03-20 17:26:19 UTC
(rev 966)
+++ trunk/java/org/apache/catalina/connector/HttpEventImpl.java 2009-03-22 01:32:22 UTC
(rev 967)
@@ -114,7 +114,7 @@
}
public String toString() {
- StringBuffer buf = new StringBuffer("CometEventImpl[");
+ StringBuffer buf = new StringBuffer("HttpEventImpl[");
buf.append(super.toString());
buf.append("] Event:");
buf.append(getType());
Modified: trunk/java/org/apache/catalina/connector/InputBuffer.java
===================================================================
--- trunk/java/org/apache/catalina/connector/InputBuffer.java 2009-03-20 17:26:19 UTC (rev
966)
+++ trunk/java/org/apache/catalina/connector/InputBuffer.java 2009-03-22 01:32:22 UTC (rev
967)
@@ -239,7 +239,7 @@
/**
- * Clear cached encoders (to save memory for Comet requests).
+ * Clear cached encoders (to save memory for event requests).
*/
public void clearEncoders() {
encoders.clear();
Modified: trunk/java/org/apache/catalina/connector/OutputBuffer.java
===================================================================
--- trunk/java/org/apache/catalina/connector/OutputBuffer.java 2009-03-20 17:26:19 UTC
(rev 966)
+++ trunk/java/org/apache/catalina/connector/OutputBuffer.java 2009-03-22 01:32:22 UTC
(rev 967)
@@ -260,7 +260,7 @@
/**
- * Clear cached encoders (to save memory for Comet requests).
+ * Clear cached encoders (to save memory for event requests).
*/
public void clearEncoders() {
encoders.clear();
Modified: trunk/java/org/apache/catalina/connector/Request.java
===================================================================
--- trunk/java/org/apache/catalina/connector/Request.java 2009-03-20 17:26:19 UTC (rev
966)
+++ trunk/java/org/apache/catalina/connector/Request.java 2009-03-22 01:32:22 UTC (rev
967)
@@ -399,6 +399,7 @@
dispatcherType = null;
requestDispatcherPath = null;
+ asyncMode = false;
eventMode = false;
if (event != null) {
event.clear();
@@ -2757,10 +2758,8 @@
return null;
}
- @Override
public boolean isAsyncStarted() {
- // TODO Auto-generated method stub
- return false;
+ return asyncMode;
}
@Override
@@ -2769,10 +2768,8 @@
return false;
}
- @Override
public void setAsyncTimeout(long timeout) {
- // TODO Auto-generated method stub
-
+ setTimeout((timeout > Integer.MAX_VALUE) ? Integer.MAX_VALUE : (int)
timeout);
}
@Override
@@ -2788,16 +2785,26 @@
return null;
}
- @Override
public DispatcherType getDispatcherType() {
- // TODO Auto-generated method stub
- return null;
+ if (dispatcherType == null) {
+ return DispatcherType.REQUEST;
+ } else if (dispatcherType == ApplicationFilterFactory.REQUEST_INTEGER) {
+ return DispatcherType.REQUEST;
+ } else if (dispatcherType == ApplicationFilterFactory.ASYNC_INTEGER) {
+ return DispatcherType.ASYNC;
+ } else if (dispatcherType == ApplicationFilterFactory.ERROR_INTEGER) {
+ return DispatcherType.ERROR;
+ } else if (dispatcherType == ApplicationFilterFactory.FORWARD_INTEGER) {
+ return DispatcherType.FORWARD;
+ } else if (dispatcherType == ApplicationFilterFactory.INCLUDE_INTEGER) {
+ return DispatcherType.INCLUDE;
+ }
+ // Never happens
+ throw new IllegalStateException();
}
- @Override
public ServletResponse getServletResponse() {
- // TODO Auto-generated method stub
- return null;
+ return response;
}
}
Modified: trunk/java/org/apache/catalina/connector/RequestFacade.java
===================================================================
--- trunk/java/org/apache/catalina/connector/RequestFacade.java 2009-03-20 17:26:19 UTC
(rev 966)
+++ trunk/java/org/apache/catalina/connector/RequestFacade.java 2009-03-22 01:32:22 UTC
(rev 967)
@@ -1047,7 +1047,7 @@
sm.getString("requestFacade.nullRequest"));
}
- return request.getServletResponse();
+ return request.getResponse().getResponse();
}
}
Modified: trunk/java/org/apache/catalina/core/ApplicationFilterFactory.java
===================================================================
--- trunk/java/org/apache/catalina/core/ApplicationFilterFactory.java 2009-03-20 17:26:19
UTC (rev 966)
+++ trunk/java/org/apache/catalina/core/ApplicationFilterFactory.java 2009-03-22 01:32:22
UTC (rev 967)
@@ -52,6 +52,8 @@
public static final Integer INCLUDE_INTEGER = new Integer(INCLUDE);
public static final int REQUEST = 8;
public static final Integer REQUEST_INTEGER = new Integer(REQUEST);
+ public static final int ASYNC = 16;
+ public static final Integer ASYNC_INTEGER = new Integer(ASYNC);
public static final String DISPATCHER_TYPE_ATTR =
Globals.DISPATCHER_TYPE_ATTR;
@@ -346,6 +348,7 @@
* matches the dispatcher types specified in the FilterMap
*/
private boolean matchDispatcher(FilterMap filterMap, int dispatcher) {
+ // FIXME: add async
switch (dispatcher) {
case FORWARD : {
if (filterMap.getDispatcherMapping() == FilterMap.FORWARD ||
@@ -355,7 +358,15 @@
filterMap.getDispatcherMapping() == FilterMap.REQUEST_FORWARD ||
filterMap.getDispatcherMapping() == FilterMap.REQUEST_ERROR_FORWARD
||
filterMap.getDispatcherMapping() ==
FilterMap.REQUEST_ERROR_FORWARD_INCLUDE ||
- filterMap.getDispatcherMapping() ==
FilterMap.REQUEST_FORWARD_INCLUDE) {
+ filterMap.getDispatcherMapping() == FilterMap.REQUEST_FORWARD_INCLUDE
||
+ filterMap.getDispatcherMapping() == FilterMap.ASYNC_FORWARD ||
+ filterMap.getDispatcherMapping() == FilterMap.ASYNC_FORWARD_ERROR ||
+ filterMap.getDispatcherMapping() == FilterMap.ASYNC_INCLUDE_FORWARD
||
+ filterMap.getDispatcherMapping() ==
FilterMap.ASYNC_INCLUDE_ERROR_FORWARD ||
+ filterMap.getDispatcherMapping() == FilterMap.ASYNC_REQUEST_FORWARD
||
+ filterMap.getDispatcherMapping() ==
FilterMap.ASYNC_REQUEST_ERROR_FORWARD ||
+ filterMap.getDispatcherMapping() ==
FilterMap.ASYNC_REQUEST_ERROR_FORWARD_INCLUDE ||
+ filterMap.getDispatcherMapping() ==
FilterMap.ASYNC_REQUEST_FORWARD_INCLUDE) {
return true;
}
break;
@@ -368,7 +379,15 @@
filterMap.getDispatcherMapping() == FilterMap.REQUEST_INCLUDE ||
filterMap.getDispatcherMapping() == FilterMap.REQUEST_ERROR_INCLUDE
||
filterMap.getDispatcherMapping() ==
FilterMap.REQUEST_ERROR_FORWARD_INCLUDE ||
- filterMap.getDispatcherMapping() ==
FilterMap.REQUEST_FORWARD_INCLUDE) {
+ filterMap.getDispatcherMapping() == FilterMap.REQUEST_FORWARD_INCLUDE
||
+ filterMap.getDispatcherMapping() == FilterMap.ASYNC_INCLUDE ||
+ filterMap.getDispatcherMapping() == FilterMap.ASYNC_INCLUDE_ERROR ||
+ filterMap.getDispatcherMapping() == FilterMap.ASYNC_INCLUDE_FORWARD
||
+ filterMap.getDispatcherMapping() ==
FilterMap.ASYNC_INCLUDE_ERROR_FORWARD ||
+ filterMap.getDispatcherMapping() == FilterMap.ASYNC_REQUEST_INCLUDE
||
+ filterMap.getDispatcherMapping() ==
FilterMap.ASYNC_REQUEST_ERROR_INCLUDE ||
+ filterMap.getDispatcherMapping() ==
FilterMap.ASYNC_REQUEST_ERROR_FORWARD_INCLUDE ||
+ filterMap.getDispatcherMapping() ==
FilterMap.ASYNC_REQUEST_FORWARD_INCLUDE) {
return true;
}
break;
@@ -381,7 +400,15 @@
filterMap.getDispatcherMapping() == FilterMap.REQUEST_FORWARD ||
filterMap.getDispatcherMapping() == FilterMap.REQUEST_ERROR_FORWARD
||
filterMap.getDispatcherMapping() == FilterMap.REQUEST_FORWARD_INCLUDE
||
- filterMap.getDispatcherMapping() ==
FilterMap.REQUEST_ERROR_FORWARD_INCLUDE) {
+ filterMap.getDispatcherMapping() ==
FilterMap.REQUEST_ERROR_FORWARD_INCLUDE ||
+ filterMap.getDispatcherMapping() == FilterMap.ASYNC_REQUEST ||
+ filterMap.getDispatcherMapping() == FilterMap.ASYNC_REQUEST_ERROR ||
+ filterMap.getDispatcherMapping() == FilterMap.ASYNC_REQUEST_INCLUDE
||
+ filterMap.getDispatcherMapping() ==
FilterMap.ASYNC_REQUEST_ERROR_INCLUDE ||
+ filterMap.getDispatcherMapping() == FilterMap.ASYNC_REQUEST_FORWARD
||
+ filterMap.getDispatcherMapping() ==
FilterMap.ASYNC_REQUEST_ERROR_FORWARD ||
+ filterMap.getDispatcherMapping() ==
FilterMap.ASYNC_REQUEST_FORWARD_INCLUDE ||
+ filterMap.getDispatcherMapping() ==
FilterMap.ASYNC_REQUEST_ERROR_FORWARD_INCLUDE) {
return true;
}
break;
@@ -394,11 +421,40 @@
filterMap.getDispatcherMapping() == FilterMap.REQUEST_ERROR ||
filterMap.getDispatcherMapping() == FilterMap.REQUEST_ERROR_FORWARD
||
filterMap.getDispatcherMapping() ==
FilterMap.REQUEST_ERROR_FORWARD_INCLUDE ||
- filterMap.getDispatcherMapping() == FilterMap.REQUEST_ERROR_INCLUDE)
{
+ filterMap.getDispatcherMapping() == FilterMap.REQUEST_ERROR_INCLUDE
||
+ filterMap.getDispatcherMapping() == FilterMap.ASYNC_ERROR ||
+ filterMap.getDispatcherMapping() == FilterMap.ASYNC_FORWARD_ERROR ||
+ filterMap.getDispatcherMapping() == FilterMap.ASYNC_INCLUDE_ERROR ||
+ filterMap.getDispatcherMapping() ==
FilterMap.ASYNC_INCLUDE_ERROR_FORWARD ||
+ filterMap.getDispatcherMapping() == FilterMap.ASYNC_REQUEST_ERROR ||
+ filterMap.getDispatcherMapping() ==
FilterMap.ASYNC_REQUEST_ERROR_FORWARD ||
+ filterMap.getDispatcherMapping() ==
FilterMap.ASYNC_REQUEST_ERROR_FORWARD_INCLUDE ||
+ filterMap.getDispatcherMapping() ==
FilterMap.ASYNC_REQUEST_ERROR_INCLUDE) {
return true;
}
break;
}
+ case ASYNC : {
+ if (filterMap.getDispatcherMapping() == FilterMap.ASYNC ||
+ filterMap.getDispatcherMapping() == FilterMap.ASYNC_ERROR ||
+ filterMap.getDispatcherMapping() == FilterMap.ASYNC_FORWARD ||
+ filterMap.getDispatcherMapping() == FilterMap.ASYNC_FORWARD_ERROR ||
+ filterMap.getDispatcherMapping() == FilterMap.ASYNC_INCLUDE ||
+ filterMap.getDispatcherMapping() == FilterMap.ASYNC_INCLUDE_ERROR ||
+ filterMap.getDispatcherMapping() ==
FilterMap.ASYNC_INCLUDE_ERROR_FORWARD ||
+ filterMap.getDispatcherMapping() == FilterMap.ASYNC_INCLUDE_FORWARD
||
+ filterMap.getDispatcherMapping() == FilterMap.ASYNC_REQUEST ||
+ filterMap.getDispatcherMapping() == FilterMap.ASYNC_REQUEST_ERROR ||
+ filterMap.getDispatcherMapping() ==
FilterMap.ASYNC_REQUEST_ERROR_FORWARD ||
+ filterMap.getDispatcherMapping() ==
FilterMap.ASYNC_REQUEST_ERROR_FORWARD_INCLUDE ||
+ filterMap.getDispatcherMapping() ==
FilterMap.ASYNC_REQUEST_ERROR_INCLUDE ||
+ filterMap.getDispatcherMapping() == FilterMap.ASYNC_REQUEST_FORWARD
||
+ filterMap.getDispatcherMapping() == FilterMap.ASYNC_REQUEST_INCLUDE
||
+ filterMap.getDispatcherMapping() ==
FilterMap.ASYNC_REQUEST_FORWARD_INCLUDE) {
+ return true;
+ }
+ break;
+ }
}
return false;
}
Modified: trunk/java/org/apache/catalina/core/BaseAnnotationScanner.java
===================================================================
--- trunk/java/org/apache/catalina/core/BaseAnnotationScanner.java 2009-03-20 17:26:19 UTC
(rev 966)
+++ trunk/java/org/apache/catalina/core/BaseAnnotationScanner.java 2009-03-22 01:32:22 UTC
(rev 967)
@@ -1,18 +1,23 @@
/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- *
http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
*/
Modified: trunk/java/org/apache/catalina/core/StandardWrapperValve.java
===================================================================
--- trunk/java/org/apache/catalina/core/StandardWrapperValve.java 2009-03-20 17:26:19 UTC
(rev 966)
+++ trunk/java/org/apache/catalina/core/StandardWrapperValve.java 2009-03-22 01:32:22 UTC
(rev 967)
@@ -392,7 +392,7 @@
}
request.setAttribute
(ApplicationFilterFactory.DISPATCHER_TYPE_ATTR,
- ApplicationFilterFactory.REQUEST_INTEGER);
+ ApplicationFilterFactory.ASYNC_INTEGER);
request.setAttribute
(ApplicationFilterFactory.DISPATCHER_REQUEST_PATH_ATTR,
requestPathMB);
Modified: trunk/java/org/apache/catalina/valves/EventOrAsyncConnectionManagerValve.java
===================================================================
---
trunk/java/org/apache/catalina/valves/EventOrAsyncConnectionManagerValve.java 2009-03-20
17:26:19 UTC (rev 966)
+++
trunk/java/org/apache/catalina/valves/EventOrAsyncConnectionManagerValve.java 2009-03-22
01:32:22 UTC (rev 967)
@@ -191,6 +191,7 @@
public void lifecycleEvent(LifecycleEvent event) {
if (event.getType() == Lifecycle.BEFORE_STOP_EVENT) {
+ // FIXME: in that case, it could be useful to wait until end events are
processed. Mmmm.
// The container is getting stopped, close all current connections
Iterator<Request> iterator = cometRequests.iterator();
while (iterator.hasNext()) {
Modified: trunk/webapps/docs/aio.xml
===================================================================
--- trunk/webapps/docs/aio.xml 2009-03-20 17:26:19 UTC (rev 966)
+++ trunk/webapps/docs/aio.xml 2009-03-22 01:32:22 UTC (rev 967)
@@ -210,7 +210,27 @@
the HttpEventFiler interface.
</p>
- </subsection>
+ <subsection name="Servlet 3.0 Async">
+
+ <p>
+ Servlet 3.0 introduces async support to regular Servlets, roughly equivalent to this
event API
+ excluding the events generated from actual IO (READ and WRITE). Internally, async
support is
+ implemented using the event functionality, and presented to the user through the
Servlet API.
+ </p>
+
+ <!--subsection name="Tracking session and webapp lifecycle">
+
+ <p>
+ Since the duration of the request processing is much longer when using event based
connections,
+ sessions might expire and webapps might be reloaded. The
EventOrAsyncConnectionManagerValve valve
+ can be used to generate END events when this occurs. It is configured using a regular
valve element,
+ using the
<code>org.apache.catalina.valves.EventOrAsyncConnectionManagerValve</code>
className, and
+ it does not have any configuration parameters. As events are asynchronous while
webapp and session
+ lifecycle are not, no guarantee is given that an END event will be sent when
redeploying a webapp, or
+ that the session will be still valid during processing of the END event.
+ </p>
+
+ </subsection-->
<subsection name="Example code">