From 4722ac1720bcd28144d0f91570c137c735ebae38 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Tue, 7 Jan 2014 17:59:56 +0100 Subject: [PATCH] Improved semantic of close() method, now executed only once. --- .../client/http/HttpConnectionOverHTTP.java | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) 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 b0195c92472..b1163d2492e 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 @@ -19,6 +19,7 @@ package org.eclipse.jetty.client.http; import java.util.concurrent.TimeoutException; +import java.util.concurrent.atomic.AtomicBoolean; import org.eclipse.jetty.client.HttpConnection; import org.eclipse.jetty.client.HttpDestination; @@ -35,9 +36,9 @@ public class HttpConnectionOverHTTP extends AbstractConnection implements Connec { private static final Logger LOG = Log.getLogger(HttpConnectionOverHTTP.class); + private final AtomicBoolean closed = new AtomicBoolean(); private final Delegate delegate; private final HttpChannelOverHTTP channel; - private boolean closed; private long idleTimeout; public HttpConnectionOverHTTP(EndPoint endPoint, HttpDestination destination) @@ -75,16 +76,9 @@ public class HttpConnectionOverHTTP extends AbstractConnection implements Connec fillInterested(); } - @Override - public void onClose() - { - closed = true; - super.onClose(); - } - protected boolean isClosed() { - return closed; + return closed.get(); } @Override @@ -126,11 +120,14 @@ public class HttpConnectionOverHTTP extends AbstractConnection implements Connec @Override public void close() { - getHttpDestination().close(this); - getEndPoint().shutdownOutput(); - LOG.debug("{} oshut", this); - getEndPoint().close(); - LOG.debug("{} closed", this); + if (closed.compareAndSet(false, true)) + { + getHttpDestination().close(this); + getEndPoint().shutdownOutput(); + LOG.debug("{} oshut", this); + getEndPoint().close(); + LOG.debug("{} closed", this); + } } @Override