/// <summary> /// Gets the connection using the value of the <c>bootstrapUrl</c> in the App.Config as the node to bootstrap from. /// </summary> /// <returns></returns> public static ClientConfiguration GetConfiguration() { var config = new ClientConfiguration { Servers = new List <Uri> { new Uri(ConfigurationManager.AppSettings["bootstrapUrl"]) } }; config.ConnectionPoolCreator = ConnectionPoolFactory.GetFactory <ConnectionPool <MultiplexingConnection> >(); config.IOServiceCreator = IOServiceFactory.GetFactory <MultiplexingIOService>(); config.Initialize(); return(config); }
public ClientConfiguration() { //For operation timing Timer = TimingFactory.GetTimer(); QueryRequestTimeout = Defaults.QueryRequestTimeout; EnableQueryTiming = Defaults.EnableQueryTiming; UseSsl = Defaults.UseSsl; SslPort = (int)Defaults.SslPort; ApiPort = (int)Defaults.ApiPort; DirectPort = (int)Defaults.DirectPort; MgmtPort = (int)Defaults.MgmtPort; HttpsMgmtPort = (int)Defaults.HttpsMgmtPort; HttpsApiPort = (int)Defaults.HttpsApiPort; ObserveInterval = (int)Defaults.ObserveInterval; //ms ObserveTimeout = (int)Defaults.ObserveTimeout; //ms MaxViewRetries = (int)Defaults.MaxViewRetries; #pragma warning disable 618 ViewHardTimeout = (int)Defaults.ViewHardTimeout; //ms #pragma warning restore 618 HeartbeatConfigInterval = Defaults.HeartbeatConfigInterval; //ms EnableConfigHeartBeat = Defaults.EnableConfigHeartBeat; #pragma warning disable 618 SerializationSettings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }; DeserializationSettings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }; #pragma warning restore 618 ViewRequestTimeout = (int)Defaults.ViewRequestTimeout; //ms SearchRequestTimeout = Defaults.SearchRequestTimeout; VBucketRetrySleepTime = Defaults.VBucketRetrySleepTime; //service point settings DefaultConnectionLimit = Defaults.DefaultConnectionLimit; //connections Expect100Continue = Defaults.Expect100Continue; MaxServicePointIdleTime = (int)Defaults.MaxServicePointIdleTime; EnableOperationTiming = Defaults.EnableOperationTiming; BufferSize = (int)Defaults.BufferSize; DefaultOperationLifespan = Defaults.DefaultOperationLifespan;//ms EnableTcpKeepAlives = Defaults.EnableTcpKeepAlives; QueryFailedThreshold = (int)Defaults.QueryFailedThreshold; TcpKeepAliveTime = Defaults.TcpKeepAliveTime; TcpKeepAliveInterval = Defaults.TcpKeepAliveInterval; NodeAvailableCheckInterval = Defaults.NodeAvailableCheckInterval;//ms IOErrorCheckInterval = Defaults.IOErrorCheckInterval; IOErrorThreshold = Defaults.IOErrorThreshold; EnableDeadServiceUriPing = Defaults.EnableDeadServiceUriPing; //the default serializer Serializer = SerializerFactory.GetSerializer(); //the default byte converter Converter = ConverterFactory.GetConverter(); //the default transcoder Transcoder = TranscoderFactory.GetTranscoder(this); //the default ioservice IOServiceCreator = IOServiceFactory.GetFactory(this); //the default connection pool creator ConnectionPoolCreator = ConnectionPoolFactory.GetFactory(); //The default sasl mechanism creator CreateSaslMechanism = SaslFactory.GetFactory(); #if NETSTANDARD LoggerFactory = new LoggerFactory(); #endif 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> { Defaults.Server }; //Set back to default _operationLifespanChanged = false; _serversChanged = false; _poolConfigurationChanged = false; }
/// <summary> /// For synchronization with App.config or Web.configs. /// </summary> /// <param name="definition"></param> public ClientConfiguration(ICouchbaseClientDefinition definition) { Timer = TimingFactory.GetTimer(); UseConnectionPooling = definition.UseConnectionPooling; EnableDeadServiceUriPing = definition.EnableDeadServiceUriPing; NodeAvailableCheckInterval = definition.NodeAvailableCheckInterval; UseSsl = definition.UseSsl; SslPort = definition.SslPort; ApiPort = definition.ApiPort; DirectPort = definition.DirectPort; MgmtPort = definition.MgmtPort; HttpsMgmtPort = definition.HttpsMgmtPort; HttpsApiPort = definition.HttpsApiPort; ObserveInterval = definition.ObserveInterval; ObserveTimeout = definition.ObserveTimeout; MaxViewRetries = definition.MaxViewRetries; #pragma warning disable 618 ViewHardTimeout = definition.ViewHardTimeout; SerializationSettings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }; DeserializationSettings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }; #pragma warning restore 618 EnableConfigHeartBeat = definition.EnableConfigHeartBeat; HeartbeatConfigInterval = definition.HeartbeatConfigInterval; ViewRequestTimeout = definition.ViewRequestTimeout; Expect100Continue = definition.Expect100Continue; DefaultConnectionLimit = definition.DefaultConnectionLimit; MaxServicePointIdleTime = definition.MaxServicePointIdleTime; EnableOperationTiming = definition.EnableOperationTiming; DefaultOperationLifespan = definition.OperationLifespan; QueryFailedThreshold = definition.QueryFailedThreshold; QueryRequestTimeout = definition.QueryRequestTimeout; EnableQueryTiming = definition.EnableQueryTiming; SearchRequestTimeout = definition.SearchRequestTimeout; VBucketRetrySleepTime = definition.VBucketRetrySleepTime; IOErrorCheckInterval = definition.IOErrorCheckInterval; IOErrorThreshold = definition.IOErrorThreshold; //transcoders, converters, and serializers...o mai. Serializer = definition.Serializer != null ? SerializerFactory.GetSerializer(definition.Serializer) : SerializerFactory.GetSerializer(); Converter = definition.Converter != null ? ConverterFactory.GetConverter(definition.Converter) : ConverterFactory.GetConverter(); Transcoder = definition.Transcoder != null ? TranscoderFactory.GetTranscoder(this, definition.Transcoder) : TranscoderFactory.GetTranscoder(this); IOServiceCreator = definition.IOService != null ? IOServiceFactory.GetFactory(definition.IOService) : IOServiceFactory.GetFactory(this); #if NETSTANDARD //TODO not implemented for json configs...yet, so default LoggerFactory = new LoggerFactory(); #endif //to enable tcp keep-alives EnableTcpKeepAlives = definition.EnableTcpKeepAlives; TcpKeepAliveInterval = definition.TcpKeepAliveInterval; TcpKeepAliveTime = definition.TcpKeepAliveTime; var keepAlivesChanged = EnableTcpKeepAlives != true || TcpKeepAliveInterval != 1000 || TcpKeepAliveTime != 2 * 60 * 60 * 1000; //The default sasl mechanism creator CreateSaslMechanism = SaslFactory.GetFactory(); //NOTE: this is a global setting and applies to all instances IgnoreRemoteCertificateNameMismatch = definition.IgnoreRemoteCertificateNameMismatch; UseInterNetworkV6Addresses = definition.UseInterNetworkV6Addresses; List <Uri> servers; if (!string.IsNullOrEmpty(definition.ServerResolverType)) { servers = ServerResolverUtil.GetServers(definition.ServerResolverType); } else if (definition.Servers != null && definition.Servers.Any()) { servers = definition.Servers.ToList(); } else { servers = new List <Uri> { Defaults.Server }; } Servers = servers; _serversChanged = true; if (definition.ConnectionPool != null) { ConnectionPoolCreator = definition.ConnectionPool.Type != null ? ConnectionPoolFactory.GetFactory(definition.ConnectionPool.Type) : ConnectionPoolFactory.GetFactory(); PoolConfiguration = new PoolConfiguration { MaxSize = definition.ConnectionPool.MaxSize, MinSize = definition.ConnectionPool.MinSize, WaitTimeout = definition.ConnectionPool.WaitTimeout, ShutdownTimeout = definition.ConnectionPool.ShutdownTimeout, UseSsl = UseSsl ? UseSsl : definition.ConnectionPool.UseSsl, BufferSize = definition.ConnectionPool.BufferSize, BufferAllocator = (p) => new BufferAllocator(p.MaxSize * p.BufferSize, p.BufferSize), ConnectTimeout = definition.ConnectionPool.ConnectTimeout, SendTimeout = definition.ConnectionPool.SendTimeout, EnableTcpKeepAlives = keepAlivesChanged ? EnableTcpKeepAlives : definition.ConnectionPool.EnableTcpKeepAlives, TcpKeepAliveInterval = keepAlivesChanged ? TcpKeepAliveInterval : definition.ConnectionPool.TcpKeepAliveInterval, TcpKeepAliveTime = keepAlivesChanged ? TcpKeepAliveTime : definition.ConnectionPool.TcpKeepAliveTime, CloseAttemptInterval = definition.ConnectionPool.CloseAttemptInterval, MaxCloseAttempts = definition.ConnectionPool.MaxCloseAttempts, ClientConfiguration = this }; } else { ConnectionPoolCreator = ConnectionPoolFactory.GetFactory(); PoolConfiguration = new PoolConfiguration(this); } BucketConfigs = new Dictionary <string, BucketConfiguration>(); if (definition.Buckets != null) { foreach (var bucket in definition.Buckets) { 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 }; //By skipping the bucket specific connection pool settings we allow inheritance from clien-wide connection pool settings. if (bucket.ConnectionPool != null) { 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; bucketConfiguration.PoolConfiguration.UseSsl = bucketConfiguration.UseSsl; bucketConfiguration.PoolConfiguration.UseEnhancedDurability = bucketConfiguration.UseEnhancedDurability; } BucketConfigs.Add(bucket.Name, bucketConfiguration); } } //Set back to default _operationLifespanChanged = false; _poolConfigurationChanged = false; }
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 ioservice IOServiceCreator = IOServiceFactory.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 ioservice - this should be refactored to come from the configsection IOServiceCreator = IOServiceFactory.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; }