/// <summary> /// Initializes a MemcahcedClient config with auto discovery enabled using the setup provided /// </summary> /// <param name="loggerFactory">The factory to provide ILogger instance to each class.</param> /// <param name="setup">The setup to get conifg settings from</param> public ElastiCacheClusterConfig(ILoggerFactory loggerFactory, ClusterConfigSettings setup) { if (setup == null) { throw new ArgumentNullException(nameof(setup)); } if (setup.ClusterEndPoint == null) { throw new ArgumentException("Cluster Settings are null"); } if (string.IsNullOrEmpty(setup.ClusterEndPoint.HostName)) { throw new ArgumentException("Hostname is null"); } if (setup.ClusterEndPoint.Port <= 0) { throw new ArgumentException("Port cannot be 0 or less"); } _loggerFactory = loggerFactory; Setup = setup; Servers = new List <EndPoint>(); Protocol = setup.Protocol; KeyTransformer = setup.KeyTransformer ?? new DefaultKeyTransformer(); SocketPool = setup.SocketPool ?? new SocketPoolConfiguration(); Authentication = setup.Authentication ?? new AuthenticationConfiguration(); NodeFactory = setup.NodeFactory ?? new DefaultConfigNodeFactory(); _nodeLocator = setup.NodeLocator ?? typeof(DefaultNodeLocator); if (setup.Transcoder != null) { _transcoder = setup.Transcoder ?? new DefaultTranscoder(); } if (setup.ClusterEndPoint.HostName.IndexOf(".cfg", StringComparison.OrdinalIgnoreCase) >= 0) { if (setup.ClusterNode != null) { var tries = setup.ClusterNode.NodeTries > 0 ? setup.ClusterNode.NodeTries : DiscoveryNode.DefaultTryCount; var delay = setup.ClusterNode.NodeDelay >= 0 ? setup.ClusterNode.NodeDelay : DiscoveryNode.DefaultTryDelay; DiscoveryNode = new DiscoveryNode(this, setup.ClusterEndPoint.HostName, setup.ClusterEndPoint.Port, tries, delay); } else { DiscoveryNode = new DiscoveryNode(this, setup.ClusterEndPoint.HostName, setup.ClusterEndPoint.Port); } } else { throw new ArgumentException("The provided endpoint does not support auto discovery"); } }
/// <summary> /// Initializes a MemcahcedClient config with auto discovery enabled using the setup provided /// </summary> /// <param name="setup">The setup to get conifg settings from</param> public ElastiCacheClusterConfig(ClusterConfigSettings setup) { if (setup == null) { try { setup = ConfigurationManager.GetSection("clusterclient") as ClusterConfigSettings; if (setup == null) { throw new ConfigurationErrorsException("Could not instantiate from app.config, setup was null"); } } catch (Exception ex) { throw new ConfigurationErrorsException("Could not instantiate from app.config\n" + ex.Message); } } if (setup.ClusterEndPoint == null) { throw new ArgumentException("Cluster Settings are null"); } if (String.IsNullOrEmpty(setup.ClusterEndPoint.HostName)) { throw new ArgumentNullException("hostname"); } if (setup.ClusterEndPoint.Port <= 0) { throw new ArgumentException("Port cannot be 0 or less"); } this.setup = setup; this.Servers = new List <IPEndPoint>(); this.Protocol = setup.Protocol; if (setup.KeyTransformer == null) { this.KeyTransformer = new DefaultKeyTransformer(); } else { this.KeyTransformer = setup.KeyTransformer.CreateInstance() ?? new DefaultKeyTransformer(); } this.SocketPool = (ISocketPoolConfiguration)setup.SocketPool ?? new SocketPoolConfiguration(); this.Authentication = (IAuthenticationConfiguration)setup.Authentication ?? new AuthenticationConfiguration(); this.nodeFactory = setup.NodeFactory ?? new DefaultConfigNodeFactory(); this.nodeLocator = setup.NodeLocator != null ? setup.NodeLocator.Type : typeof(DefaultNodeLocator); if (setup.Transcoder != null) { this.transcoder = setup.Transcoder.CreateInstance() ?? new DefaultTranscoder(); } if (setup.ClusterEndPoint.HostName.IndexOf(".cfg", StringComparison.OrdinalIgnoreCase) >= 0) { if (setup.ClusterNode != null) { var _tries = setup.ClusterNode.NodeTries > 0 ? setup.ClusterNode.NodeTries : DiscoveryNode.DEFAULT_TRY_COUNT; var _delay = setup.ClusterNode.NodeDelay >= 0 ? setup.ClusterNode.NodeDelay : DiscoveryNode.DEFAULT_TRY_DELAY; this.DiscoveryNode = new DiscoveryNode(this, setup.ClusterEndPoint.HostName, setup.ClusterEndPoint.Port, _tries, _delay); } else { this.DiscoveryNode = new DiscoveryNode(this, setup.ClusterEndPoint.HostName, setup.ClusterEndPoint.Port); } } else { throw new ArgumentException("The provided endpoint does not support auto discovery"); } }