public ClientConfiguration() { //For operation timing Timer = TimingFactory.GetTimer(Log); QueryRequestTimeout = 75000; UseSsl = false; SslPort = 11207; ApiPort = 8092; DirectPort = 11210; MgmtPort = 8091; HttpsMgmtPort = 18091; HttpsApiPort = 18092; ObserveInterval = 10; //ms ObserveTimeout = 500; //ms MaxViewRetries = 2; ViewHardTimeout = 30000; //ms HeartbeatConfigInterval = 10000; //ms EnableConfigHeartBeat = true; SerializationSettings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }; DeserializationSettings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }; ViewRequestTimeout = 75000; //ms //service point settings DefaultConnectionLimit = 5; //connections Expect100Continue = false; MaxServicePointIdleTime = 100; EnableOperationTiming = false; BufferSize = 1024 * 16; DefaultOperationLifespan = 2500;//ms EnableTcpKeepAlives = true; QueryFailedThreshold = 2; TcpKeepAliveTime = 2 * 60 * 60 * 1000; TcpKeepAliveInterval = 1000; NodeAvailableCheckInterval = 1000;//ms IOErrorCheckInterval = 500; IOErrorThreshold = 10; //the default serializer Serializer = SerializerFactory.GetSerializer(); //the default byte converter Converter = ConverterFactory.GetConverter(); //the default transcoder Transcoder = TranscoderFactory.GetTranscoder(this); //the default iostrategy IOServiceCreator = IOStrategyFactory.GetFactory(); //the default connection pool creator ConnectionPoolCreator = ConnectionPoolFactory.GetFactory(); //The default sasl mechanism creator CreateSaslMechanism = SaslFactory.GetFactory(); PoolConfiguration = new PoolConfiguration(this) { BufferSize = BufferSize, BufferAllocator = (p) => new BufferAllocator(p.MaxSize * p.BufferSize, p.BufferSize) }; BucketConfigs = new Dictionary <string, BucketConfiguration> { { DefaultBucket, new BucketConfiguration { PoolConfiguration = PoolConfiguration, } } }; Servers = new List <Uri> { _defaultServer }; //Set back to default _operationLifespanChanged = false; _serversChanged = false; _poolConfigurationChanged = false; }
/// <summary> /// For synchronization with App.config or Web.configs. /// </summary> /// <param name="section"></param> public ClientConfiguration(CouchbaseClientSection section) { Timer = TimingFactory.GetTimer(Log); NodeAvailableCheckInterval = section.NodeAvailableCheckInterval; UseSsl = section.UseSsl; SslPort = section.SslPort; ApiPort = section.ApiPort; DirectPort = section.DirectPort; MgmtPort = section.MgmtPort; HttpsMgmtPort = section.HttpsMgmtPort; HttpsApiPort = section.HttpsApiPort; ObserveInterval = section.ObserveInterval; ObserveTimeout = section.ObserveTimeout; MaxViewRetries = section.MaxViewRetries; ViewHardTimeout = section.ViewHardTimeout; SerializationSettings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }; DeserializationSettings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }; EnableConfigHeartBeat = section.EnableConfigHeartBeat; HeartbeatConfigInterval = section.HeartbeatConfigInterval; ViewRequestTimeout = section.ViewRequestTimeout; Expect100Continue = section.Expect100Continue; DefaultConnectionLimit = section.DefaultConnectionLimit; MaxServicePointIdleTime = section.MaxServicePointIdleTime; EnableOperationTiming = section.EnableOperationTiming; DefaultOperationLifespan = section.OperationLifespan; QueryRequestTimeout = section.QueryRequestTimeout; IOErrorCheckInterval = section.IOErrorCheckInterval; IOErrorThreshold = section.IOErrorThreshold; //transcoders, converters, and serializers...o mai. Serializer = SerializerFactory.GetSerializer(this, section.Serializer); Converter = ConverterFactory.GetConverter(section.Converter); Transcoder = TranscoderFactory.GetTranscoder(this, section.Transcoder); //to enable tcp keep-alives EnableTcpKeepAlives = section.EnableTcpKeepAlives; TcpKeepAliveInterval = section.TcpKeepAliveInterval; TcpKeepAliveTime = section.TcpKeepAliveTime; var keepAlivesChanged = EnableTcpKeepAlives != true || TcpKeepAliveInterval != 1000 || TcpKeepAliveTime != 2 * 60 * 60 * 1000; //the default iostrategy - this should be refactored to come from the configsection IOServiceCreator = IOStrategyFactory.GetFactory(section.IOService); //the default connection pool creator ConnectionPoolCreator = ConnectionPoolFactory.GetFactory(section.ConnectionPool); //The default sasl mechanism creator CreateSaslMechanism = SaslFactory.GetFactory(); foreach (var server in section.Servers) { Servers.Add(((UriElement)server).Uri); _serversChanged = true; } PoolConfiguration = new PoolConfiguration { MaxSize = section.ConnectionPool.MaxSize, MinSize = section.ConnectionPool.MinSize, WaitTimeout = section.ConnectionPool.WaitTimeout, ShutdownTimeout = section.ConnectionPool.ShutdownTimeout, UseSsl = section.ConnectionPool.UseSsl, BufferSize = section.ConnectionPool.BufferSize, BufferAllocator = (p) => new BufferAllocator(p.MaxSize * p.BufferSize, p.BufferSize), ConnectTimeout = section.ConnectionPool.ConnectTimeout, SendTimeout = section.ConnectionPool.SendTimeout, EnableTcpKeepAlives = keepAlivesChanged ? EnableTcpKeepAlives : section.ConnectionPool.EnableTcpKeepAlives, TcpKeepAliveInterval = keepAlivesChanged ? TcpKeepAliveInterval : section.ConnectionPool.TcpKeepAliveInterval, TcpKeepAliveTime = keepAlivesChanged ? TcpKeepAliveTime : section.ConnectionPool.TcpKeepAliveTime, CloseAttemptInterval = section.ConnectionPool.CloseAttemptInterval, MaxCloseAttempts = section.ConnectionPool.MaxCloseAttempts, ClientConfiguration = this }; BucketConfigs = new Dictionary <string, BucketConfiguration>(); foreach (var bucketElement in section.Buckets) { var bucket = (BucketElement)bucketElement; var bucketConfiguration = new BucketConfiguration { BucketName = bucket.Name, UseSsl = bucket.UseSsl, Password = bucket.Password, ObserveInterval = bucket.ObserveInterval, DefaultOperationLifespan = bucket.OperationLifespan ?? (uint)DefaultOperationLifespan, ObserveTimeout = bucket.ObserveTimeout, UseEnhancedDurability = bucket.UseEnhancedDurability }; //Configuration properties (including elements) can not be null, but we can check if it was originally presnt in xml and skip it. //By skipping the bucket specific connection pool settings we allow inheritance from clien-wide connection pool settings. if (bucket.ConnectionPool.ElementInformation.IsPresent) { bucketConfiguration.PoolConfiguration = new PoolConfiguration { MaxSize = bucket.ConnectionPool.MaxSize, MinSize = bucket.ConnectionPool.MinSize, WaitTimeout = bucket.ConnectionPool.WaitTimeout, ShutdownTimeout = bucket.ConnectionPool.ShutdownTimeout, UseSsl = bucket.ConnectionPool.UseSsl, BufferSize = bucket.ConnectionPool.BufferSize, BufferAllocator = (p) => new BufferAllocator(p.MaxSize * p.BufferSize, p.BufferSize), ConnectTimeout = bucket.ConnectionPool.ConnectTimeout, SendTimeout = bucket.ConnectionPool.SendTimeout, EnableTcpKeepAlives = keepAlivesChanged ? EnableTcpKeepAlives : bucket.ConnectionPool.EnableTcpKeepAlives, TcpKeepAliveInterval = keepAlivesChanged ? TcpKeepAliveInterval : bucket.ConnectionPool.TcpKeepAliveInterval, TcpKeepAliveTime = keepAlivesChanged ? TcpKeepAliveTime : bucket.ConnectionPool.TcpKeepAliveTime, CloseAttemptInterval = bucket.ConnectionPool.CloseAttemptInterval, MaxCloseAttempts = bucket.ConnectionPool.MaxCloseAttempts, UseEnhancedDurability = bucket.UseEnhancedDurability, ClientConfiguration = this }; } else { bucketConfiguration.PoolConfiguration = PoolConfiguration; } BucketConfigs.Add(bucket.Name, bucketConfiguration); } //Set back to default _operationLifespanChanged = false; _poolConfigurationChanged = false; }