From c3d3ba1a0abec4355226ca66c9a98415b4e39f71 Mon Sep 17 00:00:00 2001 From: fhanik Date: Thu, 6 Aug 2009 16:25:04 +0000 Subject: [PATCH] If dispatch is called on a worker thread, simply execute it, instead of throwing exception. No need to hand off to container git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@801705 13f79535-47bb-0310-9956-ffa450edef68 --- .../catalina/connector/AsyncContextImpl.java | 24 ++++++++++++++++++++-- .../apache/coyote/http11/Http11NioProcessor.java | 3 ++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/java/org/apache/catalina/connector/AsyncContextImpl.java b/java/org/apache/catalina/connector/AsyncContextImpl.java index eabb9249d..c7f31ad62 100644 --- a/java/org/apache/catalina/connector/AsyncContextImpl.java +++ b/java/org/apache/catalina/connector/AsyncContextImpl.java @@ -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()); } diff --git a/java/org/apache/coyote/http11/Http11NioProcessor.java b/java/org/apache/coyote/http11/Http11NioProcessor.java index 7eb37f6dd..5926147c7 100644 --- a/java/org/apache/coyote/http11/Http11NioProcessor.java +++ b/java/org/apache/coyote/http11/Http11NioProcessor.java @@ -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); } } } -- 2.11.0