Ejemplo n.º 1
0
 private void RemoveMessageToNodeMap(ExternalRouteRemoval routeRemoval, ReceiverIdentifier receiverNode)
 {
     if (messageToNodeMap.TryGetValue(routeRemoval.Route.Message, out var nodes))
     {
         nodes.Remove(receiverNode);
         if (!nodes.Any())
         {
             messageToNodeMap.Remove(routeRemoval.Route.Message);
         }
     }
 }
Ejemplo n.º 2
0
 private void RemoveNodeActor(ExternalRouteRemoval routeRemoval, ReceiverIdentifier nodeIdentifier)
 {
     if (nodeActors.TryGetValue(nodeIdentifier, out var actors))
     {
         if (actors.Remove(routeRemoval.Route.Receiver))
         {
             if (!actors.Any())
             {
                 nodeActors.Remove(nodeIdentifier);
             }
             RemoveMessageToNodeMap(routeRemoval, nodeIdentifier);
         }
     }
 }
Ejemplo n.º 3
0
        private void RemoveActorRoute(ExternalRouteRemoval routeRemoval)
        {
            var nodeIdentifier = new ReceiverIdentifier(routeRemoval.NodeIdentifier);

            if (actorToMessageMap.TryGetValue(routeRemoval.Route.Receiver, out var messages))
            {
                messages.Remove(routeRemoval.Route.Message);
                if (!messages.Any())
                {
                    actorToMessageMap.Remove(routeRemoval.Route.Receiver);
                    RemoveNodeActor(routeRemoval, nodeIdentifier);
                }
                logger.Debug("External message route removed " +
                             $"Node:[{nodeIdentifier}] " +
                             $"Message:[{routeRemoval.Route.Message}]");
            }
        }
Ejemplo n.º 4
0
        private void RemoveMessageHubRoute(ExternalRouteRemoval routeRemoval)
        {
            var nodeIdentifier = new ReceiverIdentifier(routeRemoval.NodeIdentifier);

            if (nodeMessageHubs.TryGetValue(nodeIdentifier, out var messageHubs))
            {
                if (messageHubs.Remove(routeRemoval.Route.Receiver))
                {
                    if (!messageHubs.Any())
                    {
                        nodeMessageHubs.Remove(nodeIdentifier);
                    }
                    logger.Debug("External MessageHub removed " +
                                 $"Node:[{nodeIdentifier}] " +
                                 $"Identity:[{routeRemoval.Route.Receiver}]");
                }
            }
        }
Ejemplo n.º 5
0
        private void RemoveActorsByMessage(ExternalRouteRemoval routeRemoval, ReceiverIdentifier nodeIdentifier)
        {
            if (messageToNodeMap.TryGetValue(routeRemoval.Route.Message, out var nodes))
            {
                if (nodes.Remove(nodeIdentifier))
                {
                    if (!nodes.Any())
                    {
                        messageToNodeMap.Remove(routeRemoval.Route.Message);
                    }

                    var emptyActors = new Bcl.List <ReceiverIdentifier>();
                    if (nodeActors.TryGetValue(nodeIdentifier, out var actors))
                    {
                        foreach (var actor in actors)
                        {
                            if (actorToMessageMap.TryGetValue(actor, out var messages))
                            {
                                if (messages.Remove(routeRemoval.Route.Message))
                                {
                                    if (!messages.Any())
                                    {
                                        actorToMessageMap.Remove(actor);
                                        emptyActors.Add(actor);
                                    }
                                }
                            }
                        }

                        foreach (var emptyActor in emptyActors)
                        {
                            actors.Remove(emptyActor);
                        }

                        if (!actors.Any())
                        {
                            nodeActors.Remove(nodeIdentifier);
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public PeerRemoveResult RemoveMessageRoute(ExternalRouteRemoval routeRemoval)
        {
            var connectionAction = PeerConnectionAction.NotFound;

            var nodeIdentifier = new ReceiverIdentifier(routeRemoval.NodeIdentifier);

            if (nodeToConnectionMap.TryGetValue(nodeIdentifier, out var connection))
            {
                connectionAction = PeerConnectionAction.KeepConnection;

                if (routeRemoval.Route.Receiver.IsMessageHub())
                {
                    RemoveMessageHubRoute(routeRemoval);
                }
                else
                {
                    if (routeRemoval.Route.Receiver.IsActor())
                    {
                        RemoveActorRoute(routeRemoval);
                    }
                    else
                    {
                        RemoveActorsByMessage(routeRemoval, nodeIdentifier);
                    }
                }

                if (!nodeActors.ContainsKey(nodeIdentifier) && !nodeMessageHubs.ContainsKey(nodeIdentifier))
                {
                    nodeToConnectionMap.Remove(nodeIdentifier);
                    connectionAction = RemovePeerNode(connection);
                    roundRobinList.Remove(connection.Node);

                    logger.Debug($"External route removed Uri:{connection?.Node.Uri.AbsoluteUri} Node:{nodeIdentifier}");
                }
            }

            return(new PeerRemoveResult
            {
                ConnectionAction = connectionAction,
                Uri = connection?.Node.Uri
            });
        }