private void init() { NameValueCollection appSettings = WebConfigurationManager.GetSection("appSettings") as NameValueCollection; _log = Logger.GetLogger(); String servers = appSettings["resin.servers"]; if ("".Equals(servers)) { servers = "127.0.0.1:6080"; _log.Info("application setting 'resin.servers' is not specified. Using '{0}'", servers); Trace.TraceInformation("application setting 'resin.servers' is not specified. Using '{0}'", servers); } else { _log.Info("Setting servers to '{0}'", servers); Trace.TraceInformation("Setting servers to '{0}'", servers); } _loadBalancer = new LoadBalancer(servers); }
//supports just one server for now public LoadBalancer(String servers, int loadBalanceConnectTimeout, int loadBalanceIdleTime, int loadBalanceRecoverTime, int loadBalanceSocketTimeout, int keepaliveTimeout, int socketTimeout, bool isDebug) { _log = Logger.GetLogger(); _loadBalanceConnectTimeout = loadBalanceConnectTimeout; _loadBalanceIdleTime = loadBalanceIdleTime; _loadBalanceRecoverTime = loadBalanceRecoverTime; _loadBalanceSocketTimeout = loadBalanceSocketTimeout; _keepaliveTimeout = keepaliveTimeout; _socketTimeout = socketTimeout; _isDebug = isDebug; List<Server> pool = new List<Server>(); String[] sruns = servers.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < sruns.Length; i++) { String server = sruns[i]; int portIdx = server.LastIndexOf(':'); String host = server.Substring(0, portIdx); IPAddress address = GetIPsForHost(host); int port = int.Parse(server.Substring(portIdx + 1, server.Length - portIdx - 1)); char c = (char)('a' + i); _log.Info("Adding Server '{0}:{1}:{2}'", c, host, port); Server srun = new Server(c, address, port, _loadBalanceConnectTimeout, _loadBalanceIdleTime, _loadBalanceRecoverTime, _socketTimeout); srun.SetDebug(_isDebug); pool.Add(srun); } _servers = pool.ToArray(); _random = new Random(); }
private void init() { try { NameValueCollection appSettings = WebConfigurationManager.GetSection("appSettings") as NameValueCollection; _log = Logger.GetLogger(); String servers = appSettings["resin.servers"]; if ("".Equals(servers)) { servers = "127.0.0.1:6800"; _log.Info("application setting 'resin.servers' is not specified. Using '{0}'", servers); Trace.TraceInformation("application setting 'resin.servers' is not specified. Using '{0}'", servers); } else { _log.Info("Setting servers to '{0}'", servers); Trace.TraceInformation("Setting servers to '{0}'", servers); } if (!String.IsNullOrEmpty(appSettings["resin.session-cookie"])) _sessionCookieName = appSettings["resin.session-cookie"]; if (!String.IsNullOrEmpty(appSettings["resin.ssl-session-cookie"])) _sslSessionCookieName = appSettings["resin.ssl-session-cookie"]; if ("false".Equals(appSettings["resin.sticky-sessions"], StringComparison.OrdinalIgnoreCase)) _isStickySessions = false; _log.Info("Setting sticky sessions to {0}", _isStickySessions); if (!String.IsNullOrEmpty(appSettings["resin.session-url-prefix"])) _sessionUrlPrefix = appSettings["resin.session-url-prefix"]; if (!String.IsNullOrEmpty(appSettings["resin.alternate-session-url-prefix"])) _sessionUrlPrefix = appSettings["resin.alternate-session-url-prefix"]; int loadBalanceConnectTimeout = 5 * 1000; if (!String.IsNullOrEmpty(appSettings["resin.load-balance-connect-timeout"])) loadBalanceConnectTimeout = ParseTime("resin.load-balance-connect-timeout", appSettings["resin.load-balance-connect-timeout"]); int loadBalanceIdleTime = 5 * 1000; if (!String.IsNullOrEmpty(appSettings["resin.load-balance-idle-time"])) loadBalanceIdleTime = ParseTime("resin.load-balance-idle-time", appSettings["resin.load-balance-idle-time"]); int loadBalanceRecoverTime = 15 * 1000; if (!String.IsNullOrEmpty(appSettings["resin.load-balance-recover-time"])) loadBalanceRecoverTime = ParseTime("resin.load-balance-recover-time", appSettings["resin.load-balance-recover-time"]); int loadBalanceSocketTimeout = 665 * 1000; if (!String.IsNullOrEmpty(appSettings["resin.load-balance-socket-timeout"])) loadBalanceSocketTimeout = ParseTime("resin.load-balance-socket-timeout", appSettings["resin.load-balance-socket-timeout"]); int keepaliveTimeout = 15 * 1000; if (!String.IsNullOrEmpty(appSettings["resin.keepalive-timeout"])) keepaliveTimeout = ParseTime("resin.keepalive-timeout", appSettings["resin.keepalive-timeout"]); int socketTimeout = 65 * 1000; if (!String.IsNullOrEmpty(appSettings["resin.socket-timeout"])) socketTimeout = ParseTime("resin.socket-timeout", appSettings["resin.socket-timeout"]); _isDebug = "true".Equals(appSettings["resin.debug"], StringComparison.OrdinalIgnoreCase); if (_isDebug) Trace.TraceInformation("Setting debug to true"); _isCauchoStatusEnabled = !"false".Equals(appSettings["resin.caucho-status"], StringComparison.OrdinalIgnoreCase); _loadBalancer = new LoadBalancer(servers, loadBalanceConnectTimeout, loadBalanceIdleTime, loadBalanceRecoverTime, loadBalanceSocketTimeout, keepaliveTimeout, socketTimeout, _isDebug); } catch (ConfigurationException e) { _e = e; } catch (FormatException e) { _e = new ConfigurationException(e.Message, e); } }