From: fhanik Date: Wed, 5 Aug 2009 20:55:50 +0000 (+0000) Subject: a little more on the timeout part X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=788143b116f3df4f8ffea6e46111de3010040166;p=tomcat7.0 a little more on the timeout part git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@801409 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/catalina/connector/AsyncContextImpl.java b/java/org/apache/catalina/connector/AsyncContextImpl.java index d27686eec..5526d4916 100644 --- a/java/org/apache/catalina/connector/AsyncContextImpl.java +++ b/java/org/apache/catalina/connector/AsyncContextImpl.java @@ -43,7 +43,7 @@ import org.apache.juli.logging.LogFactory; public class AsyncContextImpl implements AsyncContext { public static enum AsyncState { - NOT_STARTED, STARTED, DISPATCHING, DISPATCHED, COMPLETING + NOT_STARTED, STARTED, DISPATCHING, DISPATCHED, COMPLETING, TIMING_OUT } protected static Log log = LogFactory.getLog(AsyncContextImpl.class); @@ -220,7 +220,11 @@ public class AsyncContextImpl implements AsyncContext { } public void doInternalDispatch() throws ServletException, IOException { - if (this.state.compareAndSet(AsyncState.DISPATCHING, AsyncState.DISPATCHED)) { + if (this.state.compareAndSet(AsyncState.TIMING_OUT, AsyncState.DISPATCHED)) { + for (AsyncListenerWrapper listener : listeners) { + listener.fireOnTimeout(); + } + } else if (this.state.compareAndSet(AsyncState.DISPATCHING, AsyncState.DISPATCHED)) { if (this.dispatch!=null) { try { dispatch.run(); @@ -266,5 +270,13 @@ public class AsyncContextImpl implements AsyncContext { throw new IllegalStateException("Complete illegal. Invalid state:"+state.get()); } } + + public AsyncState getState() { + return state.get(); + } + + protected void setState(AsyncState st) { + state.set(st); + } } diff --git a/java/org/apache/catalina/connector/CoyoteAdapter.java b/java/org/apache/catalina/connector/CoyoteAdapter.java index 559dd8f8b..bd2f643ca 100644 --- a/java/org/apache/catalina/connector/CoyoteAdapter.java +++ b/java/org/apache/catalina/connector/CoyoteAdapter.java @@ -251,7 +251,7 @@ public class CoyoteAdapter } } - public boolean asyncDispatch(org.apache.coyote.Request req,org.apache.coyote.Response res) throws Exception { + public boolean asyncDispatch(org.apache.coyote.Request req,org.apache.coyote.Response res, SocketStatus status) throws Exception { Request request = (Request) req.getNote(ADAPTER_NOTES); Response response = (Response) res.getNote(ADAPTER_NOTES); @@ -267,6 +267,12 @@ public class CoyoteAdapter request.setAttribute(Globals.DISPATCHER_TYPE_ATTR, DispatcherType.ASYNC); // Calling the container try { + 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; diff --git a/java/org/apache/coyote/Adapter.java b/java/org/apache/coyote/Adapter.java index 05b24baf8..a712fcc78 100644 --- a/java/org/apache/coyote/Adapter.java +++ b/java/org/apache/coyote/Adapter.java @@ -50,6 +50,6 @@ public interface Adapter { public boolean event(Request req, Response res, SocketStatus status) throws Exception; - public boolean asyncDispatch(Request req,Response res) throws Exception; + public boolean asyncDispatch(Request req,Response res, SocketStatus status) throws Exception; } diff --git a/java/org/apache/coyote/http11/Http11NioProcessor.java b/java/org/apache/coyote/http11/Http11NioProcessor.java index 4534db674..8e4e4d416 100644 --- a/java/org/apache/coyote/http11/Http11NioProcessor.java +++ b/java/org/apache/coyote/http11/Http11NioProcessor.java @@ -799,7 +799,7 @@ public class Http11NioProcessor implements ActionHook { final NioEndpoint.KeyAttachment attach = (NioEndpoint.KeyAttachment)socket.getAttachment(false); try { rp.setStage(org.apache.coyote.Constants.STAGE_SERVICE); - error = !adapter.asyncDispatch(request, response); + error = !adapter.asyncDispatch(request, response, status); if ( !error ) { if (attach != null) { attach.setComet(comet); @@ -861,6 +861,7 @@ public class Http11NioProcessor implements ActionHook { error = false; keepAlive = true; comet = false; + async = false; long soTimeout = endpoint.getSoTimeout(); int keepAliveTimeout = endpoint.getKeepAliveTimeout(); @@ -870,7 +871,7 @@ public class Http11NioProcessor implements ActionHook { boolean recycle = true; final KeyAttachment ka = (KeyAttachment)socket.getAttachment(false); - while (!error && keepAlive && !comet) { + while (!error && keepAlive && !comet && !async) { //always default to our soTimeout ka.setTimeout(soTimeout); // Parsing the request header @@ -1324,9 +1325,7 @@ public class Http11NioProcessor implements ActionHook { NioEndpoint.KeyAttachment attach = (NioEndpoint.KeyAttachment)socket.getAttachment(false); long timeout = ((Long)param).longValue(); //if we are not piggy backing on a worker thread, set the timeout - RequestInfo rp = request.getRequestProcessor(); - if ( rp.getStage() != org.apache.coyote.Constants.STAGE_SERVICE ) //async handling - attach.setTimeout(timeout); + attach.setTimeout(timeout); } else if (actionCode == ActionCode.ACTION_ASYNC_DISPATCH) { RequestInfo rp = request.getRequestProcessor(); if ( rp.getStage() != org.apache.coyote.Constants.STAGE_SERVICE ) {//async handling diff --git a/java/org/apache/tomcat/util/net/NioEndpoint.java b/java/org/apache/tomcat/util/net/NioEndpoint.java index 5d63197a0..514958dc3 100644 --- a/java/org/apache/tomcat/util/net/NioEndpoint.java +++ b/java/org/apache/tomcat/util/net/NioEndpoint.java @@ -1710,6 +1710,13 @@ public class NioEndpoint { long nextTime = now+(timeout-delta); nextExpiration = (nextTime < nextExpiration)?nextTime:nextExpiration; } + }else if (ka.isAsync()) { + long delta = now - ka.getLastAccess(); + long timeout = (ka.getTimeout()==-1)?((long) socketProperties.getSoTimeout()):(ka.getTimeout()); + boolean isTimedout = delta > timeout; + if (isTimedout) { + processSocket(ka.getChannel(), SocketStatus.TIMEOUT, true); + } }//end if }catch ( CancelledKeyException ckx ) { cancelledKey(key, SocketStatus.ERROR,false);