public List <ServerWithInfo <FaultTolerenceServer> > RegisterNewSlave(ServerInternalInfo serverInternalInfo) { ServerPuppet.Instance.Wait(); lock (Servers) { var newSlave = (FaultTolerenceServer)Activator.GetObject(typeof(FaultTolerenceServer), serverInternalInfo.Url + "/FTServer"); Servers.Add(new ServerWithInfo <FaultTolerenceServer>(newSlave, serverInternalInfo.Url, serverInternalInfo.IsMaster)); new Thread(() => { lock (Servers) { Servers.AsParallel().ForAll(slave => { try { if (!slave.IsMaster && !slave.URL.Equals(serverInternalInfo.Url)) { ServerPuppet.Instance.DoDelay(slave.URL); slave.Server.AddSlave(serverInternalInfo); } } catch (SocketException) { slave.IsDead = true; } } ); } }).Start(); return(Servers); } }
private void CheckLifeProof() { var diff = DateTime.Now.TimeOfDay.Subtract(lastProof).TotalMilliseconds; if (diff > lifeCheckDelay) { lifeCheckTimer.Enabled = false; var deadServer = Servers.Find(server => personalMaster.Equals(server.URL)); TryToKill(deadServer); LocalRemoveServer(deadServer.URL); new Thread(() => { lock (Servers) { Servers.AsParallel().ForAll(slave => { try { if (!slave.URL.Equals(myUrl)) { ServerPuppet.Instance.DoDelay(slave.URL); slave.Server.RemoveServer(deadServer.URL); } } catch (SocketException) { slave.IsDead = true; } } ); } }).Start(); } }
public void AddClient(ClientInfo client) { ServerPuppet.Instance.Wait(); if (IsMaster) { new Thread(() => { lock (Servers) { Servers.AsParallel().ForAll(slave => { try { if (!slave.IsMaster) { ServerPuppet.Instance.DoDelay(slave.URL); slave.Server.AddClient(client); } } catch (SocketException) { slave.IsDead = true; } } ); } }).Start(); } else { registerClient(client); } }