tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1478537 - in /tomcat/trunk/java/org/apache/coyote/http11: AbstractOutputBuffer.java InternalAprOutputBuffer.java InternalNioOutputBuffer.java InternalOutputBuffer.java
Date Thu, 02 May 2013 20:57:46 GMT
Author: markt
Date: Thu May  2 20:57:45 2013
New Revision: 1478537

URL: http://svn.apache.org/r1478537
Log:
Pull up the buffer that holds non-blocking writes.
This allows setBlocking() to be pulled up and given a common
implementation.

Modified:
    tomcat/trunk/java/org/apache/coyote/http11/AbstractOutputBuffer.java
    tomcat/trunk/java/org/apache/coyote/http11/InternalAprOutputBuffer.java
    tomcat/trunk/java/org/apache/coyote/http11/InternalNioOutputBuffer.java
    tomcat/trunk/java/org/apache/coyote/http11/InternalOutputBuffer.java

Modified: tomcat/trunk/java/org/apache/coyote/http11/AbstractOutputBuffer.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/AbstractOutputBuffer.java?rev=1478537&r1=1478536&r2=1478537&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/AbstractOutputBuffer.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/AbstractOutputBuffer.java Thu May  2 20:57:45
2013
@@ -17,8 +17,11 @@
 package org.apache.coyote.http11;
 
 import java.io.IOException;
+import java.nio.ByteBuffer;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
+import java.util.concurrent.LinkedBlockingDeque;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.apache.coyote.ActionCode;
 import org.apache.coyote.OutputBuffer;
@@ -100,6 +103,20 @@ public abstract class AbstractOutputBuff
      */
     protected int socketBuffer = -1;
 
+    /**
+     * For "non-blocking" writes use an external set of buffers. Although the
+     * API only allows one non-blocking write at a time, due to buffering and
+     * the possible need to write HTTP headers, there may be more than one write
+     * to the OutputBuffer.
+     */
+    protected volatile LinkedBlockingDeque<ByteBufferHolder> bufferedWrites =
+            null;
+
+    /**
+     * The max size of the buffered write buffer
+     */
+    protected int bufferedWriteSize = 64*1024; //64k default write buffer
+
 
     // -------------------------------------------------------------- Variables
 
@@ -184,6 +201,16 @@ public abstract class AbstractOutputBuff
     }
 
 
+    public void setBufferedWriteSize(int bufferedWriteSize) {
+        this.bufferedWriteSize = bufferedWriteSize;
+    }
+
+
+    public int getBufferedWriteSize() {
+        return bufferedWriteSize;
+    }
+
+
     // --------------------------------------------------- OutputBuffer Methods
 
     /**
@@ -577,7 +604,6 @@ public abstract class AbstractOutputBuff
     //------------------------------------------------------ Non-blocking writes
 
     protected abstract boolean hasDataToWrite();
-    protected abstract void setBlocking(boolean blocking);
 
     /**
      * Writes any remaining buffered data.
@@ -591,6 +617,17 @@ public abstract class AbstractOutputBuff
 
 
     /**
+     * Configure the blocking behaviour of the OutputBuffer.
+     */
+    public final void setBlocking(boolean blocking) {
+        if (blocking)
+            bufferedWrites = null;
+        else
+            bufferedWrites = new LinkedBlockingDeque<>();
+    }
+
+
+    /**
      * Is standard Servlet blocking IO being used for output?
      */
     protected final boolean isBlocking() {
@@ -601,4 +638,48 @@ public abstract class AbstractOutputBuff
     protected final boolean isReady() {
         return !hasDataToWrite();
     }
+
+
+    protected static class ByteBufferHolder {
+        private final ByteBuffer buf;
+        private final AtomicBoolean flipped;
+        public ByteBufferHolder(ByteBuffer buf, boolean flipped) {
+           this.buf = buf;
+           this.flipped = new AtomicBoolean(flipped);
+        }
+        public ByteBuffer getBuf() {
+            return buf;
+        }
+        public boolean isFlipped() {
+            return flipped.get();
+        }
+
+        public boolean flip() {
+            if (flipped.compareAndSet(false, true)) {
+                buf.flip();
+                return true;
+            } else {
+                return false;
+            }
+        }
+
+        public boolean hasData() {
+            if (flipped.get()) {
+                return buf.remaining()>0;
+            } else {
+                return buf.position()>0;
+            }
+        }
+
+        @Override
+        public String toString() {
+            StringBuilder builder = new StringBuilder(super.toString());
+            builder.append("[flipped=");
+            builder.append(isFlipped()?"true, remaining=" : "false, position=");
+            builder.append(isFlipped()? buf.remaining(): buf.position());
+            builder.append("]");
+            return builder.toString();
+        }
+
+    }
 }

Modified: tomcat/trunk/java/org/apache/coyote/http11/InternalAprOutputBuffer.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/InternalAprOutputBuffer.java?rev=1478537&r1=1478536&r2=1478537&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/InternalAprOutputBuffer.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/InternalAprOutputBuffer.java Thu May  2 20:57:45
2013
@@ -174,12 +174,6 @@ public class InternalAprOutputBuffer ext
     }
 
 
-    @Override
-    protected void setBlocking(boolean blocking) {
-        // TODO
-    }
-
-
     // ----------------------------------- OutputStreamOutputBuffer Inner Class
 
     /**

Modified: tomcat/trunk/java/org/apache/coyote/http11/InternalNioOutputBuffer.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/InternalNioOutputBuffer.java?rev=1478537&r1=1478536&r2=1478537&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/InternalNioOutputBuffer.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/InternalNioOutputBuffer.java Thu May  2 20:57:45
2013
@@ -22,8 +22,6 @@ import java.nio.ByteBuffer;
 import java.nio.channels.SelectionKey;
 import java.nio.channels.Selector;
 import java.util.Iterator;
-import java.util.concurrent.LinkedBlockingDeque;
-import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.apache.coyote.OutputBuffer;
 import org.apache.coyote.Response;
@@ -84,59 +82,6 @@ public class InternalNioOutputBuffer ext
      */
     protected volatile boolean flipped = false;
 
-    /**
-     * For "non-blocking" writes use an external buffer.
-     */
-    protected volatile LinkedBlockingDeque<ByteBufferHolder> bufferedWrites = null;
-
-    /**
-     * The max size of the buffered write buffer
-     */
-    protected int bufferedWriteSize = 64*1024; //64k default write buffer
-
-    protected static class ByteBufferHolder {
-        private final ByteBuffer buf;
-        private final AtomicBoolean flipped;
-        public ByteBufferHolder(ByteBuffer buf, boolean flipped) {
-           this.buf = buf;
-           this.flipped = new AtomicBoolean(flipped);
-        }
-        public ByteBuffer getBuf() {
-            return buf;
-        }
-        public boolean isFlipped() {
-            return flipped.get();
-        }
-
-        public boolean flip() {
-            if (flipped.compareAndSet(false, true)) {
-                buf.flip();
-                return true;
-            } else {
-                return false;
-            }
-        }
-
-        public boolean hasData() {
-            if (flipped.get()) {
-                return buf.remaining()>0;
-            } else {
-                return buf.position()>0;
-            }
-        }
-
-        @Override
-        public String toString() {
-            StringBuilder builder = new StringBuilder(super.toString());
-            builder.append("[flipped=");
-            builder.append(isFlipped()?"true, remaining=" : "false, position=");
-            builder.append(isFlipped()? buf.remaining(): buf.position());
-            builder.append("]");
-            return builder.toString();
-        }
-
-    }
-
     // --------------------------------------------------------- Public Methods
 
     /**
@@ -347,18 +292,6 @@ public class InternalNioOutputBuffer ext
 
     //-------------------------------------------------- Non-blocking IO methods
 
-    @Override
-    public void setBlocking(boolean blocking) {
-        if (blocking)
-            bufferedWrites = null;
-        else
-            bufferedWrites = new LinkedBlockingDeque<>();
-    }
-
-    public void setBufferedWriteSize(int bufferedWriteSize) {
-        this.bufferedWriteSize = bufferedWriteSize;
-    }
-
     private boolean hasBufferedData() {
         boolean result = false;
         if (bufferedWrites!=null) {
@@ -375,10 +308,6 @@ public class InternalNioOutputBuffer ext
         return hasMoreDataToFlush() || hasBufferedData();
     }
 
-    public int getBufferedWriteSize() {
-        return bufferedWriteSize;
-    }
-
 
     // ----------------------------------- OutputStreamOutputBuffer Inner Class
 

Modified: tomcat/trunk/java/org/apache/coyote/http11/InternalOutputBuffer.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/InternalOutputBuffer.java?rev=1478537&r1=1478536&r2=1478537&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/InternalOutputBuffer.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/InternalOutputBuffer.java Thu May  2 20:57:45
2013
@@ -192,12 +192,6 @@ public class InternalOutputBuffer extend
 
 
     @Override
-    protected void setBlocking(boolean blocking) {
-        // TODO
-    }
-
-
-    @Override
     protected boolean flushBuffer(boolean block) throws IOException {
         // Blocking connector so ignore block parameter as this will always use
         // blocking IO.



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


Mime
View raw message