You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2006/11/22 12:11:07 UTC

svn commit: r478126 - in /jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio: impl/ impl/reactor/ reactor/

Author: olegk
Date: Wed Nov 22 03:11:06 2006
New Revision: 478126

URL: http://svn.apache.org/viewvc?view=rev&rev=478126
Log:
Extended the I/O session framework with a mechanism to query the status of I/O session buffers

Added:
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/reactor/SessionBufferStatus.java   (with props)
Modified:
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/DefaultNHttpClientConnection.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/DefaultNHttpServerConnection.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/NHttpConnectionBase.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/reactor/IOSessionImpl.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/reactor/IOSession.java

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/DefaultNHttpClientConnection.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/DefaultNHttpClientConnection.java?view=diff&rev=478126&r1=478125&r2=478126
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/DefaultNHttpClientConnection.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/DefaultNHttpClientConnection.java Wed Nov 22 03:11:06 2006
@@ -63,6 +63,9 @@
             throw new IllegalArgumentException("Response factory may not be null");
         }
         this.responseParser = new HttpResponseParser(this.inbuf, responseFactory);
+        this.hasBufferedInput = false;
+        this.hasBufferedOutput = false;
+        this.session.setBufferStatus(this);
     }
 
     private void resetInput() {
@@ -112,6 +115,9 @@
             handler.exception(this, ex);
         } catch (HttpException ex) {
             handler.exception(this, ex);
+        } finally {
+            // Finally set buffered input flag
+            this.hasBufferedInput = this.contentDecoder != null && this.inbuf.hasData();
         }
     }
 
@@ -137,6 +143,9 @@
             }
         } catch (IOException ex) {
             handler.exception(this, ex);
+        } finally {
+            // Finally set buffered output flag
+            this.hasBufferedOutput = this.contentEncoder != null && this.outbuf.hasData();
         }
     }
     

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/DefaultNHttpServerConnection.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/DefaultNHttpServerConnection.java?view=diff&rev=478126&r1=478125&r2=478126
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/DefaultNHttpServerConnection.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/DefaultNHttpServerConnection.java Wed Nov 22 03:11:06 2006
@@ -115,6 +115,9 @@
             handler.exception(this, ex);
         } catch (HttpException ex) {
             handler.exception(this, ex);
+        } finally {
+            // Finally set buffered input flag
+            this.hasBufferedInput = this.contentDecoder != null && this.inbuf.hasData();
         }
     }
 
@@ -140,6 +143,9 @@
             }
         } catch (IOException ex) {
             handler.exception(this, ex);
+        } finally {
+            // Finally set the buffered output flag
+            this.hasBufferedOutput = this.contentEncoder != null && this.outbuf.hasData();
         }
     }
     

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/NHttpConnectionBase.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/NHttpConnectionBase.java?view=diff&rev=478126&r1=478125&r2=478126
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/NHttpConnectionBase.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/NHttpConnectionBase.java Wed Nov 22 03:11:06 2006
@@ -58,6 +58,7 @@
 import org.apache.http.nio.impl.reactor.SessionOutputBuffer;
 import org.apache.http.nio.reactor.EventMask;
 import org.apache.http.nio.reactor.IOSession;
+import org.apache.http.nio.reactor.SessionBufferStatus;
 import org.apache.http.params.HttpConnectionParams;
 import org.apache.http.params.HttpParams;
 import org.apache.http.protocol.HTTP;
@@ -65,7 +66,8 @@
 import org.apache.http.protocol.SyncHttpExecutionContext;
 import org.apache.http.util.CharArrayBuffer;
 
-public class NHttpConnectionBase implements NHttpConnection, HttpInetConnection {
+public class NHttpConnectionBase 
+        implements NHttpConnection, HttpInetConnection, SessionBufferStatus {
 
     protected final IOSession session;
     protected final HttpContext context;
@@ -78,7 +80,9 @@
     protected final CharArrayBuffer lineBuffer;
     
     protected volatile ContentDecoder contentDecoder;
+    protected volatile boolean hasBufferedInput;
     protected volatile ContentEncoder contentEncoder;
+    protected volatile boolean hasBufferedOutput;
     protected volatile HttpRequest request;
     protected volatile HttpResponse response;
     
@@ -187,6 +191,14 @@
         } else {
             this.contentEncoder = new LengthDelimitedEncoder(this.session.channel(), len);
         }
+    }
+
+    public boolean hasBufferedInput() {
+        return this.hasBufferedInput;
+    }
+
+    public boolean hasBufferedOutput() {
+        return this.hasBufferedOutput;
     }
 
     public void close() throws IOException {

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/reactor/IOSessionImpl.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/reactor/IOSessionImpl.java?view=diff&rev=478126&r1=478125&r2=478126
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/reactor/IOSessionImpl.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/reactor/IOSessionImpl.java Wed Nov 22 03:11:06 2006
@@ -40,6 +40,7 @@
 import java.util.Map;
 
 import org.apache.http.nio.reactor.IOSession;
+import org.apache.http.nio.reactor.SessionBufferStatus;
 
 class IOSessionImpl implements IOSession {
     
@@ -49,6 +50,7 @@
     private final SessionClosedCallback callback;
     private final Map attributes;
     
+    private SessionBufferStatus bufferStatus;
     private int socketTimeout;
     
     public IOSessionImpl(final SelectionKey key, final SessionClosedCallback callback) {
@@ -150,6 +152,14 @@
         return this.closed || !this.key.isValid();
     }
     
+    public SessionBufferStatus getBufferStatus() {
+        return this.bufferStatus;
+    }
+
+    public void setBufferStatus(final SessionBufferStatus bufferStatus) {
+        this.bufferStatus = bufferStatus;
+    }
+    
     public Object getAttribute(final String name) {
         return this.attributes.get(name);
     }
@@ -161,5 +171,5 @@
     public void setAttribute(final String name, final Object obj) {
         this.attributes.put(name, obj);
     }
-    
+
 }

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/reactor/IOSession.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/reactor/IOSession.java?view=diff&rev=478126&r1=478125&r2=478126
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/reactor/IOSession.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/reactor/IOSession.java Wed Nov 22 03:11:06 2006
@@ -58,6 +58,10 @@
     
     void setSocketTimeout(int timeout);
     
+    SessionBufferStatus getBufferStatus();
+    
+    void setBufferStatus(SessionBufferStatus status);
+    
     void setAttribute(String name, Object obj);
     
     Object getAttribute(String name);

Added: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/reactor/SessionBufferStatus.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/reactor/SessionBufferStatus.java?view=auto&rev=478126
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/reactor/SessionBufferStatus.java (added)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/reactor/SessionBufferStatus.java Wed Nov 22 03:11:06 2006
@@ -0,0 +1,43 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date:
+ *
+ * ====================================================================
+ *
+ *  Copyright 1999-2006 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.nio.reactor;
+
+/**
+ * Interface to query the status of session I/O buffers. 
+ * 
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ */
+public interface SessionBufferStatus {
+
+    boolean hasBufferedInput();
+    
+    boolean hasBufferedOutput();
+
+}

Propchange: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/reactor/SessionBufferStatus.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/reactor/SessionBufferStatus.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain