diff --git a/http-client/src/main/java/com/proofpoint/http/client/jetty/FailedHttpResponseFuture.java b/http-client/src/main/java/com/proofpoint/http/client/jetty/FailedHttpResponseFuture.java new file mode 100644 index 000000000..f6c06ca60 --- /dev/null +++ b/http-client/src/main/java/com/proofpoint/http/client/jetty/FailedHttpResponseFuture.java @@ -0,0 +1,22 @@ +package com.proofpoint.http.client.jetty; + +import com.google.common.util.concurrent.ForwardingListenableFuture.SimpleForwardingListenableFuture; +import com.proofpoint.http.client.HttpClient; + +import static com.google.common.util.concurrent.Futures.immediateFailedFuture; + +public class FailedHttpResponseFuture + extends SimpleForwardingListenableFuture + implements HttpClient.HttpResponseFuture +{ + public FailedHttpResponseFuture(Throwable throwable) + { + super(immediateFailedFuture(throwable)); + } + + @Override + public String getState() + { + return "FAILED"; + } +} \ No newline at end of file diff --git a/http-client/src/main/java/com/proofpoint/http/client/jetty/JettyHttpClient.java b/http-client/src/main/java/com/proofpoint/http/client/jetty/JettyHttpClient.java index f8d2c3ed4..ec1caa6c6 100644 --- a/http-client/src/main/java/com/proofpoint/http/client/jetty/JettyHttpClient.java +++ b/http-client/src/main/java/com/proofpoint/http/client/jetty/JettyHttpClient.java @@ -41,7 +41,6 @@ import org.eclipse.jetty.util.thread.QueuedThreadPool; import org.eclipse.jetty.util.thread.ScheduledExecutorScheduler; import org.eclipse.jetty.util.thread.Scheduler; -import org.eclipse.jetty.util.thread.Sweeper; import org.weakref.jmx.Flatten; import org.weakref.jmx.Managed; import org.weakref.jmx.Nested; @@ -88,7 +87,6 @@ public class JettyHttpClient }; private static final String PLATFORM_STATS_KEY = "platform_stats"; - private static final long SWEEP_PERIOD_MILLIS = 5000; private static final AtomicLong NAME_COUNTER = new AtomicLong(); private static final JettyHttpClientOptions DEFAULT_CLIENT_OPTIONS = @@ -249,12 +247,6 @@ public JettyHttpClient( httpClient.getScheduler(), config.getConnectTimeout().toMillis())); - // Jetty client connections can sometimes get stuck while closing which reduces - // the available connections. The Jetty Sweeper periodically scans the active - // connection pool looking for connections in the closed state, and if a connection - // is observed in the closed state multiple times, it logs, and destroys the connection. - httpClient.addBean(new Sweeper(httpClient.getScheduler(), SWEEP_PERIOD_MILLIS), true); - try { this.httpClient.start(); @@ -478,7 +470,12 @@ public HttpResponseFuture executeAsync(Request reque requireNonNull(responseHandler, "responseHandler is null"); AtomicLong bytesWritten = new AtomicLong(0); - request = applyRequestFilters(request); + try { + request = applyRequestFilters(request); + } + catch (RuntimeException e) { + return new FailedHttpResponseFuture<>(e); + } HttpRequest jettyRequest = buildJettyRequest(request, bytesWritten);