tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fha...@apache.org
Subject svn commit: r802026 - in /tomcat/trunk: java/javax/servlet/ java/org/apache/catalina/connector/ java/org/apache/catalina/core/ webapps/examples/WEB-INF/classes/async/
Date Fri, 07 Aug 2009 14:49:20 GMT
Author: fhanik
Date: Fri Aug  7 14:49:19 2009
New Revision: 802026

URL: http://svn.apache.org/viewvc?rev=802026&view=rev
Log:
Refactor location of AsyncContextImpl to o.a.catalina.core


Added:
    tomcat/trunk/java/org/apache/catalina/core/AsyncContextImpl.java
      - copied, changed from r802006, tomcat/trunk/java/org/apache/catalina/connector/AsyncContextImpl.java
    tomcat/trunk/java/org/apache/catalina/core/AsyncListenerWrapper.java
      - copied, changed from r802006, tomcat/trunk/java/org/apache/catalina/connector/AsyncListenerWrapper.java
Removed:
    tomcat/trunk/java/org/apache/catalina/connector/AsyncContextImpl.java
    tomcat/trunk/java/org/apache/catalina/connector/AsyncListenerWrapper.java
Modified:
    tomcat/trunk/java/javax/servlet/AsyncContext.java
    tomcat/trunk/java/javax/servlet/AsyncEvent.java
    tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
    tomcat/trunk/java/org/apache/catalina/connector/Request.java
    tomcat/trunk/java/org/apache/catalina/core/StandardWrapperValve.java
    tomcat/trunk/webapps/examples/WEB-INF/classes/async/Async0.java
    tomcat/trunk/webapps/examples/WEB-INF/classes/async/Async1.java
    tomcat/trunk/webapps/examples/WEB-INF/classes/async/Async2.java

Modified: tomcat/trunk/java/javax/servlet/AsyncContext.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/servlet/AsyncContext.java?rev=802026&r1=802025&r2=802026&view=diff
==============================================================================
--- tomcat/trunk/java/javax/servlet/AsyncContext.java (original)
+++ tomcat/trunk/java/javax/servlet/AsyncContext.java Fri Aug  7 14:49:19 2009
@@ -16,7 +16,7 @@
 */
 package javax.servlet;
 
