You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ro...@apache.org on 2006/08/23 19:57:29 UTC
svn commit: r434105 -
/jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/impl/SimpleHttpDispatcher.java
Author: rolandw
Date: Wed Aug 23 10:57:29 2006
New Revision: 434105
URL: http://svn.apache.org/viewvc?rev=434105&view=rev
Log:
moved consuming of response body to background thread
Modified:
jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/impl/SimpleHttpDispatcher.java
Modified: jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/impl/SimpleHttpDispatcher.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/impl/SimpleHttpDispatcher.java?rev=434105&r1=434104&r2=434105&view=diff
==============================================================================
--- jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/impl/SimpleHttpDispatcher.java (original)
+++ jakarta/httpcomponents/httpasync/trunk/src/java/org/apache/http/async/impl/SimpleHttpDispatcher.java Wed Aug 23 10:57:29 2006
@@ -72,7 +72,7 @@
* <!-- empty lines above to avoid 'svn diff' context problems -->
* @version $Revision$ $Date$
*
- * @since 4.0
+ * @since 1.0
*/
public class SimpleHttpDispatcher extends AbstractHttpDispatcher
implements HttpDispatcher {
@@ -257,10 +257,13 @@
found = response_handles.remove(handle);
try {
if (found) {
- boolean haveresponse =
- closeResponse((SimpleHttpHandle)handle, abort);
- if (abort && !haveresponse) {
- // it is probably waiting for the response:
+ try {
+ if (abort)
+ client_connection.close();
+ } finally {
+ // Background thread can be waiting for the rsp,
+ // or for the completion of rsp processing.
+ // Either way, it needs to continue.
background_thread.interrupt();
}
}
@@ -274,28 +277,22 @@
/**
- * Close a response.
- * This includes deciding an connection re-use and whether to
+ * Gracefully closes a response.
+ * This includes deciding on connection re-use and whether to
* close the connection or read to the end of the response entity.
- * It does not include notification of the background thread.
+ * This method is called by the background thread.
*
* @param handle the handle for which to close the response
- * @param abort <code>true</code> for a hard abort, or
- * <code>false</code> for a smooth close
- *
- * @return <code>true</code> if there is a response object,
- * <code>false</code> otherwise
*
* @throws IOException in case of a problem closing the response
*/
- private final boolean closeResponse(SimpleHttpHandle handle, boolean abort)
+ private final void closeResponse(SimpleHttpHandle handle)
throws IOException {
HttpResponse response = handle.internalGetResponse();
boolean reuse = false;
try {
- if (!abort && (response != null) &&
- (reuse_strategy != null) &&
+ if ((response != null) && (reuse_strategy != null) &&
reuse_strategy.keepAlive(client_connection, response)) {
// consume rest of the entity, if there is one
@@ -312,15 +309,13 @@
client_connection.close();
}
- return (response != null);
-
} // closeResponse
// non-javadoc, see interface HttpDispatcher
public void abortAll() {
- // this will prevent interference from newly dispatcher requests
+ // this will prevent interference from newly dispatched requests
synchronized (linked_handle_monitor) {
// first, clear the request queue so handles can't be picked up
@@ -354,9 +349,11 @@
* This needs to be an inner class, since the monitors
* and handle queues should be private.
*
+ *
+ * <!-- empty lines above to avoid 'svn diff' context problems -->
* @version $Revision$ $Date$
*
- * @since 4.0
+ * @since 1.0
*/
private class SimpleHttpDispatcherThread extends Thread {
@@ -410,8 +407,10 @@
if (response.getEntity() != null) {
awaitCompletion(handle);
+ closeResponse(handle);
} else {
//@@@ close/unlink the handle?
+//@@@ calling close() on the handle would interrupt this thread - not good
}
} // if request handle