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; roundRobinList.Add(peerConnection.Node); } return(peerConnection); }
public void AddMessageRoute(InternalRouteRegistration routeRegistration) { var shouldAddSocket = false; if (routeRegistration.ReceiverIdentifier.IsMessageHub()) { var registration = new ReceiverIdentifierRegistration(routeRegistration.ReceiverIdentifier, routeRegistration.KeepRegistrationLocal); shouldAddSocket = !messageHubs.ContainsKey(registration); if (shouldAddSocket) { messageHubs.Add(registration, routeRegistration.DestinationSocket); } } else { if (routeRegistration.ReceiverIdentifier.IsActor()) { var actorMessages = MapSocketToActor(routeRegistration); foreach (var messageContract in routeRegistration.MessageContracts) { MapMessageToActor(routeRegistration, messageContract); MapActorToMessage(routeRegistration, actorMessages, messageContract); } shouldAddSocket = !actorToSocketMap.ContainsKey(routeRegistration.ReceiverIdentifier); if (shouldAddSocket) { actorToSocketMap[routeRegistration.ReceiverIdentifier] = routeRegistration.DestinationSocket; } } else { throw new ArgumentException($"Requested registration is for unknown Receiver type: [{routeRegistration.ReceiverIdentifier}]!"); } } if (shouldAddSocket) { roundRobinList.Add(routeRegistration.DestinationSocket); } }