private void GetRoutingTable(CorrelationId operationId, NodeInfo applicantInfo, RoutingTableEntry[] routingTable) { var totalTimeout = routingTable.Length * _node.Config.AwaitSettings.NetworkQueryTimeout; var assembledReply = new GetRoutingTableReply(_node.Identity, applicantInfo, operationId) { RoutingTable = routingTable, }; var networkResults = routingTable.ToDictionary(x => x.StartValue); var queryIds = GetOperationIds(routingTable.Length); var identity = _node.Identity; var multiReplyHandler = _node.CreateAwaitAllResponsesHandler(); multiReplyHandler .PerformAction(() => { for (int i = 0; i < routingTable.Length; i++) { var entryQuery = new GetRoutingEntry(identity, identity, queryIds[i]) { StartValue = routingTable[i].StartValue, }; _commMgr.SendInternal(entryQuery); } }) .AndAwaitAll(queryIds, (GetRoutingEntryReply entryReply) => { networkResults[entryReply.Entry.StartValue] = entryReply.Entry; }) .ContinueWith(() => { var replyTable = assembledReply.RoutingTable; var tableLength = replyTable.Length; for (int i = 0; i < tableLength; ++i) { var startValue = replyTable[i].StartValue; replyTable[i] = networkResults[startValue]; } _commMgr.SendInternal(assembledReply); }) .Run(operationId, totalTimeout); }
public void Handle(GetRoutingEntry message) { _commMgr.SendAck(message, message.CorrelationId); if (_node.IsInDomain(message.StartValue)) { var reply = new GetRoutingEntryReply(_node.Identity, message.From, message.CorrelationId) { Entry = new RoutingTableEntry(message.StartValue, _node.Successor), }; _commMgr.SendInternal(reply); } else { var closestNode = _node.FingerTable.FindClosestPrecedingFinger(message.StartValue); message.To = closestNode; _commMgr.Send(message); } }