@@ -0,0 +1,2892 @@
+package com.yahoo.vespa.hosted.node.admin.util;%0A%0Aimport com.yahoo.log.LogLevel;%0Aimport org.apache.http.client.config.RequestConfig;%0Aimport org.apache.http.client.methods.CloseableHttpResponse;%0Aimport org.apache.http.client.methods.HttpUriRequest;%0Aimport org.apache.http.config.Registry;%0Aimport org.apache.http.config.RegistryBuilder;%0Aimport org.apache.http.conn.socket.ConnectionSocketFactory;%0Aimport org.apache.http.conn.socket.PlainConnectionSocketFactory;%0Aimport org.apache.http.conn.ssl.SSLConnectionSocketFactory;%0Aimport org.apache.http.impl.client.CloseableHttpClient;%0Aimport org.apache.http.impl.client.HttpClientBuilder;%0Aimport org.apache.http.impl.conn.PoolingHttpClientConnectionManager;%0A%0Aimport java.io.IOException;%0Aimport java.util.logging.Logger;%0A%0A/**%0A * @author freva%0A */%0Aclass SelfCloseableHttpClient %7B%0A%0A    private static final Logger log = Logger.getLogger(SelfCloseableHttpClient.class.getName());%0A%0A    private final CloseableHttpClient httpClient;%0A%0A    SelfCloseableHttpClient() %7B%0A        this(SSLConnectionSocketFactory.getSocketFactory());%0A    %7D%0A%0A    SelfCloseableHttpClient(SSLConnectionSocketFactory sslConnectionSocketFactory) %7B%0A        Registry%3CConnectionSocketFactory%3E socketFactoryRegistry = RegistryBuilder.%3CConnectionSocketFactory%3Ecreate()%0A                .register(%22http%22, PlainConnectionSocketFactory.getSocketFactory())%0A                .register(%22https%22, sslConnectionSocketFactory)%0A                .build();%0A%0A        PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(socketFactoryRegistry);%0A        cm.setMaxTotal(200); // Increase max total connections to 200, which should be enough%0A%0A        // Have experienced hang in socket read, which may have been because of%0A        // system defaults, therefore set explicit timeouts. Set arbitrarily to%0A        // 15s %3E 10s used by Orchestrator lock timeout.%0A        int timeoutMs = 15_000;%0A        RequestConfig requestBuilder = RequestConfig.custom()%0A                .setConnectTimeout(timeoutMs) // establishment of connection%0A                .setConnectionRequestTimeout(timeoutMs) // connection from connection manager%0A                .setSocketTimeout(timeoutMs) // waiting for data%0A                .build();%0A%0A        this.httpClient = HttpClientBuilder.create()%0A                .setDefaultRequestConfig(requestBuilder)%0A                .disableAutomaticRetries()%0A                .setUserAgent(%22node-admin%22)%0A                .setConnectionManager(cm).build();%0A    %7D%0A%0A    public CloseableHttpResponse execute(HttpUriRequest request) throws IOException %7B%0A        return httpClient.execute(request);%0A    %7D%0A%0A    @Override%0A    public void finalize() throws Throwable %7B%0A        try %7B%0A            httpClient.close();%0A        %7D catch (Exception e) %7B%0A            log.log(LogLevel.WARNING, %22Ignoring exception thrown when closing http client%22, e);%0A        %7D%0A%0A        super.finalize();%0A    %7D%0A%7D%0A

Create self-closeable HTTP client