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
                        });
                    }
                }
            }
        }
示例#2
0
        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
            });
        }
        private Bcl.IEnumerable <MessageRoute> RemoveMessageHub(ILocalSendingSocket <IMessage> receivingSocket)
        {
            // Should not be many, we can iterate the collection
            var messageHub = messageHubs.Where(kv => kv.Value.Equals(receivingSocket))
                             .Select(kv => kv.Key)
                             .FirstOrDefault();

            if (messageHub != null)
            {
                messageHubs.Remove(messageHub);

                yield return(new MessageRoute {
                    Receiver = messageHub
                });
            }
        }