Author: markt
Date: Mon Apr 29 20:38:12 2013
New Revision: 1477331

URL: http://svn.apache.org/r1477331
Log:
No need to retain reference to WriteListener in OutputBuffer

Modified:
    tomcat/trunk/java/org/apache/catalina/connector/LocalStrings.properties
    tomcat/trunk/java/org/apache/catalina/connector/OutputBuffer.java
    tomcat/trunk/java/org/apache/coyote/LocalStrings.properties
    tomcat/trunk/java/org/apache/coyote/Response.java

Modified: 
tomcat/trunk/java/org/apache/catalina/connector/LocalStrings.properties
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/LocalStrings.properties?rev=1477331&r1=1477330&r2=1477331&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/LocalStrings.properties 
(original)
+++ tomcat/trunk/java/org/apache/catalina/connector/LocalStrings.properties Mon 
Apr 29 20:38:12 2013
@@ -56,10 +56,6 @@ coyoteResponse.setBufferSize.ise=Cannot 
 
 inputBuffer.streamClosed=Stream closed
 
-outputBuffer.listenerSet=The non-blocking write listener has already been set
-outputBuffer.notAsync=It is only valid to switch to non-blocking IO within 
async processing or HTTP upgrade processing
-outputBuffer.nullListener=The listener passed to setWriteListener() may not be 
null
-
 requestFacade.nullRequest=The request object has been recycled and is no 
longer associated with this facade
 
 responseFacade.nullResponse=The response object has been recycled and is no 
longer associated with this facade

Modified: tomcat/trunk/java/org/apache/catalina/connector/OutputBuffer.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/OutputBuffer.java?rev=1477331&r1=1477330&r2=1477331&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/OutputBuffer.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/OutputBuffer.java Mon Apr 
29 20:38:12 2013
@@ -16,7 +16,6 @@
  */
 package org.apache.catalina.connector;
 
-
 import java.io.IOException;
 import java.io.Writer;
 import java.security.AccessController;
@@ -33,8 +32,6 @@ import org.apache.coyote.Response;
 import org.apache.tomcat.util.buf.ByteChunk;
 import org.apache.tomcat.util.buf.C2BConverter;
 import org.apache.tomcat.util.buf.CharChunk;
