Author: markt
Date: Mon Apr 29 20:30:18 2013
New Revision: 1477322

URL: http://svn.apache.org/r1477322
Log:
No need to retain reference to ReadListener in InputBuffer

Modified:
    tomcat/trunk/java/org/apache/catalina/connector/InputBuffer.java
    tomcat/trunk/java/org/apache/catalina/connector/LocalStrings.properties
    tomcat/trunk/java/org/apache/coyote/LocalStrings.properties
    tomcat/trunk/java/org/apache/coyote/Request.java

Modified: tomcat/trunk/java/org/apache/catalina/connector/InputBuffer.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/InputBuffer.java?rev=1477322&r1=1477321&r2=1477322&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/InputBuffer.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/InputBuffer.java Mon Apr 29 
20:30:18 2013
@@ -22,7 +22,6 @@ import java.security.AccessController;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
 import java.util.HashMap;
-import java.util.concurrent.atomic.AtomicBoolean;
 
 import javax.servlet.ReadListener;
 
@@ -34,7 +33,6 @@ import org.apache.tomcat.util.buf.ByteCh
 import org.apache.tomcat.util.buf.CharChunk;
 import org.apache.tomcat.util.res.StringManager;
 
-
 /**
  * The buffer used by Tomcat request. This is a derivative of the Tomcat 3.3
  * OutputBuffer, adapted to handle input instead of output. This allows
@@ -211,8 +209,6 @@ public class InputBuffer extends Reader
 
         gotEnc = false;
         enc = null;
-        listener = null;
-
     }
 
 
@@ -251,42 +247,20 @@ public class InputBuffer extends Reader
     }
 
 
-    private volatile ReadListener listener;
     public void setReadListener(ReadListener listener) {
-        if (listener == null) {
-            throw new NullPointerException(
-                    sm.getString("inputBuffer.nullListener"));
-        }
-        if (getReadListener() != null) {
-            throw new IllegalStateException(
-                    sm.getString("inputBuffer.listenerSet"));
-        }
-        // Note: This class is not used for HTTP upgrade so only need to test
-        //       for async
-        AtomicBoolean result = new AtomicBoolean(false);
-        coyoteRequest.action(ActionCode.ASYNC_IS_ASYNC, result);
-        if (!result.get()) {
-            throw new IllegalStateException(
-                    sm.getString("inputBuffer.notAsync"));
-        }
-
-        this.listener = listener;
         coyoteRequest.setReadListener(listener);
     }
 
 
-    public ReadListener getReadListener() {
-        return listener;
-    }
-
-
     public boolean isFinished() {
         return available() == 0;
     }
 
 
     public boolean isReady() {
-        if (getReadListener()==null) throw new IllegalStateException("not in 
non blocking mode.");
+        if (coyoteRequest.getReadListener() == null) {
+            throw new IllegalStateException("not in non blocking mode.");
+        }
         int available = available();
         boolean result = available > 0;
         if (!result) {

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=1477322&r1=1477321&r2=1477322&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:30:18 2013
@@ -29,9 +29,6 @@ coyoteConnector.protocolHandlerPauseFail
 coyoteConnector.protocolHandlerResumeFailed=Protocol handler resume failed
 coyoteConnector.parseBodyMethodNoTrace=TRACE method MUST NOT include an entity 
(see RFC 2616 Section 9.6)
 
-inputBuffer.listenerSet=The non-blocking read listener has already been set
-inputBuffer.nullListener=The listener passed to setReadListener() may not be 
null
-
 coyoteRequest.getInputStream.ise=getReader() has already been called for this 
request
 coyoteRequest.getReader.ise=getInputStream() has already been called for this 
request
 coyoteRequest.sessionCreateCommitted=Cannot create a session after the 
response has been committed
@@ -57,9 +54,6 @@ coyoteResponse.sendRedirect.ise=Cannot c
 coyoteResponse.sendRedirect.note=<html><body><p>Redirecting to <a 
href="{0}">{0}</a></p></body></html>
 coyoteResponse.setBufferSize.ise=Cannot change buffer size after data has been 
written
 
-inputBuffer.listenerSet=The non-blocking read listener has already been set
-inputBuffer.notAsync=It is only valid to switch to non-blocking IO within 
async processing or HTTP upgrade processing
-inputBuffer.nullListener=The listener passed to setReadListener() may not be 
null
 inputBuffer.streamClosed=Stream closed
 
 outputBuffer.listenerSet=The non-blocking write listener has already been set

Modified: tomcat/trunk/java/org/apache/coyote/LocalStrings.properties
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/LocalStrings.properties?rev=1477322&r1=1477321&r2=1477322&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/LocalStrings.properties (original)
+++ tomcat/trunk/java/org/apache/coyote/LocalStrings.properties Mon Apr 29 
20:30:18 2013
@@ -35,3 +35,7 @@ abstractProtocolHandler.destroy=Destroyi
 abstractProtocolHandler.destroyError=Failed to destroy end point associated 
with ProtocolHandler [{0}]
 
 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

Modified: tomcat/trunk/java/org/apache/coyote/Request.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/Request.java?rev=1477322&r1=1477321&r2=1477322&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/Request.java (original)
+++ tomcat/trunk/java/org/apache/coyote/Request.java Mon Apr 29 20:30:18 2013
@@ -14,11 +14,11 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-
 package org.apache.coyote;
 
 import java.io.IOException;
 import java.util.HashMap;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import javax.servlet.ReadListener;
 
@@ -29,6 +29,7 @@ import org.apache.tomcat.util.buf.UDecod
 import org.apache.tomcat.util.http.Cookies;
 import org.apache.tomcat.util.http.MimeHeaders;
 import org.apache.tomcat.util.http.Parameters;
+import org.apache.tomcat.util.res.StringManager;
 
 /**
  * This is a low-level, efficient representation of a server request. Most
@@ -59,21 +60,20 @@ import org.apache.tomcat.util.http.Param
  */
 public final class Request {
 
+    private static final StringManager sm =
+            StringManager.getManager(Constants.Package);
 
-    // ----------------------------------------------------------- Constructors
 
+    // ----------------------------------------------------------- Constructors
 
     public Request() {
-
         parameters.setQuery(queryMB);
         parameters.setURLDecoder(urlDecoder);
-
     }
 
 
     // ----------------------------------------------------- Instance Variables
 
-
     private int serverPort = -1;
     private final MessageBytes serverNameMB = MessageBytes.newInstance();
 
@@ -141,8 +141,6 @@ public final class Request {
     private final RequestInfo reqProcessorMX=new RequestInfo(this);
 
 
-    // ------------------------------------------------------------- TODO 
SERVLET 3.1 IN PROGRESS
-
     protected volatile ReadListener listener;
 
     public ReadListener getReadListener() {
@@ -150,8 +148,23 @@ public final class Request {
     }
 
     public void setReadListener(ReadListener 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("request.nullReadListener"));
+        }
+        if (getReadListener() != null) {
+            throw new IllegalStateException(
+                    sm.getString("request.readListenerSet"));
+        }
+        // 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("request.notAsync"));
+        }
+
         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