hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r546628 - /jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpClientHandler.java
Date Tue, 12 Jun 2007 20:50:59 GMT
Author: olegk
Date: Tue Jun 12 13:50:58 2007
New Revision: 546628

URL: http://svn.apache.org/viewvc?view=rev&rev=546628
Log:
Fixed problem with the connection state synchronization

Modified:
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpClientHandler.java

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpClientHandler.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpClientHandler.java?view=diff&rev=546628&r1=546627&r2=546628
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpClientHandler.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpClientHandler.java
Tue Jun 12 13:50:58 2007
@@ -32,6 +32,7 @@
 package org.apache.http.nio.protocol;
 
 import java.io.IOException;
+import java.io.InterruptedIOException;
 import java.io.OutputStream;
 import java.net.InetAddress;
 
@@ -53,6 +54,7 @@
 import org.apache.http.nio.entity.ContentBufferEntity;
 import org.apache.http.nio.entity.ContentOutputStream;
 import org.apache.http.nio.params.HttpNIOParams;
+import org.apache.http.nio.protocol.ThrottlingHttpServiceHandler.ServerConnState;
 import org.apache.http.nio.util.ByteBufferAllocator;
 import org.apache.http.nio.util.ContentInputBuffer;
 import org.apache.http.nio.util.ContentOutputBuffer;
@@ -242,6 +244,8 @@
                                 conn);
                     }
                 }
+                
+                connState.notifyAll();
             }
             
         } catch (IOException ex) {
@@ -276,6 +280,8 @@
                 } else {
                     connState.setInputState(ClientConnState.REQUEST_BODY_STREAM);
                 }
+
+                connState.notifyAll();
             }
             
         } catch (IOException ex) {
@@ -317,16 +323,14 @@
                         conn.resetOutput();
                     }
                 }
+                
                 if (!canResponseHaveBody(request, response)) {
                     conn.resetInput();
                     response.setEntity(null);
+                    connState.setInputState(ClientConnState.RESPONSE_DONE);
                     
                     if (!this.connStrategy.keepAlive(response, context)) {
                         conn.close();
-                    } else {
-                        // Ready for another request
-                        connState.resetInput();
-                        connState.resetOutput();
                     }
                 }
 
@@ -341,6 +345,8 @@
                 this.httpProcessor.process(response, context);
                 
                 handleResponse(response, connState, conn);
+                
+                connState.notifyAll();
             }
             
         } catch (IOException ex) {
@@ -369,12 +375,15 @@
                 buffer.consumeContent(decoder);
                 if (decoder.isCompleted()) {
                     connState.setInputState(ClientConnState.RESPONSE_BODY_DONE);
+                    
                     if (!this.connStrategy.keepAlive(response, context)) {
                         conn.close();
                     }
                 } else {
                     connState.setInputState(ClientConnState.RESPONSE_BODY_STREAM);
                 }
+
+                connState.notifyAll();
             }
             
         } catch (IOException ex) {
@@ -391,9 +400,13 @@
 
         try {
             
-            if (connState.getOutputState() == ClientConnState.EXPECT_CONTINUE) {
-                connState.setOutputState(ClientConnState.REQUEST_SENT);
-                continueRequest(conn, connState);
+            synchronized (connState) {
+                if (connState.getOutputState() == ClientConnState.EXPECT_CONTINUE) {
+                    connState.setOutputState(ClientConnState.REQUEST_SENT);
+                    continueRequest(conn, connState);
+                    
+                    connState.notifyAll();
+                }
             }
             
         } catch (IOException ex) {
@@ -477,7 +490,7 @@
             });
         }
     }
-
+    
     private void handleResponse(
             final HttpResponse response,
             final ClientConnState connState,
@@ -491,7 +504,24 @@
                 try {
 
                     execHandler.handleResponse(response, context);
+                    
                     synchronized (connState) {
+                        
+                        try {
+                            for (;;) {
+                                int currentState = connState.getInputState();
+                                if (currentState == ClientConnState.RESPONSE_DONE) {
+                                    break;
+                                }
+                                if (currentState == ServerConnState.SHUTDOWN) {
+                                    throw new InterruptedIOException("Service interrupted");
+                                }
+                                connState.wait();
+                            }
+                        } catch (InterruptedException ex) {
+                            connState.shutdown();
+                        }
+                        
                         connState.resetInput();
                         connState.resetOutput();
                         conn.requestOutput();
@@ -520,6 +550,7 @@
         public static final int RESPONSE_RECEIVED          = 16;
         public static final int RESPONSE_BODY_STREAM       = 32;
         public static final int RESPONSE_BODY_DONE         = 64;
+        public static final int RESPONSE_DONE              = 64;
         
         private final SharedInputBuffer inbuffer; 
         private final SharedOutputBuffer outbuffer;



Mime
View raw message