public NetworkInformationReply NetworkInfo(NetworkInformationRequest request) { Console.WriteLine("Received NetworkInfo"); foreach (var serverUrl in request.ServerUrls) { if (!ServerUrls.ContainsKey(serverUrl.Key)) { ServerUrls[serverUrl.Key] = serverUrl.Value; } } foreach (var partition in request.ServerIdsByPartition) { if (!ServersIdByPartition.ContainsKey(partition.Key)) { if (!ServersIdByPartition.TryAdd(partition.Key, partition.Value.ServerIds.ToList())) { throw new RpcException(new Status(StatusCode.Unknown, "Could not add element")); } } } lock (ContinueExecution.WaitForInformationLock) { ContinueExecution.Value = true; Monitor.PulseAll(ContinueExecution.WaitForInformationLock); } return(new NetworkInformationReply()); }
private void SendInformationToClient(List <Partition> partitions) { Dictionary <string, string> serverUrls = new Dictionary <string, string>(); var request = new NetworkInformationRequest(); foreach (var partition in partitions) { partition.WaitForReady(); request.ServerIdsByPartition.Add(partition.Id, new PartitionServers { ServerIds = { partition.ServerIds } }); foreach (var serverId in partition.ServerIds) { if (!serverUrls.ContainsKey(serverId)) { serverUrls.Add(serverId, Servers[serverId].Url); } } } foreach (var serverUrl in serverUrls) { request.ServerUrls.Add(serverUrl.Key, serverUrl.Value); } Grpc.NetworkInformation(request); }
public override Task <NetworkInformationReply> NetworkInformation(NetworkInformationRequest request, ServerCallContext context) { return(Task.FromResult(NetworkInfo(request))); }