jetty-9 - HTTP client: moved exchange failure state from the receiver to the exchange where it better belongs.
This commit is contained in:
parent
a15d71932f
commit
5235dc6ea1
|
@ -35,6 +35,7 @@ public class HttpExchange
|
||||||
private final Request request;
|
private final Request request;
|
||||||
private final Response.Listener listener;
|
private final Response.Listener listener;
|
||||||
private final HttpResponse response;
|
private final HttpResponse response;
|
||||||
|
private volatile Throwable failure;
|
||||||
|
|
||||||
public HttpExchange(HttpConversation conversation, HttpConnection connection, Request request, Response.Listener listener)
|
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
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
|
|
|
@ -44,7 +44,6 @@ public class HttpReceiver implements HttpParser.ResponseHandler<ByteBuffer>
|
||||||
private final AtomicBoolean complete = new AtomicBoolean();
|
private final AtomicBoolean complete = new AtomicBoolean();
|
||||||
private final HttpParser parser = new HttpParser(this);
|
private final HttpParser parser = new HttpParser(this);
|
||||||
private final HttpConnection connection;
|
private final HttpConnection connection;
|
||||||
private volatile boolean failed;
|
|
||||||
|
|
||||||
public HttpReceiver(HttpConnection connection)
|
public HttpReceiver(HttpConnection connection)
|
||||||
{
|
{
|
||||||
|
@ -171,7 +170,9 @@ public class HttpReceiver implements HttpParser.ResponseHandler<ByteBuffer>
|
||||||
@Override
|
@Override
|
||||||
public boolean messageComplete(long contentLength)
|
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();
|
success();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -184,7 +185,6 @@ public class HttpReceiver implements HttpParser.ResponseHandler<ByteBuffer>
|
||||||
LOG.debug("Received {}", response);
|
LOG.debug("Received {}", response);
|
||||||
|
|
||||||
parser.reset();
|
parser.reset();
|
||||||
failed = false;
|
|
||||||
boolean complete = this.complete.getAndSet(false);
|
boolean complete = this.complete.getAndSet(false);
|
||||||
|
|
||||||
exchange.responseComplete(true);
|
exchange.responseComplete(true);
|
||||||
|
@ -208,7 +208,7 @@ public class HttpReceiver implements HttpParser.ResponseHandler<ByteBuffer>
|
||||||
LOG.debug("Failed {} {}", response, failure);
|
LOG.debug("Failed {} {}", response, failure);
|
||||||
|
|
||||||
parser.reset();
|
parser.reset();
|
||||||
failed = true;
|
exchange.failed(failure);
|
||||||
complete.set(false);
|
complete.set(false);
|
||||||
|
|
||||||
exchange.responseComplete(false);
|
exchange.responseComplete(false);
|
||||||
|
|
Loading…
Reference in New Issue