public override string ToString() { var options = new DictionaryOptions(); options.Add("RoomName", Name); options.Add("RoomIp", RoomIp); options.Add("RoomPort", RoomPort); options.Add("MaxConnections", MaxConnections <= 0 ? "Unlimited" : MaxConnections.ToString()); options.Add("Use Password", !string.IsNullOrEmpty(Password)); options.Add("AccessTimeoutPeriod", $"{AccessTimeoutPeriod} sec."); options.Add("AllowUsersRequestAccess", AllowUsersRequestAccess); options.Add("Region", string.IsNullOrEmpty(Region) ? "International" : Region); options.Append(CustomOptions); return(options.ToReadableString()); }
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(); } }