diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpExchange.java b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpExchange.java index 1385ee24fe2..bfed4453dc2 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpExchange.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpExchange.java @@ -159,10 +159,9 @@ public class HttpExchange private int update(int code, Throwable failure) { - int current; while (true) { - current = complete.get(); + int current = complete.get(); boolean updateable = (current & code) == 0; if (updateable) { @@ -177,9 +176,8 @@ public class HttpExchange if (LOG.isDebugEnabled()) LOG.debug("{} updated", this); } - break; + return current; } - return current; } public boolean abort(Throwable cause) diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpReceiver.java b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpReceiver.java index 3709c4a8fa6..10555f9a562 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpReceiver.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpReceiver.java @@ -429,16 +429,7 @@ public abstract class HttpReceiver dispose(); - // Mark atomically the response as terminated and failed, - // with respect to concurrency between request and response. - Result result = exchange.terminateResponse(failure); - - HttpResponse response = exchange.getResponse(); - if (LOG.isDebugEnabled()) - LOG.debug("Response failure {} {} on {}: {}", response, exchange, getHttpChannel(), failure); - List listeners = exchange.getConversation().getResponseListeners(); - ResponseNotifier notifier = getHttpDestination().getResponseNotifier(); - notifier.notifyFailure(listeners, response, failure); + Result result = failResponse(exchange, failure); if (fail) { @@ -453,9 +444,25 @@ public abstract class HttpReceiver return true; } + private Result failResponse(HttpExchange exchange, Throwable failure) + { + // Mark atomically the response as terminated and failed, + // with respect to concurrency between request and response. + Result result = exchange.terminateResponse(failure); + + HttpResponse response = exchange.getResponse(); + if (LOG.isDebugEnabled()) + LOG.debug("Response failure {} {} on {}: {}", response, exchange, getHttpChannel(), failure); + List listeners = exchange.getConversation().getResponseListeners(); + ResponseNotifier notifier = getHttpDestination().getResponseNotifier(); + notifier.notifyFailure(listeners, response, failure); + + return result; + } + private void terminateResponse(HttpExchange exchange, Throwable failure) { - Result result = exchange.terminateResponse(failure); + Result result = failResponse(exchange, failure); terminateResponse(exchange, result); } @@ -472,7 +479,7 @@ public abstract class HttpReceiver if (!ordered) channel.exchangeTerminated(result); if (LOG.isDebugEnabled()) - LOG.debug("Request/Response {} {}", failure == null ? "succeeded" : "failed", response); + LOG.debug("Request/Response {}: {}", failure == null ? "succeeded" : "failed", result); List listeners = exchange.getConversation().getResponseListeners(); ResponseNotifier notifier = getHttpDestination().getResponseNotifier(); notifier.notifyComplete(listeners, result); diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpSender.java b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpSender.java index 308f3cb941a..72eca44f238 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpSender.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpSender.java @@ -321,15 +321,7 @@ public abstract class HttpSender implements AsyncContentProvider.Listener dispose(); - // Mark atomically the request as terminated and failed, - // with respect to concurrency between request and response. - Result result = exchange.terminateRequest(failure); - - Request request = exchange.getRequest(); - if (LOG.isDebugEnabled()) - LOG.debug("Request failure {} {} on {}: {}", request, exchange, getHttpChannel(), failure); - HttpDestination destination = getHttpChannel().getHttpDestination(); - destination.getRequestNotifier().notifyFailure(request, failure); + Result result = failRequest(exchange, failure); if (fail) { @@ -344,11 +336,26 @@ public abstract class HttpSender implements AsyncContentProvider.Listener return true; } + private Result failRequest(HttpExchange exchange, Throwable failure) + { + // Mark atomically the request as terminated and failed, + // with respect to concurrency between request and response. + Result result = exchange.terminateRequest(failure); + + Request request = exchange.getRequest(); + if (LOG.isDebugEnabled()) + LOG.debug("Request failure {} {} on {}: {}", request, exchange, getHttpChannel(), failure); + HttpDestination destination = getHttpChannel().getHttpDestination(); + destination.getRequestNotifier().notifyFailure(request, failure); + + return result; + } + private void terminateRequest(HttpExchange exchange, Throwable failure) { if (exchange != null) { - Result result = exchange.terminateRequest(failure); + Result result = failRequest(exchange, failure); terminateRequest(exchange, failure, result); } } @@ -376,7 +383,7 @@ public abstract class HttpSender implements AsyncContentProvider.Listener if (!ordered) channel.exchangeTerminated(result); if (LOG.isDebugEnabled()) - LOG.debug("Request/Response {} {}", failure == null ? "succeeded" : "failed", request); + LOG.debug("Request/Response {}: {}", failure == null ? "succeeded" : "failed", result); HttpConversation conversation = exchange.getConversation(); destination.getResponseNotifier().notifyComplete(conversation.getResponseListeners(), result); if (ordered) diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/http/HttpConnectionOverHTTP.java b/jetty-client/src/main/java/org/eclipse/jetty/client/http/HttpConnectionOverHTTP.java index 60785f8ab4b..6b8bd947f1b 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/http/HttpConnectionOverHTTP.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/http/HttpConnectionOverHTTP.java @@ -148,7 +148,7 @@ public class HttpConnectionOverHTTP extends AbstractConnection implements Connec return closed.compareAndSet(false, true); } - private boolean abort(Throwable failure) + protected boolean abort(Throwable failure) { HttpExchange exchange = channel.getHttpExchange(); return exchange != null && exchange.getRequest().abort(failure);