tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1157204 - in /tomcat/trunk: java/org/apache/coyote/http11/ test/org/apache/coyote/http11/
Date Fri, 12 Aug 2011 18:24:21 GMT
Author: markt
Date: Fri Aug 12 18:24:21 2011
New Revision: 1157204

URL: http://svn.apache.org/viewvc?rev=1157204&view=rev
Log:
Align OutputBuffer initialisation across the connectors
Reduce visibility of properties and methods

Modified:
    tomcat/trunk/java/org/apache/coyote/http11/AbstractOutputBuffer.java
    tomcat/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java
    tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java
    tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.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
    tomcat/trunk/test/org/apache/coyote/http11/TestGzipOutputFilter.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=1157204&r1=1157203&r2=1157204&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/AbstractOutputBuffer.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/AbstractOutputBuffer.java Fri Aug 12 18:24:21
2011
@@ -28,9 +28,11 @@ import org.apache.tomcat.util.buf.ByteCh
 import org.apache.tomcat.util.buf.CharChunk;
 import org.apache.tomcat.util.buf.MessageBytes;
 import org.apache.tomcat.util.http.HttpMessages;
+import org.apache.tomcat.util.net.AbstractEndpoint;
+import org.apache.tomcat.util.net.SocketWrapper;
 import org.apache.tomcat.util.res.StringManager;
 
-public abstract class AbstractOutputBuffer implements OutputBuffer{
+public abstract class AbstractOutputBuffer<S> implements OutputBuffer{
 
     // ----------------------------------------------------- Instance Variables
 
@@ -316,7 +318,11 @@ public abstract class AbstractOutputBuff
             activeFilters[lastActiveFilter].end();
         finished = true;
     }
+
     
+    public abstract void init(SocketWrapper<S> socketWrapper,
+            AbstractEndpoint endpoint) throws IOException;
+
     public abstract void sendAck() throws IOException;
     
     protected abstract void commit() throws IOException;

Modified: tomcat/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java?rev=1157204&r1=1157203&r2=1157204&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java Fri Aug 12 18:24:21
2011
@@ -175,8 +175,7 @@ public class Http11AprProcessor extends 
         // Setting up the socket
         this.socket = socketWrapper;
         inputBuffer.init(socketWrapper, endpoint);
-        long socketRef = socketWrapper.getSocket().longValue();
-        outputBuffer.setSocket(socketRef);
+        outputBuffer.init(socketWrapper, endpoint);
 
         // Error flag
         error = false;
@@ -190,6 +189,8 @@ public class Http11AprProcessor extends 
         boolean openSocket = false;
         boolean sendfileInProgress = false;
 
+        long socketRef = socketWrapper.getSocket().longValue();
+
         while (!error && keepAlive && !comet && !isAsync() &&
!endpoint.isPaused()) {
 
             // Parsing the request header
@@ -624,7 +625,7 @@ public class Http11AprProcessor extends 
     }
 
     @Override
-    protected AbstractOutputBuffer getOutputBuffer() {
+    protected AbstractOutputBuffer<Long> getOutputBuffer() {
         return outputBuffer;
     }
 }

Modified: tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java?rev=1157204&r1=1157203&r2=1157204&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java Fri Aug 12 18:24:21
2011
@@ -206,8 +206,7 @@ public class Http11NioProcessor extends 
         // Setting up the socket
         this.socket = socketWrapper;
         inputBuffer.init(socketWrapper, endpoint);
-        outputBuffer.setSocket(this.socket.getSocket());
-        outputBuffer.setSelectorPool(((NioEndpoint)endpoint).getSelectorPool());
+        outputBuffer.init(socketWrapper, endpoint);
 
         // Error flag
         error = false;
@@ -651,7 +650,7 @@ public class Http11NioProcessor extends 
     }
 
     @Override
-    protected AbstractOutputBuffer getOutputBuffer() {
+    protected AbstractOutputBuffer<NioChannel> getOutputBuffer() {
         return outputBuffer;
     }
 

Modified: tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java?rev=1157204&r1=1157203&r2=1157204&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java Fri Aug 12 18:24:21 2011
@@ -139,7 +139,7 @@ public class Http11Processor extends Abs
         // Setting up the I/O
         this.socket = socketWrapper;
         inputBuffer.init(socketWrapper, endpoint);
-        outputBuffer.setOutputStream(socket.getSocket().getOutputStream());
+        outputBuffer.init(socketWrapper, endpoint);
 
         // Error flag
         error = false;
@@ -563,7 +563,7 @@ public class Http11Processor extends Abs
     }
 
     @Override