-import org.apache.tomcat.util.res.StringManager;
-
 
 /**
  * The buffer used by Tomcat response. This is a derivative of the Tomcat 3.3
@@ -47,10 +44,6 @@ import org.apache.tomcat.util.res.String
 public class OutputBuffer extends Writer
     implements ByteChunk.ByteOutputChannel, CharChunk.CharOutputChannel {
 
-    private static final StringManager sm =
-            StringManager.getManager(Constants.Package);
-
-
     // -------------------------------------------------------------- Constants
 
     public static final String DEFAULT_ENCODING =
@@ -249,8 +242,6 @@ public class OutputBuffer extends Writer
 
         gotEnc = false;
         enc = null;
-        listener = null;
-
     }
 
 
@@ -656,42 +647,16 @@ public class OutputBuffer extends Writer
 
 
     public boolean canWrite() {
-        if (getWriteListener()==null) throw new IllegalStateException("not in 
non blocking mode.");
+        if (coyoteResponse.getWriteListener() == null) {
+            throw new IllegalStateException("not in non blocking mode.");
+        }
         AtomicBoolean canWrite = new AtomicBoolean(true);
         coyoteResponse.action(ActionCode.NB_WRITE_INTEREST, canWrite);
         return canWrite.get();
-}
-
+    }
 
 
-    private volatile WriteListener listener;
     public void setWriteListener(WriteListener listener) {
-        if (listener == null) {
-            throw new NullPointerException(
-                    sm.getString("outputBuffer.nullListener"));
-        }
-        if (getWriteListener() != null) {
-            throw new IllegalStateException(
-                    sm.getString("outputBuffer.listenerSet"));
-        }
-        // Note: This class is not used for HTTP upgrade so only need to test
-        //       for async
-        AtomicBoolean result = new AtomicBoolean(false);
-        coyoteResponse.action(ActionCode.ASYNC_IS_ASYNC, result);
-        if (!result.get()) {
-            throw new IllegalStateException(
-                    sm.getString("outputBuffer.notAsync"));
-        }
-
-        this.listener = listener;
         coyoteResponse.setWriteListener(listener);
-        coyoteResponse.action(ActionCode.SET_WRITE_LISTENER, null);
-    }
-
-    public WriteListener getWriteListener() {
-        return listener;
     }
-
-
-
 }

Modified: tomcat/trunk/java/org/apache/coyote/LocalStrings.properties
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/LocalStrings.properties?rev=1477331&r1=1477330&r2=1477331&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/LocalStrings.properties (original)
+++ tomcat/trunk/java/org/apache/coyote/LocalStrings.properties Mon Apr 29 
20:38:12 2013
@@ -36,6 +36,10 @@ abstractProtocolHandler.destroyError=Fai
 
 asyncStateMachine.invalidAsyncState=Calling [{0}] is not valid for a request 
with Async state [{1}]
 
-request.readListenerSet=The non-blocking read listener has already been set
 request.notAsync=It is only valid to switch to non-blocking IO within async 
processing or HTTP upgrade processing
 request.nullReadListener=The listener passed to setReadListener() may not be 
null
+request.readListenerSet=The non-blocking read listener has already been set
+
+response.notAsync=It is only valid to switch to non-blocking IO within async 
processing or HTTP upgrade processing
+response.nullWriteListener=The listener passed to setWriteListener() may not 
be null
+response.writeListenerSet=The non-blocking write listener has already been set

Modified: tomcat/trunk/java/org/apache/coyote/Response.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/Response.java?rev=1477331&r1=1477330&r2=1477331&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/Response.java (original)
+++ tomcat/trunk/java/org/apache/coyote/Response.java Mon Apr 29 20:38:12 2013
@@ -19,6 +19,7 @@ package org.apache.coyote;
 import java.io.IOException;
 import java.io.StringReader;
 import java.util.Locale;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import javax.servlet.WriteListener;
 
@@ -27,6 +28,7 @@ import org.apache.tomcat.util.buf.ByteCh
 import org.apache.tomcat.util.http.MimeHeaders;
 import org.apache.tomcat.util.http.parser.HttpParser;
 import org.apache.tomcat.util.http.parser.MediaType;
+import org.apache.tomcat.util.res.StringManager;
 
 /**
  * Response object.
@@ -40,6 +42,9 @@ import org.apache.tomcat.util.http.parse
  */
 public final class Response {
 
+    private static final StringManager sm =
+            StringManager.getManager(Constants.Package);
+
     // ----------------------------------------------------- Class Variables
 
     /**
@@ -549,8 +554,27 @@ public final class Response {
 }
 
     public void setWriteListener(WriteListener listener) {
-        //TODO SERVLET 3.1 is it allowed to switch from non block to blocking?
-        setBlocking(listener==null);
+        if (listener == null) {
+            throw new NullPointerException(
+                    sm.getString("response.nullWriteListener"));
+        }
+        if (getWriteListener() != null) {
+            throw new IllegalStateException(
+                    sm.getString("response.writeListenerSet"));
+        }
+        // Note: This class is not used for HTTP upgrade so only need to test
+        //       for async
+        AtomicBoolean result = new AtomicBoolean(false);
+        action(ActionCode.ASYNC_IS_ASYNC, result);
+        if (!result.get()) {
+            throw new IllegalStateException(
+                    sm.getString("response.notAsync"));
+        }
+
+        this.listener = listener;
+        action(ActionCode.SET_WRITE_LISTENER, null);
+
+        setBlocking(false);
         this.listener = listener;
     }
 



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

Reply via email to