private static void MapActorToMessage(InternalRouteRegistration routeRegistration,
                                       Bcl.IDictionary <ReceiverIdentifier, Bcl.HashSet <MessageIdentifier> > actorMessages,
                                       MessageContract messageContract)
 {
     if (!actorMessages.TryGetValue(routeRegistration.ReceiverIdentifier, out var messages))
     {
         messages = new Bcl.HashSet <MessageIdentifier>();
         actorMessages[routeRegistration.ReceiverIdentifier] = messages;
     }
     messages.Add(messageContract.Message);
 }
 private void MapMessageToActor(InternalRouteRegistration routeRegistration, MessageContract messageContract)
 {
     if (!messageToActorMap.TryGetValue(messageContract.Message, out var actors))
     {
         actors = new HashedLinkedList <ReceiverIdentifier>();
         messageToActorMap[messageContract.Message] = actors;
     }
     if (!actors.Contains(routeRegistration.ReceiverIdentifier))
     {
         var registration = new ReceiverIdentifierRegistration(routeRegistration.ReceiverIdentifier,
                                                               messageContract.KeepRegistrationLocal);
         actors.InsertLast(registration);
     }
 }
Esempio n. 3
0
        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);
            }
        }
 private Bcl.IDictionary <ReceiverIdentifier, Bcl.HashSet <MessageIdentifier> > MapSocketToActor(InternalRouteRegistration routeRegistration)
 {
     if (!socketToActorMessagesMap.TryGetValue(routeRegistration.DestinationSocket, out var actorMessages))
     {
         actorMessages = new Bcl.Dictionary <ReceiverIdentifier, Bcl.HashSet <MessageIdentifier> >
         {
             [routeRegistration.ReceiverIdentifier] = new Bcl.HashSet <MessageIdentifier>()
         };
         socketToActorMessagesMap[routeRegistration.DestinationSocket] = actorMessages;
     }
     return(actorMessages);
 }