-    protected AbstractOutputBuffer getOutputBuffer() {
+    protected AbstractOutputBuffer<Socket> getOutputBuffer() {
         return outputBuffer;
     }
 

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=1157204&r1=1157203&r2=1157204&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/InternalAprOutputBuffer.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/InternalAprOutputBuffer.java Fri Aug 12 18:24:21
2011
@@ -26,13 +26,15 @@ import org.apache.coyote.Response;
 import org.apache.tomcat.jni.Socket;
 import org.apache.tomcat.util.buf.ByteChunk;
 import org.apache.tomcat.util.http.HttpMessages;
+import org.apache.tomcat.util.net.AbstractEndpoint;
+import org.apache.tomcat.util.net.SocketWrapper;
 
 /**
  * Output buffer.
  * 
  * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
  */
-public class InternalAprOutputBuffer extends AbstractOutputBuffer {
+public class InternalAprOutputBuffer extends AbstractOutputBuffer<Long> {
 
 
     // ----------------------------------------------------------- Constructors
@@ -72,30 +74,26 @@ public class InternalAprOutputBuffer ext
     /**
      * Underlying socket.
      */
-    protected long socket;
+    private long socket;
 
 
     /**
      * Direct byte buffer used for writing.
      */
-    protected ByteBuffer bbuf = null;
+    private ByteBuffer bbuf = null;
 
     
-    // ------------------------------------------------------------- Properties
+    // --------------------------------------------------------- Public Methods
 
+    @Override
+    public void init(SocketWrapper<Long> socketWrapper,
+            AbstractEndpoint endpoint) throws IOException {
 
-    /**
-     * Set the underlying socket.
-     */
-    public void setSocket(long socket) {
-        this.socket = socket;
+        socket = socketWrapper.getSocket().longValue();
         Socket.setsbb(this.socket, bbuf);
     }
 
 
-    // --------------------------------------------------------- Public Methods
-
-
     /**
      * Flush the response.
      * 
@@ -197,11 +195,10 @@ public class InternalAprOutputBuffer ext
     }
 
 
-
     /**
      * Callback to write data from the buffer.
      */
-    protected void flushBuffer()
+    private void flushBuffer()
         throws IOException {
         if (bbuf.position() > 0) {
             if (Socket.sendbb(socket, 0, bbuf.position()) < 0) {
@@ -253,6 +250,4 @@ public class InternalAprOutputBuffer ext
             return byteCount;
         }
     }
-
-
 }

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=1157204&r1=1157203&r2=1157204&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/InternalNioOutputBuffer.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/InternalNioOutputBuffer.java Fri Aug 12 18:24:21
2011
@@ -27,9 +27,11 @@ import org.apache.coyote.Response;
 import org.apache.tomcat.util.MutableInteger;
 import org.apache.tomcat.util.buf.ByteChunk;
 import org.apache.tomcat.util.http.HttpMessages;
+import org.apache.tomcat.util.net.AbstractEndpoint;
 import org.apache.tomcat.util.net.NioChannel;
 import org.apache.tomcat.util.net.NioEndpoint;
 import org.apache.tomcat.util.net.NioSelectorPool;
+import org.apache.tomcat.util.net.SocketWrapper;
 
 /**
  * Output buffer.
@@ -37,7 +39,7 @@ import org.apache.tomcat.util.net.NioSel
  * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
  * @author Filip Hanik
  */
-public class InternalNioOutputBuffer extends AbstractOutputBuffer {
+public class InternalNioOutputBuffer extends AbstractOutputBuffer<NioChannel> {
 
     // ----------------------------------------------------------- Constructors
 
@@ -68,37 +70,19 @@ public class InternalNioOutputBuffer ext
     /**
      * Number of bytes last written
      */
-    protected MutableInteger lastWrite = new MutableInteger(1);
+    private MutableInteger lastWrite = new MutableInteger(1);
 
     /**
      * Underlying socket.
      */
-    protected NioChannel socket;
+    private NioChannel socket;
     
     /**
      * Selector pool, for blocking reads and blocking writes
      */
-    protected NioSelectorPool pool;
+    private NioSelectorPool pool;
 
 
-    // ------------------------------------------------------------- Properties
-
-
-    /**
-     * Set the underlying socket.
-     */
-    public void setSocket(NioChannel socket) {
-        this.socket = socket;
-    }
-
-    public void setSelectorPool(NioSelectorPool pool) { 
-        this.pool = pool;
-    }
-
-    public NioSelectorPool getSelectorPool() {
-        return pool;
-    }    
-
     // --------------------------------------------------------- Public Methods
 
 
@@ -178,18 +162,18 @@ public class InternalNioOutputBuffer ext
         long writeTimeout = att.getTimeout();
         Selector selector = null;
         try {
-            selector = getSelectorPool().get();
+            selector = pool.get();
         } catch ( IOException x ) {
             //ignore
         }
         try {
-            written = getSelectorPool().write(bytebuffer, socket, selector, writeTimeout,
block,lastWrite);
+            written = pool.write(bytebuffer, socket, selector, writeTimeout, block,lastWrite);
             //make sure we are flushed 
             do {
                 if (socket.flush(true,selector,writeTimeout,lastWrite)) break;
             }while ( true );
         }finally { 
-            if ( selector != null ) getSelectorPool().put(selector);
+            if ( selector != null ) pool.put(selector);
         }
         if ( block ) bytebuffer.clear(); //only clear
         this.total = 0;
@@ -199,6 +183,14 @@ public class InternalNioOutputBuffer ext
 
     // ------------------------------------------------------ Protected Methods
 
+    @Override
+    public void init(SocketWrapper<NioChannel> socketWrapper,
+            AbstractEndpoint endpoint) throws IOException {
+
+        socket = socketWrapper.getSocket();
+        pool = ((NioEndpoint)endpoint).getSelectorPool();
+    }
+
 
     /**
      * Commit the response.
@@ -220,7 +212,7 @@ public class InternalNioOutputBuffer ext
 
     }
 
-    int total = 0;
+    private int total = 0;
     private synchronized void addToBB(byte[] buf, int offset, int length) throws IOException
{
         while (length > 0) {
             int thisTime = length;
@@ -245,8 +237,7 @@ public class InternalNioOutputBuffer ext
     /**
      * Callback to write data from the buffer.
      */
-    protected void flushBuffer()
-        throws IOException {
+    private void flushBuffer() throws IOException {
 
         //prevent timeout for async,
         SelectionKey key = socket.getIOChannel().keyFor(socket.getPoller().getSelector());
@@ -294,6 +285,4 @@ public class InternalNioOutputBuffer ext
             return byteCount;
         }
     }
-
-
 }

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=1157204&r1=1157203&r2=1157204&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/InternalOutputBuffer.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/InternalOutputBuffer.java Fri Aug 12 18:24:21
2011
@@ -19,17 +19,20 @@ package org.apache.coyote.http11;
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.net.Socket;
 
 import org.apache.coyote.OutputBuffer;
 import org.apache.coyote.Response;
 import org.apache.tomcat.util.buf.ByteChunk;
+import org.apache.tomcat.util.net.AbstractEndpoint;
+import org.apache.tomcat.util.net.SocketWrapper;
 
 /**
  * Output buffer.
  * 
  * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
  */
-public class InternalOutputBuffer extends AbstractOutputBuffer
+public class InternalOutputBuffer extends AbstractOutputBuffer<Socket>
     implements ByteChunk.ByteOutputChannel {
 
     // ----------------------------------------------------------- Constructors
@@ -58,7 +61,7 @@ public class InternalOutputBuffer extend
     }
 
     /**
-     * Underlying output stream.
+     * Underlying output stream. Note: protected to assist with unit testing
      */
     protected OutputStream outputStream;
 
@@ -66,28 +69,16 @@ public class InternalOutputBuffer extend
     /**
      * Socket buffer.
      */
-    protected ByteChunk socketBuffer;
+    private ByteChunk socketBuffer;
 
 
     /**
      * Socket buffer (extra buffering to reduce number of packets sent).
      */
-    protected boolean useSocketBuffer = false;    
+    private boolean useSocketBuffer = false;    
     
 
     /**
-     * Set the underlying socket output stream.
-     */
-    public void setOutputStream(OutputStream outputStream) {
-
-        // FIXME: Check for null ?
-
-        this.outputStream = outputStream;
-
-    }
-
-
-    /**
      * Set the socket buffer size.
      */
     public void setSocketBuffer(int socketBufferSize) {
@@ -104,6 +95,13 @@ public class InternalOutputBuffer extend
 
     // --------------------------------------------------------- Public Methods
 
+    @Override
+    public void init(SocketWrapper<Socket> socketWrapper,
+            AbstractEndpoint endpoint) throws IOException {
+
+        outputStream = socketWrapper.getSocket().getOutputStream();
+    }
+
 
     /**
      * Flush the response.
@@ -255,6 +253,4 @@ public class InternalOutputBuffer extend
             return byteCount;
         }
     }
-
-
 }

Modified: tomcat/trunk/test/org/apache/coyote/http11/TestGzipOutputFilter.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/coyote/http11/TestGzipOutputFilter.java?rev=1157204&r1=1157203&r2=1157204&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/coyote/http11/TestGzipOutputFilter.java (original)
+++ tomcat/trunk/test/org/apache/coyote/http11/TestGzipOutputFilter.java Fri Aug 12 18:24:21
2011
@@ -54,7 +54,7 @@ public class TestGzipOutputFilter {
         Response res = new Response();
         InternalOutputBuffer iob = new InternalOutputBuffer(res, 8 * 1024);
         ByteArrayOutputStream bos = new ByteArrayOutputStream();
-        iob.setOutputStream(bos);
+        iob.outputStream = bos;
         res.setOutputBuffer(iob);
 
         // set up GzipOutputFilter to attach to the InternalOutputBuffer



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


Mime
View raw message