Author: markt
Date: Tue Apr 30 08:55:53 2013
New Revision: 1477511
URL: http://svn.apache.org/r1477511
Log:
Refactor methods that call read/write listeners out of AsyncContext as
CoyoteAdapter has all the information it needs to call them itself.
Modified:
tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
tomcat/trunk/java/org/apache/catalina/core/AsyncContextImpl.java
Modified: tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java?rev=1477511&r1=1477510&r2=1477511&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
(original)
+++ tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java Tue Apr
30 08:55:53 2013
@@ -305,32 +305,85 @@ public class CoyoteAdapter implements Ad
}
} else if (status==SocketStatus.ASYNC_READ_ERROR) {
success = true;
- Throwable t =
(Throwable)req.getAttribute(RequestDispatcher.ERROR_EXCEPTION);
+ Throwable t = (Throwable)req.getAttribute(
+ RequestDispatcher.ERROR_EXCEPTION);
req.getAttributes().remove(RequestDispatcher.ERROR_EXCEPTION);
- asyncConImpl.notifyReadError(t);
+ if (req.getReadListener() != null) {
+ ClassLoader oldCL =
+ Thread.currentThread().getContextClassLoader();
+ ClassLoader newCL =
+ request.getContext().getLoader().getClassLoader();
+ try {
+ Thread.currentThread().setContextClassLoader(newCL);
+ req.getReadListener().onError(t);
+ } finally {
+ Thread.currentThread().setContextClassLoader(oldCL);
+ }
+ }
if (t != null) {
asyncConImpl.setErrorState(t, true);
}
} else if (status==SocketStatus.ASYNC_WRITE_ERROR) {
success = true;
- Throwable t =
(Throwable)req.getAttribute(RequestDispatcher.ERROR_EXCEPTION);
+ Throwable t = (Throwable)req.getAttribute(
+ RequestDispatcher.ERROR_EXCEPTION);
req.getAttributes().remove(RequestDispatcher.ERROR_EXCEPTION);
- asyncConImpl.notifyWriteError(t);
+ if (res.getWriteListener() != null) {
+ ClassLoader oldCL =
+ Thread.currentThread().getContextClassLoader();
+ ClassLoader newCL =
+ request.getContext().getLoader().getClassLoader();
+ try {
+ Thread.currentThread().setContextClassLoader(newCL);
+ res.getWriteListener().onError(t);
+ } finally {
+ Thread.currentThread().setContextClassLoader(oldCL);
+ }
+ }
if (t != null) {
asyncConImpl.setErrorState(t, true);
}
}
- if (!request.isAsyncDispatching() && request.isAsync() &&
request.isAsyncOperation()) {
+ if (!request.isAsyncDispatching() && request.isAsync() &&
+ request.isAsyncOperation()) {
if (status == SocketStatus.OPEN_WRITE) {
- // TODO Notify write listener
- success = asyncConImpl.canWrite();
+ if (res.getWriteListener() == null) {
+ success = false;
+ } else {
+ ClassLoader oldCL =
+ Thread.currentThread().getContextClassLoader();
+ ClassLoader newCL =
+
request.getContext().getLoader().getClassLoader();
+ try {
+
Thread.currentThread().setContextClassLoader(newCL);
+ res.getWriteListener().onWritePossible();
+ } finally {
+
Thread.currentThread().setContextClassLoader(oldCL);
+ }
+ success = true;
+ }
} else if (status == SocketStatus.OPEN_READ) {
- // TODO Notify read listener
- success = asyncConImpl.canRead();
+ if (req.getReadListener() == null) {
+ success = false;
+ } else {
+ ClassLoader oldCL =
+ Thread.currentThread().getContextClassLoader();
+ ClassLoader newCL =
+
request.getContext().getLoader().getClassLoader();
+ try {
+
Thread.currentThread().setContextClassLoader(newCL);
+ req.getReadListener().onDataAvailable();
+ if (request.getInputStream().isFinished()) {
+ req.getReadListener().onAllDataRead();
+ }
+ } finally {
+
Thread.currentThread().setContextClassLoader(oldCL);
+ }
+ success = true;
+ }
}
-
}
if (request.isAsyncDispatching()) {
Modified: tomcat/trunk/java/org/apache/catalina/core/AsyncContextImpl.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/AsyncContextImpl.java?rev=1477511&r1=1477510&r2=1477511&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/AsyncContextImpl.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/AsyncContextImpl.java Tue Apr 30
08:55:53 2013
@@ -132,62 +132,6 @@ public class AsyncContextImpl implements
}
}
- public boolean canRead() throws IOException {
- if (request.getCoyoteRequest().getReadListener()==null) return false;
-
- ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
- ClassLoader newCL = request.getContext().getLoader().getClassLoader();
- try {
- Thread.currentThread().setContextClassLoader(newCL);
- request.getCoyoteRequest().getReadListener().onDataAvailable();
- if (request.getInputStream().isFinished()) {
- request.getCoyoteRequest().getReadListener().onAllDataRead();
- }
- }finally {
- Thread.currentThread().setContextClassLoader(oldCL);
- }
- return true;
- }
-
- public boolean canWrite() throws IOException {
- if
(request.getResponse().getCoyoteResponse().getWriteListener()==null) return
false;
- ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
- ClassLoader newCL = request.getContext().getLoader().getClassLoader();
- try {
- Thread.currentThread().setContextClassLoader(newCL);
-
request.getResponse().getCoyoteResponse().getWriteListener().onWritePossible();
- }finally {
- Thread.currentThread().setContextClassLoader(oldCL);
- }
- return true;
- }
-
- public boolean notifyWriteError(Throwable error) {
- if
(request.getResponse().getCoyoteResponse().getWriteListener()==null) return
false;
- ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
- ClassLoader newCL = request.getContext().getLoader().getClassLoader();
- try {
- Thread.currentThread().setContextClassLoader(newCL);
-
request.getResponse().getCoyoteResponse().getWriteListener().onError(error);
- return true;
- } finally {
- Thread.currentThread().setContextClassLoader(oldCL);
- }
- }
-
- public boolean notifyReadError(Throwable error) {
- if (request.getCoyoteRequest().getReadListener()==null) return false;
- ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
- ClassLoader newCL = request.getContext().getLoader().getClassLoader();
- try {
- Thread.currentThread().setContextClassLoader(newCL);
- request.getCoyoteRequest().getReadListener().onError(error);
- return true;
- } finally {
- Thread.currentThread().setContextClassLoader(oldCL);
- }
- }
-
public boolean timeout() {
AtomicBoolean result = new AtomicBoolean();
request.getCoyoteRequest().action(ActionCode.ASYNC_TIMEOUT, result);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]