Beispiel #1
0
        public void Initialize()
        {
            // check to see if already initialized
            if (_initialized &&
                _buckets != null &&
                _availPool != null &&
                _busyPool != null)
            {
                if (Log.IsErrorEnabled)
                {
                    Log.Error(GetLocalizedString("initializing initialized pool"));
                }
                return;
            }

            // initialize empty maps
            _buckets          = new ArrayList();
            _availPool        = new Hashtable(_servers.Count * _initConns);
            _busyPool         = new Hashtable(_servers.Count * _initConns);
            _hostDeadDuration = new Hashtable();
            _hostDead         = new Hashtable();
            _createShift      = new Hashtable();
            _maxCreate        = (_poolMultiplier > _minConns) ? _minConns : _minConns / _poolMultiplier;                // only create up to maxCreate connections at once

            if (Log.IsDebugEnabled)
            {
                Log.Debug(GetLocalizedString("initializing pool")
                          .Replace("$$InitConnections$$", InitConnections.ToString(new NumberFormatInfo()))
                          .Replace("$$MinConnections$$", MinConnections.ToString(new NumberFormatInfo()))
                          .Replace("$$MaxConnections$$", MaxConnections.ToString(new NumberFormatInfo())));
            }

            // if servers is not set, or it empty, then
            // throw a runtime exception
            if (_servers == null || _servers.Count <= 0)
            {
                if (Log.IsErrorEnabled)
                {
                    Log.Error(GetLocalizedString("initialize with no servers"));
                }
                throw new ArgumentException(GetLocalizedString("initialize with no servers"));
            }

            for (int i = 0; i < _servers.Count; i++)
            {
                // add to bucket
                // with weights if we have them
                if (_weights != null && _weights.Count > i)
                {
                    for (int k = 0; k < ((int)_weights[i]); k++)
                    {
                        _buckets.Add(_servers[i]);
                        if (Log.IsDebugEnabled)
                        {
                            Log.Debug("Added " + _servers[i] + " to server bucket");
                        }
                    }
                }
                else
                {
                    _buckets.Add(_servers[i]);
                    if (Log.IsDebugEnabled)
                    {
                        Log.Debug("Added " + _servers[i] + " to server bucket");
                    }
                }

                // create initial connections
                if (Log.IsDebugEnabled)
                {
                    Log.Debug(GetLocalizedString("create initial connections").Replace("$$InitConns$$", InitConnections.ToString(new NumberFormatInfo())).Replace("$$Servers[i]$$", Servers[i].ToString()));
                }

                for (int j = 0; j < _initConns; j++)
                {
                    SockIO socket = CreateSocket((string)_servers[i]);
                    if (socket == null)
                    {
                        if (Log.IsErrorEnabled)
                        {
                            Log.Error(GetLocalizedString("failed to connect").Replace("$$Servers[i]$$", Servers[i].ToString()).Replace("$$j$$", j.ToString(new NumberFormatInfo())));
                        }
                        break;
                    }

                    AddSocketToPool(_availPool, (string)_servers[i], socket);
                    if (Log.IsDebugEnabled)
                    {
                        Log.Debug(GetLocalizedString("created and added socket").Replace("$$ToString$$", socket.ToString()).Replace("$$Servers[i]$$", Servers[i].ToString()));
                    }
                }
            }

            // mark pool as initialized
            _initialized = true;

            // start maint thread TODO: re-enable
            if (_maintThreadSleep > 0)
            {
                this.StartMaintenanceThread();
            }
        }
Beispiel #2
0
        public override int GetHashCode()
        {
            int hash = 1;

            hash ^= additionalMetricDims_.GetHashCode();
            if (AggregationEnabled != false)
            {
                hash ^= AggregationEnabled.GetHashCode();
            }
            if (AggregationMaxCount != 0UL)
            {
                hash ^= AggregationMaxCount.GetHashCode();
            }
            if (AggregationMaxSize != 0UL)
            {
                hash ^= AggregationMaxSize.GetHashCode();
            }
            if (CloudwatchEndpoint.Length != 0)
            {
                hash ^= CloudwatchEndpoint.GetHashCode();
            }
            if (CloudwatchPort != 0UL)
            {
                hash ^= CloudwatchPort.GetHashCode();
            }
            if (CollectionMaxCount != 0UL)
            {
                hash ^= CollectionMaxCount.GetHashCode();
            }
            if (CollectionMaxSize != 0UL)
            {
                hash ^= CollectionMaxSize.GetHashCode();
            }
            if (ConnectTimeout != 0UL)
            {
                hash ^= ConnectTimeout.GetHashCode();
            }
            if (EnableCoreDumps != false)
            {
                hash ^= EnableCoreDumps.GetHashCode();
            }
            if (FailIfThrottled != false)
            {
                hash ^= FailIfThrottled.GetHashCode();
            }
            if (KinesisEndpoint.Length != 0)
            {
                hash ^= KinesisEndpoint.GetHashCode();
            }
            if (KinesisPort != 0UL)
            {
                hash ^= KinesisPort.GetHashCode();
            }
            if (LogLevel.Length != 0)
            {
                hash ^= LogLevel.GetHashCode();
            }
            if (MaxConnections != 0UL)
            {
                hash ^= MaxConnections.GetHashCode();
            }
            if (MetricsGranularity.Length != 0)
            {
                hash ^= MetricsGranularity.GetHashCode();
            }
            if (MetricsLevel.Length != 0)
            {
                hash ^= MetricsLevel.GetHashCode();
            }
            if (MetricsNamespace.Length != 0)
            {
                hash ^= MetricsNamespace.GetHashCode();
            }
            if (MetricsUploadDelay != 0UL)
            {
                hash ^= MetricsUploadDelay.GetHashCode();
            }
            if (MinConnections != 0UL)
            {
                hash ^= MinConnections.GetHashCode();
            }
            if (RateLimit != 0UL)
            {
                hash ^= RateLimit.GetHashCode();
            }
            if (RecordMaxBufferedTime != 0UL)
            {
                hash ^= RecordMaxBufferedTime.GetHashCode();
            }
            if (RecordTtl != 0UL)
            {
                hash ^= RecordTtl.GetHashCode();
            }
            if (Region.Length != 0)
            {
                hash ^= Region.GetHashCode();
            }
            if (RequestTimeout != 0UL)
            {
                hash ^= RequestTimeout.GetHashCode();
            }
            if (VerifyCertificate != false)
            {
                hash ^= VerifyCertificate.GetHashCode();
            }
            return(hash);
        }