jetty-9 - HTTP client: moved exchange failure state from the receiver to the exchange where it better belongs.

This commit is contained in:
Simone Bordet 2012-09-07 15:21:17 +02:00
parent a15d71932f
commit 5235dc6ea1
2 changed files with 15 additions and 4 deletions

View File

@ -35,6 +35,7 @@ public class HttpExchange
private final Request request;
private final Response.Listener listener;
private final HttpResponse response;
private volatile Throwable failure;
public HttpExchange(HttpConversation conversation, HttpConnection connection, Request request, Response.Listener listener)
{
@ -95,6 +96,16 @@ public class HttpExchange
}
}
public boolean failed()
{
return failure != null;
}
public void failed(Throwable failure)
{
this.failure = failure;
}
@Override
public String toString()
{

View File

@ -44,7 +44,6 @@ public class HttpReceiver implements HttpParser.ResponseHandler<ByteBuffer>
private final AtomicBoolean complete = new AtomicBoolean();
private final HttpParser parser = new HttpParser(this);
private final HttpConnection connection;
private volatile boolean failed;
public HttpReceiver(HttpConnection connection)
{
@ -171,7 +170,9 @@ public class HttpReceiver implements HttpParser.ResponseHandler<ByteBuffer>
@Override
public boolean messageComplete(long contentLength)
{
if (!failed)
HttpExchange exchange = connection.getExchange();
// The exchange may be null if it was failed before
if (exchange != null && !exchange.failed())
success();
return true;
}
@ -184,7 +185,6 @@ public class HttpReceiver implements HttpParser.ResponseHandler<ByteBuffer>
LOG.debug("Received {}", response);
parser.reset();
failed = false;
boolean complete = this.complete.getAndSet(false);
exchange.responseComplete(true);
@ -208,7 +208,7 @@ public class HttpReceiver implements HttpParser.ResponseHandler<ByteBuffer>
LOG.debug("Failed {} {}", response, failure);
parser.reset();
failed = true;
exchange.failed(failure);
complete.set(false);
exchange.responseComplete(false);