HTTP client: refactored "last exchange" concept out of HttpConversation into HttpExchange.
This commit is contained in:
parent
7f37ddbc25
commit
33d97b8dd4
|
@ -35,7 +35,6 @@ public class HttpConversation implements Attributes
|
|||
private final HttpClient client;
|
||||
private final long id;
|
||||
private volatile Response.Listener listener;
|
||||
private volatile HttpExchange last;
|
||||
|
||||
public HttpConversation(HttpClient client, long id)
|
||||
{
|
||||
|
@ -63,27 +62,6 @@ public class HttpConversation implements Attributes
|
|||
this.listener = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the exchange that has been identified as the last of this conversation
|
||||
* @see #last
|
||||
*/
|
||||
public HttpExchange getLastExchange()
|
||||
{
|
||||
return last;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remembers the given {@code exchange} as the last of this conversation.
|
||||
*
|
||||
* @param exchange the exchange that is the last of this conversation
|
||||
* @see #last
|
||||
*/
|
||||
public void setLastExchange(HttpExchange exchange)
|
||||
{
|
||||
if (last == null)
|
||||
last = exchange;
|
||||
}
|
||||
|
||||
public void complete()
|
||||
{
|
||||
client.removeConversation(this);
|
||||
|
|
|
@ -39,6 +39,7 @@ public class HttpExchange
|
|||
private final Request request;
|
||||
private final Response.Listener listener;
|
||||
private final HttpResponse response;
|
||||
private volatile boolean last;
|
||||
private volatile Throwable requestFailure;
|
||||
private volatile Throwable responseFailure;
|
||||
|
||||
|
@ -81,6 +82,22 @@ public class HttpExchange
|
|||
return responseFailure;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether this exchange is the last in the conversation
|
||||
*/
|
||||
public boolean isLast()
|
||||
{
|
||||
return last;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param last whether this exchange is the last in the conversation
|
||||
*/
|
||||
public void setLast(boolean last)
|
||||
{
|
||||
this.last = last;
|
||||
}
|
||||
|
||||
public void receive()
|
||||
{
|
||||
connection.receive();
|
||||
|
@ -159,7 +176,7 @@ public class HttpExchange
|
|||
{
|
||||
// Request and response completed
|
||||
LOG.debug("{} complete", this);
|
||||
if (conversation.getLastExchange() == this)
|
||||
if (isLast())
|
||||
{
|
||||
HttpExchange first = conversation.getExchanges().peekFirst();
|
||||
Response.Listener listener = first.getResponseListener();
|
||||
|
|
|
@ -146,7 +146,7 @@ public class HttpReceiver implements HttpParser.ResponseHandler<ByteBuffer>
|
|||
Response.Listener handlerListener = protocolHandler == null ? null : protocolHandler.getResponseListener();
|
||||
if (handlerListener == null)
|
||||
{
|
||||
conversation.setLastExchange(exchange);
|
||||
exchange.setLast(true);
|
||||
if (currentListener == initialListener)
|
||||
conversation.setResponseListener(initialListener);
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue