<commit_before>package io.bootique.rabbitmq.client.connection;

import com.rabbitmq.client.Connection;
import org.apache.commons.io.IOUtils;

import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

public class ConnectionFactory {
    private Map<String, ConnectionConfig> configMap;
    private final ConcurrentMap<String, Connection> connectionList = new ConcurrentHashMap<>();

    public ConnectionFactory(Map<String, ConnectionConfig> configMap) {
        this.configMap = configMap;
    }

    public void shutdown() {
        connectionList.values().forEach(IOUtils::closeQuietly);
    }

    public Collection allNames() {
        return configMap.keySet();
    }

    public Connection forName(String connectionName) {
        return connectionList.computeIfAbsent(connectionName, this::createConnection);
    }

    private Connection createConnection(String connectionName) {
        return configMap.computeIfAbsent(connectionName, name -> {
            throw new IllegalStateException("No configuration present for Connection named '" + name + "'");
        }).createConnection();
    }
}<commit_msg>connection factory error handling<commit_after>package io.bootique.rabbitmq.client.connection;

import com.rabbitmq.client.Connection;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

public class ConnectionFactory {
    private static final Logger LOGGER = LoggerFactory.getLogger(ConnectionFactory.class);

    private Map<String, ConnectionConfig> configMap;
    private final ConcurrentMap<String, Connection> connectionList = new ConcurrentHashMap<>();
    private volatile Boolean shutdown;
    private final Object lock = new Object();

    public ConnectionFactory(Map<String, ConnectionConfig> configMap) {
        this.configMap = configMap;
    }

    public void shutdown() {
        shutdown = true;
        LOGGER.info("Shutting down RabbitMQ service...");
        synchronized (lock) {
            LOGGER.info("Closing Rabbit MQ broker connections");
            connectionList.values()
                    .stream()
                    .filter(Connection::isOpen)
                    .forEach(IOUtils::closeQuietly);
            connectionList.clear();
        }
    }

    public Collection allNames() {
        return configMap.keySet();
    }

    public Connection forName(String connectionName) {
        if (shutdown) {
            throw new IllegalStateException("Can't get connection -- Rabbit MQ service is shut down");
        }
        synchronized (lock) {
            return isConnectionValid(connectionName) ? connectionList.get(connectionName) : createConnection(connectionName);
        }
    }

    private Connection createConnection(String connectionName) {
        Connection connection = configMap.computeIfAbsent(connectionName, name -> {
            throw new IllegalStateException("No configuration present for Connection named '" + name + "'");
        }).createConnection();

        connectionList.put(connectionName, connection);
        return connection;
    }

    private boolean isConnectionValid(String connectionName) {
        return connectionList.containsKey(connectionName) && connectionList.get(connectionName).isOpen();
    }
}
{'fraction_non_alphanumeric': 0.09274193548387097, 'fraction_numerical': 0.000576036866359447, 'mean_word_length': 3.4411764705882355, 'pattern_counts': {'":': 0, '<': 11, '<?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': '539548', 'n_tokens_mistral': 869, 'n_tokens_neox': 857, 'n_words': 202}