public void Handle(JoinNetwork message) { _node.Log($"{message.TypeName()} From:{message.From}"); _commMgr.SendAck(message, message.CorrelationId); var routingCorrelation = GetNextCorrelation(); var successorCorrelation = GetNextCorrelation(); var joinNetworkReply = new JoinNetworkReply(_node.Identity, message.From, message.CorrelationId); var multiReplyHandler = _node.CreateAwaitAllResponsesHandler(); multiReplyHandler .PerformAction(() => { GetSuccessorTable(successorCorrelation, message.From); //GetRoutingTable(routingCorrelation, message.From, message.RoutingTable); }) .AndAwait(successorCorrelation, (GetSuccessorTableReply successorTableReply) => { _commMgr.SendAck(message, message.CorrelationId); joinNetworkReply.SuccessorTable = successorTableReply.SuccessorTable; }) //.AndAwait(routingCorrelation, (GetRoutingTableReply routingTableReply) => //{ // _commMgr.SendAck(message, message.CorrelationId); // joinNetworkReply.RoutingTable = routingTableReply.RoutingTable; //}) .ContinueWith(() => { _commMgr.Send(joinNetworkReply); }) .Run(message.CorrelationId); }
private void JoinToSeed(NodeInfo seedNodeInfo) { _node.Predecessor = _node.Identity; _node.FingerTable.Init(); var opId = _node.Config.CorrelationFactory.GetNextCorrelation(); var startTime = _node.Clock.Now; var responseHandler = _node.CreateAwaitAllResponsesHandler(); responseHandler .PerformAction(() => { var msg = new JoinNetwork(_node.Identity, seedNodeInfo, opId) { RoutingTable = _node.FingerTable.Entries, }; _node.Log($"Sending {msg.TypeName()} To {seedNodeInfo} Id:{opId}"); _commMgr.Send(msg); }) .AndAwait(opId, (JoinNetworkReply reply) => { _node.Log($"{reply.TypeName()} From {reply.From} Id:{reply.CorrelationId}"); _node.Log($"Join took {(_node.Clock.Now - startTime).Milliseconds} ms"); _node.Log($"Assigning successor {reply.SuccessorTable[0].SuccessorIdentity}"); _node.SuccessorTable.Copy(reply.SuccessorTable); //_node.FingerTable.Copy(reply.RoutingTable); // This node has "joined" but is not in an ideal state as it is not part of the ring network yet. }) .ContinueWith(() => { _commMgr.SendInternal(new InitStabilize()); }) .Run(opId); }