tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fha...@apache.org
Subject svn commit: r801409 - in /tomcat/trunk/java/org/apache: catalina/connector/AsyncContextImpl.java catalina/connector/CoyoteAdapter.java coyote/Adapter.java coyote/http11/Http11NioProcessor.java tomcat/util/net/NioEndpoint.java
Date Wed, 05 Aug 2009 20:55:50 GMT
Author: fhanik
Date: Wed Aug  5 20:55:50 2009
New Revision: 801409

URL: http://svn.apache.org/viewvc?rev=801409&view=rev
Log:
a little more on the timeout part

Modified:
    tomcat/trunk/java/org/apache/catalina/connector/AsyncContextImpl.java
    tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
    tomcat/trunk/java/org/apache/coyote/Adapter.java
    tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java
    tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java

Modified: tomcat/trunk/java/org/apache/catalina/connector/AsyncContextImpl.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/AsyncContextImpl.java?rev=801409&r1=801408&r2=801409&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/AsyncContextImpl.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/AsyncContextImpl.java Wed Aug  5 20:55:50
2009
@@ -43,7 +43,7 @@
 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 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 @@
             throw new IllegalStateException("Complete illegal. Invalid state:"+state.get());
         }
     }
+    
+    public AsyncState getState() {
+        return state.get();
+    }
+    
+    protected void setState(AsyncState st) {
+        state.set(st);
+    }
 
 }

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=801409&r1=801408&r2=801409&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java Wed Aug  5 20:55:50
2009
@@ -251,7 +251,7 @@
         }
     }
     
-    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 @@
             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;

Modified: tomcat/trunk/java/org/apache/coyote/Adapter.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/Adapter.java?rev=801409&r1=801408&r2=801409&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/Adapter.java (original)
+++ tomcat/trunk/java/org/apache/coyote/Adapter.java Wed Aug  5 20:55:50 2009
@@ -50,6 +50,6 @@
     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;
 
 }

Modified: tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java?rev=801409&r1=801408&r2=801409&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java Wed Aug  5 20:55:50
2009
@@ -799,7 +799,7 @@
         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 @@
         error = false;
         keepAlive = true;
         comet = false;
+        async = false;
         
         long soTimeout = endpoint.getSoTimeout();
         int keepAliveTimeout = endpoint.getKeepAliveTimeout();
@@ -870,7 +871,7 @@
         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 @@
             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

Modified: tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java?rev=801409&r1=801408&r2=801409&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Wed Aug  5 20:55:50 2009
@@ -1710,6 +1710,13 @@
                             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);



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


Mime
View raw message