<commit_before>using System;
using System.Collections.Generic;
using Jasper.Util;

namespace Jasper.Messaging.Transports
{
    public abstract class ExternalTransportSettings<TEndpoint> where TEndpoint : class
    {
        private ImHashMap<TransportUri, TEndpoint> _endpoints = ImHashMap<TransportUri,TEndpoint>.Empty;

        private readonly object _locker = new object();

        public Dictionary<string, string> Connections { get; set; } = new Dictionary<string, string>();

        protected abstract TEndpoint buildEndpoint(TransportUri uri, string connectionString);

        /// <summary>
        /// Configure a specific endpoint
        /// </summary>
        /// <param name="uriString"></param>
        /// <param name="alteration"></param>
        public void ConfigureEndpoint(string uriString, Action<TEndpoint> alteration)
        {
            ConfigureEndpoint(new TransportUri(uriString), alteration);
        }

        /// <summary>
        /// Configure a specific endpoint
        /// </summary>
        /// <param name="uri"></param>
        /// <param name="alteration"></param>
        public void ConfigureEndpoint(Uri uri, Action<TEndpoint> alteration)
        {
            ConfigureEndpoint(new TransportUri(uri), alteration);
        }

        /// <summary>
        /// Configure a specific endpoint
        /// </summary>
        /// <param name="uri"></param>
        /// <param name="alteration"></param>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        public void ConfigureEndpoint(TransportUri uri, Action<TEndpoint> alteration)
        {
            var endpoint = For(uri);
            if (endpoint == null) throw new ArgumentOutOfRangeException(nameof(uri), $"Unknown connection named '{uri.ConnectionName}'");

            alteration(endpoint);
        }

        /// <summary>
        /// Try to resolve the endpoint for the given Uri
        /// </summary>
        /// <param name="uri"></param>
        /// <returns></returns>
        public TEndpoint For(string uri)
        {
            return For(new TransportUri(uri));
        }

        /// <summary>
        /// Try to resolve the endpoint for the given TransportUri
        /// </summary>
        /// <param name="uri"></param>
        /// <returns></returns>
        public TEndpoint For(TransportUri uri)
        {
            if (_endpoints.TryFind(uri, out var endpoint))
            {
                return endpoint;
            }

            lock (_locker)
            {
                if (_endpoints.TryFind(uri, out endpoint))
                {
                    return endpoint;
                }

                if (!Connections.ContainsKey(uri.ConnectionName)) return null;

                endpoint = buildEndpoint(uri, Connections[uri.ConnectionName]);
                _endpoints = _endpoints.AddOrUpdate(uri, endpoint);

                return endpoint;

            }
        }

        // TODO -- use the service name if you can?
        public TransportUri ReplyUri { get; set; }
    }
}<commit_msg>Removed a TODO from ExternalTransportSettings<commit_after>using System;
using System.Collections.Generic;
using Jasper.Util;

namespace Jasper.Messaging.Transports
{
    public abstract class ExternalTransportSettings<TEndpoint> where TEndpoint : class
    {
        private ImHashMap<TransportUri, TEndpoint> _endpoints = ImHashMap<TransportUri,TEndpoint>.Empty;

        private readonly object _locker = new object();

        public Dictionary<string, string> Connections { get; set; } = new Dictionary<string, string>();

        protected abstract TEndpoint buildEndpoint(TransportUri uri, string connectionString);

        /// <summary>
        /// Configure a specific endpoint
        /// </summary>
        /// <param name="uriString"></param>
        /// <param name="alteration"></param>
        public void ConfigureEndpoint(string uriString, Action<TEndpoint> alteration)
        {
            ConfigureEndpoint(new TransportUri(uriString), alteration);
        }

        /// <summary>
        /// Configure a specific endpoint
        /// </summary>
        /// <param name="uri"></param>
        /// <param name="alteration"></param>
        public void ConfigureEndpoint(Uri uri, Action<TEndpoint> alteration)
        {
            ConfigureEndpoint(new TransportUri(uri), alteration);
        }

        /// <summary>
        /// Configure a specific endpoint
        /// </summary>
        /// <param name="uri"></param>
        /// <param name="alteration"></param>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        public void ConfigureEndpoint(TransportUri uri, Action<TEndpoint> alteration)
        {
            var endpoint = For(uri);
            if (endpoint == null) throw new ArgumentOutOfRangeException(nameof(uri), $"Unknown connection named '{uri.ConnectionName}'");

            alteration(endpoint);
        }

        /// <summary>
        /// Try to resolve the endpoint for the given Uri
        /// </summary>
        /// <param name="uri"></param>
        /// <returns></returns>
        public TEndpoint For(string uri)
        {
            return For(new TransportUri(uri));
        }

        /// <summary>
        /// Try to resolve the endpoint for the given TransportUri
        /// </summary>
        /// <param name="uri"></param>
        /// <returns></returns>
        public TEndpoint For(TransportUri uri)
        {
            if (_endpoints.TryFind(uri, out var endpoint))
            {
                return endpoint;
            }

            lock (_locker)
            {
                if (_endpoints.TryFind(uri, out endpoint))
                {
                    return endpoint;
                }

                if (!Connections.ContainsKey(uri.ConnectionName)) return null;

                endpoint = buildEndpoint(uri, Connections[uri.ConnectionName]);
                _endpoints = _endpoints.AddOrUpdate(uri, endpoint);

                return endpoint;

            }
        }

        public TransportUri ReplyUri { get; set; }
    }
}
{'fraction_non_alphanumeric': 0.11684693543100623, 'fraction_numerical': 0.0, 'mean_word_length': 1.9103481163567, 'pattern_counts': {'":': 0, '<': 83, '<?xml version=': 0, '>': 83, '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': '7390002', 'n_tokens_mistral': 1518, 'n_tokens_neox': 1453, 'n_words': 378}