<commit_before>package me.itzg.mccy.services;

import com.google.common.base.Optional;
import com.spotify.docker.client.DefaultDockerClient;
import com.spotify.docker.client.DockerCertificateException;
import com.spotify.docker.client.DockerCertificates;
import com.spotify.docker.client.DockerClient;
import com.spotify.docker.client.DockerException;
import me.itzg.mccy.config.MccySettings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.nio.file.Paths;

/**
 * @author <NAME>
 * @since 12/21/2015
 */
@Service
public class DockerClientProxy {
    @Autowired
    private MccySettings mccySettings;

    public interface Consumer<T> {
        T use(DockerClient dockerClient) throws DockerException, InterruptedException;
    }

    public <T> T access(Consumer<T> consumer) throws DockerException, InterruptedException {

        DefaultDockerClient dockerClient = null;

        try {
            dockerClient = createClient(dockerClient);

            return consumer.use(dockerClient);
        }
        finally {
            if (dockerClient != null) {
                dockerClient.close();
            }
        }
    }

    private DefaultDockerClient createClient(DefaultDockerClient dockerClient) {
        Optional<DockerCertificates> certs = Optional.absent();
        if (mccySettings.getDockerCertPath() != null) {
            try {
                certs = DockerCertificates.builder()
                        .dockerCertPath(Paths.get(mccySettings.getDockerCertPath())).build();
            } catch (DockerCertificateException e) {
                throw new IllegalArgumentException("Unable to initialize Docker certificates with given configuration");
            }
        }

        final DefaultDockerClient.Builder clientBuilder = DefaultDockerClient.builder();

        if (certs.isPresent()) {
            clientBuilder
                    .dockerCertificates(certs.get());
        }

        dockerClient = clientBuilder
                .uri(mccySettings.getDockerHostUri())
                .build();
        return dockerClient;
    }
}<commit_msg>Attempting to fix "connection pool shutdown" error via docker client access<commit_after>package me.itzg.mccy.services;

import com.google.common.base.Optional;
import com.spotify.docker.client.DefaultDockerClient;
import com.spotify.docker.client.DockerCertificateException;
import com.spotify.docker.client.DockerCertificates;
import com.spotify.docker.client.DockerClient;
import com.spotify.docker.client.DockerException;
import me.itzg.mccy.config.MccySettings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.nio.file.Paths;

/**
 * @author <NAME>
 * @since 12/21/2015
 */
@Service
public class DockerClientProxy {
    private MccySettings mccySettings;
    private DockerClient dockerClient;

    public interface Consumer<T> {
        T use(DockerClient dockerClient) throws DockerException, InterruptedException;
    }

    public <T> T access(Consumer<T> consumer) throws DockerException, InterruptedException {

        return consumer.use(dockerClient);
    }

    @Autowired
    public void setMccySettings(MccySettings mccySettings) {
        this.mccySettings = mccySettings;

        this.dockerClient = createClient();
    }

    private DefaultDockerClient createClient() {
        DefaultDockerClient dockerClient;
        Optional<DockerCertificates> certs = Optional.absent();
        if (mccySettings.getDockerCertPath() != null) {
            try {
                certs = DockerCertificates.builder()
                        .dockerCertPath(Paths.get(mccySettings.getDockerCertPath())).build();
            } catch (DockerCertificateException e) {
                throw new IllegalArgumentException("Unable to initialize Docker certificates with given configuration");
            }
        }

        final DefaultDockerClient.Builder clientBuilder = DefaultDockerClient.builder();

        if (certs.isPresent()) {
            clientBuilder
                    .dockerCertificates(certs.get());
        }

        dockerClient = clientBuilder
                .uri(mccySettings.getDockerHostUri())
                .build();
        return dockerClient;
    }
}
{'fraction_non_alphanumeric': 0.08960074280408542, 'fraction_numerical': 0.003714020427112349, 'mean_word_length': 2.8889891696750905, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5933901', 'n_tokens_mistral': 1211, 'n_tokens_neox': 1126, 'n_words': 221}