private void EncodeDead(DeadMessage message, BinaryWriter writer) { writer.Write(message.Name); writer.Write(message.Incarnation); }
private void HandleDead(IPEndPoint remoteEndPoint, DeadMessage message) { TrackedGossipNode node; lock(_lock) { if (!_nodes.TryGetValue(message.Name, out node)) return; if (message.Incarnation < node.Incarnation) return; if (node.State == GossipNodeState.Dead) return; if (node.Name == _configuration.Name) { // we need to rebut this if we aren't leaving if (_leaveEvent == null) { int incarnation = GetNextIncarnationNumber(); while ((incarnation = GetNextIncarnationNumber()) <= message.Incarnation) ; var alive = new AliveMessage( _configuration.Name, _configuration.LocalEndPoint, _configuration.Metadata, incarnation); _messagePump.Broadcast(alive, null); node.Incarnation = incarnation; return; } } node.Incarnation = message.Incarnation; node.State = GossipNodeState.Dead; node.UpdatedAtUtc = DateTime.UtcNow; _nodes.Remove(node); } // leave event will not be null if we are leaving. // therefore, we will wait in the shutdown method // until this broadcast goes out. _messagePump.Broadcast(message, _leaveEvent); if(NodeLeft != null) { NodeLeft(node); } }