public void OnStatusCommand(StatusCommand command) { CreatePartitionsIfRequired(); ImmutableList <string> serverUrls = nameServiceDB.ListServers(); ImmutableList <string> clientUrls = nameServiceDB.ListClients(); serverUrls.ForEach(url => { ServerConfigurationConnection connection = new ServerConfigurationConnection(url); connection.StatusAsync().ContinueWith(antecedent => { if (antecedent.Result) { Console.WriteLine("Status sent to server {0}", url); } }); }); clientUrls.ForEach(url => { ClientConfigurationConnection connection = new ClientConfigurationConnection(url); connection.StatusAsync().ContinueWith(antecedent => { if (antecedent.Result) { Console.WriteLine("Status sent to client {0}", url); } }); }); }
private void CreatePartitionsIfRequired() { if (partitionsCreated) { return; } List <Task> joinPartitionTasks = new List <Task>(); foreach ((string partitionId, string[] serverIds) in partitions) { // Lookup servers urls IEnumerable <Tuple <string, string> > servers = serverIds.Select(id => { nameServiceDB.TryLookupServer(id, out string url); return(new Tuple <string, string>(id, url)); }); // Check if all servers already existed if (!servers.All(server => server.Item2 != null)) { Console.WriteLine("Unknown server ids"); return; } // Send to all servers, even those not in the partition // so that everyone knowns the state of the system foreach (string url in nameServiceDB.ListServers()) { ServerConfigurationConnection connection = new ServerConfigurationConnection(url); joinPartitionTasks.Add( connection.JoinPartitionAsync(partitionId, servers, serverIds[0])); } } Task.WaitAll(joinPartitionTasks.ToArray()); Console.WriteLine( "[{0}] Partitions created", DateTime.Now.ToString("HH:mm:ss")); partitionsCreated = true; }
public void OnCrashServerCommand(CrashServerCommand command) { CreatePartitionsIfRequired(); // Check if server exists if (!nameServiceDB.TryLookupServer(command.ServerId, out string url)) { Console.Error.WriteLine("Server with id {0} doesn't exist", command.ServerId); return; } ServerConfigurationConnection connection = new ServerConfigurationConnection(url); connection.CrashAsync().ContinueWith((antecedent) => { Console.WriteLine( "[{0}] Server with id {1} crashed", DateTime.Now.ToString("HH:mm:ss"), command.ServerId); }); }