private PeerConnectionAction RemovePeerNode(PeerConnection connection) { var uri = connection.Node.Uri.ToSocketAddress(); if (uriToNodeMap.TryGetValue(uri, out var nodes)) { if (nodes.Remove(new ReceiverIdentifier(connection.Node.SocketIdentity))) { if (!nodes.Any()) { uriToNodeMap.Remove(uri); logger.Debug($"Zero nodes left registered at {uri}. Endpoint will be disconnected."); return(PeerConnectionAction.Disconnect); } logger.Debug($"[{nodes.Count}] node(s) left at {uri}."); return(PeerConnectionAction.KeepConnection); } } return(PeerConnectionAction.NotFound); }
private Bcl.IEnumerable <MessageRoute> RemoveActors(ILocalSendingSocket <IMessage> receivingSocket) { if (socketToActorMessagesMap.TryGetValue(receivingSocket, out var actorMessages)) { socketToActorMessagesMap.Remove(receivingSocket); foreach (var actor in actorMessages.Keys) { actorToSocketMap.Remove(actor); foreach (var message in actorMessages[actor]) { if (messageToActorMap.TryGetValue(message, out var messageHandlers)) { messageHandlers.Remove(actor); if (!messageHandlers.Any()) { messageToActorMap.Remove(message); } } yield return(new MessageRoute { Message = message, Receiver = actor }); } } } }
public PeerRemoveResult RemoveNodeRoute(ReceiverIdentifier nodeIdentifier) { var peerConnectionAction = PeerConnectionAction.NotFound; if (nodeToConnectionMap.TryGetValue(nodeIdentifier, out var connection)) { nodeToConnectionMap.Remove(nodeIdentifier); peerConnectionAction = RemovePeerNode(connection); roundRobinList.Remove(connection.Node); nodeMessageHubs.Remove(nodeIdentifier); if (nodeActors.TryGetValue(nodeIdentifier, out var actors)) { nodeActors.Remove(nodeIdentifier); foreach (var actor in actors) { if (actorToMessageMap.TryGetValue(actor, out var messages)) { actorToMessageMap.Remove(actor); foreach (var message in messages) { if (messageToNodeMap.TryGetValue(message, out var nodes)) { nodes.Remove(nodeIdentifier); if (!nodes.Any()) { messageToNodeMap.Remove(message); } } } } } } logger.Debug($"External route removed Uri:{connection.Node.Uri.AbsoluteUri} " + $"Node:{nodeIdentifier.Identity.GetAnyString()}"); } return(new PeerRemoveResult { Uri = connection?.Node.Uri, ConnectionAction = peerConnectionAction }); }