-import org.apache.catalina.connector.AsyncContextImpl.AsyncState;
+import org.apache.catalina.core.AsyncContextImpl.AsyncState;
 
 /**
  * @since Servlet 3.0

Modified: tomcat/trunk/java/javax/servlet/AsyncEvent.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/servlet/AsyncEvent.java?rev=802026&r1=802025&r2=802026&view=diff
==============================================================================
--- tomcat/trunk/java/javax/servlet/AsyncEvent.java (original)
+++ tomcat/trunk/java/javax/servlet/AsyncEvent.java Fri Aug  7 14:49:19 2009
@@ -25,7 +25,7 @@
     private ServletRequest request;
     private ServletResponse response;
     
-    AsyncEvent(ServletRequest request, ServletResponse response) {
+    public AsyncEvent(ServletRequest request, ServletResponse response) {
         this.request = request;
         this.response = response;
     }

Modified: tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java?rev=802026&r1=802025&r2=802026&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java Fri Aug  7 14:49:19
2009
@@ -29,6 +29,7 @@
 import org.apache.catalina.Globals;
 import org.apache.catalina.Wrapper;
 import org.apache.tomcat.util.res.StringManager;
+import org.apache.catalina.core.AsyncContextImpl;
 import org.apache.catalina.util.URLEncoder;
 import org.apache.coyote.ActionCode;
 import org.apache.coyote.Adapter;
@@ -269,14 +270,8 @@
                    AsyncContextImpl asyncConImpl = (AsyncContextImpl)request.getAsyncContext();
                    //TODO SERVLET3 - async
                    //configure settings for timed out
-                   asyncConImpl.setState(AsyncContextImpl.AsyncState.TIMING_OUT);
+                   asyncConImpl.setTimeoutState();
                 }
-                if (status==SocketStatus.TIMEOUT) {
-                    AsyncContextImpl asyncConImpl = (AsyncContextImpl)request.getAsyncContext();
-                    //TODO SERVLET3 - async
-                    //configure settings for timed out
-                    asyncConImpl.setState(AsyncContextImpl.AsyncState.TIMING_OUT);
-                 }
                 connector.getContainer().getPipeline().getFirst().invoke(request, response);
             }catch (RuntimeException x) {
                 success = false;

Modified: tomcat/trunk/java/org/apache/catalina/connector/Request.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/Request.java?rev=802026&r1=802025&r2=802026&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/Request.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/Request.java Fri Aug  7 14:49:19 2009
@@ -36,6 +36,7 @@
 
 import javax.security.auth.Subject;
 import javax.servlet.AsyncContext;
+import javax.servlet.AsyncEvent;
 import javax.servlet.AsyncListener;
 import javax.servlet.DispatcherType;
 import javax.servlet.FilterChain;
@@ -62,6 +63,7 @@
 import org.apache.catalina.Realm;
 import org.apache.catalina.Session;
 import org.apache.catalina.Wrapper;
+import org.apache.catalina.core.AsyncContextImpl;
 import org.apache.catalina.realm.GenericPrincipal;
 import org.apache.catalina.util.Enumerator;
 import org.apache.catalina.util.ParameterMap;
@@ -1465,19 +1467,17 @@
 
     public AsyncContext startAsync() {
         // TODO SERVLET3 - async
+        return startAsync(getRequest(),response.getResponse());
+    }
+
+    public AsyncContext startAsync(ServletRequest request, ServletResponse response) {
         if (!isAsyncSupported()) throw new IllegalStateException("Not supported.");
         if (asyncContext==null) asyncContext = new AsyncContextImpl(this);
         else if (asyncContext.isStarted()) throw new IllegalStateException("Already started.");
         asyncContext.setStarted(getContext());
-        asyncContext.setServletRequest(getRequest());
-        asyncContext.setServletResponse(response.getResponse());
-        return asyncContext;
-    }
-
-    public AsyncContext startAsync(ServletRequest request, ServletResponse response) {
-        startAsync();
         asyncContext.setServletRequest(request);
         asyncContext.setServletResponse(response);
+        asyncContext.initEvent();
         //TODO SERVLET3 - async - need to retrieve the ServletContext here
         //or just the webapp classloader associated with to do 
         //run with start(Runnable)

Copied: tomcat/trunk/java/org/apache/catalina/core/AsyncContextImpl.java (from r802006, tomcat/trunk/java/org/apache/catalina/connector/AsyncContextImpl.java)
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/AsyncContextImpl.java?p2=tomcat/trunk/java/org/apache/catalina/core/AsyncContextImpl.java&p1=tomcat/trunk/java/org/apache/catalina/connector/AsyncContextImpl.java&r1=802006&r2=802026&rev=802026&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/AsyncContextImpl.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/AsyncContextImpl.java Fri Aug  7 14:49:19 2009
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.catalina.connector;
+package org.apache.catalina.core;
 
 import java.io.IOException;
 import java.util.ArrayList;
@@ -23,6 +23,7 @@
 import java.util.concurrent.atomic.AtomicReference;
 
 import javax.servlet.AsyncContext;
+import javax.servlet.AsyncEvent;
 import javax.servlet.AsyncListener;
 import javax.servlet.DispatcherType;
 import javax.servlet.RequestDispatcher;
@@ -35,6 +36,7 @@
 
 import org.apache.catalina.Context;
 import org.apache.catalina.Globals;
+import org.apache.catalina.connector.Request;
 import org.apache.coyote.ActionCode;
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
@@ -59,6 +61,7 @@
     private Context context = null;
     private AtomicReference<AsyncState> state = new AtomicReference<AsyncState>(AsyncState.NOT_STARTED);
     private long timeout = -1;
+    private AsyncEvent event = null;
     
     private Request request;
     
@@ -73,7 +76,7 @@
             state.compareAndSet(AsyncState.DISPATCHED, AsyncState.COMPLETING)) {
             // TODO SERVLET3 - async
             AtomicBoolean dispatched = new AtomicBoolean(false);
-            request.coyoteRequest.action(ActionCode.ACTION_ASYNC_COMPLETE,dispatched);
+            request.getCoyoteRequest().action(ActionCode.ACTION_ASYNC_COMPLETE,dispatched);
             if (!dispatched.get()) doInternalComplete(false);
         } else {
             throw new IllegalStateException("Complete not allowed. Invalid state:"+state.get());
@@ -129,7 +132,7 @@
             };
             this.dispatch = run;
             AtomicBoolean dispatched = new AtomicBoolean(false);
-            request.coyoteRequest.action(ActionCode.ACTION_ASYNC_DISPATCH, dispatched );
+            request.getCoyoteRequest().action(ActionCode.ACTION_ASYNC_DISPATCH, dispatched
);
             if (!dispatched.get()) {
                 try {
                     doInternalDispatch();
@@ -174,7 +177,7 @@
             };
             this.dispatch = r;
             AtomicBoolean dispatched = new AtomicBoolean(false);
-            request.coyoteRequest.action(ActionCode.ACTION_ASYNC_DISPATCH, dispatched );
+            request.getCoyoteRequest().action(ActionCode.ACTION_ASYNC_DISPATCH, dispatched
);
             if (!dispatched.get()) {
                 try {
                     doInternalDispatch();
@@ -192,21 +195,17 @@
     public void addAsyncListener(AsyncListener listener) {
         AsyncListenerWrapper wrapper = new AsyncListenerWrapper();
         wrapper.setListener(listener);
-        wrapper.setServletRequest(getServletRequest());
-        wrapper.setServletResponse(getServletResponse());
         listeners.add(wrapper);
     }
 
     public void addAsyncListener(AsyncListener listener, ServletRequest servletRequest, ServletResponse
servletResponse) {
         AsyncListenerWrapper wrapper = new AsyncListenerWrapper();
         wrapper.setListener(listener);
-        wrapper.setServletRequest(servletRequest);
-        wrapper.setServletResponse(servletResponse);
         listeners.add(wrapper);
     }
     
     
-    protected void recycle() {
+    public void recycle() {
         servletRequest = null;
         servletResponse = null;
         listeners.clear();
@@ -214,6 +213,7 @@
         state.set(AsyncState.NOT_STARTED);
         context = null;
         timeout = -1;
+        event = null;
     }
 
     public boolean isStarted() {
@@ -263,10 +263,10 @@
     
     public void doInternalDispatch() throws ServletException, IOException {
         if (this.state.compareAndSet(AsyncState.TIMING_OUT, AsyncState.DISPATCHED)) {
-            log.info("TIMING OUT!");
+            log.debug("TIMING OUT!");
             boolean listenerInvoked = false;
             for (AsyncListenerWrapper listener : listeners) {
-                listener.fireOnTimeout();
+                listener.fireOnTimeout(event);
                 listenerInvoked = true;
             }
             if (!listenerInvoked) {
@@ -302,7 +302,7 @@
         } else if (state.compareAndSet(AsyncState.COMPLETING, AsyncState.NOT_STARTED)) {
             for (AsyncListenerWrapper wrapper : listeners) {
                 try {
-                    wrapper.fireOnComplete();
+                    wrapper.fireOnComplete(event);
                 }catch (IOException x) {
                     //how does this propagate, or should it?
                     //TODO SERVLET3 - async 
@@ -336,7 +336,15 @@
     
     public void setAsyncTimeout(long timeout) {
         this.timeout = timeout;
-        request.coyoteRequest.action(ActionCode.ACTION_ASYNC_SETTIMEOUT,new Long(timeout));
+        request.getCoyoteRequest().action(ActionCode.ACTION_ASYNC_SETTIMEOUT,new Long(timeout));
+    }
+    
+    public void setTimeoutState() {
+        state.set(AsyncState.TIMING_OUT);
+    }
+    
+    public void initEvent() {
+        event = new AsyncEvent(getRequest(),getResponse()); 
     }
 
 }

Copied: tomcat/trunk/java/org/apache/catalina/core/AsyncListenerWrapper.java (from r802006,
tomcat/trunk/java/org/apache/catalina/connector/AsyncListenerWrapper.java)
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/AsyncListenerWrapper.java?p2=tomcat/trunk/java/org/apache/catalina/core/AsyncListenerWrapper.java&p1=tomcat/trunk/java/org/apache/catalina/connector/AsyncListenerWrapper.java&r1=802006&r2=802026&rev=802026&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/AsyncListenerWrapper.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/AsyncListenerWrapper.java Fri Aug  7 14:49:19
2009
@@ -14,10 +14,11 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
-package org.apache.catalina.connector;
+package org.apache.catalina.core;
 
 import java.io.IOException;
 
+import javax.servlet.AsyncEvent;
 import javax.servlet.AsyncListener;
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
@@ -29,34 +30,16 @@
 public class AsyncListenerWrapper {
 
     private AsyncListener listener = null;
-    private ServletRequest servletRequest = null;
-    private ServletResponse servletResponse = null;
     
-    public void fireOnComplete() throws IOException {
-        // TODO SERVLET 3 - async 
-
+    public void fireOnComplete(AsyncEvent event) throws IOException {
+        // TODO SERVLET 3 - async
+        listener.onComplete(event);
     }
 
 
-    public void fireOnTimeout() throws IOException {
+    public void fireOnTimeout(AsyncEvent event) throws IOException {
         // TODO SERVLET 3 - async 
-
-    }
-
-    public ServletRequest getServletRequest() {
-        return servletRequest;
-    }
-
-    public void setServletRequest(ServletRequest servletRequest) {
-        this.servletRequest = servletRequest;
-    }
-
-    public ServletResponse getServletResponse() {
-        return servletResponse;
-    }
-
-    public void setServletResponse(ServletResponse servletResponse) {
-        this.servletResponse = servletResponse;
+        listener.onTimeout(event);
     }
 
     public AsyncListener getListener() {

Modified: tomcat/trunk/java/org/apache/catalina/core/StandardWrapperValve.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardWrapperValve.java?rev=802026&r1=802025&r2=802026&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/StandardWrapperValve.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/StandardWrapperValve.java Fri Aug  7 14:49:19
2009
@@ -33,7 +33,6 @@
 import org.apache.catalina.CometProcessor;
 import org.apache.catalina.Context;
 import org.apache.catalina.Globals;
-import org.apache.catalina.connector.AsyncContextImpl;
 import org.apache.catalina.connector.ClientAbortException;
 import org.apache.catalina.connector.Request;
 import org.apache.catalina.connector.Response;

Modified: tomcat/trunk/webapps/examples/WEB-INF/classes/async/Async0.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/WEB-INF/classes/async/Async0.java?rev=802026&r1=802025&r2=802026&view=diff
==============================================================================
--- tomcat/trunk/webapps/examples/WEB-INF/classes/async/Async0.java (original)
+++ tomcat/trunk/webapps/examples/WEB-INF/classes/async/Async0.java Fri Aug  7 14:49:19 2009
@@ -48,7 +48,7 @@
                     try {
                         Thread.currentThread().setName("Async0-Thread");
                         log.info("Putting AsyncThread to sleep");
-                        Thread.sleep(10*1000);
+                        Thread.sleep(2*1000);
                         log.info("Dispatching");
                         actx.dispatch();
                     }catch (InterruptedException x) {

Modified: tomcat/trunk/webapps/examples/WEB-INF/classes/async/Async1.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/WEB-INF/classes/async/Async1.java?rev=802026&r1=802025&r2=802026&view=diff
==============================================================================
--- tomcat/trunk/webapps/examples/WEB-INF/classes/async/Async1.java (original)
+++ tomcat/trunk/webapps/examples/WEB-INF/classes/async/Async1.java Fri Aug  7 14:49:19 2009
@@ -42,7 +42,7 @@
                     String path = "/jsp/async/async1.jsp";
                     Thread.currentThread().setName("Async1-Thread");
                     log.info("Putting AsyncThread to sleep");
-                    Thread.sleep(10*1000);
+                    Thread.sleep(2*1000);
                     log.info("Dispatching to "+path);
                     actx.dispatch(path);
                 }catch (InterruptedException x) {

Modified: tomcat/trunk/webapps/examples/WEB-INF/classes/async/Async2.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/WEB-INF/classes/async/Async2.java?rev=802026&r1=802025&r2=802026&view=diff
==============================================================================
--- tomcat/trunk/webapps/examples/WEB-INF/classes/async/Async2.java (original)
+++ tomcat/trunk/webapps/examples/WEB-INF/classes/async/Async2.java Fri Aug  7 14:49:19 2009
@@ -41,7 +41,7 @@
                 try {
                     Thread.currentThread().setName("Async2-Thread");
                     log.info("Putting AsyncThread to sleep");
-                    Thread.sleep(10*1000);
+                    Thread.sleep(2*1000);
                     log.info("Writing data.");
                     actx.getResponse().getWriter().write("Output from background thread.
Time:"+System.currentTimeMillis()+"\n");
                     actx.complete();



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message