hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r515681 - in /jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio: protocol/ util/
Date Wed, 07 Mar 2007 18:26:37 GMT
Author: olegk
Date: Wed Mar  7 10:26:36 2007
New Revision: 515681

URL: http://svn.apache.org/viewvc?view=rev&rev=515681
Log:
Refactored connection state classes

Removed:
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ClientConnState.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ServerConnState.java
Modified:
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpClientHandler.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpServiceHandler.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpServiceHandler.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/ContentInputBuffer.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/ContentOutputBuffer.java

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpClientHandler.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpClientHandler.java?view=diff&rev=515681&r1=515680&r2=515681
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpClientHandler.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpClientHandler.java
Wed Mar  7 10:26:36 2007
@@ -130,10 +130,7 @@
         
         initialize(conn, attachment);
         
-        ClientConnState connState = new ClientConnState(
-                new SimpleInputBuffer(2048),
-                new SimpleOutputBuffer(2048)); 
-
+        ClientConnState connState = new ClientConnState(); 
         context.setAttribute(CONN_STATE, connState);
 
         if (this.eventListener != null) {
@@ -441,11 +438,103 @@
         
         if (!this.connStrategy.keepAlive(response, context)) {
             conn.close();
-            connState.shutdown();
         } else {
             // Ready for another request
             connState.resetInput();
             conn.requestOutput();
+        }
+    }
+    
+    static class ClientConnState {
+        
+        public static final int READY                      = 0;
+        public static final int REQUEST_SENT               = 1;
+        public static final int EXPECT_CONTINUE            = 2;
+        public static final int REQUEST_BODY_STREAM        = 4;
+        public static final int REQUEST_BODY_DONE          = 8;
+        public static final int RESPONSE_RECEIVED          = 16;
+        public static final int RESPONSE_BODY_STREAM       = 32;
+        public static final int RESPONSE_BODY_DONE         = 64;
+        
+        private SimpleInputBuffer inbuffer; 
+        private ContentOutputBuffer outbuffer;
+
+        private volatile int inputState;
+        private volatile int outputState;
+        
+        private volatile HttpRequest request;
+        private volatile HttpResponse response;
+
+        private int timeout;
+        
+        public ClientConnState() {
+            super();
+        }
+
+        public ContentInputBuffer getInbuffer() {
+            if (this.inbuffer == null) {
+                this.inbuffer = new SimpleInputBuffer(2048);
+            }
+            return this.inbuffer;
+        }
+
+        public ContentOutputBuffer getOutbuffer() {
+            if (this.outbuffer == null) {
+                this.outbuffer = new SimpleOutputBuffer(2048);
+            }
+            return this.outbuffer;
+        }
+        
+        public int getInputState() {
+            return this.inputState;
+        }
+
+        public void setInputState(int inputState) {
+            this.inputState = inputState;
+        }
+
+        public int getOutputState() {
+            return this.outputState;
+        }
+
+        public void setOutputState(int outputState) {
+            this.outputState = outputState;
+        }
+
+        public HttpRequest getRequest() {
+            return this.request;
+        }
+
+        public void setRequest(final HttpRequest request) {
+            this.request = request;
+        }
+
+        public HttpResponse getResponse() {
+            return this.response;
+        }
+
+        public void setResponse(final HttpResponse response) {
+            this.response = response;
+        }
+
+        public int getTimeout() {
+            return this.timeout;
+        }
+
+        public void setTimeout(int timeout) {
+            this.timeout = timeout;
+        }
+            
+        public void resetInput() {
+            this.inbuffer = null;
+            this.response = null;
+            this.inputState = READY;
+        }
+        
+        public void resetOutput() {
+            this.outbuffer = null;
+            this.request = null;
+            this.outputState = READY;
         }
     }
     

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpServiceHandler.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpServiceHandler.java?view=diff&rev=515681&r1=515680&r2=515681
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpServiceHandler.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpServiceHandler.java
Wed Mar  7 10:26:36 2007
@@ -132,10 +132,7 @@
     public void connected(final NHttpServerConnection conn) {
         HttpContext context = conn.getContext();
 
-        ServerConnState connState = new ServerConnState(
-                new SimpleInputBuffer(2048),
-                new SimpleOutputBuffer(2048)); 
-
+        ServerConnState connState = new ServerConnState(); 
         context.setAttribute(CONN_STATE, connState);
 
         if (this.eventListener != null) {
@@ -317,6 +314,7 @@
             buffer.produceContent(encoder);
             if (encoder.isCompleted()) {
                 connState.setOutputState(ServerConnState.RESPONSE_BODY_DONE);
+                connState.resetOutput();
                 if (!this.connStrategy.keepAlive(response, context)) {
                     conn.close();
                 }
@@ -423,9 +421,8 @@
         conn.submitResponse(response);
 
         // Update connection state
-        connState.resetOutput();
         connState.setResponse(response);
-        connState.setInputState(ServerConnState.RESPONSE_SENT);
+        connState.setOutputState(ServerConnState.RESPONSE_SENT);
         
         if (response.getEntity() != null) {
             HttpEntity entity = response.getEntity();
@@ -435,7 +432,94 @@
                 outstream.flush();
                 outstream.close();
             }
+        } else {
+            connState.resetOutput();
         }
     }
 
+    static class ServerConnState {
+        
+        public static final int READY                      = 0;
+        public static final int REQUEST_RECEIVED           = 1;
+        public static final int REQUEST_BODY_STREAM        = 2;
+        public static final int REQUEST_BODY_DONE          = 4;
+        public static final int RESPONSE_SENT              = 8;
+        public static final int RESPONSE_BODY_STREAM       = 16;
+        public static final int RESPONSE_BODY_DONE         = 32;
+        
+        private SimpleInputBuffer inbuffer; 
+        private ContentOutputBuffer outbuffer;
+
+        private volatile int inputState;
+        private volatile int outputState;
+        
+        private volatile HttpRequest request;
+        private volatile HttpResponse response;
+        
+        public ServerConnState() {
+            super();
+            this.inputState = READY;
+            this.outputState = READY;
+        }
+
+        public ContentInputBuffer getInbuffer() {
+            if (this.inbuffer == null) {
+                this.inbuffer = new SimpleInputBuffer(2048);
+            }
+            return this.inbuffer;
+        }
+
+        public ContentOutputBuffer getOutbuffer() {
+            if (this.outbuffer == null) {
+                this.outbuffer = new SimpleOutputBuffer(2048);
+            }
+            return this.outbuffer;
+        }
+        
+        public int getInputState() {
+            return this.inputState;
+        }
+
+        public void setInputState(int inputState) {
+            this.inputState = inputState;
+        }
+
+        public int getOutputState() {
+            return this.outputState;
+        }
+
+        public void setOutputState(int outputState) {
+            this.outputState = outputState;
+        }
+
+        public HttpRequest getRequest() {
+            return this.request;
+        }
+
+        public void setRequest(final HttpRequest request) {
+            this.request = request;
+        }
+
+        public HttpResponse getResponse() {
+            return this.response;
+        }
+
+        public void setResponse(final HttpResponse response) {
+            this.response = response;
+        }
+
+        public void resetInput() {
+            this.inbuffer = null;
+            this.request = null;
+            this.inputState = READY;
+        }
+        
+        public void resetOutput() {
+            this.outbuffer = null;
+            this.response = null;
+            this.outputState = READY;
+        }
+        
+    }
+    
 }

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpServiceHandler.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpServiceHandler.java?view=diff&rev=515681&r1=515680&r2=515681
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpServiceHandler.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpServiceHandler.java
Wed Mar  7 10:26:36 2007
@@ -153,11 +153,7 @@
         if (bufsize < 0) {
             bufsize = 20480;
         }
