private void ReloadStatisticsAndChooseAServer(object obj) { Logging.Debug("Reloading statistics and choose a new server...."); var servers = _controller.GetCurrentConfiguration().configs; LoadStatistics(); ChooseNewServer(servers); }
private void GetCurrServerInfo(out int currIndex, out int serverCount) { var currConfig = _controller.GetCurrentConfiguration(); currIndex = currConfig.index; serverCount = currConfig.configs.Count; }
public void ReloadServers() { // make a copy to avoid locking var newServerStatus = new Dictionary <Server, ServerStatus>(_serverStatus); foreach (var server in _controller.GetCurrentConfiguration().configs) { if (!newServerStatus.ContainsKey(server)) { var status = new ServerStatus(); status.server = server; status.lastFailure = DateTime.MinValue; status.lastRead = DateTime.Now; status.lastWrite = DateTime.Now; status.latency = new TimeSpan(0, 0, 0, 0, 10); status.lastTimeDetectLatency = DateTime.Now; newServerStatus[server] = status; } else { // update settings for existing server newServerStatus[server].server = server; } } _serverStatus = newServerStatus; ChooseNewServer(); }
public StatisticsStrategy(PhotonController controller) { _controller = controller; var servers = controller.GetCurrentConfiguration().configs; var randomIndex = new Random().Next() % servers.Count; _currentServer = servers[randomIndex]; //choose a server randomly at first _timer = new Timer(ReloadStatisticsAndChooseAServer); }
private void LoadConfiguration() { var configs = _controller.GetCurrentConfiguration().configs; _servers = configs.Select(server => server.Identifier()).ToList(); _configuration = _controller.StatisticsConfiguration ?? new StatisticsStrategyConfiguration(); if (_configuration.Calculations == null) { _configuration = new StatisticsStrategyConfiguration(); } }
public Server GetAServer(IStrategyCallerType type, IPEndPoint localIPEndPoint, EndPoint destEndPoint) { var configs = _controller.GetCurrentConfiguration().configs; int index; if (type == IStrategyCallerType.TCP) { index = _random.Next(); } else { index = localIPEndPoint.GetHashCode(); } return(configs[index % configs.Count]); }