Return-Path: Delivered-To: apmail-jakarta-httpcomponents-commits-archive@www.apache.org Received: (qmail 44772 invoked from network); 7 Mar 2007 18:26:58 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 7 Mar 2007 18:26:58 -0000 Received: (qmail 35096 invoked by uid 500); 7 Mar 2007 18:27:07 -0000 Delivered-To: apmail-jakarta-httpcomponents-commits-archive@jakarta.apache.org Received: (qmail 35082 invoked by uid 500); 7 Mar 2007 18:27:07 -0000 Mailing-List: contact httpcomponents-commits-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: httpcomponents-dev@jakarta.apache.org Delivered-To: mailing list httpcomponents-commits@jakarta.apache.org Received: (qmail 35073 invoked by uid 99); 7 Mar 2007 18:27:06 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Mar 2007 10:27:06 -0800 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Mar 2007 10:26:57 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id 61BF21A9838; Wed, 7 Mar 2007 10:26:37 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: httpcomponents-commits@jakarta.apache.org From: olegk@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070307182637.61BF21A9838@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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;