-        
-        ServerConnState connState = new ServerConnState(
-                new SharedInputBuffer(bufsize, conn),
-                new SharedOutputBuffer(bufsize, conn)); 
-
+        ServerConnState connState = new ServerConnState(bufsize, conn); 
         context.setAttribute(CONN_STATE, connState);
 
         if (this.eventListener != null) {
@@ -554,5 +550,94 @@
             connState.resetOutput();
         }
     }
+
+    static class ServerConnState {
+        
+        public static final int SHUTDOWN                   = -1;
+        public static final int READY                      = 0;
+        public static final int REQUEST_RECEIVED           = 1;
+        public static final int REQUEST_BODY_STREAM        = 2;
+        public static final int REQUEST_BODY_DONE          = 4;
+        public static final int RESPONSE_SENT              = 8;
+        public static final int RESPONSE_BODY_STREAM       = 16;
+        public static final int RESPONSE_BODY_DONE         = 32;
+        
+        private final SharedInputBuffer inbuffer; 
+        private final SharedOutputBuffer outbuffer;
+
+        private volatile int inputState;
+        private volatile int outputState;
+        
+        private volatile HttpRequest request;
+        private volatile HttpResponse response;
+        
+        public ServerConnState(int bufsize, final IOControl ioControl) {
+            super();
+            this.inbuffer = new SharedInputBuffer(bufsize, ioControl);
+            this.outbuffer = new SharedOutputBuffer(bufsize, ioControl);
+            this.inputState = READY;
+            this.outputState = READY;
+        }
+
+        public ContentInputBuffer getInbuffer() {
+            return this.inbuffer;
+        }
+
+        public ContentOutputBuffer getOutbuffer() {
+            return this.outbuffer;
+        }
+        
+        public int getInputState() {
+            return this.inputState;
+        }
+
+        public void setInputState(int inputState) {
+            this.inputState = inputState;
+        }
+
+        public int getOutputState() {
+            return this.outputState;
+        }
+
+        public void setOutputState(int outputState) {
+            this.outputState = outputState;
+        }
+
+        public HttpRequest getRequest() {
+            return this.request;
+        }
+
+        public void setRequest(final HttpRequest request) {
+            this.request = request;
+        }
+
+        public HttpResponse getResponse() {
+            return this.response;
+        }
+
+        public void setResponse(final HttpResponse response) {
+            this.response = response;
+        }
+
+        public void shutdown() {
+            this.inbuffer.shutdown();
+            this.outbuffer.shutdown();
+            this.inputState = SHUTDOWN;
+            this.outputState = SHUTDOWN;
+        }
+
+        public void resetInput() {
+            this.inbuffer.reset();
+            this.request = null;
+            this.inputState = READY;
+        }
+        
+        public void resetOutput() {
+            this.outbuffer.reset();
+            this.response = null;
+            this.outputState = READY;
+        }
+        
+    }    
     
 }

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/ContentInputBuffer.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/ContentInputBuffer.java?view=diff&rev=515681&r1=515680&r2=515681
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/ContentInputBuffer.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/ContentInputBuffer.java
Wed Mar  7 10:26:36 2007
@@ -39,8 +39,6 @@
 
     int consumeContent(ContentDecoder decoder) throws IOException;
     
-    void shutdown();
-
     void reset();
     
     int read(byte[] b, int off, int len) throws IOException;

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/ContentOutputBuffer.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/ContentOutputBuffer.java?view=diff&rev=515681&r1=515680&r2=515681
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/ContentOutputBuffer.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/ContentOutputBuffer.java
Wed Mar  7 10:26:36 2007
@@ -39,8 +39,6 @@
 
     int produceContent(ContentEncoder encoder) throws IOException;
     
-    void shutdown();
-
     void reset();
     
     public void flush() throws IOException;



Mime
View raw message