If dispatch is called on a worker thread, simply execute it, instead of throwing...
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 6 Aug 2009 16:25:04 +0000 (16:25 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 6 Aug 2009 16:25:04 +0000 (16:25 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@801705 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/connector/AsyncContextImpl.java
java/org/apache/coyote/http11/Http11NioProcessor.java

index eabb924..c7f31ad 100644 (file)
@@ -122,7 +122,17 @@ public class AsyncContextImpl implements AsyncContext {
                 }
             };
             this.dispatch = run;
-            request.coyoteRequest.action(ActionCode.ACTION_ASYNC_DISPATCH, null );
+            AtomicBoolean dispatched = new AtomicBoolean(false);
+            request.coyoteRequest.action(ActionCode.ACTION_ASYNC_DISPATCH, dispatched );
+            if (!dispatched.get()) {
+                try {
+                    doInternalDispatch();
+                }catch (ServletException sx) {
+                    throw new RuntimeException(sx);
+                }catch (IOException ix) {
+                    throw new RuntimeException(ix);
+                }
+            }
 
         } else {
             throw new IllegalStateException("Dispatch not allowed. Invalid state:"+state.get());
@@ -154,7 +164,17 @@ public class AsyncContextImpl implements AsyncContext {
                 }
             };
             this.dispatch = r;
-            request.coyoteRequest.action(ActionCode.ACTION_ASYNC_DISPATCH, null );
+            AtomicBoolean dispatched = new AtomicBoolean(false);
+            request.coyoteRequest.action(ActionCode.ACTION_ASYNC_DISPATCH, dispatched );
+            if (!dispatched.get()) {
+                try {
+                    doInternalDispatch();
+                }catch (ServletException sx) {
+                    throw new RuntimeException(sx);
+                }catch (IOException ix) {
+                    throw new RuntimeException(ix);
+                }
+            }
         } else {
             throw new IllegalStateException("Dispatch not allowed. Invalid state:"+state.get());
         }
index 7eb37f6..5926147 100644 (file)
@@ -1323,10 +1323,11 @@ public class Http11NioProcessor implements ActionHook {
             attach.setTimeout(timeout);
         } else if (actionCode == ActionCode.ACTION_ASYNC_DISPATCH) {
             RequestInfo rp = request.getRequestProcessor();
+            AtomicBoolean dispatch = (AtomicBoolean)param;
             if ( rp.getStage() != org.apache.coyote.Constants.STAGE_SERVICE ) {//async handling
                 endpoint.processSocket(this.socket, SocketStatus.OPEN, true);
             } else { 
-                throw new UnsupportedOperationException("Can't call dispatch on the worker thread.");
+                dispatch.set(true);
             }
         }
     }