예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ClientSocketConnection"/> class.
        /// </summary>
        /// <param name="id">The unique identifier of the connection.</param>
        /// <param name="endpoint">The socket endpoint.</param>
        /// <param name="options">Networking options.</param>
        /// <param name="sslOptions">SSL options.</param>
        /// <param name="loggerFactory">A logger factory.</param>
        /// <param name="prefixLength">An optional prefix length.</param>
        public ClientSocketConnection(Guid id, IPEndPoint endpoint, NetworkingOptions options, SslOptions sslOptions, ILoggerFactory loggerFactory, int prefixLength = 0)
            : base(id, prefixLength)
        {
            _endpoint      = endpoint ?? throw new ArgumentNullException(nameof(endpoint));
            _options       = options ?? throw new ArgumentNullException(nameof(options));
            _sslOptions    = sslOptions ?? throw new ArgumentNullException(nameof(sslOptions));
            _loggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));

            HConsole.Configure(x => x.Configure(this).SetIndent(16).SetPrefix($"CLT.CONN [{id.ToShortString()}]"));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="NetworkingOptions"/> class.
        /// </summary>
        private NetworkingOptions(NetworkingOptions other)
        {
            Addresses        = new List <string>(other.Addresses);
            ShuffleAddresses = other.ShuffleAddresses;
            SmartRouting     = other.SmartRouting;
            RedoOperations   = other.RedoOperations;
            ReconnectMode    = other.ReconnectMode;
            ConnectionTimeoutMilliseconds = other.ConnectionTimeoutMilliseconds;

            Ssl             = other.Ssl.Clone();
            Cloud           = other.Cloud.Clone();
            Socket          = other.Socket.Clone();
            ConnectionRetry = other.ConnectionRetry.Clone();
        }
예제 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NetworkingOptions"/> class.
        /// </summary>
        private NetworkingOptions(NetworkingOptions other)
        {
            Addresses                     = new List <string>(other.Addresses);
            ShuffleAddresses              = other.ShuffleAddresses;
            SmartRouting                  = other.SmartRouting;
            RetryOnTargetDisconnected     = other.RetryOnTargetDisconnected;
            ConnectionTimeoutMilliseconds = other.ConnectionTimeoutMilliseconds;
            WaitForClientMilliseconds     = other.WaitForClientMilliseconds;
            ReconnectMode                 = other.ReconnectMode;

            Ssl                = other.Ssl.Clone();
            Cloud              = other.Cloud.Clone();
            Socket             = other.Socket.Clone();
            SocketInterception = other.SocketInterception.Clone();
            ConnectionRetry    = other.ConnectionRetry.Clone();
        }
예제 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AddressProvider"/> class.
        /// </summary>
        /// <param name="networkingOptions">The networking configuration.</param>
        /// <param name="loggerFactory">A logger factory.</param>
        public AddressProvider(NetworkingOptions networkingOptions, ILoggerFactory loggerFactory)
        {
            if (networkingOptions == null)
            {
                throw new ArgumentNullException(nameof(networkingOptions));
            }
            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }

            var cloudConfiguration = networkingOptions.Cloud;
            var addresses          = networkingOptions.Addresses;

            if (cloudConfiguration != null && cloudConfiguration.Enabled)
            {
                // fail fast
                if (addresses.Count > 0)
                {
                    throw new ConfigurationException("Only one address configuration method can be enabled at a time.");
                }

                // initialize cloud discovery
                var token   = cloudConfiguration.DiscoveryToken;
                var urlBase = cloudConfiguration.UrlBase;
                var connectionTimeoutMilliseconds = networkingOptions.ConnectionTimeoutMilliseconds;
                connectionTimeoutMilliseconds = connectionTimeoutMilliseconds == 0 ? int.MaxValue : connectionTimeoutMilliseconds;
                var cloudScanner = new CloudDiscovery(token, connectionTimeoutMilliseconds, urlBase, loggerFactory);

                _createMap = () => cloudScanner.Scan();
                _isMapping = true;
            }
            else
            {
                _configurationAddresses = addresses.Count > 0 ? addresses : new List <string> {
                    "localhost"
                };
                _createMap = CreateMapFromConfiguration;
            }
        }