private void MapActorToNode(ExternalRouteRegistration routeRegistration, ReceiverIdentifier nodeIdentifier)
 {
     if (!nodeActors.TryGetValue(nodeIdentifier, out var actors))
     {
         actors = new Bcl.HashSet <ReceiverIdentifier>();
         nodeActors[nodeIdentifier] = actors;
     }
     actors.Add(routeRegistration.Route.Receiver);
 }
 private void MapActorToMessage(ExternalRouteRegistration routeRegistration)
 {
     if (!actorToMessageMap.TryGetValue(routeRegistration.Route.Receiver, out var actorMessages))
     {
         actorMessages = new Bcl.HashSet <MessageIdentifier>();
         actorToMessageMap[routeRegistration.Route.Receiver] = actorMessages;
     }
     actorMessages.Add(routeRegistration.Route.Message);
 }
        private void MapMessageHubToNode(ExternalRouteRegistration routeRegistration, ReceiverIdentifier nodeIdentifier)
        {
            var messageHub = routeRegistration.Route.Receiver;

            if (!nodeMessageHubs.TryGetValue(nodeIdentifier, out var messageHubs))
            {
                messageHubs = new Bcl.HashSet <ReceiverIdentifier>();
                nodeMessageHubs[nodeIdentifier] = messageHubs;
            }
            messageHubs.Add(messageHub);
        }
 private PeerConnection MapNodeToConnection(ExternalRouteRegistration routeRegistration, ReceiverIdentifier nodeIdentifier)
 {
     if (!nodeToConnectionMap.TryGetValue(nodeIdentifier, out var peerConnection))
     {
         peerConnection = new PeerConnection
         {
             Node      = routeRegistration.Peer,
             Health    = routeRegistration.Health,
             Connected = false
         };
         nodeToConnectionMap[nodeIdentifier] = peerConnection;
     }
     return(peerConnection);
 }
        private void MapMessageToNode(ExternalRouteRegistration routeRegistration, ReceiverIdentifier nodeIdentifier)
        {
            var messageIdentifier = routeRegistration.Route.Message;

            if (!messageToNodeMap.TryGetValue(messageIdentifier, out var nodes))
            {
                nodes = new HashedLinkedList <ReceiverIdentifier>();
                messageToNodeMap[messageIdentifier] = nodes;
            }
            if (!nodes.Contains(nodeIdentifier))
            {
                nodes.InsertLast(nodeIdentifier);
            }
        }
Exemple #6
0
        public PeerConnection AddMessageRoute(ExternalRouteRegistration routeRegistration)
        {
            var nodeIdentifier = new ReceiverIdentifier(routeRegistration.Peer.SocketIdentity);

            if (routeRegistration.Route.Receiver.IsActor())
            {
                MapMessageToNode(routeRegistration, nodeIdentifier);
                MapActorToMessage(routeRegistration);
                MapActorToNode(routeRegistration, nodeIdentifier);

                logger.Debug("External route added "
                             + $"Uri:{routeRegistration.Peer.Uri.AbsoluteUri} "
                             + $"Node:{nodeIdentifier} "
                             + $"Actor:{routeRegistration.Route.Receiver}"
                             + $"Message:{routeRegistration.Route.Message}");
            }
            else
            {
                if (routeRegistration.Route.Receiver.IsMessageHub())
                {
                    MapMessageHubToNode(routeRegistration, nodeIdentifier);

                    logger.Debug("External route added "
                                 + $"Uri:{routeRegistration.Peer.Uri.AbsoluteUri} "
                                 + $"Node:{nodeIdentifier} "
                                 + $"MessageHub:{routeRegistration.Route.Receiver}");
                }
                else
                {
                    throw new ArgumentException($"Requested registration is for unknown Receiver type: [{routeRegistration.Route.Receiver}]!");
                }
            }

            var connection = MapNodeToConnection(routeRegistration, nodeIdentifier);

            MapConnectionToNode(connection);

            return(connection);
        }